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 2014/07/03 17:01:08 UTC

[02/63] [abbrv] [partial] ISIS-832: mothballing components

http://git-wip-us.apache.org/repos/asf/isis/blob/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/NoSqlObjectStoreTest_interactWith_db.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/NoSqlObjectStoreTest_interactWith_db.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/NoSqlObjectStoreTest_interactWith_db.java
new file mode 100644
index 0000000..59b0b24
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/NoSqlObjectStoreTest_interactWith_db.java
@@ -0,0 +1,224 @@
+/*
+ *  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.objectstore.nosql;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.jmock.Expectations;
+import org.jmock.Sequence;
+import org.jmock.auto.Mock;
+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.adapter.ResolveState;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+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.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.core.runtime.system.persistence.OidGenerator;
+import org.apache.isis.core.runtime.system.persistence.PersistenceQuery;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.objectstore.nosql.db.NoSqlDataDatabase;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+
+public class NoSqlObjectStoreTest_interactWith_db {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+    
+    @Mock
+    private NoSqlDataDatabase db;
+    
+    @Mock
+    private VersionCreator versionCreator;
+
+    @Mock
+    private PersistenceCommand command;
+
+    @Mock
+    private ObjectSpecification cusSpecification;
+
+    @Mock
+    private ObjectSpecification serviceSpecification;
+
+    @Mock
+    private ObjectAdapter cusAdapter;
+
+    private final ObjectSpecId cusSpecId = ObjectSpecId.of("CUS");
+    private RootOid cusRootOid = RootOidDefault.create(cusSpecId, "3");
+
+    final ObjectSpecId serviceSpecId = ObjectSpecId.of("service");
+
+    private Map<String, DataEncryption> dataEncrypter = Maps.newHashMap();
+
+    private NoSqlObjectStore store;
+
+
+
+
+
+    @Before
+    public void setup() {
+        org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
+
+        context.checking(new Expectations() {
+            {
+                // in the constructor of the object store
+                one(db).open();
+                one(db).containsData();
+                will(returnValue(false));
+                one(db).close();
+
+                allowing(cusAdapter).getOid();
+                will(returnValue(cusRootOid));
+
+                allowing(cusAdapter).getSpecification();
+                will(returnValue(cusSpecification));
+
+                allowing(cusSpecification).getSpecId();
+                will(returnValue(cusSpecId));
+
+                allowing(serviceSpecification).getSpecId();
+                will(returnValue(serviceSpecId));
+            }
+        });
+
+        store = new NoSqlObjectStore(db, new OidGenerator(new NoSqlIdentifierGenerator(db)), versionCreator, null, dataEncrypter);
+    }
+
+    @Test
+    public void open() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).open();
+            }
+        });
+        store.open();
+    }
+
+    @Test
+    public void close() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).close();
+            }
+        });
+        store.close();
+    }
+
+    @Test
+    public void registerService() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).addService(serviceSpecId, "4");
+            }
+        });
+        store.registerService(RootOidDefault.create(serviceSpecId, "4"));
+    }
+
+    @Test
+    public void oidForService() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).getService(serviceSpecId);
+                will(returnValue("4"));
+            }
+        });
+        store.getOidForService(serviceSpecification);
+    }
+
+    @Test
+    public void hasInstances() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(db).hasInstances(cusSpecification.getSpecId());
+                will(returnValue(true));
+            }
+        });
+        store.hasInstances(cusSpecification);
+    }
+
+    @Test
+    public void execute() throws Exception {
+        final List<PersistenceCommand> commands = new ArrayList<PersistenceCommand>();
+        commands.add(command);
+
+        context.checking(new Expectations() {
+            {
+                // Hone(command).execute(null); // REVIEW: DKH ... how was this expectation ever met?
+                one(db).write(commands);
+            }
+        });
+
+        store.execute(commands);
+    }
+
+    @Test
+    public void instances() throws Exception {
+        final PersistenceQuery persistenceQuery = context.mock(PersistenceQuery.class);
+        context.checking(new Expectations() {
+            {
+                one(persistenceQuery).getSpecification();
+                will(returnValue(cusSpecification));
+
+                one(db).instancesOf(cusSpecification.getSpecId());
+                will(returnIterator());
+                
+                allowing(cusSpecification).subclasses();
+            }
+        });
+
+        store.loadInstancesAndAdapt(persistenceQuery);
+    }
+
+    @Test
+    public void resolve() throws Exception {
+        final Sequence changingState = context.sequence("changingState");
+        context.checking(new Expectations() {
+            {
+                one(db).getInstance("3", cusSpecId);
+
+                allowing(cusAdapter).getResolveState();
+                inSequence(changingState);
+                will(returnValue(ResolveState.GHOST));
+
+                ignoring(cusSpecification);
+                
+                one(cusAdapter).changeState(ResolveState.RESOLVING);
+                inSequence(changingState);
+                one(cusAdapter).changeState(ResolveState.RESOLVED);
+                inSequence(changingState);
+                
+                one(cusAdapter).setVersion(null);
+            }
+        });
+        store.resolveImmediately(cusAdapter);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/WriteObjectCommandTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/WriteObjectCommandTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/WriteObjectCommandTest.java
new file mode 100644
index 0000000..5850846
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/WriteObjectCommandTest.java
@@ -0,0 +1,220 @@
+/*
+ *  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.objectstore.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.integtestsupport.IsisSystemWithFixtures;
+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.tck.dom.refs.ParentEntity;
+import org.apache.isis.core.tck.dom.refs.ReferencingEntity;
+import org.apache.isis.core.tck.dom.refs.SimpleEntity;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.apache.isis.objectstore.nosql.db.StateWriter;
+import org.apache.isis.objectstore.nosql.encryption.DataEncryption;
+import org.apache.isis.objectstore.nosql.versions.VersionCreator;
+
+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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/ChecksummingPerfomance.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/ChecksummingPerfomance.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/ChecksummingPerfomance.java
new file mode 100644
index 0000000..c932f46
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/ChecksummingPerfomance.java
@@ -0,0 +1,140 @@
+/*
+ *  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.objectstore.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.objectstore.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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/ClientConnectionTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/ClientConnectionTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/ClientConnectionTest.java
new file mode 100644
index 0000000..e373747
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/ClientConnectionTest.java
@@ -0,0 +1,124 @@
+/*
+ *  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.objectstore.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.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.lang.InputStreamExtensions;
+import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
+import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
+
+public class ClientConnectionTest {
+
+    private InputStream input;
+    private ByteArrayOutputStream output;
+    private ClientConnection connection;
+
+    @Before
+    public void setup() throws Exception {
+        org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
+
+        input = InputStreamExtensions.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 = InputStreamExtensions.asUtf8ByteStream("ok xx xx\n{data...}");
+        connection = new ClientConnection(input, output);
+        connection.validateRequest();
+    }
+
+    @Test(expected = RemotingException.class)
+    public void validateResponseError() throws Exception {
+        input = InputStreamExtensions.asUtf8ByteStream("error message about it\n");
+        connection = new ClientConnection(input, output);
+        connection.validateRequest();
+    }
+
+    @Test(expected = ObjectNotFoundException.class)
+    public void validateObjectNotFound() throws Exception {
+        input = InputStreamExtensions.asUtf8ByteStream("not-found message about it\n");
+        connection = new ClientConnection(input, output);
+        connection.validateRequest();
+    }
+
+    @Test(expected = ConcurrencyException.class)
+    public void validateConcurrencyException() throws Exception {
+        input = InputStreamExtensions.asUtf8ByteStream("concurrency message about it\n");
+        connection = new ClientConnection(input, output);
+        connection.validateRequest();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/JsonStateReaderTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/JsonStateReaderTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/JsonStateReaderTest.java
new file mode 100644
index 0000000..bbdb7d7
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/JsonStateReaderTest.java
@@ -0,0 +1,126 @@
+/*
+ *  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.objectstore.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.objectstore.nosql.db.StateReader;
+
+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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/JsonStateWriterTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/JsonStateWriterTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/JsonStateWriterTest.java
new file mode 100644
index 0000000..cdc8f8e
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/JsonStateWriterTest.java
@@ -0,0 +1,124 @@
+/*
+ *  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.objectstore.nosql.db.file;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.objectstore.nosql.db.StateWriter;
+
+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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/DataReaderTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/DataReaderTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/DataReaderTest.java
new file mode 100644
index 0000000..a3694ed
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/DataReaderTest.java
@@ -0,0 +1,84 @@
+/*
+ *  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.objectstore.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;
+
+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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/DataWriterTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/DataWriterTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/DataWriterTest.java
new file mode 100644
index 0000000..a6ec0e5
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/DataWriterTest.java
@@ -0,0 +1,106 @@
+/*
+ *  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.objectstore.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.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+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 {
+        org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/FileServerTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/FileServerTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/FileServerTest.java
new file mode 100644
index 0000000..abd1a86
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/FileServerTest.java
@@ -0,0 +1,280 @@
+/*
+ *  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.objectstore.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.InputStreamExtensions;
+
+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 = InputStreamExtensions.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 = InputStreamExtensions.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 = InputStreamExtensions.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 = InputStreamExtensions.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 = InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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(InputStreamExtensions.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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/LockManagerTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/LockManagerTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/LockManagerTest.java
new file mode 100644
index 0000000..cdf12d3
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/LockManagerTest.java
@@ -0,0 +1,55 @@
+/*
+ *  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.objectstore.nosql.db.file.server;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/LogWriterTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/LogWriterTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/LogWriterTest.java
new file mode 100644
index 0000000..f4573f2
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/file/server/LogWriterTest.java
@@ -0,0 +1,108 @@
+/*
+ *  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.objectstore.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;
+
+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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/DemoMongo.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/DemoMongo.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/DemoMongo.java
new file mode 100644
index 0000000..92db8f0
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/DemoMongo.java
@@ -0,0 +1,81 @@
+/*
+ *  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.objectstore.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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoIntegrationTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoIntegrationTest.java
new file mode 100644
index 0000000..09a58aa
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoIntegrationTest.java
@@ -0,0 +1,112 @@
+/*
+ *  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.objectstore.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.integtestsupport.IsisSystemWithFixtures;
+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.objectstore.nosql.keys.KeyCreatorDefault;
+
+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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoStateReaderIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoStateReaderIntegrationTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoStateReaderIntegrationTest.java
new file mode 100644
index 0000000..af77921
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoStateReaderIntegrationTest.java
@@ -0,0 +1,128 @@
+/*
+ *  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.objectstore.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.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 {
+        org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.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/680f0c8d/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoStateWriterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoStateWriterIntegrationTest.java b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoStateWriterIntegrationTest.java
new file mode 100644
index 0000000..a628389
--- /dev/null
+++ b/mothballed/component/objectstore/nosql/src/test/java/org/apache/isis/objectstore/nosql/db/mongo/MongoStateWriterIntegrationTest.java
@@ -0,0 +1,129 @@
+/*
+ *  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.objectstore.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.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 {
+        org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.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"));
+    }
+
+}