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/06 11:10:37 UTC

[48/51] [partial] ISIS-188: moving modules into core

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/StandardAuthenticationManager_AuthenticatorsTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/StandardAuthenticationManager_AuthenticatorsTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/StandardAuthenticationManager_AuthenticatorsTest.java
new file mode 100644
index 0000000..3d85b44
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/StandardAuthenticationManager_AuthenticatorsTest.java
@@ -0,0 +1,80 @@
+/*
+ *  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.runtime.authentication.standard;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequestPassword;
+import org.apache.isis.core.runtime.authentication.standard.AuthenticationManagerStandard;
+import org.apache.isis.core.runtime.authentication.standard.Authenticator;
+import org.apache.isis.core.runtime.authentication.standard.NoAuthenticatorException;
+
+@RunWith(JMock.class)
+public class StandardAuthenticationManager_AuthenticatorsTest {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private IsisConfiguration mockConfiguration;
+    private AuthenticationManagerStandard authenticationManager;
+    private Authenticator mockAuthenticator;
+
+    @Before
+    public void setUp() throws Exception {
+        mockConfiguration = mockery.mock(IsisConfiguration.class);
+        mockAuthenticator = mockery.mock(Authenticator.class);
+        authenticationManager = new AuthenticationManagerStandard(mockConfiguration);
+    }
+
+    @Test
+    public void shouldInitiallyHaveNoAuthenticators() throws Exception {
+        assertThat(authenticationManager.getAuthenticators().size(), is(0));
+    }
+
+    @Test(expected = NoAuthenticatorException.class)
+    public void shouldNotBeAbleToAuthenticateWithNoAuthenticators() throws Exception {
+        authenticationManager.authenticate(new AuthenticationRequestPassword("foo", "bar"));
+    }
+
+    @Test
+    public void shouldBeAbleToAddAuthenticators() throws Exception {
+        authenticationManager.addAuthenticator(mockAuthenticator);
+        assertThat(authenticationManager.getAuthenticators().size(), is(1));
+        assertThat(authenticationManager.getAuthenticators().get(0), is(sameInstance(mockAuthenticator)));
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void shouldNotBeAbleToModifyReturnedAuthenticators() throws Exception {
+        final List<Authenticator> authenticators = authenticationManager.getAuthenticators();
+        authenticators.add(mockAuthenticator);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/exploration/ExplorationAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/exploration/ExplorationAuthenticatorTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/exploration/ExplorationAuthenticatorTest.java
new file mode 100644
index 0000000..192eda3
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/exploration/ExplorationAuthenticatorTest.java
@@ -0,0 +1,130 @@
+/*
+ *  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.runtime.authentication.standard.exploration;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequestAbstract;
+import org.apache.isis.runtimes.dflt.runtime.authentication.exploration.AuthenticationRequestExploration;
+import org.apache.isis.runtimes.dflt.runtime.authentication.exploration.ExplorationAuthenticator;
+import org.apache.isis.runtimes.dflt.runtime.authentication.exploration.ExplorationAuthenticatorConstants;
+import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+import org.apache.isis.runtimes.dflt.runtime.system.SystemConstants;
+
+@RunWith(JMock.class)
+public class ExplorationAuthenticatorTest {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private IsisConfiguration mockConfiguration;
+    private ExplorationAuthenticator authenticator;
+
+    private AuthenticationRequestExploration explorationRequest;
+
+    private SomeOtherAuthenticationRequest someOtherRequest;
+
+    private static class SomeOtherAuthenticationRequest extends AuthenticationRequestAbstract {
+        public SomeOtherAuthenticationRequest() {
+            super("other");
+        }
+    }
+
+    @Before
+    public void setUp() {
+        mockConfiguration = mockery.mock(IsisConfiguration.class);
+
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
+                will(returnValue(DeploymentType.EXPLORATION.name()));
+            }
+        });
+
+        explorationRequest = new AuthenticationRequestExploration();
+        someOtherRequest = new SomeOtherAuthenticationRequest();
+
+        authenticator = new ExplorationAuthenticator(mockConfiguration);
+    }
+
+    @Test
+    public void canAuthenticateExplorationRequest() throws Exception {
+        assertThat(authenticator.canAuthenticate(explorationRequest.getClass()), is(true));
+    }
+
+    @Test
+    public void canAuthenticateSomeOtherTypeOfRequest() throws Exception {
+        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
+    }
+
+    @Test
+    public void isValidExplorationRequestWhenRunningInExplorationMode() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
+                will(returnValue(DeploymentType.EXPLORATION.name()));
+            }
+        });
+        assertThat(authenticator.isValid(explorationRequest), is(true));
+    }
+
+    @Test
+    public void isNotValidExplorationRequestWhenRunningInSomethingOtherThanExplorationMode() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
+                will(returnValue(DeploymentType.PROTOTYPE.name()));
+            }
+        });
+        assertThat(authenticator.isValid(explorationRequest), is(false));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void expectsThereToBeADeploymentTypeInIsisConfiguration() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
+                will(returnValue(null));
+            }
+        });
+        authenticator.isValid(explorationRequest);
+    }
+
+    @Test
+    public void isValidSomeOtherTypeOfRequest() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
+                will(returnValue(DeploymentType.EXPLORATION.name()));
+            }
+        });
+        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/fixture/LogonFixtureAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/fixture/LogonFixtureAuthenticatorTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/fixture/LogonFixtureAuthenticatorTest.java
new file mode 100644
index 0000000..5a4bf52
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/fixture/LogonFixtureAuthenticatorTest.java
@@ -0,0 +1,132 @@
+/*
+ *  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.runtime.authentication.standard.fixture;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.isis.applib.fixtures.LogonFixture;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequestAbstract;
+import org.apache.isis.runtimes.dflt.runtime.authentication.fixture.LogonFixtureAuthenticator;
+import org.apache.isis.runtimes.dflt.runtime.fixtures.authentication.AuthenticationRequestLogonFixture;
+import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+
+@RunWith(JMock.class)
+public class LogonFixtureAuthenticatorTest {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private IsisConfiguration mockConfiguration;
+    private LogonFixtureAuthenticator authenticator;
+
+    private AuthenticationRequestLogonFixture logonFixtureRequest;
+
+    private SomeOtherAuthenticationRequest someOtherRequest;
+
+    private static class SomeOtherAuthenticationRequest extends AuthenticationRequestAbstract {
+        public SomeOtherAuthenticationRequest() {
+            super("other");
+        }
+    }
+
+    @Before
+    public void setUp() {
+        mockConfiguration = mockery.mock(IsisConfiguration.class);
+
+        logonFixtureRequest = new AuthenticationRequestLogonFixture(new LogonFixture("joebloggs"));
+        someOtherRequest = new SomeOtherAuthenticationRequest();
+        authenticator = new LogonFixtureAuthenticator(mockConfiguration);
+    }
+
+    @Test
+    public void canAuthenticateExplorationRequest() throws Exception {
+        assertThat(authenticator.canAuthenticate(logonFixtureRequest.getClass()), is(true));
+    }
+
+    @Test
+    public void canAuthenticateSomeOtherTypeOfRequest() throws Exception {
+        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
+    }
+
+    @Test
+    public void isValidLogonFixtureRequestWhenRunningInExplorationMode() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString("isis.deploymentType");
+                will(returnValue(DeploymentType.EXPLORATION.name()));
+            }
+        });
+        assertThat(authenticator.isValid(logonFixtureRequest), is(true));
+    }
+
+    @Test
+    public void isValidLogonFixtureRequestWhenRunningInPrototypeMode() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString("isis.deploymentType");
+                will(returnValue(DeploymentType.PROTOTYPE.name()));
+            }
+        });
+        assertThat(authenticator.isValid(logonFixtureRequest), is(true));
+    }
+
+    @Test
+    public void isNotValidExplorationRequestWhenRunningInSomethingOtherThanExplorationOrPrototypeMode() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString("isis.deploymentType");
+                will(returnValue(DeploymentType.SERVER.name()));
+            }
+        });
+        assertThat(authenticator.isValid(logonFixtureRequest), is(false));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void expectsThereToBeADeploymentTypeInIsisConfiguration() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString("isis.deploymentType");
+                will(returnValue(null));
+            }
+        });
+        authenticator.isValid(logonFixtureRequest);
+    }
+
+    @Test
+    public void isValidSomeOtherTypeOfRequest() throws Exception {
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString("isis.deploymentType");
+                will(returnValue(DeploymentType.EXPLORATION.name()));
+            }
+        });
+        assertThat(authenticator.canAuthenticate(SomeOtherAuthenticationRequest.class), is(false));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/context/IsisContextTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/context/IsisContextTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/context/IsisContextTest.java
new file mode 100644
index 0000000..f3ca77f
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/context/IsisContextTest.java
@@ -0,0 +1,157 @@
+/*
+ *  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.runtime.context;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.jmock.Expectations;
+import org.jmock.auto.Mock;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authentication.standard.SimpleSession;
+import org.apache.isis.core.runtime.authorization.AuthorizationManager;
+import org.apache.isis.core.runtime.imageloader.TemplateImageLoader;
+import org.apache.isis.core.runtime.userprofile.UserProfileLoader;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContextStatic;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSessionFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.session.IsisSessionFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.session.IsisSessionFactoryDefault;
+
+public class IsisContextTest {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+    
+
+    private IsisConfiguration configuration;
+    
+    @Mock
+    private PersistenceSession mockPersistenceSession;
+    
+    @Mock
+    private SpecificationLoaderSpi mockSpecificationLoader;
+
+    @Mock
+    protected TemplateImageLoader mockTemplateImageLoader;
+    @Mock
+    protected PersistenceSessionFactory mockPersistenceSessionFactory;
+    @Mock
+    private UserProfileLoader mockUserProfileLoader;
+    @Mock
+    protected AuthenticationManager mockAuthenticationManager;
+    @Mock
+    protected AuthorizationManager mockAuthorizationManager;
+
+    protected OidMarshaller oidMarshaller;
+
+    private List<Object> servicesList;
+
+
+    private AuthenticationSession authSession;
+
+
+    private IsisSessionFactory sessionFactory;
+
+    @Before
+    public void setUp() throws Exception {
+        IsisContext.testReset();
+
+        servicesList = Collections.emptyList();
+
+        configuration = new IsisConfigurationDefault();
+        
+        oidMarshaller = new OidMarshaller();
+        
+        context.checking(new Expectations() {
+            {
+                allowing(mockPersistenceSessionFactory).createPersistenceSession();
+                will(returnValue(mockPersistenceSession));
+                
+                ignoring(mockPersistenceSession);
+                ignoring(mockSpecificationLoader);
+                ignoring(mockPersistenceSessionFactory);
+                ignoring(mockUserProfileLoader);
+                ignoring(mockAuthenticationManager);
+                ignoring(mockAuthorizationManager);
+                ignoring(mockTemplateImageLoader);
+            }
+        });
+
+        sessionFactory = new IsisSessionFactoryDefault(DeploymentType.EXPLORATION, configuration, mockTemplateImageLoader, mockSpecificationLoader, mockAuthenticationManager, mockAuthorizationManager, mockUserProfileLoader, mockPersistenceSessionFactory, servicesList, oidMarshaller);
+        authSession = new SimpleSession("tester", Collections.<String>emptyList());
+        
+        IsisContext.setConfiguration(configuration);
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        if(IsisContext.inSession()) {
+            IsisContext.closeSession();
+        }
+    }
+    
+    @Test
+    public void getConfiguration() {
+        IsisContextStatic.createRelaxedInstance(sessionFactory);
+        Assert.assertEquals(configuration, IsisContext.getConfiguration());
+    }
+
+    @Test
+    public void openSession_getSpecificationLoader() {
+        IsisContextStatic.createRelaxedInstance(sessionFactory);
+        IsisContext.openSession(authSession);
+
+        Assert.assertEquals(mockSpecificationLoader, IsisContext.getSpecificationLoader());
+    }
+
+    @Test
+    public void openSession_getAuthenticationLoader() {
+        IsisContextStatic.createRelaxedInstance(sessionFactory);
+        IsisContext.openSession(authSession);
+
+        Assert.assertEquals(authSession, IsisContext.getAuthenticationSession());
+    }
+    
+    @Test
+    public void openSession_getPersistenceSession() {
+        IsisContextStatic.createRelaxedInstance(sessionFactory);
+        IsisContext.openSession(authSession);
+
+        Assert.assertSame(mockPersistenceSession, IsisContext.getPersistenceSession());
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/AggregatedFacetAlways.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/AggregatedFacetAlways.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/AggregatedFacetAlways.java
new file mode 100644
index 0000000..076b285
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/AggregatedFacetAlways.java
@@ -0,0 +1,32 @@
+/*
+ *  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.runtime.persistence;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.MarkerFacetAbstract;
+import org.apache.isis.core.metamodel.facets.object.aggregated.ParentedFacet;
+
+public class AggregatedFacetAlways extends MarkerFacetAbstract {
+
+    public AggregatedFacetAlways(final FacetHolder holder) {
+        super(ParentedFacet.class, holder);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
new file mode 100644
index 0000000..82bc6bc
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adapterfactory/pojo/PojoAdapterTest.java
@@ -0,0 +1,151 @@
+/*
+ *  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.runtime.persistence.adapterfactory.pojo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.Date;
+
+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.applib.profiles.Localization;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.version.ConcurrencyException;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adapter.PojoAdapter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PojoAdapterBuilder;
+
+public class PojoAdapterTest {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+    
+    private ObjectAdapter adapter;
+    private RuntimeTestPojo domainObject;
+
+    @Mock
+    private Version mockVersion;
+    @Mock
+    private Version mockVersion2;
+    @Mock
+    private SpecificationLoaderSpi mockSpecificationLoader;
+    @Mock
+    private AuthenticationSession mockAuthenticationSession;
+    @Mock
+    private AdapterManager mockObjectAdapterLookup;
+    @Mock
+    private Localization mockLocalization;
+    
+    @Before
+    public void setUp() throws Exception {
+        domainObject = new RuntimeTestPojo();
+        
+        adapter = new PojoAdapter(domainObject, RootOidDefault.create(ObjectSpecId.of("CUS"), "1"), mockSpecificationLoader, mockObjectAdapterLookup, mockLocalization, mockAuthenticationSession);
+        adapter.setVersion(mockVersion);
+        
+        allowUnimportantMethodCallsOn(mockVersion);
+        allowUnimportantMethodCallsOn(mockVersion2);
+    }
+
+    private void allowUnimportantMethodCallsOn(final Version version) {
+        context.checking(new Expectations() {
+            {
+                allowing(version).getSequence();
+                allowing(version).getUtcTimestamp();
+                allowing(version).sequence();
+                allowing(version).getUser();
+                
+                allowing(version).getTime();
+                will(returnValue(new Date()));
+                
+                allowing(mockAuthenticationSession).getUserName();
+                will(returnValue("fredbloggs"));
+            }
+        });
+    }
+
+    @Test
+    public void getOid_initially() {
+        assertEquals(RootOidDefault.create(ObjectSpecId.of("CUS"), "1"), adapter.getOid());
+    }
+
+    @Test
+    public void getObject_initially() {
+        assertEquals(domainObject, adapter.getObject());
+    }
+
+    @Test
+    public void getResolveState_initially() {
+        assertEquals(ResolveState.NEW, adapter.getResolveState());
+    }
+
+    @Test
+    public void changeState_newToTransient() {
+        adapter.changeState(ResolveState.TRANSIENT);
+        assertEquals(ResolveState.TRANSIENT, adapter.getResolveState());
+    }
+
+    @Test
+    public void getVersion_initially() throws Exception {
+        assertSame(mockVersion, adapter.getVersion());
+    }
+
+    @Test
+    public void checkLock_whenVersionsSame() throws Exception {
+
+        context.checking(new Expectations() {
+            {
+                one(mockVersion).different(mockVersion2);
+                will(returnValue(false));
+            }
+        });
+        
+        adapter.checkLock(mockVersion2);
+    }
+
+    @Test(expected=ConcurrencyException.class)
+    public void checkLock_whenVersionsDifferent() throws Exception {
+
+        adapter = PojoAdapterBuilder.create().with(mockSpecificationLoader).withTitleString("some pojo").with(mockVersion).with(mockAuthenticationSession).build();
+        
+        context.checking(new Expectations() {
+            {
+                one(mockVersion).different(mockVersion2);
+                will(returnValue(true));
+            }
+        });
+        
+        adapter.checkLock(mockVersion2);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adapterfactory/pojo/RuntimeTestPojo.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adapterfactory/pojo/RuntimeTestPojo.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adapterfactory/pojo/RuntimeTestPojo.java
new file mode 100644
index 0000000..f2de453
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adapterfactory/pojo/RuntimeTestPojo.java
@@ -0,0 +1,51 @@
+/*
+ *  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.runtime.persistence.adapterfactory.pojo;
+
+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/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault_aggregateAdapters.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault_aggregateAdapters.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault_aggregateAdapters.java
new file mode 100644
index 0000000..8243dd1
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/adaptermanager/AdapterManagerDefault_aggregateAdapters.java
@@ -0,0 +1,225 @@
+/*
+ *  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.runtime.persistence.adaptermanager;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+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.applib.annotation.Aggregated;
+import org.apache.isis.applib.annotation.MemberOrder;
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapterFactory;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.adapter.oid.AggregatedOid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
+import org.apache.isis.core.metamodel.adapter.oid.TypedOid;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.core.progmodel.app.IsisMetaModel;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.progmodels.dflt.ProgrammingModelFacetsJava5;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adapter.PojoAdapterFactory;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adaptermanager.AdapterManagerDefault;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adaptermanager.PojoRecreatorDefault;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
+
+public class AdapterManagerDefault_aggregateAdapters {
+
+    public static class Customer {
+        // {{ Name (property)
+        private Name name;
+
+        @MemberOrder(sequence = "1")
+        public Name getName() {
+            return name;
+        }
+
+        public void setName(final Name name) {
+            this.name = name;
+        }
+        // }}
+    }
+    
+    @Aggregated
+    public static class Name {}
+    
+    public static class CustomerRepository {
+        public Customer x() { return null; }
+    }
+
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+    @Mock
+    private OneToManyAssociation mockCollection;
+
+    @Mock
+    private RuntimeContext mockRuntimeContext;
+    
+    @Mock
+    private OidGenerator mockOidGenerator;
+
+    @Mock
+    protected Localization mockLocalization;
+    
+    @Mock
+    private AuthenticationSession mockAuthenticationSession;
+    
+    @Mock
+    private IsisConfiguration mockConfiguration;
+    
+    private IsisMetaModel isisMetaModel;
+    
+    private ObjectAdapterFactory adapterFactory;
+    
+    private AdapterManagerDefault adapterManager;
+    
+    private Customer rootObject;
+    private Name aggregatedObject;
+    
+    private ObjectAdapter persistentParentAdapter;
+    private ObjectAdapter aggregatedAdapter;
+
+
+    
+    
+    @Before
+    public void setUp() throws Exception {
+        Logger.getRootLogger().setLevel(Level.OFF);
+
+        context.ignoring(mockRuntimeContext);
+        context.ignoring(mockAuthenticationSession);
+        context.ignoring(mockConfiguration);
+        
+        isisMetaModel = IsisMetaModel.builder(mockRuntimeContext, new ProgrammingModelFacetsJava5()).withServices(new CustomerRepository()).build();
+        isisMetaModel.init();
+
+        adapterFactory = new PojoAdapterFactory() {
+            @Override
+            protected Localization getLocalization() {
+                return mockLocalization;
+            }
+            @Override
+            protected SpecificationLoaderSpi getSpecificationLoader() {
+                return isisMetaModel.getSpecificationLoader();
+            }
+            
+            @Override
+            protected AuthenticationSession getAuthenticationSession() {
+                return mockAuthenticationSession;
+            }
+        };
+
+        adapterManager = new AdapterManagerDefault(new PojoRecreatorDefault()) {
+            @Override
+            protected SpecificationLoaderSpi getSpecificationLoader() {
+                return isisMetaModel.getSpecificationLoader();
+            }
+            @Override
+            protected ObjectAdapterFactory getObjectAdapterFactory() {
+                return adapterFactory;
+            }
+            @Override
+            public OidGenerator getOidGenerator() {
+                return mockOidGenerator;
+            }
+            @Override
+            protected ServicesInjector getServicesInjector() {
+                return isisMetaModel.getDependencyInjector();
+            }
+        };
+
+        rootObject = new Customer();
+        aggregatedObject = new Name();
+        
+        persistentParentAdapter = adapterManager.mapRecreatedPojo(
+                RootOidDefault.create(ObjectSpecId.of("CUS"), "1"), rootObject);
+    }
+
+    private void allowing_oidGenerator_createAggregatedOid(final Object value, final AggregatedOid resultOid) {
+        context.checking(new Expectations() {
+            {
+                allowing(mockOidGenerator).createAggregateOid(with(equalTo(value)), with(any(ObjectAdapter.class)));
+                will(returnValue(resultOid));
+                ignoring(mockOidGenerator);
+            }
+        });
+    }
+
+
+    @Test
+    public void adapterFor_whenAggregated() throws Exception {
+        // given
+        allowing_oidGenerator_createAggregatedOid(
+                aggregatedObject, 
+                new AggregatedOid(ObjectSpecId.of("NME"), (TypedOid) persistentParentAdapter.getOid(), "123"));
+        
+        // when
+        aggregatedAdapter = adapterManager.adapterFor(aggregatedObject, persistentParentAdapter);
+
+        // then
+        final AggregatedOid aggregatedOid = (AggregatedOid) aggregatedAdapter.getOid();
+        assertEquals(persistentParentAdapter.getOid(), aggregatedOid.getParentOid());
+    }
+
+    @Test
+    public void testOidHasSubId() throws Exception {
+        allowing_oidGenerator_createAggregatedOid(aggregatedObject, new AggregatedOid(ObjectSpecId.of("NME"), (TypedOid) persistentParentAdapter.getOid(), "123"));
+        aggregatedAdapter = adapterManager.adapterFor(aggregatedObject, persistentParentAdapter);
+
+        final AggregatedOid aggregatedOid = (AggregatedOid) aggregatedAdapter.getOid();
+        assertEquals("123", aggregatedOid.getLocalId());
+    }
+
+    @Test
+    public void getResolveState_isInitiallyGhost() throws Exception {
+        allowing_oidGenerator_createAggregatedOid(aggregatedObject, new AggregatedOid(ObjectSpecId.of("NME"), (TypedOid) persistentParentAdapter.getOid(), "123"));
+        aggregatedAdapter = adapterManager.adapterFor(aggregatedObject, persistentParentAdapter);
+
+        assertEquals(ResolveState.GHOST, aggregatedAdapter.getResolveState());
+    }
+
+    @Test
+    public void testSameParametersRetrievesSameAdapter() throws Exception {
+        allowing_oidGenerator_createAggregatedOid(aggregatedObject, new AggregatedOid(ObjectSpecId.of("NME"), (TypedOid) persistentParentAdapter.getOid(), "123"));
+        aggregatedAdapter = adapterManager.adapterFor(aggregatedObject, persistentParentAdapter);
+
+        final ObjectAdapter valueAdapter2 = adapterManager.adapterFor(aggregatedObject, persistentParentAdapter, mockCollection);
+        assertSame(aggregatedAdapter, valueAdapter2);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/PersistenceSessionObjectStoreTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/PersistenceSessionObjectStoreTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/PersistenceSessionObjectStoreTest.java
new file mode 100644
index 0000000..793147f
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/PersistenceSessionObjectStoreTest.java
@@ -0,0 +1,247 @@
+/*
+ *  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.runtime.persistence.objectstore;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+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.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.matchers.IsisMatchers;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapterFactory;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+import org.apache.isis.core.metamodel.services.ServicesInjectorDefault;
+import org.apache.isis.core.metamodel.services.container.DomainObjectContainerDefault;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.progmodel.app.IsisMetaModel;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.progmodels.dflt.ProgrammingModelFacetsJava5;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adapter.PojoAdapter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adapter.PojoAdapterFactory;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adaptermanager.AdapterManagerDefault;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adaptermanager.PojoRecreatorDefault;
+import org.apache.isis.runtimes.dflt.runtime.persistence.internal.RuntimeContextFromSession;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithm;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.CreateObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.DestroyObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommand;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PojoAdapterBuilder;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PojoAdapterBuilder.Persistence;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.SaveObjectCommand;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManagerSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.IdentifierGeneratorDefault;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.ObjectFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSessionFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransactionManager;
+
+public class PersistenceSessionObjectStoreTest {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+    private ServicesInjectorDefault servicesInjector;
+    private AdapterManagerSpi adapterManager;
+    private ObjectAdapterFactory adapterFactory;
+    
+    
+    private PersistenceSession persistenceSession;
+    private IsisTransactionManager transactionManager;
+    
+    private ObjectAdapter persistentAdapter;
+    private PojoAdapter transientAdapter;
+    
+    @Mock
+    private PersistenceSessionFactory mockPersistenceSessionFactory;
+    
+    @Mock
+    private ObjectStoreSpi mockObjectStore;
+    @Mock
+    private ObjectFactory objectFactory;
+    @Mock
+    private PersistAlgorithm mockPersistAlgorithm;
+
+    @Mock
+    private CreateObjectCommand createObjectCommand;
+    @Mock
+    private SaveObjectCommand saveObjectCommand;
+    @Mock
+    private DestroyObjectCommand destroyObjectCommand;
+
+    @Mock
+    private Version mockVersion;
+
+    @Mock
+    private RuntimeContext mockRuntimeContext;
+
+    @Mock
+    private IsisConfiguration mockConfiguration;
+    
+    
+    private IsisMetaModel isisMetaModel;
+
+
+
+    public static class Customer {
+    }
+
+    public static class CustomerRepository {
+        public Customer x() {return null;}
+    }
+    
+    @Before
+    public void setUp() throws Exception {
+        Logger.getRootLogger().setLevel(Level.OFF);
+
+        context.ignoring(mockRuntimeContext);
+        context.ignoring(mockConfiguration);
+
+        isisMetaModel = new IsisMetaModel(mockRuntimeContext, new ProgrammingModelFacetsJava5(), new CustomerRepository());
+        isisMetaModel.init();
+        
+        context.checking(new Expectations() {
+            {
+                ignoring(mockObjectStore).open();
+                ignoring(mockObjectStore).close();
+                ignoring(mockObjectStore).name();
+                ignoring(mockPersistAlgorithm).name();
+                
+                ignoring(createObjectCommand);
+                ignoring(saveObjectCommand);
+                ignoring(destroyObjectCommand);
+                ignoring(mockVersion);
+            }
+        });
+
+        final RuntimeContextFromSession runtimeContext = new RuntimeContextFromSession();
+        final DomainObjectContainerDefault container = new DomainObjectContainerDefault();
+
+        runtimeContext.injectInto(container);
+        runtimeContext.setContainer(container);
+
+        servicesInjector = new ServicesInjectorDefault();
+        servicesInjector.setContainer(container);
+
+        adapterManager = new AdapterManagerDefault(new PojoRecreatorDefault());
+        adapterFactory = new PojoAdapterFactory();
+        persistenceSession = new PersistenceSession(mockPersistenceSessionFactory, adapterFactory, objectFactory, servicesInjector, new OidGenerator(new IdentifierGeneratorDefault()), adapterManager, mockPersistAlgorithm, mockObjectStore) {
+            @Override
+            protected SpecificationLoaderSpi getSpecificationLoader() {
+                return isisMetaModel.getSpecificationLoader();
+            }
+            
+        };
+        
+        transactionManager = new IsisTransactionManager(persistenceSession, mockObjectStore);
+        persistenceSession.setTransactionManager(transactionManager);
+
+        servicesInjector.setServices(Collections.emptyList());
+
+        persistentAdapter = PojoAdapterBuilder.create().withOid("CUS|1").withPojo(new Customer()).with(Persistence.PERSISTENT).with(mockVersion).with(isisMetaModel.getSpecificationLoader()).build();
+        transientAdapter = PojoAdapterBuilder.create().withOid("CUS|2").withPojo(new Customer()).with(Persistence.TRANSIENT).with(isisMetaModel.getSpecificationLoader()).build();
+    }
+
+
+    @Test
+    public void destroyObjectThenAbort() {
+        
+        final Sequence tran = context.sequence("tran");
+        context.checking(new Expectations() {
+            {
+                one(mockObjectStore).startTransaction();
+                inSequence(tran);
+
+                one(mockObjectStore).createDestroyObjectCommand(persistentAdapter);
+                inSequence(tran);
+
+                one(mockObjectStore).abortTransaction();
+                inSequence(tran);
+            }
+        });
+        
+        transactionManager.startTransaction();
+        persistenceSession.destroyObject(persistentAdapter);
+        transactionManager.abortTransaction();
+    }
+
+    @Test
+    public void destroyObject_thenCommit() {
+
+        final Sequence tran = context.sequence("tran");
+        context.checking(new Expectations() {
+            {
+                one(mockObjectStore).startTransaction();
+                inSequence(tran);
+
+                one(mockObjectStore).createDestroyObjectCommand(persistentAdapter);
+                inSequence(tran);
+                will(returnValue(destroyObjectCommand));
+                
+                one(mockObjectStore).execute(with(IsisMatchers.listContaining((PersistenceCommand)destroyObjectCommand)));
+                inSequence(tran);
+
+                one(mockObjectStore).endTransaction();
+                inSequence(tran);
+            }
+
+        });
+
+        transactionManager.startTransaction();
+        persistenceSession.destroyObject(persistentAdapter);
+        transactionManager.endTransaction();
+    }
+
+    @Test
+    public void makePersistent_happyCase() {
+
+        final Sequence tran = context.sequence("tran");
+        context.checking(new Expectations() {
+            {
+                one(mockObjectStore).startTransaction();
+                inSequence(tran);
+                one(mockPersistAlgorithm).makePersistent(transientAdapter, persistenceSession);
+                inSequence(tran);
+                one(mockObjectStore).execute(with(equalTo(Collections.<PersistenceCommand>emptyList())));
+                inSequence(tran);
+                one(mockObjectStore).endTransaction();
+                inSequence(tran);
+            }
+        });
+
+        transactionManager.startTransaction();
+        persistenceSession.makePersistent(transientAdapter);
+        transactionManager.endTransaction();
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmContractTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmContractTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmContractTest.java
new file mode 100644
index 0000000..c583c76
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/PersistAlgorithmContractTest.java
@@ -0,0 +1,158 @@
+/*
+ *  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.runtime.persistence.objectstore.algorithm;
+
+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.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.Persistability;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.persistence.NotPersistableException;
+import org.apache.isis.runtimes.dflt.runtime.persistence.adapter.PojoAdapter;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PojoAdapterBuilder;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PojoAdapterBuilder.Persistence;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PojoAdapterBuilder.Type;
+
+public abstract class PersistAlgorithmContractTest {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+    @Mock
+    private ToPersistObjectSet mockAdder;
+
+    @Mock
+    private ObjectSpecification objectSpec;
+
+    @Mock
+    private AdapterManager mockObjectAdapterLookup;
+    
+    private PersistAlgorithm persistAlgorithm;
+
+    
+
+    @Before
+    public void setUp() throws Exception {
+        persistAlgorithm = createPersistAlgorithm();
+    }
+
+    /**
+     * Hook for any implementation to implement.
+     * 
+     * @return
+     */
+    protected abstract PersistAlgorithm createPersistAlgorithm();
+
+    @Test
+    public void makePersistent_skipsValueObjects() {
+        
+        context.checking(new Expectations() {
+            {
+                allowing(objectSpec).isParentedOrFreeCollection();
+                will(returnValue(false));
+
+                allowing(objectSpec).persistability();
+                will(returnValue(Persistability.USER_PERSISTABLE));
+                
+                never(mockAdder);
+            }
+        });
+
+        final PojoAdapter valueAdapter = PojoAdapterBuilder.create().with(Type.VALUE).with(objectSpec).build();
+        persistAlgorithm.makePersistent(valueAdapter, mockAdder);
+    }
+
+    
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectIsAggregated() {
+        final PojoAdapter rootAdapter = PojoAdapterBuilder.create().with(Type.ROOT).with(Persistence.TRANSIENT).with(objectSpec).build();
+        context.checking(new Expectations() {
+            {
+                allowing(objectSpec).isService();
+                will(returnValue(false));
+                
+                allowing(objectSpec).isParentedOrFreeCollection();
+                will(returnValue(false));
+
+                allowing(objectSpec).persistability();
+                will(returnValue(Persistability.USER_PERSISTABLE));
+    
+                allowing(mockObjectAdapterLookup).getAdapterFor(with(any(Oid.class)));
+                will(returnValue(rootAdapter));
+                
+                never(mockAdder);
+            }
+        });
+        
+
+        final PojoAdapter aggregatedAdapter = PojoAdapterBuilder.create().with(Type.AGGREGATED).with(Persistence.TRANSIENT).with(objectSpec).with(mockObjectAdapterLookup).build();
+        persistAlgorithm.makePersistent(aggregatedAdapter, mockAdder);
+    }
+
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectAlreadyPersistent() {
+        context.checking(new Expectations() {
+            {
+                allowing(objectSpec).isService();
+                will(returnValue(false));
+
+                allowing(objectSpec).isParentedOrFreeCollection();
+                will(returnValue(false));
+
+                allowing(objectSpec).persistability();
+                will(returnValue(Persistability.PROGRAM_PERSISTABLE));
+                
+                never(mockAdder);
+            }
+        });
+        
+        final PojoAdapter rootAdapter = PojoAdapterBuilder.create().with(Type.ROOT).with(Persistence.PERSISTENT).with(objectSpec).build();
+        persistAlgorithm.makePersistent(rootAdapter, mockAdder);
+    }
+    
+    
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectMustBeTransient() {
+        context.checking(new Expectations() {
+            {
+                allowing(objectSpec).isService();
+                will(returnValue(false));
+
+                allowing(objectSpec).isParentedOrFreeCollection();
+                will(returnValue(false));
+
+                allowing(objectSpec).persistability();
+                will(returnValue(Persistability.TRANSIENT));
+                
+                never(mockAdder);
+            }
+        });
+        
+        final PojoAdapter rootAdapter = PojoAdapterBuilder.create().with(Type.ROOT).with(Persistence.TRANSIENT).with(objectSpec).build();
+        persistAlgorithm.makePersistent(rootAdapter, mockAdder);
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/dflt/DefaultPersistAlgorithmContractTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/dflt/DefaultPersistAlgorithmContractTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/dflt/DefaultPersistAlgorithmContractTest.java
new file mode 100644
index 0000000..d6e2bee
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/dflt/DefaultPersistAlgorithmContractTest.java
@@ -0,0 +1,33 @@
+/*
+ *  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.runtime.persistence.objectstore.algorithm.dflt;
+
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithm;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithmContractTest;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithmDefault;
+
+public class DefaultPersistAlgorithmContractTest extends PersistAlgorithmContractTest {
+
+    @Override
+    protected PersistAlgorithm createPersistAlgorithm() {
+        return new PersistAlgorithmDefault();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/dflt/DefaultPersistAlgorithmTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/dflt/DefaultPersistAlgorithmTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/dflt/DefaultPersistAlgorithmTest.java
new file mode 100644
index 0000000..a85b56e
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/dflt/DefaultPersistAlgorithmTest.java
@@ -0,0 +1,258 @@
+/*
+ *  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.runtime.persistence.objectstore.algorithm.dflt;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithmDefault;
+
+public class DefaultPersistAlgorithmTest {
+
+//    private final static class PersistedObjectAdderSpy implements ToPersistObjectSet {
+//        private final List<ObjectAdapter> persistedObjects = new ArrayList<ObjectAdapter>();
+//
+//        public List<ObjectAdapter> getPersistedObjects() {
+//            return persistedObjects;
+//        }
+//
+//        @Override
+//        public void addPersistedObject(final ObjectAdapter object) {
+//            persistedObjects.add(object);
+//        }
+//
+//        @Override
+//        public void remapAsPersistent(final ObjectAdapter object) {
+//            object.changeState(ResolveState.RESOLVED);
+//        }
+//    }
+//
+//    private final String objectType = "CUS";
+//
+    private PersistAlgorithmDefault algorithm;
+    
+//    private PersistedObjectAdderSpy adder;
+//    private ObjectAdapter object;
+//    private TestProxyAdapter fieldsObject;
+//
+//    protected TestProxySystem system;
+//    private int nextId;
+//
+//    private TestProxyConfiguration mockConfiguration;
+//    private TestProxyReflector mockReflector;
+//    private AuthenticationSession mockAuthSession;
+//    private TestProxyPersistenceSessionFactory mockPersistenceSessionFactory;
+//    private TestProxyPersistenceSession mockPersistenceSession;
+//    private TestUserProfileStore mockUserProfileStore;
+//
+//
+//    @Override
+//    protected void setUp() throws Exception {
+//        Logger.getRootLogger().setLevel(Level.OFF);
+//        system = new TestProxySystem();
+//        nextId = 0;
+//        
+//        mockConfiguration = new TestProxyConfiguration();
+//        mockReflector = new TestProxyReflector();
+//        mockAuthSession = new TestProxySession();
+//        mockPersistenceSessionFactory = new TestProxyPersistenceSessionFactory();
+//        mockPersistenceSession = new TestProxyPersistenceSession(mockPersistenceSessionFactory);
+//        mockPersistenceSessionFactory.setPersistenceSessionToCreate(mockPersistenceSession);
+//        mockUserProfileStore = new TestUserProfileStore();
+//        
+//        system.openSession(mockConfiguration, mockReflector, mockAuthSession, null, null, null, mockUserProfileStore, null, mockPersistenceSessionFactory, null);
+//
+//        
+//        algorithm = new DefaultPersistAlgorithm();
+//        final RuntimeTestPojo transientTestPojo = new RuntimeTestPojo();
+//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+ (nextId++));
+//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(transientTestPojo, transientTestOid);
+//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
+//
+//        object = adapterForTransient;
+//        // object.setupResolveState(ResolveState.TRANSIENT);
+//
+//        final TestProxySpecification spec = (TestProxySpecification) object.getSpecification();
+//        final List<ObjectAssociation> fields = Arrays.asList((ObjectAssociation) new OneToOneAssociationTest() {
+//
+//            @Override
+//            public void initAssociation(final ObjectAdapter inObject, final ObjectAdapter associate) {
+//            }
+//
+//            @Override
+//            public Consent isAssociationValid(final ObjectAdapter inObject, final ObjectAdapter associate) {
+//                return null;
+//            }
+//
+//            @Override
+//            public void setAssociation(final ObjectAdapter inObject, final ObjectAdapter associate) {
+//            }
+//
+//            @Override
+//            public void set(final ObjectAdapter owner, final ObjectAdapter newValue) {
+//            }
+//
+//            @Override
+//            public ObjectAdapter get(final ObjectAdapter target) {
+//                return null;
+//            }
+//
+//            @Override
+//            public ObjectSpecification getSpecification() {
+//                return null;
+//            }
+//
+//            @Override
+//            public String debugData() {
+//                return null;
+//            }
+//
+//            @Override
+//            public String getId() {
+//                return null;
+//            }
+//
+//            @Override
+//            public String getName() {
+//                return null;
+//            }
+//
+//            @Override
+//            public FeatureType getFeatureType() {
+//                return FeatureType.PROPERTY;
+//            }
+//
+//        });
+//        spec.setupFields(fields);
+//
+//        fieldsObject = new TestProxyAdapter();
+//        fieldsObject.setupResolveState(ResolveState.TRANSIENT);
+//        fieldsObject.setupSpecification((TestProxySpecification) mockReflector.loadSpecification(String.class));
+//
+//        adder = new PersistedObjectAdderSpy();
+//    }
+
+    
+    @Before
+    public void setUp() throws Exception {
+        algorithm = new PersistAlgorithmDefault();
+    }
+    
+
+    @Ignore //DKH
+    @Test
+    public void testMakePersistent() {
+//        algorithm.makePersistent(object, adder);
+//        assertEquals(ResolveState.RESOLVED, object.getResolveState());
+//        assertTrue(adder.getPersistedObjects().contains(object));
+    }
+
+    @Ignore //DKH
+    @Test
+    public void testMakePersistentRecursesThroughReferenceFields() {
+//        /*
+//         * fieldControl.expectAndReturn(oneToOneAssociation.isPersisted(),
+//         * true); fieldControl.expectAndReturn(oneToOneAssociation.isValue(),
+//         * false); fieldControl.expectAndReturn(oneToOneAssociation.get(object),
+//         * fieldsObject);
+//         * IsisContext.getObjectPersistor().getIdentityMap().madePersistent
+//         * (object);
+//         * IsisContext.getObjectPersistor().getIdentityMap().madePersistent
+//         * (fieldsObject);
+//         * 
+//         * adder.addPersistedObject(object);
+//         * adder.addPersistedObject(fieldsObject);
+//         */
+//
+//        // replay();
+//        algorithm.makePersistent(object, adder);
+//        // verify();
+    }
+
+    @Ignore //DKH
+    @Test
+    public void testMakePersistentRecursesThroughReferenceFieldsSkippingNullReferences() {
+//        /*
+//         * fieldControl.expectAndReturn(oneToOneAssociation.isPersisted(),
+//         * true); fieldControl.expectAndReturn(oneToOneAssociation.isValue(),
+//         * false); fieldControl.expectAndReturn(oneToOneAssociation.get(object),
+//         * null);
+//         * 
+//         * IsisContext.getObjectPersistor().getIdentityMap().madePersistent(object
+//         * );
+//         * 
+//         * adder.addPersistedObject(object);
+//         */
+//        algorithm.makePersistent(object, adder);
+    }
+
+    @Ignore //DKH
+    @Test
+    public void testMakePersistentRecursesThroughReferenceFieldsSkippingNonPersistentFields() {
+//        /*
+//         * fieldControl.expectAndReturn(oneToOneAssociation.isPersisted(),
+//         * false);
+//         * 
+//         * IsisContext.getObjectPersistor().getIdentityMap().madePersistent(object
+//         * );
+//         * 
+//         * adder.addPersistedObject(object);
+//         */
+//        algorithm.makePersistent(object, adder);
+    }
+
+    @Ignore //DKH
+    @Test
+    public void testMakePersistentRecursesThroughReferenceFieldsSkippingObjectsThatAreAlreadyPersistent() {
+//        /*
+//         * fieldControl.expectAndReturn(oneToOneAssociation.isPersisted(),
+//         * true); fieldControl.expectAndReturn(oneToOneAssociation.isValue(),
+//         * false); fieldControl.expectAndReturn(oneToOneAssociation.get(object),
+//         * fieldsObject); fieldsObject.setupResolveState(ResolveState.RESOLVED);
+//         * 
+//         * IsisContext.getObjectPersistor().getIdentityMap().madePersistent(object
+//         * );
+//         * 
+//         * adder.addPersistedObject(object);
+//         */
+//        algorithm.makePersistent(object, adder);
+    }
+
+    @Ignore //DKH
+    @Test
+    public void testMakePersistentSkipsAggregatedObjects() {
+//        class DefaultPersistAlgorithmSubclassForTesting extends DefaultPersistAlgorithm {
+//            @Override
+//            protected void persist(final ObjectAdapter object, final ToPersistObjectSet persistor) {
+//                super.persist(object, persistor);
+//            }
+//
+//            public void sensingPersist(final ObjectAdapter object, final ToPersistObjectSet persistor) {
+//                persist(object, persistor);
+//            }
+//        }
+//        final PojoAdapter aggregatedObject = new PojoAdapter(new Object(), RootOidDefault.createTransient(objectType, ""+1));
+//        aggregatedObject.changeState(ResolveState.VALUE);
+//        new DefaultPersistAlgorithmSubclassForTesting().sensingPersist(aggregatedObject, adder);
+//        assertEquals(0, adder.getPersistedObjects().size());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/topdown/TopDownPersistAlgorithmContractTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/topdown/TopDownPersistAlgorithmContractTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/topdown/TopDownPersistAlgorithmContractTest.java
new file mode 100644
index 0000000..b965f83
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/topdown/TopDownPersistAlgorithmContractTest.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.runtimes.dflt.runtime.persistence.objectstore.algorithm.topdown;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.runtime.persistence.NotPersistableException;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithm;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithmContractTest;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithmTopDown;
+
+public class TopDownPersistAlgorithmContractTest extends PersistAlgorithmContractTest {
+
+    @Override
+    protected PersistAlgorithm createPersistAlgorithm() {
+        return new PersistAlgorithmTopDown();
+    }
+
+    @Ignore
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectIsAggregated() {
+        // does not pass...
+    }
+
+    @Ignore
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectAlreadyPersistent() {
+        // does not pass...
+    }
+    
+    @Ignore
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectMustBeTransient() {
+        // does not pass...
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/twopass/TwoPassPersistAlgorithmContractTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/twopass/TwoPassPersistAlgorithmContractTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/twopass/TwoPassPersistAlgorithmContractTest.java
new file mode 100644
index 0000000..255ffe4
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/algorithm/twopass/TwoPassPersistAlgorithmContractTest.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.runtimes.dflt.runtime.persistence.objectstore.algorithm.twopass;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.runtime.persistence.NotPersistableException;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithm;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithmContractTest;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.algorithm.PersistAlgorithmTwoPass;
+
+public class TwoPassPersistAlgorithmContractTest extends PersistAlgorithmContractTest {
+
+    @Override
+    protected PersistAlgorithm createPersistAlgorithm() {
+        return new PersistAlgorithmTwoPass();
+    }
+
+    @Ignore
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectIsAggregated() {
+        // does not pass...
+    }
+
+    @Ignore
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectAlreadyPersistent() {
+        // does not pass...
+    }
+    
+    @Ignore
+    @Test(expected=NotPersistableException.class)
+    public void makePersistent_failsIfObjectMustBeTransient() {
+        // does not pass...
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManagerAbstractTestCase.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManagerAbstractTestCase.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManagerAbstractTestCase.java
new file mode 100644
index 0000000..4ffbdfd
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManagerAbstractTestCase.java
@@ -0,0 +1,66 @@
+/*
+ *  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.runtime.persistence.objectstore.transaction;
+
+import org.jmock.Expectations;
+import org.jmock.auto.Mock;
+import org.junit.Rule;
+
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.runtime.system.session.IsisSession;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransactionManager;
+
+public abstract class ObjectStoreTransactionManagerAbstractTestCase {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+    protected IsisTransactionManager transactionManager;
+    @Mock
+    protected IsisSession mockSession;
+    @Mock
+    protected PersistenceSession mockPersistenceSession;
+    @Mock
+    protected TransactionalResource mockObjectStore;
+
+
+    // //////////////////////////////////////////////////
+    // Helpers
+    // //////////////////////////////////////////////////
+
+    protected void ignoreCallsToPersistenceSession() {
+        context.checking(new Expectations() {
+            {
+                ignoring(mockPersistenceSession);
+            }
+        });
+    }
+
+    protected void ignoreCallsToObjectStore() {
+        context.checking(new Expectations() {
+            {
+                ignoring(mockObjectStore);
+            }
+        });
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java
----------------------------------------------------------------------
diff --git a/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java
new file mode 100644
index 0000000..96ea0d0
--- /dev/null
+++ b/framework/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/persistence/objectstore/transaction/ObjectStoreTransactionManager_EndTransactionTest.java
@@ -0,0 +1,107 @@
+/*
+ *  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.runtime.persistence.objectstore.transaction;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
+
+import org.jmock.Expectations;
+import org.jmock.Sequence;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransactionManager;
+
+public class ObjectStoreTransactionManager_EndTransactionTest extends ObjectStoreTransactionManagerAbstractTestCase {
+
+    @Before
+    public void setUpTransactionManager() throws Exception {
+        transactionManager = new IsisTransactionManager(mockPersistenceSession, mockObjectStore);
+    }
+
+    @Test
+    public void endTransactionDecrementsTransactionLevel() throws Exception {
+        // setup
+        ignoreCallsToObjectStore();
+        transactionManager.startTransaction();
+        transactionManager.startTransaction();
+
+        assertThat(transactionManager.getTransactionLevel(), is(2));
+        transactionManager.endTransaction();
+        assertThat(transactionManager.getTransactionLevel(), is(1));
+    }
+
+    @Test
+    public void endTransactionCommitsTransactionWhenLevelDecrementsDownToZero() throws Exception {
+        // setup
+        ignoreCallsToObjectStore();
+        transactionManager.startTransaction();
+
+        context.checking(new Expectations() {
+            {
+                one(mockPersistenceSession).objectChangedAllDirty();
+            }
+        });
+        assertThat(transactionManager.getTransactionLevel(), is(1));
+        transactionManager.endTransaction();
+        assertThat(transactionManager.getTransactionLevel(), is(0));
+    }
+
+    @Test
+    public void startTransactionInteractsWithObjectStore() throws Exception {
+        // setup
+        ignoreCallsToPersistenceSession();
+
+        context.checking(new Expectations() {
+            {
+                one(mockObjectStore).startTransaction();
+            }
+        });
+        transactionManager.startTransaction();
+
+    }
+
+    @Test
+    public void endTransactionInteractsWithObjectStore() throws Exception {
+        // setup
+        ignoreCallsToPersistenceSession();
+
+        context.checking(new Expectations() {
+            {
+                final Sequence transactionOrdering = context.sequence("transactionOrdering");
+                one(mockObjectStore).startTransaction();
+                inSequence(transactionOrdering);
+
+                one(mockObjectStore).execute(with(equalTo(Collections.<PersistenceCommand>emptyList())));
+                inSequence(transactionOrdering);
+
+                one(mockObjectStore).endTransaction();
+                inSequence(transactionOrdering);
+            }
+        });
+
+        transactionManager.startTransaction();
+        transactionManager.endTransaction();
+    }
+
+}