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 01:01:08 UTC
[46/52] [partial] ISIS-188: renaming packages in line with
groupId:artifactId
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/tck/ObjectStoreContractTest_persist.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/tck/ObjectStoreContractTest_persist.java b/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/tck/ObjectStoreContractTest_persist.java
deleted file mode 100644
index b70d221..0000000
--- a/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/tck/ObjectStoreContractTest_persist.java
+++ /dev/null
@@ -1,171 +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.testsupport.tck;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-
-import java.util.Date;
-import java.util.List;
-
-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.oid.RootOid;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStoreSpi;
-import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByTitle;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
-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.SimpleEntity;
-
-public abstract class ObjectStoreContractTest_persist {
-
- @Rule
- public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder()
- .with(createPersistenceMechanismInstaller())
- .with(iswfListener()).build();
-
-
- /**
- * Mandatory hook.
- */
- protected abstract PersistenceMechanismInstaller createPersistenceMechanismInstaller();
-
- protected IsisSystemWithFixtures.Listener iswfListener() {
- return null;
- }
-
- /**
- * hook method
- */
- protected void resetPersistenceStore() {
- }
-
- protected ObjectAdapter epv2Adapter;
- protected ObjectSpecification epvSpecification;
-
- protected ObjectStoreSpi getStore() {
- PersistenceSession psos = IsisContext.getPersistenceSession();
- return (ObjectStoreSpi) psos.getObjectStore();
- }
-
-
- @Before
- public void setUpFixtures() throws Exception {
- epv2Adapter = iswf.adapterFor(iswf.fixtures.smpl2);
- epvSpecification = iswf.loadSpecification(SimpleEntity.class);
- }
-
-
- @Test
- public void getInstances_usingFindByTitle() throws Exception {
-
- // given nothing in DB
- resetPersistenceStore();
-
- // when search for any object
- boolean hasInstances = getStore().hasInstances(epvSpecification);
-
- // then find none
- assertFalse(hasInstances);
-
- // given now persisted
- final SimpleEntity epv2 = iswf.fixtures.smpl2;
- epv2.setName("foo");
- epv2.setDate(new Date());
- epv2.setNullable(1234567890L);
- epv2.setSize(123);
-
- iswf.persist(epv2);
-
- iswf.bounceSystem();
-
- // when search for object
- List<ObjectAdapter> retrievedInstance = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, epv2Adapter.titleString()));
-
- // then find
- assertEquals(1, retrievedInstance.size());
- final ObjectAdapter retrievedAdapter = retrievedInstance.get(0);
-
- assertNotSame(epv2Adapter, retrievedAdapter);
- assertEquals(((SimpleEntity)epv2Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
- assertEquals(epv2Adapter.getOid(), retrievedAdapter.getOid());
-
- // and when search for some other title
- retrievedInstance = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, "some other title"));
-
- // then don't find
- assertEquals(0, retrievedInstance.size());
- }
-
-
- @Test
- public void updateInstance() throws Exception {
-
- // given persisted
- resetPersistenceStore();
- ObjectAdapter adapter = iswf.persist(iswf.fixtures.smpl2);
- final RootOid oid = (RootOid) adapter.getOid();
- iswf.bounceSystem();
-
- // when change
- adapter = iswf.reload(oid);
-
- SimpleEntity epv = (SimpleEntity) adapter.getObject();
- epv.setName("changed");
-
- iswf.bounceSystem();
-
- // then found
- List<ObjectAdapter> retrievedInstance = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, adapter.titleString()));
- assertEquals(1, retrievedInstance.size());
-
- final ObjectAdapter retrievedAdapter = retrievedInstance.get(0);
- assertNotSame(adapter, retrievedAdapter);
- assertEquals(((SimpleEntity)adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
- assertEquals(adapter.getOid(), retrievedAdapter.getOid());
- }
-
- @Test
- public void removeInstance() throws Exception {
-
- // given persisted
- resetPersistenceStore();
- ObjectAdapter adapter = iswf.persist(iswf.fixtures.smpl2);
- final RootOid oid = (RootOid) adapter.getOid();
- iswf.bounceSystem();
-
- // when destroy
- adapter = iswf.reload(oid);
-
- SimpleEntity epv = (SimpleEntity) adapter.getObject();
- iswf.destroy(epv);
- iswf.bounceSystem();
-
- // then not found
- assertEquals(false, getStore().hasInstances(epvSpecification));
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java b/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java
new file mode 100644
index 0000000..dd069b0
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.core.integtestsupport;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.tck.dom.scalars.JdkValuedEntity;
+
+public class IsisSystemWithFixturesTest_basicTest {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ @Test
+ public void savePojo() throws Exception {
+
+ assertThat(iswf.container.allInstances(JdkValuedEntity.class).size(), is(0));
+
+ iswf.container.persist(iswf.fixtures.jve1);
+
+ assertThat(iswf.container.allInstances(JdkValuedEntity.class).size(), is(1));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/persistence/PersistorSessionHydratorTest.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/persistence/PersistorSessionHydratorTest.java b/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/persistence/PersistorSessionHydratorTest.java
new file mode 100644
index 0000000..9502da1
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/persistence/PersistorSessionHydratorTest.java
@@ -0,0 +1,119 @@
+/*
+ * 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.core.integtestsupport.persistence;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.jmock.Expectations;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures.Fixtures.Initialization;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+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.objectstore.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.system.persistence.IdentifierGenerator;
+import org.apache.isis.core.tck.dom.refs.ParentEntityRepository;
+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;
+
+public class PersistorSessionHydratorTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private RootOid epvTransientOid = RootOidDefault.deString("!SMPL:-999", new OidMarshaller());
+
+ private IdentifierGenerator mockIdentifierGenerator = context.mock(IdentifierGenerator.class);
+ {
+ context.checking(new Expectations() {
+ {
+ allowing(mockIdentifierGenerator).createTransientIdentifierFor(with(equalTo(ObjectSpecId.of("ParentEntities"))), with(an(ParentEntityRepository.class)));
+ will(returnValue("1"));
+ allowing(mockIdentifierGenerator).createPersistentIdentifierFor(with(equalTo(ObjectSpecId.of("ParentEntities"))), with(an(ParentEntityRepository.class)), with(any(RootOid.class)));
+ will(returnValue("1"));
+
+ allowing(mockIdentifierGenerator).createTransientIdentifierFor(with(equalTo(ObjectSpecId.of("SMPL"))), with(an(SimpleEntity.class)));
+ will(returnValue("-999"));
+
+ allowing(mockIdentifierGenerator).createPersistentIdentifierFor(with(equalTo(ObjectSpecId.of("SMPL"))), with(an(SimpleEntity.class)), with(any(RootOid.class)));
+ will(returnValue("1"));
+ }
+ });
+ }
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder()
+ .with(Initialization.NO_INIT)
+ .with(new InMemoryPersistenceMechanismInstaller() {
+ public IdentifierGenerator createIdentifierGenerator(IsisConfiguration configuration) {
+ return mockIdentifierGenerator;
+ };
+ })
+ .build();
+
+
+ @Test
+ public void adaptorFor_whenTransient() {
+ // given
+ iswf.fixtures.smpl1 = iswf.container.newTransientInstance(SimpleEntity.class);
+
+ // when
+ final ObjectAdapter adapter = iswf.adapterFor(iswf.fixtures.smpl1);
+
+ // then
+ assertEquals(epvTransientOid, adapter.getOid());
+ assertEquals(iswf.fixtures.smpl1, adapter.getObject());
+ assertEquals(ResolveState.TRANSIENT, adapter.getResolveState());
+ assertEquals(null, adapter.getVersion());
+ }
+
+ @Test
+ public void recreateAdapter_whenPersistent() throws Exception {
+
+ // given persisted object
+ iswf.fixtures.smpl1 = iswf.container.newTransientInstance(SimpleEntity.class);
+ iswf.fixtures.smpl1.setName("Fred");
+ iswf.persist(iswf.fixtures.smpl1);
+ iswf.tearDownSystem();
+ iswf.setUpSystem();
+
+ // when
+ final RootOidDefault oid = RootOidDefault.deString("SMPL:1", new OidMarshaller());
+ final ObjectAdapter adapter = iswf.recreateAdapter(oid);
+
+ // then
+ assertEquals(oid, adapter.getOid());
+ assertEquals(ResolveState.GHOST, adapter.getResolveState());
+
+ final SimpleEntity epv = (SimpleEntity)adapter.getObject();
+ assertEquals("Fred", epv.getName());
+ assertNotNull(adapter.getVersion());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/persistence/RuntimeTestPojo.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/persistence/RuntimeTestPojo.java b/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/persistence/RuntimeTestPojo.java
new file mode 100644
index 0000000..9b570a0
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/persistence/RuntimeTestPojo.java
@@ -0,0 +1,52 @@
+/*
+ * 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.core.integtestsupport.persistence;
+
+public class RuntimeTestPojo {
+
+ private static int nextId;
+ private final int id = nextId++;
+ private final String state = "pojo" + id;
+
+ @Override
+ public String toString() {
+ return "Pojo#" + id;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (other == this) {
+ return true;
+ }
+ if (other.getClass() == getClass()) {
+ final RuntimeTestPojo otherTestPojo = (RuntimeTestPojo) other;
+ return otherTestPojo.state.equals(state);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return state.hashCode();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_debug.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_debug.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_debug.java
new file mode 100644
index 0000000..7998135
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_debug.java
@@ -0,0 +1,79 @@
+/*
+ * 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.core.objectstore;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.core.commons.debug.DebugString;
+import org.apache.isis.core.commons.matchers.IsisMatchers;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.objectstore.InMemoryObjectStore;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class InMemoryObjectStoreTest_debug {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ private static InMemoryObjectStore getStore() {
+ return (InMemoryObjectStore) IsisContext.getPersistenceSession().getObjectStore();
+ }
+
+ @Test
+ public void debugTitle() throws Exception {
+
+ // when
+ final String debugTitle = getStore().debugTitle();
+
+ // then
+ assertThat(debugTitle, is("In-Memory Object Store"));
+ }
+
+
+ @Test
+ public void debugXxx_whenHasObject() throws Exception {
+
+ // given
+ iswf.persist(iswf.fixtures.smpl1);
+
+ // when
+ final DebugString debug = new DebugString();
+ getStore().debugData(debug);
+
+
+ // then
+ assertThat(debug.toString(), IsisMatchers.containsStripNewLines("SMPL:2"));
+ }
+
+
+ @Test
+ public void testEmpty() throws Exception {
+
+ // when
+ final DebugString debug = new DebugString();
+ getStore().debugData(debug);
+
+ // then
+ assertThat(debug.toString(), is("\nDomain Objects\n--------------\n\n"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_init.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_init.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_init.java
new file mode 100644
index 0000000..5e65de3
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_init.java
@@ -0,0 +1,45 @@
+/*
+ * 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.core.objectstore;
+
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.objectstore.InMemoryObjectStore;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+
+public class InMemoryObjectStoreTest_init {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ private static InMemoryObjectStore getStore() {
+ return (InMemoryObjectStore) IsisContext.getPersistenceSession().getObjectStore();
+ }
+
+ @Test
+ public void testStartsUpInUnitializedSate() throws Exception {
+ assertFalse(getStore().isFixturesInstalled());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_name.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_name.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_name.java
new file mode 100644
index 0000000..0192537
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_name.java
@@ -0,0 +1,42 @@
+/*
+ * 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.core.objectstore;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.isis.core.objectstore.InMemoryObjectStore;
+import org.junit.Before;
+import org.junit.Test;
+
+public class InMemoryObjectStoreTest_name {
+
+ private InMemoryObjectStore store;
+
+ @Before
+ public void setUp() throws Exception {
+ store = new InMemoryObjectStore();
+ }
+
+ @Test
+ public void testName() throws Exception {
+ assertEquals("In-Memory Object Store", store.name());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_openAndClose.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_openAndClose.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_openAndClose.java
new file mode 100644
index 0000000..4703d5d
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_openAndClose.java
@@ -0,0 +1,122 @@
+/*
+ * 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.core.objectstore;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.objectstore.InMemoryObjectStore;
+import org.apache.isis.core.objectstore.InMemoryPersistenceSessionFactory;
+import org.apache.isis.core.objectstore.internal.ObjectStorePersistedObjects;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.core.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+
+/**
+ * Tested in style of <i>Working Effectively with Legacy Code</i> (Feathers) and
+ * <i>Growing Object-Oriented Software</i> (Freeman & Pryce).
+ */
+public class InMemoryObjectStoreTest_openAndClose {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ @Mock
+ private InMemoryPersistenceSessionFactory mockInMemoryPersistenceSessionFactory;
+ @Mock
+ private PersistenceSession mockPersistenceSession;
+ @Mock
+ private ObjectStorePersistedObjects mockObjectStorePersistedObjects;
+
+ private boolean recreatedAdapters = false;
+
+ private InMemoryObjectStore objectStore;
+
+ @Before
+ public void setUp() throws Exception {
+ objectStore = new InMemoryObjectStore() {
+ @Override
+ protected InMemoryPersistenceSessionFactory getInMemoryPersistenceSessionFactory() {
+ return mockInMemoryPersistenceSessionFactory;
+ }
+
+ @Override
+ protected PersistenceSession getPersistenceSession() {
+ return mockPersistenceSession;
+ }
+
+ @Override
+ protected void recreateAdapters() {
+ recreatedAdapters = true;
+ }
+ };
+ }
+
+ @Test
+ public void whenOpenForFirstTimeThenCreatesPersistedObjects() throws Exception {
+ context.never(mockPersistenceSession);
+ context.checking(new Expectations() {
+ {
+ one(mockInMemoryPersistenceSessionFactory).getPersistedObjects();
+ will(returnValue(null));
+
+ one(mockInMemoryPersistenceSessionFactory).createPersistedObjects();
+ will(returnValue(mockObjectStorePersistedObjects));
+ }
+ });
+ objectStore.open();
+ }
+
+ @Test
+ public void whenOpenSubsequentlyThenObtainsPersistedObjectsFromObjectStoreFactoryAndRecreatesAdapters() throws Exception {
+ context.never(mockPersistenceSession);
+ context.checking(new Expectations() {
+ {
+ one(mockInMemoryPersistenceSessionFactory).getPersistedObjects();
+ will(returnValue(mockObjectStorePersistedObjects));
+ }
+ });
+
+ assertThat(recreatedAdapters, is(false));
+ objectStore.open();
+ assertThat(recreatedAdapters, is(true));
+ }
+
+ @Test
+ public void whenCloseThenGivesObjectsBackToObjectStoreFactory() throws Exception {
+ context.never(mockPersistenceSession);
+ whenOpenSubsequentlyThenObtainsPersistedObjectsFromObjectStoreFactoryAndRecreatesAdapters();
+
+ context.checking(new Expectations() {
+ {
+ one(mockInMemoryPersistenceSessionFactory).attach(with(mockPersistenceSession), with(mockObjectStorePersistedObjects));
+ never(mockPersistenceSession);
+ }
+ });
+ objectStore.close();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_persist.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_persist.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_persist.java
new file mode 100644
index 0000000..03f46f9
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_persist.java
@@ -0,0 +1,38 @@
+/*
+ * 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.core.objectstore;
+
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures.Listener;
+import org.apache.isis.core.integtestsupport.tck.ObjectStoreContractTest_persist;
+import org.apache.isis.core.objectstore.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+
+public class InMemoryObjectStoreTest_persist extends ObjectStoreContractTest_persist {
+
+ @Override
+ protected PersistenceMechanismInstaller createPersistenceMechanismInstaller() {
+ return new InMemoryPersistenceMechanismInstaller();
+ }
+
+ @Override
+ protected Listener iswfListener() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_persistAggregated.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_persistAggregated.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_persistAggregated.java
new file mode 100644
index 0000000..20b9e6c
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_persistAggregated.java
@@ -0,0 +1,58 @@
+/*
+ * 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.core.objectstore;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures.Listener;
+import org.apache.isis.core.integtestsupport.tck.ObjectStoreContractTest_persist;
+import org.apache.isis.core.objectstore.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.core.tck.dom.refs.ReferencingEntity;
+
+public class InMemoryObjectStoreTest_persistAggregated {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder()
+ .with(createPersistenceMechanismInstaller())
+ .build();
+
+ protected PersistenceMechanismInstaller createPersistenceMechanismInstaller() {
+ return new InMemoryPersistenceMechanismInstaller();
+ }
+
+ @Test
+ public void persistAggregatedEntityWithinCollection() throws Exception {
+ final ReferencingEntity referencingEntity = iswf.fixtures.rfcg2;
+ referencingEntity.addAggregatedEntityToCollection().setName("Aggregated Entity #1");
+ iswf.persist(referencingEntity);
+ }
+
+
+ @Test
+ public void persistAggregatedEntityWithinProperty() throws Exception {
+ final ReferencingEntity referencingEntity = iswf.fixtures.rfcg2;
+ referencingEntity.addAggregatedReference().setName("Aggregated Entity #1");
+ iswf.persist(referencingEntity);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_reset.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_reset.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_reset.java
new file mode 100644
index 0000000..bdfb304
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_reset.java
@@ -0,0 +1,82 @@
+/*
+ * 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.core.objectstore;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+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.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.objectstore.InMemoryObjectStore;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.core.tck.dom.refs.SimpleEntity;
+
+/**
+ * This is really just a test of the test infrastructure, not a real test per se.
+ */
+public class InMemoryObjectStoreTest_reset {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ protected ObjectAdapter epv2Adapter;
+ protected ObjectSpecification epvSpecification;
+
+ protected InMemoryObjectStore getStore() {
+ return (InMemoryObjectStore) IsisContext.getPersistenceSession().getObjectStore();
+ }
+
+ @Before
+ public void setUpFixtures() throws Exception {
+ epv2Adapter = iswf.adapterFor(iswf.fixtures.smpl2);
+ epvSpecification = iswf.loadSpecification(SimpleEntity.class);
+ }
+
+ @Test
+ public void reset_clearsAdapterFromLoader() throws Exception {
+
+ iswf.persist(iswf.fixtures.smpl2);
+ iswf.bounceSystem();
+
+ assertNotNull(getAdapterManager().getAdapterFor(epv2Adapter.getObject()));
+
+ IsisContext.getPersistenceSession().testReset();
+
+ assertNull(getAdapterManager().getAdapterFor(epv2Adapter.getObject()));
+ }
+
+
+ private PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+ private AdapterManager getAdapterManager() {
+ return getPersistenceSession().getAdapterManager();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_retrieve.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_retrieve.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_retrieve.java
new file mode 100644
index 0000000..f9bcf51
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_retrieve.java
@@ -0,0 +1,143 @@
+/*
+ * 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.core.objectstore;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.fail;
+
+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.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.oid.TypedOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.objectstore.InMemoryObjectStore;
+import org.apache.isis.core.runtime.persistence.ObjectNotFoundException;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindAllInstances;
+import org.apache.isis.core.runtime.persistence.query.PersistenceQueryFindByTitle;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.tck.dom.refs.SimpleEntity;
+
+public class InMemoryObjectStoreTest_retrieve {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ protected ObjectAdapter epv2Adapter;
+ protected ObjectSpecification epvSpecification;
+
+ protected InMemoryObjectStore getStore() {
+ return (InMemoryObjectStore) IsisContext.getPersistenceSession().getObjectStore();
+ }
+
+ @Before
+ public void setUpFixtures() throws Exception {
+ epv2Adapter = iswf.adapterFor(iswf.fixtures.smpl2);
+ epvSpecification = iswf.loadSpecification(SimpleEntity.class);
+ }
+
+ @Test
+ public void getObject_whenDoesNotExist() {
+ final TypedOid oid = RootOidDefault.deString("SMPL:10", new OidMarshaller());
+ try {
+ getStore().loadInstanceAndAdapt(oid);
+ fail();
+ } catch (final ObjectNotFoundException expected) {
+ }
+ }
+
+ @Test
+ public void getObject_whenExists_returnsAdapter() throws Exception {
+
+ // given
+ iswf.persist(iswf.fixtures.smpl2);
+ iswf.bounceSystem();
+
+ final ObjectAdapter retrievedAdapter = getStore().loadInstanceAndAdapt((TypedOid) epv2Adapter.getOid());
+
+ assertNotSame(epv2Adapter, retrievedAdapter);
+ assertEquals(((SimpleEntity)epv2Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
+ assertEquals(epv2Adapter.getOid(), retrievedAdapter.getOid());
+ }
+
+ @Test
+ public void getInstances_whenDoesNotExist() throws Exception {
+ final List<ObjectAdapter> retrievedAdapters = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, epv2Adapter.titleString()));
+ assertEquals(0, retrievedAdapters.size());
+ }
+
+ @Test
+ public void getInstances_findByTitle() throws Exception {
+ // given
+ iswf.persist(iswf.fixtures.smpl2);
+ iswf.bounceSystem();
+
+ // when
+ final List<ObjectAdapter> retrievedAdapters = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, epv2Adapter.titleString()));
+
+ // then
+ assertEquals(1, retrievedAdapters.size());
+ final ObjectAdapter retrievedAdapter = retrievedAdapters.get(0);
+
+ assertNotSame(epv2Adapter, retrievedAdapter);
+ assertEquals(((SimpleEntity)epv2Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
+ assertEquals(epv2Adapter.getOid(), retrievedAdapter.getOid());
+ }
+
+ @Test
+ public void getInstances_findAll() throws Exception {
+ // given
+ iswf.persist(iswf.fixtures.smpl2);
+ iswf.bounceSystem();
+
+ // when
+ final List<ObjectAdapter> retrievedAdapters = getStore().loadInstancesAndAdapt(new PersistenceQueryFindAllInstances(epvSpecification));
+
+ // then
+ assertEquals(1, retrievedAdapters.size());
+ final ObjectAdapter retrievedAdapter = retrievedAdapters.get(0);
+
+ assertNotSame(epv2Adapter, retrievedAdapter);
+ assertEquals(((SimpleEntity)epv2Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
+ assertEquals(epv2Adapter.getOid(), retrievedAdapter.getOid());
+ }
+
+ @Test
+ public void hasInstances_whenEmpty() throws Exception {
+ assertEquals(false, getStore().hasInstances(epvSpecification));
+ }
+
+ @Test
+ public void hasInstances_whenHasSome() throws Exception {
+ iswf.persist(iswf.fixtures.smpl2);
+ iswf.bounceSystem();
+
+ assertEquals(true, getStore().hasInstances(epvSpecification));
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_serviceRegistry.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_serviceRegistry.java b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_serviceRegistry.java
new file mode 100644
index 0000000..43b5072
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/objectstore/InMemoryObjectStoreTest_serviceRegistry.java
@@ -0,0 +1,115 @@
+/*
+ * 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.core.objectstore;
+
+import static org.junit.Assert.assertEquals;
+
+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.adapter.oid.Oid;
+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.objectstore.InMemoryObjectStore;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.tck.dom.refs.ParentEntityRepository;
+import org.apache.isis.core.tck.dom.refs.SimpleEntity;
+
+public class InMemoryObjectStoreTest_serviceRegistry {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ protected ObjectAdapter epv2Adapter;
+ protected ObjectSpecification epvSpecification;
+
+ protected InMemoryObjectStore getStore() {
+ return (InMemoryObjectStore) IsisContext.getPersistenceSession().getObjectStore();
+ }
+
+ @Before
+ public void setUpFixtures() throws Exception {
+ epv2Adapter = iswf.adapterFor(iswf.fixtures.smpl2);
+ epvSpecification = iswf.loadSpecification(SimpleEntity.class);
+ }
+
+ @Test
+ public void getOidForServices() throws Exception {
+ final Oid oidForService = getStore().getOidForService(iswf.loadSpecification(ParentEntityRepository.class));
+ assertEquals(RootOidDefault.create(ObjectSpecId.of("ParentEntities"), "1"), oidForService);
+ }
+
+
+// @Test
+// public void registerService_canBeRetrieved() throws Exception {
+// registerService14();
+//
+// final Oid oidForService = store.getOidForService(serviceSpecification);
+// assertEquals(oid14, oidForService);
+// }
+//
+// @Test
+// public void testCantRegisterServiceMoreThanOnce() throws Exception {
+// registerService14();
+// try {
+// registerService14();
+// fail();
+// } catch (final IsisException expected) {
+// }
+// }
+//
+// @Test
+// public void testCanRegisterMoreThanOneService() throws Exception {
+// registerService14();
+// registerService15();
+// }
+//
+//
+// private void resetIdentityMap() {
+// IsisContext.getPersistenceSession().testReset();
+// }
+//
+// protected void addObjectToStore(final ObjectAdapter object) {
+// final PersistenceCommand command = store.createCreateObjectCommand(object);
+// assertEquals(object, command.onObject());
+// store.execute(Collections.<PersistenceCommand> singletonList(command));
+// }
+//
+// private RootOidDefault registerService14() {
+// return oid14 = registerService(""+14);
+// }
+//
+// private RootOidDefault registerService15() {
+// return registerService(""+15);
+// }
+//
+// private RootOidDefault registerService(final String id) {
+// final RootOidDefault oid = RootOidDefault.createPersistent("SVC", id);
+// store.registerService(oid);
+// resetIdentityMap();
+// return oid;
+// }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureFilePersistorTest.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureFilePersistorTest.java b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureFilePersistorTest.java
new file mode 100644
index 0000000..62e3084
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureFilePersistorTest.java
@@ -0,0 +1,212 @@
+/*
+ * 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.core.runtime.fixturedomainservice;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+import static org.junit.Assume.assumeThat;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.text.SimpleDateFormat;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+import java.util.TimeZone;
+
+import junit.framework.Assert;
+
+import com.google.common.collect.Sets;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+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.config.IsisConfigurationDefault;
+import org.apache.isis.core.commons.matchers.IsisMatchers;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.runtime.fixturedomainservice.FixtureException;
+import org.apache.isis.core.runtime.fixturedomainservice.ObjectFixtureFilePersistor;
+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;
+
+public class ObjectFixtureFilePersistorTest {
+
+ private static final String DATEFORMAT_PATTERN = "dd-MMM-yyyy HH:mm z";
+
+ private static final SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT_PATTERN);
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder()
+ .with(configuration()).build();
+
+ private static IsisConfiguration configuration() {
+ final IsisConfigurationDefault config = new IsisConfigurationDefault();
+ config.add("isis.value.format.datetime", DATEFORMAT_PATTERN);
+ return config;
+ }
+
+ private ObjectFixtureFilePersistor persistor;
+
+ @Before
+ public void setup() throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ Locale.setDefault(Locale.UK);
+
+ persistor = new ObjectFixtureFilePersistor();
+
+ iswf.fixtures.smpl1.setName("Fred Smith");
+ iswf.fixtures.smpl1.setDate(dateFormat.parse("08-Mar-2010 01:00 UTC"));
+
+ iswf.fixtures.smpl2.setName("Joe Bloggs");
+ iswf.fixtures.smpl2.setDate(dateFormat.parse("09-Apr-2011 02:10 UTC"));
+
+ assumeThat(TimeZone.getDefault().getDisplayName(), is("Greenwich Mean Time"));
+ }
+
+
+ @Test
+ public void loadInstance() throws Exception {
+
+ final StringReader reader = new StringReader(SimpleEntity.class.getName() + "#1\n name: Fred Smith\n date: 08-Mar-2010 01:00 UTC");
+ final Set<Object> objects = persistor.loadData(reader);
+
+ assertEquals(1, objects.size());
+ final Object object = objects.toArray()[0];
+ assertThat(object instanceof SimpleEntity, is(true));
+ final SimpleEntity epv = (SimpleEntity) object;
+ assertEquals("Fred Smith", epv.getName());
+
+ assertEquals(dateFormat.parse("08-Mar-2010 01:00 GMT"), epv.getDate());
+ }
+
+ @Test
+ public void invalidFieldLine() throws Exception {
+ try {
+ final StringReader reader = new StringReader(SimpleEntity.class.getName() + "#1\n name Fred Smith");
+ persistor.loadData(reader);
+ Assert.fail();
+ } catch (final FixtureException e) {
+ Assert.assertEquals("failed to load data at line 2", e.getMessage());
+ Assert.assertEquals("no colon (:) in: name Fred Smith", e.getCause().getMessage());
+ }
+ }
+
+ @Test
+ public void oldFieldNameSkipped() throws Exception {
+ final StringReader reader = new StringReader(SimpleEntity.class.getName() + "#1\n xname: Fred Smith");
+ final Set<Object> objects = persistor.loadData(reader);
+ final Object object = objects.toArray()[0];
+ Assert.assertNull(((SimpleEntity) object).getName());
+
+ }
+
+ @Test
+ public void saveNoObjects() throws Exception {
+ // Person person = new Person();
+ final Set<Object> objects = new HashSet<Object>();
+ final StringWriter out = new StringWriter();
+ persistor.save(objects, out);
+ Assert.assertEquals("", out.toString());
+ }
+
+ @Test
+ public void saveOneObject() throws Exception {
+ final Set<Object> objects = Sets.newLinkedHashSet();
+ objects.add(iswf.fixtures.smpl1);
+
+ final StringWriter out = new StringWriter();
+ persistor.save(objects, out);
+ final String actual = out.toString().replaceAll("\r\n", "\n");
+
+ final String expected = SimpleEntity.class.getName() + "#2\n date: 08-Mar-2010 01:00 UTC\n name: Fred Smith\n";
+
+ assertThat(actual, IsisMatchers.startsWith(expected));
+ }
+
+ @Test
+ public void saveTwoObjects() throws Exception {
+ final Set<Object> objects = Sets.newLinkedHashSet();
+ objects.add(iswf.fixtures.smpl1);
+ objects.add(iswf.fixtures.smpl3);
+
+ final StringWriter out = new StringWriter();
+ persistor.save(objects, out);
+ final String actual = out.toString().replaceAll("\r\n", "\n");
+
+ final String expected1 = SimpleEntity.class.getName() + "#2\n date: 08-Mar-2010 01:00 UTC\n name: Fred Smith\n";
+ final String expected2 = SimpleEntity.class.getName() + "#3\n date: \n name: \n";
+ assertThat(actual, IsisMatchers.contains(expected1));
+ assertThat(actual, IsisMatchers.contains(expected2));
+ }
+
+ @Test
+ public void saveReferencedObject() throws Exception {
+
+ final Set<Object> objects = Sets.newLinkedHashSet();
+
+ iswf.fixtures.rfcg1.setReference(iswf.fixtures.smpl1);
+ objects.add(iswf.fixtures.rfcg1);
+ objects.add(iswf.fixtures.smpl1);
+
+ final StringWriter out = new StringWriter();
+ persistor.save(objects, out);
+ final String actual = out.toString().replaceAll("\r\n", "\n");
+
+ final String expected1 = ReferencingEntity.class.getName() + "#2\n aggregatedEntities: \n aggregatedReference: \n reference: " + SimpleEntity.class.getName() + "#3";
+ final String expected2 = SimpleEntity.class.getName() + "#3\n date: 08-Mar-2010 01:00 UTC\n name: Fred Smith\n";
+ assertThat(actual, IsisMatchers.contains(expected1));
+ assertThat(actual, IsisMatchers.contains(expected2));
+ }
+
+
+ @Test
+ public void saveObjectAndAssociatedCollection() throws Exception {
+
+ final Set<Object> objects = Sets.newLinkedHashSet();
+
+ iswf.fixtures.prnt1.getHomogeneousCollection().add(iswf.fixtures.smpl1);
+ iswf.fixtures.prnt1.getHomogeneousCollection().add(iswf.fixtures.smpl2);
+ objects.add(iswf.fixtures.prnt1);
+
+ objects.add(iswf.fixtures.smpl1);
+ objects.add(iswf.fixtures.smpl2);
+
+ final StringWriter out = new StringWriter();
+ persistor.save(objects, out);
+ final String actual = out.toString().replaceAll("\r\n", "\n");
+
+ final String expected1a = ParentEntity.class.getName() + "#2\n";
+ final String expected1b = "heterogeneousCollection: \n homogeneousCollection: " + SimpleEntity.class.getName() + "#3 " + SimpleEntity.class.getName() + "#4 " + "\n";
+ final String expected2 = SimpleEntity.class.getName() + "#3\n date: 08-Mar-2010 01:00 UTC\n name: Fred Smith\n";
+ final String expected3 = SimpleEntity.class.getName() + "#4\n date: 09-Apr-2011 02:10 UTC\n name: Joe Bloggs\n";
+ assertThat(actual.replaceAll("\n", "###"), IsisMatchers.contains(expected1a.replaceAll("\n", "###")));
+ assertThat(actual.replaceAll("\n", "###"), IsisMatchers.contains(expected1b.replaceAll("\n", "###")));
+ assertThat(actual, IsisMatchers.contains(expected2));
+ assertThat(actual, IsisMatchers.contains(expected3));
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_loadFile.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_loadFile.java b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_loadFile.java
new file mode 100644
index 0000000..19423fd
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_loadFile.java
@@ -0,0 +1,88 @@
+/*
+ * 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.core.runtime.fixturedomainservice;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.ConfigurationConstants;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.runtime.fixturedomainservice.ObjectFixtureService;
+import org.apache.isis.core.tck.dom.movies.Person;
+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;
+
+public class ObjectFixtureServiceTest_loadFile {
+
+ private static IsisConfiguration configuration() {
+ IsisConfigurationDefault configuration = new IsisConfigurationDefault();
+ configuration.add(ConfigurationConstants.ROOT + "exploration-objects.file", "test.data");
+ return configuration;
+ }
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().with(configuration()).build();
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private ObjectFixtureService service;
+
+
+ @Before
+ public void setup() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+ Locale.setDefault(Locale.UK);
+
+ service = new ObjectFixtureService();
+ }
+
+
+ @Test
+ public void loadFile() throws Exception {
+
+ // when
+ service.loadFile();
+
+ // then
+ final Set<Object> objects = service.allSavedObjects();
+ Assert.assertEquals(1, objects.size());
+ final Object object = objects.toArray()[0];
+ assertThat(object instanceof SimpleEntity, is(true));
+ Assert.assertEquals("Fred Smith", ((SimpleEntity) object).getName());
+ Assert.assertEquals(new Date(110, 2, 8, 13, 32), ((SimpleEntity) object).getDate());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_loadFile_nothingExists.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_loadFile_nothingExists.java b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_loadFile_nothingExists.java
new file mode 100644
index 0000000..c91f9ba
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_loadFile_nothingExists.java
@@ -0,0 +1,72 @@
+/*
+ * 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.core.runtime.fixturedomainservice;
+
+import java.io.File;
+import java.util.Locale;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.runtime.fixturedomainservice.ObjectFixtureService;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+
+public class ObjectFixtureServiceTest_loadFile_nothingExists {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private ObjectFixtureService service;
+
+
+ @Before
+ public void setup() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+ Locale.setDefault(Locale.UK);
+
+ service = new ObjectFixtureService();
+ deleteFixtureData();
+ }
+
+
+ private static void deleteFixtureData() {
+ new File("fixture-data").delete();
+ }
+
+ @Test
+ public void loadNothingIfNoFileExists() throws Exception {
+ service.loadFile();
+
+ final Set<Object> objects = service.allSavedObjects();
+ Assert.assertEquals(0, objects.size());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_save.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_save.java b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_save.java
new file mode 100644
index 0000000..c97f250
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/fixturedomainservice/ObjectFixtureServiceTest_save.java
@@ -0,0 +1,83 @@
+/*
+ * 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.core.runtime.fixturedomainservice;
+
+import java.io.File;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.runtime.fixturedomainservice.ObjectFixtureService;
+import org.apache.isis.core.tck.dom.refs.ParentEntity;
+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;
+
+public class ObjectFixtureServiceTest_save {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private ObjectFixtureService service;
+
+
+ @Before
+ public void setup() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+ Locale.setDefault(Locale.UK);
+
+ service = new ObjectFixtureService();
+ deleteFixtureData();
+ }
+
+
+ private static void deleteFixtureData() {
+ new File("fixture-data").delete();
+ }
+
+
+ @Test
+ public void saveObjectAddedToList() throws Exception {
+
+ final SimpleEntity epv = iswf.fixtures.smpl1;
+ epv.setName("Fred Smith");
+ epv.setDate(new Date(110, 2, 8, 13, 32));
+
+ final ParentEntity epc = iswf.fixtures.prnt1;
+ epc.getHomogeneousCollection().add(iswf.fixtures.smpl1);
+ epc.getHomogeneousCollection().add(iswf.fixtures.smpl2);
+ service.save(epc);
+
+ final Set<Object> savedObjects = service.allSavedObjects();
+ Assert.assertEquals(3, savedObjects.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest.java b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest.java
new file mode 100644
index 0000000..e9b2833
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest.java
@@ -0,0 +1,219 @@
+/*
+ * 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.core.runtime.memento;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.encoding.DataInputStreamExtended;
+import org.apache.isis.core.commons.encoding.DataOutputStreamExtended;
+import org.apache.isis.core.commons.encoding.FieldType;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.runtime.memento.Memento;
+import org.apache.isis.core.tck.dom.refs.BaseEntity;
+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;
+
+public class MementoTest {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ private ObjectAdapter originalAdapterForEpv1;
+ private ObjectAdapter originalAdapterForEpr1;
+ private ObjectAdapter originalAdapterForEpc1;
+
+ private ObjectAdapter recreatedAdapter;
+
+ private Memento mementoForEpv1;
+ private Memento mementoForEpr1;
+ private Memento mementoForEpc1;
+
+ private byte[] bytesForEpv1;
+ private byte[] bytesForEpr1;
+ private byte[] bytesForEpc1;
+
+ private ByteArrayInputStream bais;
+
+
+ @Before
+ public void setUpSystem() throws Exception {
+
+// final Logger logger = Logger.getLogger(FieldType.class);
+// logger.setLevel(Level.DEBUG);
+// logger.addAppender(new ConsoleAppender());
+// BasicConfigurator.configure();
+
+ iswf.fixtures.smpl1.setName("Fred");
+ iswf.fixtures.smpl2.setName("Harry");
+
+ iswf.fixtures.rfcg1_a1.setName("Tom");
+
+ iswf.fixtures.rfcg1.setReference(iswf.fixtures.smpl1);
+ iswf.fixtures.rfcg1.setAggregatedReference(iswf.fixtures.rfcg1_a1);
+
+ iswf.fixtures.prnt1.getHomogeneousCollection().add(iswf.fixtures.smpl1);
+ iswf.fixtures.prnt1.getHomogeneousCollection().add(iswf.fixtures.smpl2);
+
+ iswf.fixtures.prnt1.getHeterogeneousCollection().add(iswf.fixtures.smpl1);
+ iswf.fixtures.prnt1.getHeterogeneousCollection().add(iswf.fixtures.rfcg1);
+
+ originalAdapterForEpv1 = iswf.adapterFor(iswf.fixtures.smpl1);
+ originalAdapterForEpr1 = iswf.adapterFor(iswf.fixtures.rfcg1);
+ originalAdapterForEpc1 = iswf.adapterFor(iswf.fixtures.prnt1);
+
+ mementoForEpv1 = new Memento(originalAdapterForEpv1);
+ mementoForEpr1 = new Memento(originalAdapterForEpr1);
+ mementoForEpc1 = new Memento(originalAdapterForEpc1);
+
+ bytesForEpv1 = toBytes(mementoForEpv1);
+ bytesForEpr1 = toBytes(mementoForEpr1);
+ bytesForEpc1 = toBytes(mementoForEpc1);
+
+ iswf.tearDownSystem();
+
+// logger.debug("*************************************");
+
+ iswf.setUpSystem();
+
+ mementoForEpv1 = fromBytes(bytesForEpv1);
+ mementoForEpr1 = fromBytes(bytesForEpr1);
+ mementoForEpc1 = fromBytes(bytesForEpc1);
+ }
+
+
+ private Memento fromBytes(final byte[] bytes) throws IOException {
+ bais = new ByteArrayInputStream(bytes);
+ DataInputStreamExtended input = new DataInputStreamExtended(bais);
+ final Memento recreate = Memento.recreateFrom(input);
+ return recreate;
+ }
+
+
+ private static byte[] toBytes(final Memento memento) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStreamExtended output = new DataOutputStreamExtended(baos);
+ memento.encodedData(output);
+ return baos.toByteArray();
+ }
+
+
+ @Test
+ public void recreateObject_adaptersAreNotSame() throws Exception {
+
+ recreatedAdapter = mementoForEpv1.recreateObject();
+
+ assertNotSame(originalAdapterForEpv1, recreatedAdapter);
+ }
+
+ @Test
+ public void recreateObject_getOid_areEquals() throws Exception {
+ recreatedAdapter = mementoForEpv1.recreateObject();
+
+ assertEquals(originalAdapterForEpv1.getOid(), recreatedAdapter.getOid());
+ }
+
+ @Test
+ public void recreateObject_getSpecification_isSame() throws Exception {
+ recreatedAdapter = mementoForEpv1.recreateObject();
+
+ final ObjectSpecification specification = originalAdapterForEpv1.getSpecification();
+ final ObjectSpecification recreatedSpecification = recreatedAdapter.getSpecification();
+ assertSame(specification, recreatedSpecification);
+ }
+
+ @Test
+ public void recreateObject_valuePreserved() throws Exception {
+ recreatedAdapter = mementoForEpv1.recreateObject();
+ final SimpleEntity recreatedObject = (SimpleEntity)recreatedAdapter.getObject();
+ assertEquals("Fred", recreatedObject.getName());
+ }
+
+ @Test
+ public void recreateObject_referencePreserved() throws Exception {
+ recreatedAdapter = mementoForEpr1.recreateObject();
+ final ReferencingEntity recreatedObject = (ReferencingEntity)recreatedAdapter.getObject();
+ final SimpleEntity reference1 = recreatedObject.getReference();
+ assertNotNull(reference1);
+
+ assertThat("Fred", equalTo(reference1.getName()));
+ }
+
+ @Test
+ public void recreateObject_homogeneousCollectionPreserved() throws Exception {
+ recreatedAdapter = mementoForEpc1.recreateObject();
+ final ParentEntity recreatedObject = (ParentEntity)recreatedAdapter.getObject();
+ final List<SimpleEntity> homogenousCollection = recreatedObject.getHomogeneousCollection();
+ assertNotNull(homogenousCollection);
+
+ assertThat(homogenousCollection.size(), is(2));
+ assertThat(homogenousCollection.get(0).getName(), is("Fred"));
+ assertThat(homogenousCollection.get(1).getName(), is("Harry"));
+ }
+
+ @Test
+ public void recreateObject_heterogeneousCollectionPreserved() throws Exception {
+ recreatedAdapter = mementoForEpc1.recreateObject();
+ final ParentEntity recreatedObject = (ParentEntity)recreatedAdapter.getObject();
+ final List<BaseEntity> hetrogenousCollection = recreatedObject.getHeterogeneousCollection();
+ assertNotNull(hetrogenousCollection);
+
+ assertThat(hetrogenousCollection.size(), is(2));
+ final SimpleEntity firstObj = (SimpleEntity)hetrogenousCollection.get(0);
+ assertThat(firstObj.getName(), is("Fred"));
+
+ final ReferencingEntity secondObj = (ReferencingEntity)hetrogenousCollection.get(1);
+ final SimpleEntity reference1 = secondObj.getReference();
+ assertThat(reference1.getName(), is("Fred"));
+
+ assertSame(firstObj, reference1);
+ }
+
+ @Test
+ public void recreateObject_whenNull() throws Exception {
+ final Memento memento = new Memento(null);
+ ObjectAdapter returnedAdapter = memento.recreateObject();
+ assertNull(returnedAdapter);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest_data.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest_data.java b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest_data.java
new file mode 100644
index 0000000..0cb7304
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest_data.java
@@ -0,0 +1,96 @@
+/*
+ * 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.core.runtime.memento;
+
+import static org.junit.Assert.assertEquals;
+
+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.adapter.oid.Oid;
+import org.apache.isis.core.runtime.memento.Data;
+import org.apache.isis.core.runtime.memento.Memento;
+import org.apache.isis.core.runtime.memento.ObjectData;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.tck.dom.scalars.WrapperValuedEntity;
+
+public class MementoTest_data {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ private ObjectAdapter originalAdapter1, originalAdapter2;
+ private Oid oid1, oid2;
+
+ private Memento memento1, memento2;
+ private Data data1, data2;
+
+ @Before
+ public void setUpSystem() throws Exception {
+ iswf.fixtures.wve1.setStringProperty("Fred");
+
+ originalAdapter1 = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(iswf.fixtures.wve1);
+ oid1 = originalAdapter1.getOid();
+ memento1 = new Memento(originalAdapter1);
+ data1 = memento1.getData();
+
+ iswf.fixtures.wve2.setStringProperty("Harry");
+ iswf.container.persist(iswf.fixtures.wve2);
+
+ originalAdapter2 = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(iswf.fixtures.wve2);
+ oid2 = originalAdapter2.getOid();
+ memento2 = new Memento(originalAdapter2);
+ data2 = memento2.getData();
+ }
+
+
+ @Test
+ public void data_whenNull() throws Exception {
+ final Memento memento = new Memento(null);
+ Data data = memento.getData();
+
+ assertEquals(null, data);
+ }
+
+
+ @Test
+ public void data_getOid_equal() throws Exception {
+ assertEquals(oid1, data1.getOid());
+ }
+
+
+
+ @Test
+ public void data_getClassName() throws Exception {
+ assertEquals(WrapperValuedEntity.class.getName(), data1.getClassName());
+ }
+
+
+ @Test
+ public void data_getEntry_forStringField() throws Exception {
+ assertEquals(ObjectData.class, data1.getClass());
+ final ObjectData objectData = (ObjectData) data1;
+ assertEquals("Fred", objectData.getEntry("stringProperty"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest_encodedData.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest_encodedData.java b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest_encodedData.java
new file mode 100644
index 0000000..2858332
--- /dev/null
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/runtime/memento/MementoTest_encodedData.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.core.runtime.memento;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.encoding.DataOutputStreamExtended;
+import org.apache.isis.core.integtestsupport.IsisSystemWithFixtures;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.runtime.memento.Memento;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+
+public class MementoTest_encodedData {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ private ObjectAdapter rootAdapter;
+
+ private Memento memento;
+
+ @Mock
+ private DataOutputStreamExtended mockOutputImpl;
+
+ @Before
+ public void setUpSystem() throws Exception {
+ iswf.fixtures.smpl1.setName("Fred");
+ iswf.fixtures.smpl2.setName("Harry");
+
+ iswf.fixtures.rfcg1.setReference(iswf.fixtures.smpl1);
+
+ iswf.fixtures.prnt1.getHomogeneousCollection().add(iswf.fixtures.smpl1);
+ iswf.fixtures.prnt1.getHomogeneousCollection().add(iswf.fixtures.smpl2);
+
+ iswf.fixtures.prnt1.getHeterogeneousCollection().add(iswf.fixtures.smpl1);
+ iswf.fixtures.prnt1.getHeterogeneousCollection().add(iswf.fixtures.rfcg1);
+
+
+ rootAdapter = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(iswf.fixtures.smpl1);
+
+ memento = new Memento(rootAdapter);
+ }
+
+
+ @Test
+ public void encodedData() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(mockOutputImpl).writeEncodable(memento.getData());
+ }
+ });
+ memento.encodedData(mockOutputImpl);
+ }
+
+}