incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1331449 - in /incubator/isis/branches/0.3.0-incubating-NEW-OIDs: runtimes/dflt/testsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/ viewer/html/src/main/java/org/apache/isis/viewer/html/context/ viewer/html/src/test/java/or...
Date Fri, 27 Apr 2012 14:47:06 GMT
Author: danhaywood
Date: Fri Apr 27 14:47:06 2012
New Revision: 1331449

URL: http://svn.apache.org/viewvc?rev=1331449&view=rev
Log:
ISIS-214: html viewer tests are now green again, reinstated tests that had been commented
out

Added:
    incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapAction.java
      - copied, changed from r1307476, incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest.java
    incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapCollection.java
  (with props)
    incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapObject.java
      - copied, changed from r1307476, incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextSessionDataTest.java
Removed:
    incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextSessionDataTest.java
    incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest.java
Modified:
    incubator/isis/branches/0.3.0-incubating-NEW-OIDs/runtimes/dflt/testsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java
    incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/main/java/org/apache/isis/viewer/html/context/Context.java
    incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_serialization.java

Modified: incubator/isis/branches/0.3.0-incubating-NEW-OIDs/runtimes/dflt/testsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java
URL: http://svn.apache.org/viewvc/incubator/isis/branches/0.3.0-incubating-NEW-OIDs/runtimes/dflt/testsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java?rev=1331449&r1=1331448&r2=1331449&view=diff
==============================================================================
--- incubator/isis/branches/0.3.0-incubating-NEW-OIDs/runtimes/dflt/testsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java
(original)
+++ incubator/isis/branches/0.3.0-incubating-NEW-OIDs/runtimes/dflt/testsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java
Fri Apr 27 14:47:06 2012
@@ -364,9 +364,5 @@ public class IsisSystemWithFixtures impl
 
 
 
-
-
-
-
     
 }

Modified: incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/main/java/org/apache/isis/viewer/html/context/Context.java
URL: http://svn.apache.org/viewvc/incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/main/java/org/apache/isis/viewer/html/context/Context.java?rev=1331449&r1=1331448&r2=1331449&view=diff
==============================================================================
--- incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/main/java/org/apache/isis/viewer/html/context/Context.java
(original)
+++ incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/main/java/org/apache/isis/viewer/html/context/Context.java
Fri Apr 27 14:47:06 2012
@@ -19,6 +19,7 @@
 
 package org.apache.isis.viewer.html.context;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -53,23 +54,27 @@ import org.apache.isis.viewer.html.crumb
 import org.apache.isis.viewer.html.request.Request;
 import org.apache.isis.viewer.html.task.Task;
 
-public class Context {
+public class Context implements Serializable {
+
+    private static final long serialVersionUID = 1L;
 
     private static final Logger LOG = Logger.getLogger(Context.class);
     
+    private transient ObjectHistory history;
+
     private final ComponentFactory componentFactory;
-    private final ObjectHistory history = new ObjectHistory();
-    
+
     private final Map<String, ObjectMapping> objectMap = Maps.newHashMap();
     private final Map<String, ObjectMapping> serviceMap = Maps.newHashMap();
     private final Map<String, CollectionMapping> collectionMap = Maps.newHashMap();
     private final Map<String, ObjectAction> actionMap = Maps.newHashMap();
     
     private final Stack<Crumb> crumbs = new Stack<Crumb>();
-    private final List<String> messages = new ArrayList<String>();
-    private final List<String> warnings = new ArrayList<String>();
+    private final List<String> messages = Lists.newArrayList();
+    private final List<String> warnings = Lists.newArrayList();
 
     private AuthenticationSession session;
+    
     private boolean isValid;
     private int max;
 
@@ -150,7 +155,7 @@ public class Context {
 
     private void processChangeFor(final ObjectMapping mapping) {
         final String existingId = findExistingInMap(objectMap, mapping);
-        history.remove(existingId);
+        getObjectHistory().remove(existingId);
 
         final List<Crumb> relatedCrumbs = Lists.newArrayList();
         for (final Crumb crumb : getCrumbs()) {
@@ -380,7 +385,7 @@ public class Context {
         final Map<String, CollectionMapping> collMappingById = Maps.newHashMap();
         final Map<String, ObjectMapping> objectMappingById = Maps.newHashMap();
 
-        for (HistoryEntry entry : history) {
+        for (HistoryEntry entry : getObjectHistory()) {
             if (entry.type == HistoryEntry.OBJECT) {
                 copyObjectMapping(objectMappingById, entry);
             } else if (entry.type == HistoryEntry.COLLECTION) {
@@ -507,15 +512,15 @@ public class Context {
 
 
     public void listHistory(final Context context, final Block navigation) {
-        history.listObjects(context, navigation);
+        getObjectHistory().listObjects(context, navigation);
     }
 
     public void addObjectToHistory(final String idString) {
-        history.addObject(idString);
+        getObjectHistory().addObject(idString);
     }
 
     public void addCollectionToHistory(final String idString) {
-        history.addCollection(idString);
+        getObjectHistory().addCollection(idString);
     }
 
     // ////////////////////////////////////////////////////
@@ -587,7 +592,7 @@ public class Context {
         debug.endSection();
 
         debug.startSection("History");
-        history.debug(debug);
+        getObjectHistory().debug(debug);
         debug.endSection();
 
         debug.endSection();
@@ -603,6 +608,18 @@ public class Context {
 
 
     // ////////////////////////////////////////////////////
+    // Non-serializable
+    // ////////////////////////////////////////////////////
+    
+    private ObjectHistory getObjectHistory() {
+        if(history == null) {
+            history = new ObjectHistory();
+        }
+        return history;
+    }
+
+
+    // ////////////////////////////////////////////////////
     // Dependencies (from context)
     // ////////////////////////////////////////////////////
 

Copied: incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapAction.java
(from r1307476, incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest.java)
URL: http://svn.apache.org/viewvc/incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapAction.java?p2=incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapAction.java&p1=incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest.java&r1=1307476&r2=1331449&rev=1331449&view=diff
==============================================================================
--- incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest.java
(original)
+++ incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapAction.java
Fri Apr 27 14:47:06 2012
@@ -19,336 +19,80 @@
 
 package org.apache.isis.viewer.html.context;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.jmock.auto.Mock;
 import org.junit.Before;
-import org.junit.Ignore;
 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.metamodel.specloader.ObjectReflector;
-import org.apache.isis.core.runtime.userprofile.UserProfileStore;
-import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
-import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
 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.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.viewer.html.action.ActionException;
 
-public class ContextTest {
+public class ContextTest_mapAction {
 
     @Rule
-    public JUnitRuleMockery2 mockContext = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+    public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
 
     private Context context;
 
-//    protected TestProxySystem system;
-//    private int nextId;
-//
-//    private TestProxyConfiguration mockConfiguration;
-//    private TestProxyReflector mockReflector;
-//    private AuthenticationSession mockAuthSession;
-//    private TestProxyPersistenceSessionFactory mockPersistenceSessionFactory;
-//    private TestProxyPersistenceSession mockPersistenceSession;
-//    private UserProfileStoreNoop mockUserProfileStore;
-
-    @Mock
-    private IsisConfiguration mockConfiguration;
-    @Mock
-    private ObjectReflector mockReflector;
-    @Mock
-    private AuthenticationSession mockAuthSession;
-    @Mock
-    private PersistenceSessionFactory mockPersistenceSessionFactory;
-    @Mock
-    private PersistenceSession mockPersistenceSession;
-    @Mock
-    private UserProfileStore mockUserProfileStore;
 
     @Before
     public void setUp() throws Exception {
         Logger.getRootLogger().setLevel(Level.OFF);
-//        system = new TestProxySystem();
-//        nextId = 0;
-//
-//        mockConfiguration = new TestProxyConfiguration();
-//        mockReflector = new TestProxyReflector();
-//        mockAuthSession = new TestAuthenticationSession();
-//        mockPersistenceSessionFactory = new TestProxyPersistenceSessionFactory();
-//        mockPersistenceSession = new TestProxyPersistenceSession(mockPersistenceSessionFactory);
-//        mockPersistenceSessionFactory.setPersistenceSessionToCreate(mockPersistenceSession);
-//        mockUserProfileStore = new UserProfileStoreNoop();
-//        
-//        system.openSession(mockConfiguration, mockReflector, mockAuthSession, null, null,
null, mockUserProfileStore, null, mockPersistenceSessionFactory, null);
-
         context = new Context(null);
     }
 
-    @Ignore // DKH
-    @Test
-    public void testExceptionThrownWhenNoCollectionForIdentity() {
-        
-//        final TestProxyCollectionAdapter collection = new TestProxyCollectionAdapter(new
Vector());
-//        final TestProxySpecification specification = (TestProxySpecification) mockReflector.loadSpecification(Vector.class);
-//        final TestProxySpecification elementSpecification = (TestProxySpecification) mockReflector.loadSpecification(Object.class);
-//        specification.addFacet(new TestProxyCollectionFacet());
-//        specification.addFacet(new TypeOfFacetDefaultToObject(elementSpecification, mockReflector)
{
-//        });
-//        collection.setupSpecification(specification);
-//        final TestProxyCollectionAdapter createPersistentTestCollection = collection;
-//        context.mapCollection(createPersistentTestCollection);
-//        try {
-//            assertNull(context.getMappedCollection("112"));
-//            fail();
-//        } catch (final ActionException expected) {
-//        }
-    }
-
-    @Ignore // DKH
-    @Test
-    public void testExceptionThrownWhenNoObjectForIdentity() {
-//        context.mapAction(new ObjectActionNoop());
-//        try {
-//            assertNull(context.getMappedAction("112"));
-//            fail();
-//        } catch (final ActionException expected) {
-//        }
-    }
-
-    @Ignore // DKH
-    @Test
-    public void testExceptionThrownWhenNoActionForIdentity() {
-//        final TestPojo pojo = new TestPojo();
-//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+
(nextId++));
-//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(pojo,
transientTestOid);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
-//        final ObjectAdapter adapter = adapterForTransient;
-//        
-//        // similar to object store implementation
-//        ((AdapterManagerPersist) mockPersistenceSession.getAdapterManager()).remapAsPersistent(adapter);
-//        
-//        // would be done by the object store, we must do ourselves.
-//        adapter.setOptimisticLock(new TestProxyVersion(1));
-//        final ObjectAdapter object = adapter;
-//        context.mapObject(object);
-//        try {
-//            assertNull(context.getMappedObject("112"));
-//            fail();
-//        } catch (final ActionException expected) {
-//        }
-    }
-
-    /*
-     * REVIEW public void testIdentityUsedToLookupCollection() {
-     * DummyCollectionAdapter collection1 = new DummyCollectionAdapter(); String
-     * id = context.mapCollection(collection1); assertEquals(collection1,
-     * context.getMappedCollection(id)); }
-     */
-    @Ignore // DKH
-    @Test
-    public void testIdentityUsedToLookupObject() {
-//        final TestPojo pojo = new TestPojo();
-//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+
(nextId++));
-//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(pojo,
transientTestOid);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
-//        final ObjectAdapter adapter = adapterForTransient;
-//        
-//        // similar to object store implementation
-//        ((AdapterManagerPersist) mockPersistenceSession.getAdapterManager()).remapAsPersistent(adapter);
-//        
-//        // would be done by the object store, we must do ourselves.
-//        adapter.setOptimisticLock(new TestProxyVersion(1));
-//        final ObjectAdapter object = adapter;
-//        final String id = context.mapObject(object);
-//        assertEquals(object, context.getMappedObject(id));
-    }
-
-    @Ignore // DKH
-    @Test
-    public void testLookedUpObjectHasDifferentVersion() {
-//        final TestPojo pojo = new TestPojo();
-//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+
(nextId++));
-//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(pojo,
transientTestOid);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
-//        final ObjectAdapter adapter = adapterForTransient;
-//        
-//        // similar to object store implementation
-//        ((AdapterManagerPersist) mockPersistenceSession.getAdapterManager()).remapAsPersistent(adapter);
-//        
-//        // would be done by the object store, we must do ourselves.
-//        adapter.setOptimisticLock(new TestProxyVersion(1));
-//        final ObjectAdapter object = adapter;
-//        final String id = context.mapObject(object);
-//        // change version on the object being passed back
-//        object.setOptimisticLock(new TestProxyVersion(5));
-//        context.getMappedObject(id);
-//        assertEquals("Reloaded object " + object.titleString(), context.getMessage(1));
-    }
 
     @Test
-    public void testIdentityUsedToLookupAction() {
-//        final ObjectActionNoop action = new ObjectActionNoop();
-//        final String id = context.mapAction(action);
-//        assertEquals(action, context.getMappedAction(id));
+    public void getMappedAction_forNonExistentId() {
+        try {
+            assertNull(context.getMappedAction("NON-EXISTENT-ID"));
+            fail();
+        } catch (final ActionException ex) {
+            // expected
+        }
     }
 
-    @Ignore // DKH
-    @Test
-    public void testRegisteredCollectionReturnSameIdentityForSameCollection() {
-//        final TestProxyCollectionAdapter collection1 = new TestProxyCollectionAdapter(new
Vector());
-//        final TestProxySpecification specification = (TestProxySpecification) mockReflector.loadSpecification(Vector.class);
-//        final TestProxySpecification elementSpecification = (TestProxySpecification) mockReflector.loadSpecification(Object.class);
-//        specification.addFacet(new TestProxyCollectionFacet());
-//        specification.addFacet(new TypeOfFacetDefaultToObject(elementSpecification, mockReflector)
{});
-//        collection1.setupSpecification(specification);
-//        final TestProxyCollectionAdapter collection = collection1;
-//        final String id = context.mapCollection(collection);
-//        final String id2 = context.mapCollection(collection);
-//        assertEquals(id, id2);
-    }
-
-    /*
-     * REVIEW public void
-     * testRegisteredCollectionReturnDifferentIdentityForDifferentCollection() {
-     * replay(); String id = context.mapCollection(new
-     * DummyCollectionAdapter()); String id2 = context.mapCollection(new
-     * DummyCollectionAdapter()); assertNotSame(id, id2); verify(); }
-     */
 
-    @Ignore // DKH
     @Test
-    public void testRegisteredObjectReturnSameIdentityForSameObject() {
-//        final TestPojo pojo = new TestPojo();
-//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+
(nextId++));
-//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(pojo,
transientTestOid);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
-//        final ObjectAdapter adapter = adapterForTransient;
-//        
-//        // similar to object store implementation
-//        ((AdapterManagerPersist) mockPersistenceSession.getAdapterManager()).remapAsPersistent(adapter);
-//        
-//        // would be done by the object store, we must do ourselves.
-//        adapter.setOptimisticLock(new TestProxyVersion(1));
-//        final ObjectAdapter object = adapter;
-//        final String id = context.mapObject(object);
-//        final String id2 = context.mapObject(object);
-//        assertEquals(id, id2);
+    public void mapAction_then_getMappedAction() {
+        final ObjectAction action = new ObjectActionNoop();
+        final String id = context.mapAction(action);
+        assertEquals(action, context.getMappedAction(id));
     }
 
-    @Ignore // DKH
-    @Test
-    public void testTransientObjectReturnSameIdentityForSameObject() {
-//        final TestPojo transientTestPojo = new TestPojo();
-//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+
(nextId++));
-//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(transientTestPojo,
transientTestOid);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
-//        final ObjectAdapter object = adapterForTransient;
-//        final String id = context.mapObject(object);
-//        final String id2 = context.mapObject(object);
-//        assertEquals(id, id2);
-    }
 
-    /*
-     * TODO reinstate public void testClearRemovesObject() { replay();
-     * DummyObjectAdapter object = new DummyObjectAdapter(new DummyOid(13));
-     * String id = context.mapObject(object); context.clearMappedObject(object);
-     * try { context.getMappedObject(id); fail(); } catch
-     * (ObjectAdapterRuntimeException expected) {
-     * assertEquals("No object in object map with id " + id,
-     * expected.getMessage()); } verify(); }
-     */
-    @Ignore // DKH
     @Test
-    public void testRegisteredObjectReturnDifferentIdentityForDifferentObject() {
-//        final TestPojo pojo1 = new TestPojo();
-//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+
(nextId++));
-//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(pojo1,
transientTestOid);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
-//        final ObjectAdapter adapter = adapterForTransient;
-//        
-//        // similar to object store implementation
-//        ((AdapterManagerPersist) mockPersistenceSession.getAdapterManager()).remapAsPersistent(adapter);
-//        
-//        // would be done by the object store, we must do ourselves.
-//        adapter.setOptimisticLock(new TestProxyVersion(1));
-//        final ObjectAdapter dummyObjectAdapter = adapter;
-//        
-//        final TestPojo pojo = new TestPojo();
-//        final RootOidDefault transientTestOid2 = RootOidDefault.createTransient("CUS",
""+ (nextId++));
-//        final ObjectAdapter adapterForTransient2 = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(pojo,
transientTestOid2);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient2.getResolveState());
-//        final ObjectAdapter adapter2 = adapterForTransient2;
-//        
-//        // similar to object store implementation
-//        ((AdapterManagerPersist) mockPersistenceSession.getAdapterManager()).remapAsPersistent(adapter2);
-//        
-//        // would be done by the object store, we must do ourselves.
-//        adapter2.setOptimisticLock(new TestProxyVersion(1));
-//        final ObjectAdapter dummyObjectAdapter2 = adapter2;
-//
-//        final String id = context.mapObject(dummyObjectAdapter);
-//        final String id2 = context.mapObject(dummyObjectAdapter2);
-//
-//        assertNotSame(id, id2);
+    public void mapAction_returnsSameIdForSameAction() {
+        final ObjectAction action = new ObjectActionNoop();
+        final String id = context.mapAction(action);
+        final String id2 = context.mapAction(action);
+        assertEquals(id, id2);
     }
 
-    @Ignore // DKH
     @Test
-    public void testRegisteredActionReturnSameIdentityForSameAction() {
-//        final ObjectActionNoop action = new ObjectActionNoop();
-//        final String id = context.mapAction(action);
-//        final String id2 = context.mapAction(action);
-//        assertEquals(id, id2);
+    public void mapAction_returnsDifferentIdsForDifferentActions() {
+        final String id = context.mapAction(new ObjectActionNoop());
+        final String id2 = context.mapAction(new ObjectActionNoop());
+        assertNotSame(id, id2);
     }
 
-    @Ignore // DKH
-    @Test
-    public void testRegisteredActionReturnDifferentIdentityForDifferentAction() {
-//        final String id = context.mapAction(new ObjectActionNoop());
-//        final String id2 = context.mapAction(new ObjectActionNoop());
-//        assertNotSame(id, id2);
+    
+    private PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
     }
 
-    @Ignore // DKH
-    @Test
-    public void testPersistentObjectsRestoredAsGhostToObjectLoader() {
-//        final TestPojo pojo = new TestPojo();
-//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+
(nextId++));
-//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(pojo,
transientTestOid);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
-//        final ObjectAdapter adapter = adapterForTransient;
-//        
-//        // similar to object store implementation
-//        ((AdapterManagerPersist) mockPersistenceSession.getAdapterManager()).remapAsPersistent(adapter);
-//        
-//        // would be done by the object store, we must do ourselves.
-//        adapter.setOptimisticLock(new TestProxyVersion(1));
-//        final ObjectAdapter object = adapter;
-//        context.mapObject(object);
-//        final Oid oid = object.getOid();
-//        mockPersistenceSession.testReset();
-//
-//        assertNull("loader still has the object", getAdapterManager().getAdapterFor(oid));
-//        context.restoreAllObjectsToLoader();
-//
-//        assertNotNull("loaders is missing the object", getAdapterManager().getAdapterFor(oid));
-//        final ObjectAdapter newAdapter = getAdapterManager().getAdapterFor(oid);
-//        assertNotSame("expect the loader to have a new adapter", object, newAdapter);
-//        assertEquals("expect oids to match", object.getOid(), newAdapter.getOid());
-//        assertNotSame(object.getObject(), newAdapter.getObject());
-//        assertEquals(object.getObject().getClass(), newAdapter.getObject().getClass());
-//        assertEquals("expect versions to match", object.getVersion(), newAdapter.getVersion());
-//        assertEquals(ResolveState.GHOST, newAdapter.getResolveState());
+    private AdapterManager getAdapterManager() {
+        return getPersistenceSession().getAdapterManager();
     }
 
-    
-//    private PersistenceSession getPersistenceSession() {
-//        return IsisContext.getPersistenceSession();
-//    }
-//
-//    private AdapterManager getAdapterManager() {
-//        return getPersistenceSession().getAdapterManager();
-//    }
-
 }

Added: incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapCollection.java
URL: http://svn.apache.org/viewvc/incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapCollection.java?rev=1331449&view=auto
==============================================================================
--- incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapCollection.java
(added)
+++ incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapCollection.java
Fri Apr 27 14:47:06 2012
@@ -0,0 +1,159 @@
+/*
+ *  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.viewer.html.context;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+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.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.tck.dom.eg.ExamplePojoWithValues;
+import org.apache.isis.viewer.html.action.ActionException;
+
+public class ContextTest_mapCollection {
+
+    @Rule
+    public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+    private Context context;
+
+    @Before
+    public void setUp() throws Exception {
+        Logger.getRootLogger().setLevel(Level.OFF);
+        context = new Context(null);
+    }
+
+    @Test
+    public void getMappedCollection_forNonExistentId() {
+
+
+        try {
+            assertNull(context.getMappedCollection("NON-EXISTENT-ID"));
+            fail();
+        } catch (final ActionException ex) {
+            // expected
+        }
+    }
+
+    @Test
+    public void mapCollection_then_getMappedCollection() throws Exception {
+
+        // given
+        iswf.persist(iswf.fixtures.epv1);
+        iswf.persist(iswf.fixtures.epv2);
+
+        final List<ExamplePojoWithValues> collection = Lists.newArrayList();
+        collection.add(iswf.fixtures.epv1);
+        collection.add(iswf.fixtures.epv2);
+        
+        final Oid oid1 = getAdapterManager().adapterFor(iswf.fixtures.epv1).getOid();
+        final Oid oid2 = getAdapterManager().adapterFor(iswf.fixtures.epv2).getOid();
+        
+        final ObjectAdapter collectionAdapter = getAdapterManager().adapterFor(collection);
+        final String id = context.mapCollection(collectionAdapter);
+        
+        iswf.bounceSystem();
+
+        // when
+        final ObjectAdapter mappedCollection = context.getMappedCollection(id);
+        
+        // then
+        final List<?> list = (List<?>) mappedCollection.getObject();
+
+        final Oid oid1Remapped = getAdapterManager().adapterFor(list.get(0)).getOid();
+        final Oid oid2Remapped = getAdapterManager().adapterFor(list.get(1)).getOid();
+        assertEquals(oid1, oid1Remapped);
+        assertEquals(oid2, oid2Remapped);
+    }
+
+    
+
+    @Test
+    public void testRegisteredCollectionReturnSameIdentityForSameCollection() {
+        
+        // given
+        iswf.persist(iswf.fixtures.epv1);
+        iswf.persist(iswf.fixtures.epv2);
+
+        final List<ExamplePojoWithValues> collection = Lists.newArrayList();
+        collection.add(iswf.fixtures.epv1);
+        collection.add(iswf.fixtures.epv2);
+        
+        final ObjectAdapter collectionAdapter = getAdapterManager().adapterFor(collection);
+        
+        // when
+        final String id = context.mapCollection(collectionAdapter);
+        final String id2 = context.mapCollection(collectionAdapter);
+        
+        // then
+        assertEquals(id, id2);
+    }
+
+    @Test
+    public void testRegisteredCollectionReturnDifferentIdentityForDifferentCollection() {
+
+        // given
+        iswf.persist(iswf.fixtures.epv1);
+        iswf.persist(iswf.fixtures.epv2);
+
+        final List<ExamplePojoWithValues> collection1 = Lists.newArrayList();
+        collection1.add(iswf.fixtures.epv1);
+        final ObjectAdapter collection1Adapter = getAdapterManager().adapterFor(collection1);
+
+        final List<ExamplePojoWithValues> collection2 = Lists.newArrayList();
+        collection2.add(iswf.fixtures.epv2);
+        final ObjectAdapter collection2Adapter = getAdapterManager().adapterFor(collection2);
+
+        // when
+        final String id = context.mapCollection(collection1Adapter);
+        final String id2 = context.mapCollection(collection2Adapter);
+        
+        // then
+        assertThat(id, not(equalTo(id2)));
+    }
+
+    
+    private PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
+    }
+
+    private AdapterManager getAdapterManager() {
+        return getPersistenceSession().getAdapterManager();
+    }
+
+}

Propchange: incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapObject.java
(from r1307476, incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextSessionDataTest.java)
URL: http://svn.apache.org/viewvc/incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapObject.java?p2=incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapObject.java&p1=incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextSessionDataTest.java&r1=1307476&r2=1331449&rev=1331449&view=diff
==============================================================================
--- incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextSessionDataTest.java
(original)
+++ incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_mapObject.java
Fri Apr 27 14:47:06 2012
@@ -19,8 +19,18 @@
 
 package org.apache.isis.viewer.html.context;
 
-import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+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.assertThat;
+import static org.junit.Assert.fail;
 
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -28,75 +38,222 @@ import org.junit.Test;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.ResolveState;
 import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
-import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.core.metamodel.adapter.version.Version;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.viewer.html.action.ActionException;
 
-public class ContextSessionDataTest {
+public class ContextTest_mapObject {
 
     @Rule
-    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+    public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
 
     private ObjectAdapter originalAdapter;
     private Oid oid;
     private ObjectAdapter restoredAdapter;
 
+    private Context context;
 
     @Before
     public void setUp() throws Exception {
-        
-//        final RootOidDefault transientTestOid = RootOidDefault.createTransient("CUS", ""+
(nextId++));
-//        final ObjectAdapter adapterForTransient = ((AdapterManagerTestSupport) mockPersistenceSession.getAdapterManager()).testCreateTransient(new
TestPojo(), transientTestOid);
-//        Assert.assertEquals("", ResolveState.TRANSIENT, adapterForTransient.getResolveState());
-//
-//        originalAdapter = adapterForTransient;
-//        oid = originalAdapter.getOid();
-
-//        final Context context = new Context(null);
-//        context.mapObject(originalAdapter);
-//
-//        assertNotNull("loader still has the object", getAdapterManager().getAdapterFor(oid));
-//        mockPersistenceSession.testReset();
-//        assertNull("loader no longer has the object", getAdapterManager().getAdapterFor(oid));
-//
-//        context.restoreAllObjectsToLoader();
-//        restoredAdapter = getAdapterManager().getAdapterFor(oid);
+        Logger.getRootLogger().setLevel(Level.OFF);
+        context = new Context(null);
     }
-
+    
     @Test
-    public void testExistsInLoader() {
+    public void mapObject_then_restoreAllObjectsToLoader() throws Exception {
+
+        // given
+        originalAdapter = getAdapterManager().adapterFor(iswf.fixtures.epv1);
+        oid = originalAdapter.getOid();
+        context.mapObject(originalAdapter);
+        
+        iswf.bounceSystem();
+        
+        // when
+        context.restoreAllObjectsToLoader();
+        restoredAdapter = getAdapterManager().getAdapterFor(oid);
+
         assertNotNull("loaders is missing the object", getAdapterManager().getAdapterFor(oid));
         assertNotSame("expect the loader to have a new adapter", originalAdapter, restoredAdapter);
+        
+        // then
+        assertEquals(originalAdapter.getOid(), restoredAdapter.getOid());
+        assertNotSame(originalAdapter, restoredAdapter);
+        assertEquals(originalAdapter.getObject().getClass(), restoredAdapter.getObject().getClass());
+        assertEquals(originalAdapter.getVersion(), restoredAdapter.getVersion());
+        assertEquals(ResolveState.TRANSIENT, restoredAdapter.getResolveState());
     }
 
+    
     @Test
-    public void testHasSameOid() {
-        assertEquals(originalAdapter.getOid(), restoredAdapter.getOid());
+    public void mapObject_forTransient_then_getMappedObject_byId() {
+
+        // given
+        originalAdapter = getAdapterManager().adapterFor(iswf.fixtures.epv1);
+        oid = originalAdapter.getOid();
+        final String id = context.mapObject(originalAdapter);
+        
+        // when
+        restoredAdapter = context.getMappedObject(id);
+        
+        // then
+        assertEquals(originalAdapter, restoredAdapter);
     }
 
+
     @Test
-    public void testNotSameAdapter() {
-        assertNotSame(originalAdapter, restoredAdapter);
+    public void mapObject_forPersistent_then_getMappedObject_byId() {
+
+        // given
+        iswf.persist(iswf.fixtures.epv1);
+
+        originalAdapter = getAdapterManager().adapterFor(iswf.fixtures.epv1);
+        oid = originalAdapter.getOid();
+        final String id = context.mapObject(originalAdapter);
+        
+        // when
+        restoredAdapter = context.getMappedObject(id);
+        
+        // then
+        assertEquals(originalAdapter, restoredAdapter);
     }
 
+
     @Test
-    public void testSamePojo() {
-        assertEquals(originalAdapter.getObject().getClass(), restoredAdapter.getObject().getClass());
+    public void getMappedObject_forPersistent_whenChanged() throws Exception {
+
+        // given
+        iswf.persist(iswf.fixtures.epv1);
+        
+        originalAdapter = getAdapterManager().adapterFor(iswf.fixtures.epv1);
+        final Oid oid = originalAdapter.getOid();
+        final String id = context.mapObject(originalAdapter);
+        
+        final Version version = originalAdapter.getVersion();
+        
+        iswf.fixtures.epv1.setName("changed date");
+        iswf.bounceSystem(); // does a commit, which will bump the version
+        
+        originalAdapter = getAdapterManager().getAdapterFor(oid);
+        
+        final Version version2 = originalAdapter.getVersion();
+        
+        assertThat(version.different(version2), is(true));
+        
+        
+        // when
+        restoredAdapter = context.getMappedObject(id);
+        final String message = context.getMessage(1);
+        
+        // then
+        assertEquals("Reloaded object " + restoredAdapter.titleString(), message);
     }
 
+    
     @Test
-    public void testHasSameVersion() {
-        assertEquals(originalAdapter.getVersion(), restoredAdapter.getVersion());
+    public void mapObject_forTransient_alwaysReturnsSameId() {
+
+        // given
+        originalAdapter = getAdapterManager().adapterFor(iswf.fixtures.epv1);
+        
+        // when
+        final String id = context.mapObject(originalAdapter);
+        final String id2 = context.mapObject(originalAdapter);
+        
+        // then
+        assertEquals(id, id2);
     }
 
+    
     @Test
-    public void testHasResolveStateOfTransient() {
-        assertEquals(ResolveState.TRANSIENT, restoredAdapter.getResolveState());
+    public void mapObject_forPersistent_alwaysReturnsSameId() {
+
+        // given
+        iswf.persist(iswf.fixtures.epv1);
+        
+        originalAdapter = getAdapterManager().adapterFor(iswf.fixtures.epv1);
+        
+        // when
+        final String id = context.mapObject(originalAdapter);
+        final String id2 = context.mapObject(originalAdapter);
+        
+        // then
+        assertEquals(id, id2);
     }
 
     
+    @Test
+    public void mapObject_forTransient_returnsDifferentIdsForDifferentObjects() {
+
+        // when
+        final String id = context.mapObject(getAdapterManager().adapterFor(iswf.fixtures.epv1));
+        final String id2 = context.mapObject(getAdapterManager().adapterFor(iswf.fixtures.epv2));
+        
+        // then
+        assertThat(id, not(equalTo(id2)));
+    }
+
+
+    @Test
+    public void mapObject_forPersistent_returnsDifferentIdsForDifferentObjects() {
+
+        // given
+        iswf.persist(iswf.fixtures.epv1);
+        iswf.persist(iswf.fixtures.epv2);
+        
+        // when
+        final String id = context.mapObject(getAdapterManager().adapterFor(iswf.fixtures.epv1));
+        final String id2 = context.mapObject(getAdapterManager().adapterFor(iswf.fixtures.epv2));
+        
+        // then
+        assertThat(id, not(equalTo(id2)));
+    }
+
+    
+    @Test
+    public void restoreAllObjectsToLoader_restoredAsGhosts() throws Exception {
+
+        // given
+        iswf.persist(iswf.fixtures.epv1);
+        originalAdapter = getAdapterManager().adapterFor(iswf.fixtures.epv1);
+        oid = originalAdapter.getOid();
+        
+        iswf.bounceSystem();
+        
+        // when
+        context.restoreAllObjectsToLoader();
+        
+        // then
+        restoredAdapter = getAdapterManager().getAdapterFor(oid);
+        
+        assertEquals("expect versions to match", originalAdapter.getVersion(), restoredAdapter.getVersion());
+        assertEquals(ResolveState.GHOST, restoredAdapter.getResolveState());
+    }
+
+    
+    
+    @Test
+    public void testExceptionThrownWhenNoActionForIdentity() {
+        
+        iswf.persist(iswf.fixtures.epv1);
+        iswf.persist(iswf.fixtures.epv2);
+        
+        // when
+        context.mapObject(getAdapterManager().adapterFor(iswf.fixtures.epv1));
+
+        try {
+            assertNull(context.getMappedObject("NON-EXISTENT-ID"));
+            fail();
+        } catch (final ActionException ex) {
+            // expected
+        }
+    }
+
+    
+
     private PersistenceSession getPersistenceSession() {
         return IsisContext.getPersistenceSession();
     }

Modified: incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_serialization.java
URL: http://svn.apache.org/viewvc/incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_serialization.java?rev=1331449&r1=1331448&r2=1331449&view=diff
==============================================================================
--- incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_serialization.java
(original)
+++ incubator/isis/branches/0.3.0-incubating-NEW-OIDs/viewer/html/src/test/java/org/apache/isis/viewer/html/context/ContextTest_serialization.java
Fri Apr 27 14:47:06 2012
@@ -5,17 +5,18 @@ import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
 
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
 import org.jmock.Expectations;
 import org.jmock.auto.Mock;
-import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
 import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
 import org.apache.isis.viewer.html.HtmlViewerConstants;
 import org.apache.isis.viewer.html.PathBuilder;
 import org.apache.isis.viewer.html.PathBuilderDefault;
@@ -25,6 +26,9 @@ import org.apache.isis.viewer.html.compo
 public class ContextTest_serialization {
 
     @Rule
+    public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+    @Rule
     public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
     
     @Mock
@@ -37,6 +41,8 @@ public class ContextTest_serialization {
 
     @Before
     public void setUp() throws Exception {
+        Logger.getRootLogger().setLevel(Level.OFF);
+        
         pathBuilder = new PathBuilderDefault("shtml");
         context.checking(new Expectations() {
             {
@@ -62,13 +68,9 @@ public class ContextTest_serialization {
         viewerContext = new Context(factory);
     }
 
-    @After
-    public void tearDown() throws Exception {
-    }
 
-    @Ignore // REVIEW: I'm not convinced that Context needs to be serializable, but I've
seen Tomcat try to do so in some circumstances..
     @Test
-    public void test() throws IOException {
+    public void writeObject() throws IOException {
         OutputStream baos = new ByteArrayOutputStream();
         final ObjectOutputStream objectOutputStream = new ObjectOutputStream(baos);
         objectOutputStream.writeObject(viewerContext);



Mime
View raw message