You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2012/12/13 08:30:03 UTC
[28/58] [partial] ISIS-188: renaming packages in line with
groupId:artifactId
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java
deleted file mode 100644
index 3de31df..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-
-import java.util.ArrayList;
-
-import org.jmock.Expectations;
-import org.jmock.auto.Mock;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
-import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
-import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateWriter;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
-import org.apache.isis.tck.dom.refs.ParentEntity;
-import org.apache.isis.tck.dom.refs.ReferencingEntity;
-import org.apache.isis.tck.dom.refs.SimpleEntity;
-
-public class WriteObjectCommandTest {
-
- @Rule
- public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
-
- @Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
-
- @Mock
- private StateWriter writer;
- @Mock
- private VersionCreator versionCreator;
-
- @Mock
- private NoSqlCommandContext commandContext;
-
- private DataEncryption dataEncrypter;
-
- private ObjectAdapter smpl1Adapter;
- private ObjectAdapter rfcg1Adapter;
- private ObjectAdapter prnt1Adapter;
-
- private SimpleEntity smpl1;
- private SimpleEntity smpl2;
-
- private ReferencingEntity rfcg1;
-
- private ParentEntity prnt1;
-
- @Before
- public void setup() {
-
- smpl1 = iswf.fixtures.smpl1;
- smpl1.setName("Fred Smith");
- smpl1.setSize(108);
- smpl1Adapter = iswf.remapAsPersistent(smpl1, RootOidDefault.deString("SMPL:1", new OidMarshaller()));
-
- smpl2 = iswf.fixtures.smpl2;
- smpl2.setName("John Brown");
- iswf.remapAsPersistent(smpl2, RootOidDefault.deString("SMPL:2", new OidMarshaller()));
-
- rfcg1 = iswf.fixtures.rfcg1;
- rfcg1.setReference(smpl1);
- rfcg1Adapter = iswf.remapAsPersistent(rfcg1, RootOidDefault.deString("RFCG:1", new OidMarshaller()));
-
- prnt1 = iswf.fixtures.prnt1;
- prnt1.getHomogeneousCollection().add(smpl1);
- prnt1.getHomogeneousCollection().add(smpl2);
-
- prnt1Adapter = iswf.remapAsPersistent(prnt1, RootOidDefault.deString("PRNT:1", new OidMarshaller()));
-
- final Version version = SerialNumberVersion.create(2, "username", null);
-
- context.checking(new Expectations() {
- {
- one(versionCreator).newVersion("tester");
- will(returnValue(version));
- one(versionCreator).versionString(version);
- will(returnValue("2"));
- one(versionCreator).timeString(version);
- will(returnValue("1057"));
- }
- });
-
- dataEncrypter = new DataEncryption() {
- @Override
- public String getType() {
- return "etc1";
- }
-
- @Override
- public void init(final IsisConfiguration configuration) {
- }
-
- @Override
- public String encrypt(final String plainText) {
- return "ENC" + plainText;
- }
-
- @Override
- public String decrypt(final String encryptedText) {
- throw new UnexpectedCallException();
- }
- };
- }
-
-
- @Test
- public void objectWithValues() throws Exception {
-
- context.checking(new Expectations() {
-
- {
- one(commandContext).createStateWriter(smpl1Adapter.getSpecification().getSpecId());
- will(returnValue(writer));
-
- final RootOidDefault oid = RootOidDefault.create(smpl1Adapter.getSpecification().getSpecId(), "1");
- exactly(2).of(writer).writeOid(oid); // once for the id, once for the type
-
- one(writer).writeField("name", "ENCFred Smith");
- one(writer).writeField("size", "ENC108");
- one(writer).writeField("date", null);
- one(writer).writeField("nullable", null);
- one(writer).writeVersion(null, "2");
- one(writer).writeUser("username");
- one(writer).writeTime("1057");
- one(writer).writeEncryptionType("etc1");
-
- one(commandContext).insert(writer);
-
- }
- });
-
- final WriteObjectCommand command = new WriteObjectCommand(WriteObjectCommand.Mode.NON_UPDATE, versionCreator, dataEncrypter, smpl1Adapter);
- command.execute(commandContext);
- }
-
- @Test
- public void objectWithReferences() throws Exception {
-
- context.checking(new Expectations() {
- {
- one(commandContext).createStateWriter(rfcg1Adapter.getSpecification().getSpecId());
- will(returnValue(writer));
-
- final RootOidDefault oid = RootOidDefault.create(rfcg1Adapter.getSpecification().getSpecId(), "1");
- exactly(2).of(writer).writeOid(oid); // once for the id, once for the type
-
- one(writer).writeField("reference", "SMPL:1");
- one(writer).writeField("aggregatedReference", null);
- one(writer).writeCollection(with(equalTo("aggregatedEntities")), with(equalTo(new ArrayList<StateWriter>())));
-
- one(writer).writeVersion(null, "2");
- one(writer).writeUser("username");
- one(writer).writeTime("1057");
- one(writer).writeEncryptionType("etc1");
-
- one(commandContext).insert(writer);
- }
- });
-
- final WriteObjectCommand command = new WriteObjectCommand(WriteObjectCommand.Mode.NON_UPDATE, versionCreator, dataEncrypter, rfcg1Adapter);
- command.execute(commandContext);
- }
-
- @Test
- public void objectWithCollections() throws Exception {
-
- context.checking(new Expectations() {
- {
- one(commandContext).createStateWriter(prnt1Adapter.getSpecification().getSpecId());
- will(returnValue(writer));
-
- final RootOidDefault oid = RootOidDefault.create(prnt1Adapter.getSpecification().getSpecId(), "1");
- exactly(2).of(writer).writeOid(oid); // once for the id, once for the type
-
- one(writer).writeField("name", null);
- one(writer).writeField("homogeneousCollection", "SMPL:1|SMPL:2|");
-
- one(writer).writeVersion(null, "2");
- one(writer).writeUser("username");
- one(writer).writeTime("1057");
- one(writer).writeEncryptionType("etc1");
-
- one(commandContext).insert(writer);
- }
- });
-
- final WriteObjectCommand command = new WriteObjectCommand(WriteObjectCommand.Mode.NON_UPDATE, versionCreator, dataEncrypter, prnt1Adapter);
- command.execute(commandContext);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java
deleted file mode 100644
index 8f3e1e5..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ChecksummingPerfomance.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
-import java.util.zip.CRC32;
-import java.util.zip.CheckedInputStream;
-
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
-
-public class ChecksummingPerfomance {
-
- public static void main(final String[] args) throws Exception {
-
- //final CRC32 inputChecksum = new CRC32();
- //final CheckedInputStream in = new CheckedInputStream(new FileInputStream("test.data"), inputChecksum);
- //final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Util.ENCODING));
-
- for (int i = 0; i < 30; i++) {
- long time = System.currentTimeMillis();
- StringBuffer buf = null;
- for (int j = 0; j < 1000; j++) {
- buf = readFile(i);
- }
- time = System.currentTimeMillis() - time;
- System.out.print(time);
- System.out.print(" ");
-
- time = System.currentTimeMillis();
- for (int j = 0; j < 1000; j++) {
- readChecksummedFile(i);
- }
- time = System.currentTimeMillis() - time;
- System.out.print(time);
- System.out.print(" ");
-
- time = System.currentTimeMillis();
- for (int j = 0; j < 1000; j++) {
- testArray(buf);
- }
- time = System.currentTimeMillis() - time;
- System.out.print(time);
- System.out.print(" ");
-
- byte[] data = null;
- time = System.currentTimeMillis();
- for (int j = 0; j < 1000; j++) {
- data = extractArray(buf);
- }
- time = System.currentTimeMillis() - time;
- System.out.print(time);
- System.out.print(" ");
-
- time = System.currentTimeMillis();
- for (int j = 0; j < 1000; j++) {
- checksumArray(data);
- }
- time = System.currentTimeMillis() - time;
- System.out.println(time);
- }
-
- }
-
- private static void testArray(final StringBuffer buf) {
- final byte[] data = buf.toString().getBytes();
-
- final CRC32 inputChecksum = new CRC32();
- inputChecksum.reset();
- inputChecksum.update(data);
-
- // System.out.println(inputChecksum.getValue());
- }
-
- private static byte[] extractArray(final StringBuffer buf) {
- final byte[] data = buf.toString().getBytes();
- return data;
- }
-
- private static void checksumArray(final byte[] data) {
- final CRC32 inputChecksum = new CRC32();
- inputChecksum.reset();
- inputChecksum.update(data);
-
- // System.out.println(inputChecksum.getValue());
- }
-
- private static StringBuffer readChecksummedFile(final int i) throws Exception {
- final CRC32 inputChecksum = new CRC32();
- final CheckedInputStream in = new CheckedInputStream(new FileInputStream("test" + i % 3 + ".data"), inputChecksum);
- final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Util.ENCODING));
-
- final StringBuffer buf = new StringBuffer();
- String line;
- while ((line = reader.readLine()) != null) {
- buf.append(line);
- buf.append('\n');
- }
-
- // System.out.println(inputChecksum.getValue());
-
- reader.close();
-
- return buf;
- }
-
- private static StringBuffer readFile(final int i) throws Exception {
- final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("test" + i % 3 + ".data"), Util.ENCODING));
-
- final StringBuffer buf = new StringBuffer();
- String line;
- while ((line = reader.readLine()) != null) {
- buf.append(line);
- buf.append('\n');
- }
-
- // System.out.println(inputChecksum.getValue());
-
- reader.close();
-
- return buf;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java
deleted file mode 100644
index 2a57d28..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/ClientConnectionTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file;
-
-import static org.hamcrest.Matchers.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.commons.lang.IoUtils;
-import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
-import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectNotFoundException;
-
-public class ClientConnectionTest {
-
- private InputStream input;
- private ByteArrayOutputStream output;
- private ClientConnection connection;
-
- @Before
- public void setup() throws Exception {
- Logger.getRootLogger().setLevel(Level.OFF);
-
- input = IoUtils.asUtf8ByteStream("org.domain.Class false true 1025\n{data...}\n\n102334");
- output = new ByteArrayOutputStream();
- connection = new ClientConnection(input, output);
- }
-
- @Test
- public void testRequest() throws Exception {
- connection.request('D', "xxx yyy");
- connection.close();
- assertEquals("Dxxx yyy\n", output.toString());
- }
-
- @Test
- public void testRequestData() throws Exception {
- connection.requestData("{data...}");
- connection.close();
- // assertEquals("{data...}\n\n5de98274", output.toString());
- }
-
- @Test
- public void testResponseHeaders() throws Exception {
- connection.getReponseHeader();
- assertEquals("org.domain.Class", connection.getResponse());
- assertEquals(false, connection.getResponseAsBoolean());
- assertEquals(true, connection.getResponseAsBoolean());
- assertEquals(1025L, connection.getResponseAsLong());
- }
-
- @Test
- public void tooManyResponseHeadersExpected() throws Exception {
- connection.getReponseHeader();
- connection.getResponse();
- connection.getResponse();
- connection.getResponse();
- connection.getResponse();
- try {
- connection.getResponse();
- fail();
- } catch (final RemotingException e) {
- assertThat(e.getMessage(), containsString("are only 4"));
- }
- }
-
- @Test
- public void testResponseData() throws Exception {
- connection.getReponseHeader();
- final String data = connection.getResponseData();
- assertEquals("{data...}\n", data);
- }
-
- @Test
- public void validateResponseOk() throws Exception {
- input = IoUtils.asUtf8ByteStream("ok xx xx\n{data...}");
- connection = new ClientConnection(input, output);
- connection.validateRequest();
- }
-
- @Test(expected = RemotingException.class)
- public void validateResponseError() throws Exception {
- input = IoUtils.asUtf8ByteStream("error message about it\n");
- connection = new ClientConnection(input, output);
- connection.validateRequest();
- }
-
- @Test(expected = ObjectNotFoundException.class)
- public void validateObjectNotFound() throws Exception {
- input = IoUtils.asUtf8ByteStream("not-found message about it\n");
- connection = new ClientConnection(input, output);
- connection.validateRequest();
- }
-
- @Test(expected = ConcurrencyException.class)
- public void validateConcurrencyException() throws Exception {
- input = IoUtils.asUtf8ByteStream("concurrency message about it\n");
- connection = new ClientConnection(input, output);
- connection.validateRequest();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java
deleted file mode 100644
index 89b6db8..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateReaderTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateReader;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.JsonStateReader;
-
-public class JsonStateReaderTest {
-
- private JsonStateReader reader;
-
- @Before
- public void setup() {
- reader = new JsonStateReader(
- "{" +
- "\"_encrypt\": \"etc1\"," +
- "\"_oid\": \"com.package.ClassName:#2\"," +
- "\"_time\": \"ddmmyy\"," +
- "\"_user\": \"fred\"," +
- "\"_version\": \"2\"," +
- "\"field-1\": \"1234\"," +
- "\"field-2\": \"data\"," +
- "\"field-3\": null,"
- + "\"list\": [{}, {}]," +
- "\"aggregate\": {" +
- "\"_oid\": \"com.package.ClassName:#2~com.package.AggregatedClassName:#3\"" +
- "}," +
- "}");
- }
-
- @Test
- public void readEncryptionType() throws Exception {
- assertEquals("etc1", reader.readEncrytionType());
- }
-
-// @Test
-// public void readId() throws Exception {
-// assertEquals("#2", reader.readId());
-// }
-//
-// @Test
-// public void readObjectType() throws Exception {
-// assertEquals("com.package.ClassName", reader.readObjectType());
-// }
-
- @Test
- public void readOid() throws Exception {
- assertEquals("com.package.ClassName:#2", reader.readOid());
- }
-
- @Test
- public void readTime() throws Exception {
- assertEquals("ddmmyy", reader.readTime());
- }
-
- @Test
- public void readUser() throws Exception {
- assertEquals("fred", reader.readUser());
- }
-
- @Test
- public void readVersion() throws Exception {
- assertEquals("2", reader.readVersion());
- }
-
- @Test
- public void readNumberField() throws Exception {
- assertEquals(1234L, reader.readLongField("field-1"));
- }
-
- @Test
- public void readNumberFieldAsNull() throws Exception {
- assertEquals(0L, reader.readLongField("field-4"));
- }
-
- @Test
- public void readStringField() throws Exception {
- assertEquals("data", reader.readField("field-2"));
- }
-
- @Test
- public void readStringFieldAsNull() throws Exception {
- assertEquals(null, reader.readField("field-4"));
- }
-
- @Test
- public void readUnsavedCollection() throws Exception {
- assertEquals(new ArrayList<StateReader>(), reader.readCollection("unknown-list"));
- }
-
- @Test
- public void readList() throws Exception {
- final List<StateReader> collection = reader.readCollection("list");
- assertEquals(2, collection.size());
- // assertEquals(null, reader.readField("field-4"));
- }
-
- @Test
- public void readAggregate() throws Exception {
- final StateReader aggregate = reader.readAggregate("aggregate");
- assertEquals("com.package.ClassName:#2~com.package.AggregatedClassName:#3", aggregate.readOid());
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java
deleted file mode 100644
index 163ce1b..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/JsonStateWriterTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateWriter;
-import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-public class JsonStateWriterTest {
-
- @Rule
- public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
-
- private JsonStateWriter writer;
-
- @Before
- public void setup() {
- writer = new JsonStateWriter();
- }
-
- @Test
- public void noData() throws Exception {
- assertEquals("{}", writer.getData());
- }
-
- @Test
- public void basicData() throws Exception {
-// writer.writeObjectType("com.planchase.ClassName");
-// writer.writeId("#1");
- writer.writeOid(RootOidDefault.deString("com.planchase.ClassName:1", new OidMarshaller()));
- writer.writeTime("ddmmyy");
- writer.writeVersion("1", "2");
- writer.writeUser("fred");
- assertEquals("{\n" +
- " \"_oid\": \"com.planchase.ClassName:1\",\n" +
- " \"_time\": \"ddmmyy\",\n" +
- " \"_user\": \"fred\",\n" +
- " \"_version\": \"2\"\n" +
- "}",
- writer.getData());
- }
-
- @Test
- public void encrytionVersion() throws Exception {
- writer.writeEncryptionType("etc1");
- assertEquals("{\"_encrypt\": \"etc1\"}", writer.getData());
- }
-
- @Test
- public void numberData() throws Exception {
- writer.writeField("number", 1239912);
- assertEquals("{\"number\": \"1239912\"}", writer.getData());
- }
-
- @Test
- public void stringData() throws Exception {
- writer.writeField("number", "string-data");
- assertEquals("{\"number\": \"string-data\"}", writer.getData());
- }
-
- @Test
- public void nullData() throws Exception {
- writer.writeField("number", null);
- assertEquals("{\"number\": null}", writer.getData());
- }
-
- @Test
- public void addAggregate() throws Exception {
- final StateWriter aggregate = writer.addAggregate("#4");
- aggregate.writeField("number", "string-data");
- assertEquals("{\"#4\": {\"number\": \"string-data\"}}", writer.getData());
- }
-
- @Test
- public void elementData() throws Exception {
- final List<StateWriter> elements = new ArrayList<StateWriter>();
- final StateWriter elementWriter1 = writer.createElementWriter();
- elementWriter1.writeField("number", "1");
- elements.add(elementWriter1);
- final StateWriter elementWriter2 = writer.createElementWriter();
- elementWriter2.writeField("number", "4");
- elements.add(elementWriter2);
-
- writer.writeCollection("coll", elements);
-
- assertEquals("{\"coll\": [\n {\"number\": \"1\"},\n {\"number\": \"4\"}\n]}", writer.getData());
- }
-
- @Test
- public void requestData() throws Exception {
-// writer.writeObjectType("com.planchase.ClassName");
-// writer.writeId("#8");
- writer.writeOid(RootOidDefault.deString("com.planchase.ClassName:8", new OidMarshaller()));
- writer.writeVersion("1", "2");
- assertEquals("com.planchase.ClassName:8 1 2", writer.getRequest());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java
deleted file mode 100644
index fbdc8ce..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataReaderTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server;
-
-import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.DataFileReader;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileServerException;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
-
-public class DataReaderTest {
-
- private DataFileReader reader;
-
- @BeforeClass
- public static void setUp() throws Exception {
- Util.setDirectory("target/test", "services", "logs", "archive");
- Util.ensureDirectoryExists();
- new File("target/test/type").mkdir();
- }
-
- @Test
- public void noFileCausesException() throws Exception {
- try {
- new DataFileReader("type", "nonexistant");
- fail();
- } catch (final FileNotFoundException expected) {
- }
- }
-
- @Test
- public void noDataRead() throws Exception {
- final FileWriter writer = new FileWriter("target/test/type/0013.data");
- writer.write("");
- writer.close();
-
- try {
- reader = new DataFileReader("type", "0013");
- fail();
- } catch (final FileServerException expected) {
- assertThat(expected.getMessage(), startsWith("No data in file:"));
- }
-
- }
-
- @Test
- public void readIdAndVersion() throws Exception {
- final FileWriter writer = new FileWriter("target/test/type/0012.data");
- writer.write("class.type 0012 17\n{data}");
- writer.close();
-
- reader = new DataFileReader("type", "0012");
-
- assertEquals("0012", reader.getId());
- assertEquals("17", reader.getVersion());
-
- final String data = reader.getData();
- assertEquals("{data}\n", data);
- reader.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java
deleted file mode 100644
index 27cc9c8..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/DataWriterTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.DataFileWriter;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileContent;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
-
-public class DataWriterTest {
-
- private static final String TARGET_DIRECTORY = "target/test/";
- private static final String FULLY_QUALIFIED_CLASSNAME = "org.domain.Class";
- private static final String FULLY_QUALIFIED_CLASSNAME_2 = "org.domain.Class2";
- private DataFileWriter writer;
-
- @Before
- public void setUp() throws Exception {
- Logger.getRootLogger().setLevel(Level.OFF);
- Util.setDirectory(TARGET_DIRECTORY, "services", "logs", "archive");
- Util.ensureDirectoryExists();
- }
-
- @After
- public void tearDown() throws Exception {
- if (writer != null) {
- writer.close();
- }
- }
-
- @Test
- public void testWriteData() throws Exception {
- final File file = new File(TARGET_DIRECTORY + FULLY_QUALIFIED_CLASSNAME + "/1030.data");
- file.mkdirs();
- file.createNewFile();
- Assert.assertTrue(file.exists());
-
- final List<FileContent> files = new ArrayList<FileContent>();
- files.add(new FileContent('I', "1023", "1", "2", FULLY_QUALIFIED_CLASSNAME, "{data1}"));
- files.add(new FileContent('U', "1024", "21", "22", FULLY_QUALIFIED_CLASSNAME, "{data2}"));
- files.add(new FileContent('D', "1030", "66", "", FULLY_QUALIFIED_CLASSNAME, ""));
- final DataFileWriter writer = new DataFileWriter(files);
- writer.writeData();
-
- BufferedReader reader = new BufferedReader(new FileReader(TARGET_DIRECTORY + FULLY_QUALIFIED_CLASSNAME + "/1023.data"));
- Assert.assertEquals("org.domain.Class 1023 2", reader.readLine());
- Assert.assertEquals("{data1}", reader.readLine());
-
- reader = new BufferedReader(new FileReader(TARGET_DIRECTORY + FULLY_QUALIFIED_CLASSNAME + "/1024.data"));
- Assert.assertEquals(FULLY_QUALIFIED_CLASSNAME + " 1024 22", reader.readLine());
- Assert.assertEquals("{data2}", reader.readLine());
-
- Assert.assertFalse("file still exists", file.exists());
- }
-
- @Test
- public void createsTypeDirectory() throws Exception {
- final String dir = TARGET_DIRECTORY + FULLY_QUALIFIED_CLASSNAME_2;
- final File file = deleteDirectory(dir);
- Assert.assertFalse(file.exists());
-
- final List<FileContent> files = new ArrayList<FileContent>();
- files.add(new FileContent('I', "1023", "1", "2", FULLY_QUALIFIED_CLASSNAME_2, "{data1}"));
- writer = new DataFileWriter(files);
- writer.writeData();
-
- Assert.assertTrue(file.exists());
- }
-
- protected File deleteDirectory(final String dir) {
- final File file = new File(dir);
- if (file.exists()) {
- for (final File f : file.listFiles()) {
- f.delete();
- }
- file.delete();
-
- }
- return file;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java
deleted file mode 100644
index f2b6fb0..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/FileServerTest.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server;
-
-import static org.apache.isis.core.commons.matchers.IsisMatchers.existsAndNotEmpty;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStream;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import org.apache.isis.core.commons.lang.IoUtils;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileServerProcessor;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.ServerConnection;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
-
-public class FileServerTest {
- private FileServerProcessor server;
- private File logFile1;
- private File logFile2;
- private ByteArrayOutputStream out;
-
- @BeforeClass
- public static void setUp() throws Exception {
- Util.setDirectory("target/test", "services", "logs", "archive");
- Util.ensureDirectoryExists();
- new File("target/test/type").mkdir();
- }
-
- @Before
- public void startup() {
- logFile1 = recreateFile("target/test/logs", "recovery0.log");
- logFile2 = recreateFile("target/test/logs", "recovery1.log");
-
- final File dir = new File("target/test/org.domain.Class");
- dir.mkdirs();
- final File dir2 = new File("target/test/org.domain.Class2");
- dir2.mkdirs();
-
- server = new FileServerProcessor();
- server.startup();
-
- out = new ByteArrayOutputStream();
- }
-
- private static File recreateFile(final String parent, final String child) {
- final File file = new File(parent, child);
- file.delete();
- assertFalse(file.exists());
- return file;
- }
-
- @After
- public void tearDown() throws Exception {
- if (server != null) {
- server.shutdown();
- }
- }
-
- @Test
- public void cantReadOrWriteAfterShutdown() throws Exception {
- final InputStream in = IoUtils.asUtf8ByteStream("R[org.domain.Class 1025]\n");
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final ServerConnection connection = new ServerConnection(in, out);
-
- server.shutdown();
- server.process(connection);
- assertThat(new String(out.toByteArray(), "utf-8"), is(equalTo("abort\n")));
- }
-
- @Test
- public void writeAbortedAsDataNotComplete() throws Exception {
- final InputStream in = IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025 null 1 \n{da");
- final ServerConnection connection = new ServerConnection(in, out);
- server.process(connection);
-
- assertThat(out.toString(), is(containsString("stream ended prematurely while reading data, aborting request")));
- }
-
- @Test
- public void writeAbortsIfMissingNextDataBlock() throws Exception {
- final InputStream in = IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025 null 1 \n{data1}\n\n");
- final ServerConnection connection = new ServerConnection(in, out);
- server.process(connection);
-
- assertThat(out.toString(), is(containsString("stream ended prematurely while reading header, aborting request")));
- }
-
- @Test
- public void writeAbortedAsHeaderNotComplete() throws Exception {
- final InputStream in = IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025");
- final ServerConnection connection = new ServerConnection(in, out);
- server.process(connection);
-
- assertThat(out.toString(), is(containsString("invalid header string, aborting request")));
- }
-
- @Test
- public void writeCreatesFilesUsingDataWriter() throws Exception {
- final File file1 = new File("target/test/org.domain.Class", "1025.data");
- final File file2 = new File("target/test/org.domain.Class", "1026.data");
- file1.delete();
- file2.delete();
- assertFalse(file1.exists());
- assertFalse(file2.exists());
-
- final InputStream in = IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025 null 1 \n{data1}\n\nIorg.domain.Class 1026 null 1\n{data2}\n\n\n");
- final ServerConnection connection = new ServerConnection(in, out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("ok\n")));
- assertThat(file1, existsAndNotEmpty());
- assertThat(file2, existsAndNotEmpty());
- }
-
- @Test
- public void writeUpdatesFilesUsingDataWriter() throws Exception {
- final File file2 = new File("target/test/org.domain.Class2", "1026.data");
- final FileWriter fileWriter = new FileWriter(file2);
- final String originalData = "org.domain.Class 1026 21 {}";
- fileWriter.write(originalData);
- fileWriter.close();
-
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("W\nUorg.domain.Class2 1026 21 22 \n{data2}\n\n\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("ok\n")));
- assertThat(file2.length(), is(greaterThan((long) originalData.length())));
- }
-
- @Test
- public void writeUpdateFailsWhenVersionsDontMatch() throws Exception {
- final File file2 = new File("target/test/org.domain.Class", "1026.data");
- final FileWriter fileWriter = new FileWriter(file2);
- final String originalData = "org.domain.Class 1026 21\n{datax}\n\n\n***";
- fileWriter.write(originalData);
- fileWriter.close();
-
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("W\nUorg.domain.Class 1026 19 21 \n{data2}\n\n\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("error\nmismatch between FileContent version (19) and DataReader version (21)\n")));
- }
-
- @Test
- public void writeCreatesLogFile() throws Exception {
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("W\nIorg.domain.Class 1025 6 7\n{data1}\n\n\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("ok\n")));
-
- assertThat(logFile1, existsAndNotEmpty());
- assertThat(logFile2, not(existsAndNotEmpty()));
- }
-
- @Test
- public void readNonExistingFileThrowsException() throws Exception {
- final File file1 = new File("target/test/org.domain.Class", "2020.data");
- file1.delete();
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class 2020\n\n"), out);
- server.process(connection);
-
- final String string = out.toString();
- assertThat(string, startsWith("not-found"));
- assertThat(string, containsString("File not found for org.domain.Class/2020"));
- }
-
- @Test
- public void aTestTheTests() throws Exception {
- final File dir = new File("target/test/org.domain.Class");
- assertTrue(dir.exists());
-
- final File file1 = new File("target/test/org.domain.Class", "2025.data");
- assertTrue(file1.getParentFile().exists());
-
- final FileWriter fileWriter = new FileWriter(file1);
- assertNotNull(fileWriter);
- fileWriter.write("data");
- fileWriter.close();
- }
-
- @Test
- public void copyOfReadTest() throws Exception {
- final File file1 = new File("target/test/org.domain.Class2", "2025.data");
- final FileWriter fileWriter = new FileWriter(file1);
- fileWriter.write("type 1025 1\n{data1}");
- fileWriter.close();
-
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class2 2025\n\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("ok\n{data1}\n\n")));
- }
-
- @Test
- public void ReadFailIfEndsEarly() throws Exception {
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class 2010\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(containsString("stream ended prematurely while reading end of command, aborting request")));
- }
-
- @Test
- public void lookReadRenamed() throws Exception {
- final File file1 = new File("target/test/org.domain.Class2", "2025.data");
- final FileWriter fileWriter = new FileWriter(file1);
- fileWriter.write("type 1025 1\n{data1}");
- fileWriter.close();
-
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class2 2025\n\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("ok\n{data1}\n\n")));
- }
-
- @Test
- public void read2() throws Exception {
- final File file1 = new File("target/test/org.domain.Class2", "2025.data");
- final FileWriter fileWriter = new FileWriter(file1);
- fileWriter.write("type 1025 1\n{data1}");
- fileWriter.close();
-
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Rorg.domain.Class2 2025\n\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("ok\n{data1}\n\n")));
- }
-
- @Test
- public void hasNoInstances() throws Exception {
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Iorg.domain.None\n\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("ok false\n")));
- }
-
- @Test
- public void hasInstances() throws Exception {
- final File file1 = new File("target/test/org.domain.Class2", "2025.data");
- // file1.getParentFile().mkdirs();
- final FileWriter fileWriter = new FileWriter(file1);
- fileWriter.write("type 1025 1\n{data1}");
- fileWriter.close();
-
- final ServerConnection connection = new ServerConnection(IoUtils.asUtf8ByteStream("Iorg.domain.Class2\n\n"), out);
- server.process(connection);
-
- assertThat(out.toString(), is(equalTo("ok true\n")));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java
deleted file mode 100644
index f448313..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LockManagerTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.LockManager;
-
-public class LockManagerTest {
-
- private LockManager manager;
-
- @Before
- public void setUp() throws Exception {
- manager = new LockManager();
- }
-
- @Test
- public void readDoesNotBlockReads() throws Exception {
- final Thread tx1 = new Thread();
- final Thread tx2 = new Thread();
- manager.acquireRead("2", tx1);
- manager.acquireRead("2", tx2);
- manager.release("2", tx1);
- manager.release("2", tx2);
- }
-
- @Test
- public void writeAbortsSecondWrite() throws Exception {
- final Thread tx1 = new Thread();
- final Thread tx2 = new Thread();
- assertTrue(manager.acquireWrite("2", tx1));
- assertFalse(manager.acquireWrite("2", tx2));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java
deleted file mode 100644
index 8f327ff..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/file/server/LogWriterTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.DataFileWriter;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.FileContent;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.LogWriter;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.file.server.Util;
-
-public class LogWriterTest {
-
- private LogWriter logger;
- private File logFile1;
- private File logFile2;
- private List<FileContent> items;
-
- @BeforeClass
- public static void directory() {
- Util.setDirectory("target/test", "services", "logs", "archive");
- Util.ensureDirectoryExists();
- }
-
- @Before
- public void setUp() throws Exception {
- logFile1 = new File("target/test/logs", "recovery0.log");
- logFile1.delete();
- assertFalse(logFile1.exists());
- logFile2 = new File("target/test/logs", "recovery1.log");
- logFile2.delete();
- assertFalse(logFile2.exists());
-
- logger = new LogWriter();
- logger.startup();
-
- items = new ArrayList<FileContent>();
- items.add(new FileContent('U', "20", "6", "7", "type", "{data}"));
- new DataFileWriter(items);
- }
-
- @After
- public void tearDown() throws Exception {
- if (logger != null) {
- logger.shutdown();
- }
- }
-
- @Test
- public void newLogFileCreatedOnStartup() throws Exception {
- assertTrue(logFile1.exists() && logFile1.length() == 0);
- assertFalse(logFile2.exists());
- }
-
- @Test
- public void logsData() throws Exception {
- logger.logWrites(items);
-
- final BufferedReader reader = new BufferedReader(new FileReader(logFile1));
- String line = reader.readLine();
- line = reader.readLine();
- Assert.assertEquals("Utype 20 7", line);
- line = reader.readLine();
- Assert.assertEquals("{data}", line);
- reader.close();
-
- }
-
- @Test
- public void logAddedToExistingFile() throws Exception {
- logger.logWrites(items);
- assertTrue(logFile1.exists() && logFile1.length() > 0);
- assertFalse(logFile2.exists());
- }
-
- @Test
- public void logAddedToNewFileWhenRotated() throws Exception {
- logger.logWrites(items);
- logger.startNewFile();
- logger.logWrites(items);
- assertTrue(logFile2.exists() && logFile1.length() > 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java
deleted file mode 100644
index a5d6146..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/DemoMongo.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
-
-import java.util.Set;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.Mongo;
-
-public class DemoMongo {
-
- // @Test
- public void installed() throws Exception {
-
- final Mongo m = new Mongo();
-
- for (final String s : m.getDatabaseNames()) {
- System.out.println(s);
- }
-
- /*
- * Mongo m = new Mongo( "localhost" ); Mongo m = new Mongo( "localhost"
- * , 27017 );
- */
- m.dropDatabase("mydb");
-
- System.out.println("\n...");
- for (final String s : m.getDatabaseNames()) {
- System.out.println(s);
- }
-
- final DB db = m.getDB("mydb");
- /*
- * DBCollection coll = db.getCollection("testCollection1"); coll =
- * db.getCollection("testCollection2");
- */
-
- final DBCollection coll = db.getCollection("testCollection1");
-
- final BasicDBObject doc = new BasicDBObject();
-
- doc.put("name", "MongoDB");
- doc.put("type", "database");
- doc.put("count", 1);
-
- final BasicDBObject info = new BasicDBObject();
-
- info.put("x", 203);
- info.put("y", 102);
-
- doc.put("info", info);
-
- coll.insert(doc);
-
- final Set<String> colls = db.getCollectionNames();
-
- for (final String s : colls) {
- System.out.println(s);
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoIntegrationTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoIntegrationTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoIntegrationTest.java
deleted file mode 100644
index 7c69edc..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoIntegrationTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeThat;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.Mongo;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.keys.KeyCreatorDefault;
-import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
-
-public class MongoIntegrationTest {
-
- @Rule
- public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().with(new MongoPersistorMechanismInstaller()).build();
-
- private MongoDb db;
- private DB testDb;
-
- private ObjectAdapter adapter1;
-
- private ObjectSpecification specification;
-
- @Before
- public void setupMongo() throws Exception {
-
- try {
- final Mongo m = new Mongo();
- m.dropDatabase("testdb");
- testDb = m.getDB("testdb");
- } catch (final Exception e) {
- assumeThat(true, is(false)); // ignore if no MongoDB instance to
- // connect to
- return;
- }
-
- db = new MongoDb("localhost", 0, "testdb", new KeyCreatorDefault());
- db.open();
-
- adapter1 = iswf.adapterFor(iswf.fixtures.smpl1);
- specification = adapter1.getSpecification();
- }
-
- @Test
- public void newDatabaseContainsNothing() throws Exception {
- assertFalse(db.containsData());
- }
-
- @Test
- public void serialNumberSaved() throws Exception {
- assertEquals(1, db.nextSerialNumberBatch(ObjectSpecId.of("oid"), 10));
- assertEquals(11, db.nextSerialNumberBatch(ObjectSpecId.of("oid"), 10));
- }
-
- @Test
- public void hasInstances() throws Exception {
- assertFalse(db.hasInstances(specification.getSpecId()));
- db.close();
-
- final DBCollection instances = testDb.getCollection(specification.getSpecId().asString());
- instances.insert(new BasicDBObject().append("test", "test"));
-
- db.open();
- assertTrue(db.hasInstances(specification.getSpecId()));
- assertFalse(db.hasInstances(ObjectSpecId.of("org.xxx.unknown")));
- }
-
- @Test
- public void serviceIds() throws Exception {
- final ObjectSpecId osi = ObjectSpecId.of("one");
- db.addService(osi, "123");
- assertEquals("123", db.getService(osi));
- }
-
- @Test
- public void unknownServiceIds() throws Exception {
- assertNull(db.getService(ObjectSpecId.of("two")));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderIntegrationTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderIntegrationTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderIntegrationTest.java
deleted file mode 100644
index f3fd962..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateReaderIntegrationTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeThat;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.Mongo;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-
-public class MongoStateReaderIntegrationTest {
-
- private static final String OBJECT_TYPE = "org.test.Object";
-
- private DB testDb;
- private MongoStateReader reader;
-
- @Before
- public void setup() throws Exception {
- Logger.getRootLogger().setLevel(Level.OFF);
-
- final Mongo m = new Mongo();
- try {
- m.dropDatabase("mydb");
- } catch (final Exception e) {
- assumeThat(true, is(false));// ie ignore test because we've had an
- // exception
- return;
- }
-
- testDb = m.getDB("mydb");
-
- final BasicDBObject object = new BasicDBObject();
-// object.put("_id", "1023");
-// object.put("_type", "org.xxx.Class");
- object.put("_oid", OBJECT_TYPE + ":1023");
- object.put("_id", "1023"); // the MongoDB internal identifier
-
- object.put("name", "Fred Smith");
- object.put("null name", "null");
- object.put("null name 2", null);
- object.put("number", "102");
- object.put("null number", "null");
- final DBCollection instances = testDb.getCollection(OBJECT_TYPE);
- instances.insert(object);
-
- reader = new MongoStateReader(testDb, ObjectSpecId.of(OBJECT_TYPE), "1023");
- }
-
- @Test
- public void readNonexistantFieldAsNull() throws Exception {
- assumeThat(reader, is(not(nullValue())));
- assertEquals(null, reader.readField("unknown"));
- }
-
- @Test
- public void readStringField() throws Exception {
- assertEquals("Fred Smith", reader.readField("name"));
- }
-
- @Test
- public void readStringFieldAsNull() throws Exception {
- assertEquals(null, reader.readField("null name"));
- }
-
- @Test
- public void readNullFieldAsNull() throws Exception {
- assertEquals(null, reader.readField("null name 2"));
- }
-
-// @Test
-// public void readType() throws Exception {
-// assertEquals("org.xxx.Class", reader.readObjectType());
-// }
-//
-// @Test
-// public void readId() throws Exception {
-// assertEquals("1023", reader.readId());
-// }
-
- @Test
- public void readOid() throws Exception {
- assertEquals(OBJECT_TYPE + ":1023", reader.readOid());
- }
-
- @Test
- public void readNumberField() throws Exception {
- assertEquals(102L, reader.readLongField("number"));
- }
-
- @Test
- public void readNumberFieldAsNull() throws Exception {
- assertEquals(0L, reader.readLongField("null number"));
- }
-
- @Test
- public void readNonexistingNumberFieldAsZero() throws Exception {
- assertEquals(0L, reader.readLongField("unknown"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterIntegrationTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterIntegrationTest.java
deleted file mode 100644
index 3df43a8..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/MongoStateWriterIntegrationTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeThat;
-
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.DBObject;
-import com.mongodb.Mongo;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-
-public class MongoStateWriterIntegrationTest {
-
- private static final String SPEC_NAME = "org.test.Object";
- private DB testDb;
- private MongoStateWriter writer;
-
- @Before
- public void setup() throws Exception {
- Logger.getRootLogger().setLevel(Level.OFF);
-
- try {
-
- final Mongo m = new Mongo();
- m.dropDatabase("mydb");
- testDb = m.getDB("mydb");
- } catch (final Exception e) {
- assumeThat(true, is(false)); // ie no exceptions
- return;
- }
-
- writer = new MongoStateWriter(testDb, ObjectSpecId.of(SPEC_NAME));
- }
-
- @Test
- public void flushSavesObject() throws Exception {
- writer.flush();
-
- final DBCollection instances = testDb.getCollection(SPEC_NAME);
- assertEquals(1, instances.getCount());
- }
-
- @Test
- public void objectNotSavedUntilFlush() throws Exception {
- writer.writeField("number", 1023);
- writer.writeField("string", "testing");
-
- final DBCollection instances = testDb.getCollection(SPEC_NAME);
- assertEquals(0, instances.getCount());
- }
-
- @Test
- public void serialNumberNotStored() throws Exception {
- //writer.writeId("D01");
- writer.writeOid(RootOidDefault.deString(SPEC_NAME+":"+"D01", new OidMarshaller()));
- writer.flush();
-
- final DBCollection instances = testDb.getCollection(SPEC_NAME);
- assertEquals(1, instances.getCount());
- final DBObject object = instances.findOne();
-
- assertEquals(SPEC_NAME+":"+"D01", object.get("_oid"));
- assertEquals("D01", object.get("_id"));
-
- assertEquals(2, object.keySet().size());
- }
-
- @Test
- public void writeFields() throws Exception {
- //writer.writeObjectType(SPEC_NAME);
- writer.writeOid(RootOidDefault.deString(SPEC_NAME+":"+"D01", new OidMarshaller()));
- writer.writeField("number", 1023);
- writer.writeField("string", "testing");
- writer.flush();
-
- final DBCollection instances = testDb.getCollection(SPEC_NAME);
- assertEquals(1, instances.getCount());
- final DBObject object = instances.findOne();
- assertEquals(SPEC_NAME+":"+"D01", object.get("_oid"));
- assertEquals("1023", object.get("number"));
- assertEquals("testing", object.get("string"));
- }
-
- @Test
- public void writeFields2() throws Exception {
-// writer.writeId("3");
-// writer.writeObjectType(SPEC_NAME);
- writer.writeOid(RootOidDefault.deString(SPEC_NAME + ":" + "3", new OidMarshaller()));
- writer.flush();
-
- writer.writeField("number", 1023);
- writer.writeField("string", "testing");
- writer.flush();
-
- final DBCollection instances = testDb.getCollection(SPEC_NAME);
- assertEquals(1, instances.getCount());
- final DBObject object = instances.findOne();
- assertEquals(SPEC_NAME + ":" + "3", object.get("_oid"));
- assertEquals("1023", object.get("number"));
- assertEquals("testing", object.get("string"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/ObjectReaderMongoIntegrationTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/ObjectReaderMongoIntegrationTest.java b/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/ObjectReaderMongoIntegrationTest.java
deleted file mode 100644
index 15cfd7a..0000000
--- a/component/objectstore/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/db/mongo/ObjectReaderMongoIntegrationTest.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.runtimes.dflt.objectstores.nosql.db.mongo;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.hamcrest.CoreMatchers;
-import org.jmock.Expectations;
-import org.jmock.auto.Mock;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.ResolveState;
-import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
-import org.apache.isis.core.metamodel.spec.ObjectSpecId;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
-import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
-import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.ObjectReader;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.db.StateReader;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.encryption.DataEncryption;
-import org.apache.isis.runtimes.dflt.objectstores.nosql.versions.VersionCreator;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManagerSpi;
-import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
-import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
-import org.apache.isis.tck.dom.refs.ParentEntity;
-import org.apache.isis.tck.dom.refs.ReferencingEntity;
-import org.apache.isis.tck.dom.refs.SimpleEntity;
-
-public class ObjectReaderMongoIntegrationTest {
-
- @Rule
- public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().with(new MongoPersistorMechanismInstaller()).build();
-
- @Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
-
- @Mock
- private VersionCreator versionCreator;
-
- @Mock
- private StateReader reader1;
- @Mock
- private StateReader reader2;
-
- private ObjectReader objectReader;
-
- private Map<String, DataEncryption> dataEncrypter;
-
- private OidMarshaller oidMarshaller = new OidMarshaller();
-
- private final RootOidDefault oid3 = RootOidDefault.deString("SMPL:3", oidMarshaller );
- private final RootOidDefault oid4 = RootOidDefault.deString("RFCG:4", oidMarshaller);
- private final RootOidDefault oid5 = RootOidDefault.deString("PRNT:5", oidMarshaller);
-
-
- @Before
- public void setup() {
- objectReader = new ObjectReader();
-
- dataEncrypter = new HashMap<String, DataEncryption>();
- final DataEncryption etcEncryption = new DataEncryption() {
- @Override
- public String getType() {
- return "etc1";
- }
-
- @Override
- public void init(final IsisConfiguration configuration) {
- }
-
- @Override
- public String encrypt(final String plainText) {
- throw new UnexpectedCallException();
- }
-
- @Override
- public String decrypt(final String encryptedText) {
- return encryptedText.substring(3);
- }
- };
- dataEncrypter.put(etcEncryption.getType(), etcEncryption);
- }
-
- @Test
- public void testReadingValues() throws Exception {
- setupObject1();
-
- context.checking(new Expectations() {
- {
- one(reader1).readOid();
- will(returnValue("SMPL:3"));
-
- one(reader1).readEncrytionType();
- will(returnValue("etc1"));
- one(reader1).readVersion();
- will(returnValue("3"));
- one(reader1).readUser();
- will(returnValue("username"));
- one(reader1).readTime();
- will(returnValue("1020"));
- one(versionCreator).version("3", "username", "1020");
- }
- });
-
- final ObjectAdapter readObject = objectReader.load(reader1, versionCreator, dataEncrypter);
- assertEquals(oid3, readObject.getOid());
- assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
-
- final SimpleEntity pojo = (SimpleEntity) readObject.getObject();
- assertEquals("Fred Smith", pojo.getName());
- assertEquals(34, pojo.getSize());
-
- context.assertIsSatisfied();
- }
-
- @Test
- public void testReadingReference() throws Exception {
- context.checking(new Expectations() {
- {
- one(reader2).readOid();
- will(returnValue("RFCG:4"));
-
- one(reader2).readEncrytionType();
- will(returnValue("etc1"));
- one(reader2).readVersion();
- will(returnValue("3"));
- one(reader2).readUser();
- will(returnValue("username"));
- one(reader2).readTime();
- will(returnValue("1020"));
- one(versionCreator).version("3", "username", "1020");
-
- one(reader2).readField("reference");
- will(returnValue("SMPL:3"));
-
- one(reader2).readCollection("aggregatedEntities");
- will(returnValue(new ArrayList<StateReader>()));
-
- one(reader2).readAggregate("aggregatedReference");
- will(returnValue(null));
- }
- });
-
- final ObjectAdapter readObject = objectReader.load(reader2, versionCreator, dataEncrypter);
- assertEquals(oid4, readObject.getOid());
- assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
-
- final ReferencingEntity pojo = (ReferencingEntity) readObject.getObject();
- assertEquals(null, pojo.getAggregatedReference());
- assertThat(pojo.getReference(), CoreMatchers.instanceOf(SimpleEntity.class));
-
- context.assertIsSatisfied();
- }
-
- @Test
- public void testReadingCollection() throws Exception {
- //final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExamplePojoWithValues.class);
- context.checking(new Expectations() {
- {
- one(reader2).readOid();
- will(returnValue("PRNT:5"));
-
- one(reader2).readEncrytionType();
- will(returnValue("etc1"));
- one(reader2).readVersion();
- will(returnValue("3"));
- one(reader2).readUser();
- will(returnValue("username"));
- one(reader2).readTime();
- will(returnValue("1020"));
- one(versionCreator).version("3", "username", "1020");
-
- one(reader2).readField("name");
- will(returnValue(null));
- one(reader2).readField("children");
- will(returnValue(null));
- one(reader2).readField("heterogeneousCollection");
- will(returnValue(null));
- one(reader2).readField("homogeneousCollection");
- will(returnValue("SMPL:3|SMPL:4|"));
- }
- });
-
- final ObjectAdapter readObject = objectReader.load(reader2, versionCreator, dataEncrypter);
- assertEquals(oid5, readObject.getOid());
- assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
-
- final ParentEntity pojo = (ParentEntity) readObject.getObject();
- final List<SimpleEntity> collection2 = pojo.getHomogeneousCollection();
- assertEquals(2, collection2.size());
-
- assertThat(collection2.get(0), CoreMatchers.instanceOf(SimpleEntity.class));
- assertThat(collection2.get(1), CoreMatchers.instanceOf(SimpleEntity.class));
-
- context.assertIsSatisfied();
- }
-
- @Test
- public void updateObjectsState() throws Exception {
- setupObject1();
- context.checking(new Expectations() {
- {
-
- one(reader1).readEncrytionType();
- will(returnValue("etc1"));
- one(reader1).readVersion();
- will(returnValue("3"));
- one(reader1).readUser();
- will(returnValue("username"));
- one(reader1).readTime();
- will(returnValue("1020"));
- one(versionCreator).version("3", "username", "1020");
- }
- });
-
- final ObjectAdapter readObject = getAdapterManager().adapterFor(RootOidDefault.create(ObjectSpecId.of("SMPL"), ""+4));
-
- objectReader.update(reader1, versionCreator, dataEncrypter, readObject);
-
- final SimpleEntity pojo = (SimpleEntity) readObject.getObject();
- assertEquals("Fred Smith", pojo.getName());
- assertEquals(34, pojo.getSize());
-
- context.assertIsSatisfied();
- }
-
- private void setupObject1() {
- context.checking(new Expectations() {
- {
- one(reader1).readField("date");
- will(returnValue("null"));
-
- one(reader1).readField("name");
- will(returnValue("ENCFred Smith"));
-
- one(reader1).readField("size");
- will(returnValue("ENC34"));
-
- one(reader1).readField("nullable");
- will(returnValue("null"));
- }
- });
- }
-
- protected SpecificationLoaderSpi getSpecificationLoader() {
- return IsisContext.getSpecificationLoader();
- }
-
- protected PersistenceSession getPersistenceSession() {
- return IsisContext.getPersistenceSession();
- }
-
- protected AdapterManager getAdapterManager() {
- return getPersistenceSession().getAdapterManager();
- }
-
-
-}