incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1098939 [9/11] - in /incubator/isis/trunk/runtimes/dflt: profilestores/dflt/src/main/java/org/apache/isis/runtimes/dflt/profilestores/dflt/ profilestores/xml/src/main/java/org/apache/isis/runtimes/dflt/profilestores/xml/ profilestores/xml/...
Date Tue, 03 May 2011 06:33:49 GMT
Modified: incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/exchange/SetAssociationRequestEncodabilityTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/exchange/SetAssociationRequestEncodabilityTest.java?rev=1098939&r1=1098938&r2=1098939&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/exchange/SetAssociationRequestEncodabilityTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/exchange/SetAssociationRequestEncodabilityTest.java Tue May  3 06:33:43 2011
@@ -17,59 +17,53 @@
  *  under the License.
  */
 
+package org.apache.isis.runtimes.dflt.remoting.common.exchange;
 
-package org.apache.isis.runtimes.dflt.remoting.common.exchange;
-
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 import java.io.IOException;
 
-import org.apache.isis.runtimes.dflt.remoting.common.data.common.IdentityData;
-import org.apache.isis.runtimes.dflt.remoting.common.exchange.SetAssociationRequest;
 import org.apache.isis.core.commons.encoding.EncodabilityContractTest;
 import org.apache.isis.core.commons.encoding.Encodable;
+import org.apache.isis.runtimes.dflt.remoting.common.data.common.IdentityData;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
-
-public class SetAssociationRequestEncodabilityTest extends EncodabilityContractTest {
-
-
-	private IdentityData mockTargetData;
-	private IdentityData mockAssociateData;
-	
-	@Override
-	@Before
-	public void setUp() throws Exception {
-		super.setUp();
-		mockTargetData = context.mock(IdentityData.class, "identity");
-		mockAssociateData = context.mock(IdentityData.class, "target");
-	}
-	
-
-	protected Encodable createEncodable() {
-		return new SetAssociationRequest(mockAuthSession, "firstName", mockTargetData, mockAssociateData);
-	}
-	
-	
-	@Override
-	@Ignore
-	@Test
-	public void shouldRoundTrip() throws IOException {
-		super.shouldRoundTrip();
-	}
-
-	@Override
-	protected void assertRoundtripped(
-			Object decodedEncodable,
-			Object originalEncodable) {
-		SetAssociationRequest decoded = (SetAssociationRequest) decodedEncodable;
-		SetAssociationRequest original = (SetAssociationRequest) originalEncodable;
-		
-		// TODO: to complete, may need to setup mock expectations
-		assertThat(decoded.getId(), is(equalTo(original.getId())));
-	}
-
-}
+
+public class SetAssociationRequestEncodabilityTest extends EncodabilityContractTest {
+
+    private IdentityData mockTargetData;
+    private IdentityData mockAssociateData;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        mockTargetData = context.mock(IdentityData.class, "identity");
+        mockAssociateData = context.mock(IdentityData.class, "target");
+    }
+
+    @Override
+    protected Encodable createEncodable() {
+        return new SetAssociationRequest(mockAuthSession, "firstName", mockTargetData, mockAssociateData);
+    }
+
+    @Override
+    @Ignore
+    @Test
+    public void shouldRoundTrip() throws IOException {
+        super.shouldRoundTrip();
+    }
+
+    @Override
+    protected void assertRoundtripped(final Object decodedEncodable, final Object originalEncodable) {
+        final SetAssociationRequest decoded = (SetAssociationRequest) decodedEncodable;
+        final SetAssociationRequest original = (SetAssociationRequest) originalEncodable;
+
+        // TODO: to complete, may need to setup mock expectations
+        assertThat(decoded.getId(), is(equalTo(original.getId())));
+    }
+
+}

Modified: incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/exchange/SetValueRequestEncodabilityTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/exchange/SetValueRequestEncodabilityTest.java?rev=1098939&r1=1098938&r2=1098939&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/exchange/SetValueRequestEncodabilityTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/exchange/SetValueRequestEncodabilityTest.java Tue May  3 06:33:43 2011
@@ -17,60 +17,54 @@
  *  under the License.
  */
 
+package org.apache.isis.runtimes.dflt.remoting.common.exchange;
 
-package org.apache.isis.runtimes.dflt.remoting.common.exchange;
-
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
 import java.io.IOException;
 
-import org.apache.isis.runtimes.dflt.remoting.common.data.common.EncodableObjectData;
-import org.apache.isis.runtimes.dflt.remoting.common.data.common.IdentityData;
-import org.apache.isis.runtimes.dflt.remoting.common.exchange.SetValueRequest;
 import org.apache.isis.core.commons.encoding.EncodabilityContractTest;
 import org.apache.isis.core.commons.encoding.Encodable;
+import org.apache.isis.runtimes.dflt.remoting.common.data.common.EncodableObjectData;
+import org.apache.isis.runtimes.dflt.remoting.common.data.common.IdentityData;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
-
-public class SetValueRequestEncodabilityTest extends EncodabilityContractTest {
-
-
-	private IdentityData mockTargetData;
-	private EncodableObjectData mockEncodeableData;
-	
-	@Override
-	@Before
-	public void setUp() throws Exception {
-		super.setUp();
-		mockTargetData = context.mock(IdentityData.class);
-		mockEncodeableData = context.mock(EncodableObjectData.class);
-	}
-	
-
-	protected Encodable createEncodable() {
-		return new SetValueRequest(mockAuthSession, "firstName", mockTargetData, mockEncodeableData);
-	}
-	
-	
-	@Override
-	@Ignore
-	@Test
-	public void shouldRoundTrip() throws IOException {
-		super.shouldRoundTrip();
-	}
-
-	@Override
-	protected void assertRoundtripped(
-			Object decodedEncodable,
-			Object originalEncodable) {
-		SetValueRequest decoded = (SetValueRequest) decodedEncodable;
-		SetValueRequest original = (SetValueRequest) originalEncodable;
-		
-		// TODO: to complete, may need to setup mock expectations
-		assertThat(decoded.getId(), is(equalTo(original.getId())));
-	}
-
-}
+
+public class SetValueRequestEncodabilityTest extends EncodabilityContractTest {
+
+    private IdentityData mockTargetData;
+    private EncodableObjectData mockEncodeableData;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        mockTargetData = context.mock(IdentityData.class);
+        mockEncodeableData = context.mock(EncodableObjectData.class);
+    }
+
+    @Override
+    protected Encodable createEncodable() {
+        return new SetValueRequest(mockAuthSession, "firstName", mockTargetData, mockEncodeableData);
+    }
+
+    @Override
+    @Ignore
+    @Test
+    public void shouldRoundTrip() throws IOException {
+        super.shouldRoundTrip();
+    }
+
+    @Override
+    protected void assertRoundtripped(final Object decodedEncodable, final Object originalEncodable) {
+        final SetValueRequest decoded = (SetValueRequest) decodedEncodable;
+        final SetValueRequest original = (SetValueRequest) originalEncodable;
+
+        // TODO: to complete, may need to setup mock expectations
+        assertThat(decoded.getId(), is(equalTo(original.getId())));
+    }
+
+}

Modified: incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/facade/DummyServerFacade.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/facade/DummyServerFacade.java?rev=1098939&r1=1098938&r2=1098939&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/facade/DummyServerFacade.java (original)
+++ incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/facade/DummyServerFacade.java Tue May  3 06:33:43 2011
@@ -17,10 +17,9 @@
  *  under the License.
  */
 
+package org.apache.isis.runtimes.dflt.remoting.common.facade;
 
-package org.apache.isis.runtimes.dflt.remoting.common.facade;
-
-
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.runtimes.dflt.remoting.common.data.common.ObjectData;
 import org.apache.isis.runtimes.dflt.remoting.common.exchange.AuthorizationRequestUsability;
 import org.apache.isis.runtimes.dflt.remoting.common.exchange.AuthorizationRequestVisibility;
@@ -55,91 +54,106 @@ import org.apache.isis.runtimes.dflt.rem
 import org.apache.isis.runtimes.dflt.remoting.common.exchange.SetAssociationResponse;
 import org.apache.isis.runtimes.dflt.remoting.common.exchange.SetValueRequest;
 import org.apache.isis.runtimes.dflt.remoting.common.exchange.SetValueResponse;
-import org.apache.isis.runtimes.dflt.remoting.common.facade.ServerFacade;
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-
-
-/**
- * previously called <tt>DummyDistribution</tt>.
- */
-public class DummyServerFacade implements ServerFacade {
-    public ObjectData[] allInstances(final AuthenticationSession session, final String fullName, final boolean includeSubclasses) {
-        return null;
-    }
-
-    public OpenSessionResponse openSession(OpenSessionRequest request) {
-        return null;
-    }
-
-    public AuthorizationResponse authorizeUsability(AuthorizationRequestUsability request) {
-        return new AuthorizationResponse(false);
-    }
-
-    public AuthorizationResponse authorizeVisibility(AuthorizationRequestVisibility request) {
-        return new AuthorizationResponse(false);
-    }
-
-    public ClearAssociationResponse clearAssociation(
-            ClearAssociationRequest request) {
-        return null;
-    }
-
-    public ClearValueResponse clearValue(ClearValueRequest request) {
-        return null;
-    }
-
-    public CloseSessionResponse closeSession(CloseSessionRequest request) {
-    	return null;
-    }
-
-    public ExecuteServerActionResponse executeServerAction(
-            ExecuteServerActionRequest request) {
-        return null;
-    }
-
-    public ExecuteClientActionResponse executeClientAction(ExecuteClientActionRequest request) {
-        return null;
-    }
-
-    public FindInstancesResponse findInstances(FindInstancesRequest request) {
-        return null;
-    }
-
-    public HasInstancesResponse hasInstances(HasInstancesRequest request) {
-        return null;
-    }
-
-    public GetObjectResponse getObject(GetObjectRequest request) {
-        return null;
-    }
-
-    public GetPropertiesResponse getProperties(GetPropertiesRequest request) {
-        return null;
-    }
-
-    public OidForServiceResponse oidForService(OidForServiceRequest request) {
-        return null;
-    }
-
-    public ResolveFieldResponse resolveField(ResolveFieldRequest request) {
-        return null;
-    }
-
-    public ResolveObjectResponse resolveImmediately(ResolveObjectRequest request) {
-        return null;
-    }
-
-    public SetAssociationResponse setAssociation(
-            SetAssociationRequest request) {
-        return null;
-    }
-
-    public SetValueResponse setValue(
-            SetValueRequest request) {
-        return null;
-    }
-
-    public void init() {}
-
-    public void shutdown() {}
-}
+
+/**
+ * previously called <tt>DummyDistribution</tt>.
+ */
+public class DummyServerFacade implements ServerFacade {
+    public ObjectData[] allInstances(final AuthenticationSession session, final String fullName,
+        final boolean includeSubclasses) {
+        return null;
+    }
+
+    @Override
+    public OpenSessionResponse openSession(final OpenSessionRequest request) {
+        return null;
+    }
+
+    @Override
+    public AuthorizationResponse authorizeUsability(final AuthorizationRequestUsability request) {
+        return new AuthorizationResponse(false);
+    }
+
+    @Override
+    public AuthorizationResponse authorizeVisibility(final AuthorizationRequestVisibility request) {
+        return new AuthorizationResponse(false);
+    }
+
+    @Override
+    public ClearAssociationResponse clearAssociation(final ClearAssociationRequest request) {
+        return null;
+    }
+
+    @Override
+    public ClearValueResponse clearValue(final ClearValueRequest request) {
+        return null;
+    }
+
+    @Override
+    public CloseSessionResponse closeSession(final CloseSessionRequest request) {
+        return null;
+    }
+
+    @Override
+    public ExecuteServerActionResponse executeServerAction(final ExecuteServerActionRequest request) {
+        return null;
+    }
+
+    @Override
+    public ExecuteClientActionResponse executeClientAction(final ExecuteClientActionRequest request) {
+        return null;
+    }
+
+    @Override
+    public FindInstancesResponse findInstances(final FindInstancesRequest request) {
+        return null;
+    }
+
+    @Override
+    public HasInstancesResponse hasInstances(final HasInstancesRequest request) {
+        return null;
+    }
+
+    @Override
+    public GetObjectResponse getObject(final GetObjectRequest request) {
+        return null;
+    }
+
+    @Override
+    public GetPropertiesResponse getProperties(final GetPropertiesRequest request) {
+        return null;
+    }
+
+    @Override
+    public OidForServiceResponse oidForService(final OidForServiceRequest request) {
+        return null;
+    }
+
+    @Override
+    public ResolveFieldResponse resolveField(final ResolveFieldRequest request) {
+        return null;
+    }
+
+    @Override
+    public ResolveObjectResponse resolveImmediately(final ResolveObjectRequest request) {
+        return null;
+    }
+
+    @Override
+    public SetAssociationResponse setAssociation(final SetAssociationRequest request) {
+        return null;
+    }
+
+    @Override
+    public SetValueResponse setValue(final SetValueRequest request) {
+        return null;
+    }
+
+    @Override
+    public void init() {
+    }
+
+    @Override
+    public void shutdown() {
+    }
+}

Modified: incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/protocol/encoding/ObjectDecoderCollectionTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/protocol/encoding/ObjectDecoderCollectionTest.java?rev=1098939&r1=1098938&r2=1098939&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/protocol/encoding/ObjectDecoderCollectionTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/protocol/encoding/ObjectDecoderCollectionTest.java Tue May  3 06:33:43 2011
@@ -17,14 +17,18 @@
  *  under the License.
  */
 
+package org.apache.isis.runtimes.dflt.remoting.common.protocol.encoding;
 
-package org.apache.isis.runtimes.dflt.remoting.common.protocol.encoding;
-
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Vector;
 
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.collections.CollectionFacetAbstract;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.testspec.TestProxySpecification;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyCollectionData;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyObjectData;
 import org.apache.isis.runtimes.dflt.remoting.common.data.common.CollectionData;
@@ -32,106 +36,106 @@ import org.apache.isis.runtimes.dflt.rem
 import org.apache.isis.runtimes.dflt.remoting.common.data.common.ReferenceData;
 import org.apache.isis.runtimes.dflt.remoting.protocol.internal.FieldOrderCache;
 import org.apache.isis.runtimes.dflt.remoting.protocol.internal.ObjectDeserializer;
-import org.apache.isis.core.commons.exceptions.NotYetImplementedException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.facets.collections.CollectionFacetAbstract;
-import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
-import org.apache.isis.core.metamodel.testspec.TestProxySpecification;
 import org.apache.isis.runtimes.dflt.runtime.persistence.adaptermanager.ObjectToAdapterTransformer;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.ProxyJunit3TestCase;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestPojo;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyOid;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyVersion;
-
-
-public class ObjectDecoderCollectionTest extends ProxyJunit3TestCase {
-
-    private ObjectDeserializer deserializer;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        FieldOrderCache fieldOrderCache = null;  // TODO: should provide a mock here?
-		deserializer = new ObjectDeserializer(fieldOrderCache);
-
-        final TestProxySpecification specification = system.getSpecification(Vector.class);
-        specification.addFacet(new CollectionFacetAbstract(specification) {
-
-            public void init(final ObjectAdapter collection, final ObjectAdapter[] initData) {
-                for (int i = 0; i < initData.length; i++) {
-                    collectionOfUnderlying(collection).add(initData[i].getObject());
-                }
-            }
-
-            @SuppressWarnings("unchecked")
-            public Collection<ObjectAdapter> collection(ObjectAdapter collectionAdapter) {
-                Collection<Object> collection = collectionOfUnderlying(collectionAdapter);
-                return CollectionUtils.collect(collection, new ObjectToAdapterTransformer());
-            }
-
-            public ObjectAdapter firstElement(final ObjectAdapter collection) {
-                throw new NotYetImplementedException();
-            }
-
-            public int size(final ObjectAdapter collection) {
-                return collectionOfUnderlying(collection).size();
-            }
-
-            @SuppressWarnings("unchecked")
-            private Collection<Object> collectionOfUnderlying(final ObjectAdapter collectionNO) {
-                return (Collection<Object>) collectionNO.getObject();
-            }
-
-        });
-    }
-
-    public void testRecreateEmptyCollection() {
-        final TestProxyOid collectionOid = new TestProxyOid(123);
-        final ReferenceData[] elementData = null;
-        final CollectionData data = new DummyCollectionData(collectionOid, Vector.class.getName(), TestPojo.class.getName(),
-                elementData, new TestProxyVersion());
-
-        final ObjectAdapter adapter = deserializer.deserialize(data);
-
-        final Vector restoredCollection = (Vector) adapter.getObject();
-        assertEquals(0, restoredCollection.size());
-
-        final CollectionFacet facet = adapter.getSpecification().getFacet(CollectionFacet.class);
-        assertEquals(0, facet.size(adapter));
-    }
-
-    public void testRecreateCollection() {
-        final ReferenceData elements[] = new ObjectData[2];
-        final TestProxyOid element0Oid = new TestProxyOid(345, true);
-        elements[0] = new DummyObjectData(element0Oid, TestPojo.class.getName(), false, new TestProxyVersion(3));
-        final TestProxyOid element1Oid = new TestProxyOid(678, true);
-        elements[1] = new DummyObjectData(element1Oid, TestPojo.class.getName(), false, new TestProxyVersion(7));
-
-        final TestProxyOid collectionOid = new TestProxyOid(123);
-        final CollectionData data = new DummyCollectionData(collectionOid, Vector.class.getName(), TestPojo.class.getName(),
-                elements, new TestProxyVersion());
-
-        final ObjectAdapter adapter = deserializer.deserialize(data);
-
-        final Vector restoredCollection = (Vector) adapter.getObject();
-        assertEquals(2, restoredCollection.size());
-
-        final CollectionFacet facet = adapter.getSpecification().getFacet(CollectionFacet.class);
-        final Enumeration elements2 = facet.elements(adapter);
-        final ObjectAdapter element0 = (ObjectAdapter) elements2.nextElement();
-        final ObjectAdapter element2 = (ObjectAdapter) elements2.nextElement();
-
-        assertNotNull(element0.getObject());
-        assertNotNull(element2.getObject());
-
-        assertEquals(TestPojo.class, element0.getObject().getClass());
-        assertEquals(TestPojo.class, element2.getObject().getClass());
-
-        assertEquals(new TestProxyOid(678, true), element2.getOid());
-        assertEquals(new TestProxyOid(345, true), element0.getOid());
-
-        // version not set as there is no field data for elements
-        // assertEquals(new DummyVersion(3), adapter.elementAt(0).getVersion());
-        // assertEquals(new DummyVersion(7), adapter.elementAt(1).getVersion());
-    }
-}
+
+public class ObjectDecoderCollectionTest extends ProxyJunit3TestCase {
+
+    private ObjectDeserializer deserializer;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        final FieldOrderCache fieldOrderCache = null; // TODO: should provide a mock here?
+        deserializer = new ObjectDeserializer(fieldOrderCache);
+
+        final TestProxySpecification specification = system.getSpecification(Vector.class);
+        specification.addFacet(new CollectionFacetAbstract(specification) {
+
+            @Override
+            public void init(final ObjectAdapter collection, final ObjectAdapter[] initData) {
+                for (final ObjectAdapter element : initData) {
+                    collectionOfUnderlying(collection).add(element.getObject());
+                }
+            }
+
+            @Override
+            @SuppressWarnings("unchecked")
+            public Collection<ObjectAdapter> collection(final ObjectAdapter collectionAdapter) {
+                final Collection<Object> collection = collectionOfUnderlying(collectionAdapter);
+                return CollectionUtils.collect(collection, new ObjectToAdapterTransformer());
+            }
+
+            @Override
+            public ObjectAdapter firstElement(final ObjectAdapter collection) {
+                throw new NotYetImplementedException();
+            }
+
+            @Override
+            public int size(final ObjectAdapter collection) {
+                return collectionOfUnderlying(collection).size();
+            }
+
+            @SuppressWarnings("unchecked")
+            private Collection<Object> collectionOfUnderlying(final ObjectAdapter collectionNO) {
+                return (Collection<Object>) collectionNO.getObject();
+            }
+
+        });
+    }
+
+    public void testRecreateEmptyCollection() {
+        final TestProxyOid collectionOid = new TestProxyOid(123);
+        final ReferenceData[] elementData = null;
+        final CollectionData data =
+            new DummyCollectionData(collectionOid, Vector.class.getName(), TestPojo.class.getName(), elementData,
+                new TestProxyVersion());
+
+        final ObjectAdapter adapter = deserializer.deserialize(data);
+
+        final Vector restoredCollection = (Vector) adapter.getObject();
+        assertEquals(0, restoredCollection.size());
+
+        final CollectionFacet facet = adapter.getSpecification().getFacet(CollectionFacet.class);
+        assertEquals(0, facet.size(adapter));
+    }
+
+    public void testRecreateCollection() {
+        final ReferenceData elements[] = new ObjectData[2];
+        final TestProxyOid element0Oid = new TestProxyOid(345, true);
+        elements[0] = new DummyObjectData(element0Oid, TestPojo.class.getName(), false, new TestProxyVersion(3));
+        final TestProxyOid element1Oid = new TestProxyOid(678, true);
+        elements[1] = new DummyObjectData(element1Oid, TestPojo.class.getName(), false, new TestProxyVersion(7));
+
+        final TestProxyOid collectionOid = new TestProxyOid(123);
+        final CollectionData data =
+            new DummyCollectionData(collectionOid, Vector.class.getName(), TestPojo.class.getName(), elements,
+                new TestProxyVersion());
+
+        final ObjectAdapter adapter = deserializer.deserialize(data);
+
+        final Vector restoredCollection = (Vector) adapter.getObject();
+        assertEquals(2, restoredCollection.size());
+
+        final CollectionFacet facet = adapter.getSpecification().getFacet(CollectionFacet.class);
+        final Enumeration elements2 = facet.elements(adapter);
+        final ObjectAdapter element0 = (ObjectAdapter) elements2.nextElement();
+        final ObjectAdapter element2 = (ObjectAdapter) elements2.nextElement();
+
+        assertNotNull(element0.getObject());
+        assertNotNull(element2.getObject());
+
+        assertEquals(TestPojo.class, element0.getObject().getClass());
+        assertEquals(TestPojo.class, element2.getObject().getClass());
+
+        assertEquals(new TestProxyOid(678, true), element2.getOid());
+        assertEquals(new TestProxyOid(345, true), element0.getOid());
+
+        // version not set as there is no field data for elements
+        // assertEquals(new DummyVersion(3), adapter.elementAt(0).getVersion());
+        // assertEquals(new DummyVersion(7), adapter.elementAt(1).getVersion());
+    }
+}

Modified: incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/protocol/encoding/ObjectEncoderImplTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/protocol/encoding/ObjectEncoderImplTest.java?rev=1098939&r1=1098938&r2=1098939&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/protocol/encoding/ObjectEncoderImplTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/protocol/encoding/ObjectEncoderImplTest.java Tue May  3 06:33:43 2011
@@ -17,38 +17,33 @@
  *  under the License.
  */
 
-
 package org.apache.isis.runtimes.dflt.remoting.common.protocol.encoding;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.ResolveState;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.testsupport.testdomain.Movie;
+import org.apache.isis.core.testsupport.testdomain.Person;
 import org.apache.isis.runtimes.dflt.remoting.common.data.Data;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyEncodeableObjectData;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyNullValue;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyObjectData;
 import org.apache.isis.runtimes.dflt.remoting.common.data.common.NullData;
 import org.apache.isis.runtimes.dflt.remoting.protocol.internal.ObjectEncoderDecoderDefault;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.ResolveState;
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
 import org.apache.isis.runtimes.dflt.runtime.testspec.MovieSpecification;
 import org.apache.isis.runtimes.dflt.runtime.testspec.PersonSpecification;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.ProxyJunit4TestCase;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyOid;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyVersion;
-import org.apache.isis.core.testsupport.testdomain.Movie;
-import org.apache.isis.core.testsupport.testdomain.Person;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-
-
-
-
 public class ObjectEncoderImplTest extends ProxyJunit4TestCase {
 
     private ObjectEncoderDecoderDefault encoder;
@@ -63,49 +58,61 @@ public class ObjectEncoderImplTest exten
         system.getSpecification(String.class).setupIsEncodeable();
         system.getSpecification(String.class).addFacet(new EncodableFacet() {
 
+            @Override
             public String toEncodedString(final ObjectAdapter object) {
                 return object.getObject().toString();
             }
 
+            @Override
             public ObjectAdapter fromEncodedString(final String encodedData) {
                 return getAdapterManager().adapterFor(encodedData);
             }
 
+            @Override
             public Class<? extends Facet> facetType() {
                 return EncodableFacet.class;
             }
 
+            @Override
             public FacetHolder getFacetHolder() {
                 return null;
             }
 
-            public void setFacetHolder(final FacetHolder facetHolder) {}
+            @Override
+            public void setFacetHolder(final FacetHolder facetHolder) {
+            }
 
+            @Override
             public boolean alwaysReplace() {
                 return false;
             }
 
+            @Override
             public boolean isDerived() {
-            	return false;
+                return false;
             }
 
+            @Override
             public boolean isNoop() {
                 return false;
             }
-            
-        	public Facet getUnderlyingFacet() {
-        		return null;
-        	}
-        	public void setUnderlyingFacet(Facet underlyingFacet) {
-        		throw new UnsupportedOperationException();
-        	}
+
+            @Override
+            public Facet getUnderlyingFacet() {
+                return null;
+            }
+
+            @Override
+            public void setUnderlyingFacet(final Facet underlyingFacet) {
+                throw new UnsupportedOperationException();
+            }
 
         });
 
         /*
-         * TestProxySpecification specification = new MovieSpecification(); specification.setupFields(new
-         * ObjectField[] { new TestProxyField("name", system.getSpecification(String.class)), new
-         * TestProxyField("person", system.getSpecification(Person.class)) });
+         * TestProxySpecification specification = new MovieSpecification(); specification.setupFields(new ObjectField[]
+         * { new TestProxyField("name", system.getSpecification(String.class)), new TestProxyField("person",
+         * system.getSpecification(Person.class)) });
          */
     }
 
@@ -116,8 +123,8 @@ public class ObjectEncoderImplTest exten
 
     @Test
     public void testRestoreCreatesNewAdapter() {
-        final DummyObjectData data = new DummyObjectData(new TestProxyOid(5, true), Movie.class.getName(), true,
-                new TestProxyVersion(3));
+        final DummyObjectData data =
+            new DummyObjectData(new TestProxyOid(5, true), Movie.class.getName(), true, new TestProxyVersion(3));
         final DummyEncodeableObjectData name = new DummyEncodeableObjectData("ET", "java.lang.String");
         final DummyNullValue reference = new DummyNullValue(Person.class.getName());
         // note - the order of the fields is by name, not the order that are defined in the specification
@@ -131,13 +138,13 @@ public class ObjectEncoderImplTest exten
         assertEquals("ET", movie.getName());
         assertEquals(new TestProxyOid(5, true), object.getOid());
         assertEquals(new TestProxyVersion(3), object.getVersion());
-        
+
     }
 
     @Test
     public void testRestoreCreatesNewAdapterInUnresolvedState() {
-        final DummyObjectData data = new DummyObjectData(new TestProxyOid(5, true), Movie.class.getName(), false,
-                new TestProxyVersion(3));
+        final DummyObjectData data =
+            new DummyObjectData(new TestProxyOid(5, true), Movie.class.getName(), false, new TestProxyVersion(3));
 
         final ObjectAdapter object = encoder.decode(data);
 
@@ -153,7 +160,8 @@ public class ObjectEncoderImplTest exten
         final ObjectAdapter adapter = system.createPersistentTestObject(movie);
         adapter.changeState(ResolveState.RESOLVED);
 
-        final DummyObjectData data = new DummyObjectData(adapter.getOid(), Movie.class.getName(), true, new TestProxyVersion(3));
+        final DummyObjectData data =
+            new DummyObjectData(adapter.getOid(), Movie.class.getName(), true, new TestProxyVersion(3));
         final DummyEncodeableObjectData name = new DummyEncodeableObjectData("ET", "java.lang.String");
         final DummyNullValue reference = new DummyNullValue(Person.class.getName());
         data.setFieldContent(new Data[] { reference, name });
@@ -173,7 +181,8 @@ public class ObjectEncoderImplTest exten
         final ObjectAdapter adapter = system.createPersistentTestObject(movie);
         adapter.changeState(ResolveState.RESOLVED);
 
-        final DummyObjectData data = new DummyObjectData(adapter.getOid(), Movie.class.getName(), false, new TestProxyVersion(3));
+        final DummyObjectData data =
+            new DummyObjectData(adapter.getOid(), Movie.class.getName(), false, new TestProxyVersion(3));
 
         final ObjectAdapter object = encoder.decode(data);
 
@@ -198,4 +207,3 @@ public class ObjectEncoderImplTest exten
 
     }
 }
-

Modified: incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_AssociationTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_AssociationTest.java?rev=1098939&r1=1098938&r2=1098939&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_AssociationTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_AssociationTest.java Tue May  3 06:33:43 2011
@@ -17,22 +17,20 @@
  *  under the License.
  */
 
+package org.apache.isis.runtimes.dflt.remoting.common.server;
 
-package org.apache.isis.runtimes.dflt.remoting.common.server;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 import java.util.Arrays;
 
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.testspec.TestProxySpecification;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyReferenceData;
 import org.apache.isis.runtimes.dflt.remoting.common.data.common.ObjectData;
 import org.apache.isis.runtimes.dflt.remoting.common.exchange.ClearAssociationRequest;
@@ -41,146 +39,152 @@ import org.apache.isis.runtimes.dflt.rem
 import org.apache.isis.runtimes.dflt.remoting.common.exchange.SetAssociationResponse;
 import org.apache.isis.runtimes.dflt.remoting.common.facade.impl.ServerFacadeImpl;
 import org.apache.isis.runtimes.dflt.remoting.common.protocol.ObjectEncoderDecoder;
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.testspec.TestProxySpecification;
-import org.apache.isis.core.runtime.authentication.AuthenticationManager;
 import org.apache.isis.runtimes.dflt.runtime.persistence.ConcurrencyException;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.ProxyJunit4TestCase;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyAssociation;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyVersion;
-
-
-@RunWith(JMock.class)
-public class ServerFacadeImpl_AssociationTest extends ProxyJunit4TestCase {
-
-    private Mockery mockery = new JUnit4Mockery();
-
-
-    private ServerFacadeImpl server;
-    private AuthenticationSession authenticationSession;
-    private ObjectAdapter movieAdapter;
-    private DummyReferenceData movieData;
-    private DummyReferenceData personData;
-    private TestProxyAssociation nameField;
-    private ObjectAdapter personAdapter;
-
-    private AuthenticationManager mockAuthenticationManager;
-    private ObjectEncoderDecoder mockObjectEncoder;
-
-    /*
-     * Testing the Distribution implementation ServerDistribution. This uses the encoder to unmarshall objects
-     * and then calls the persistor and reflector; all of which should be mocked.
-     */
-    @Before
-    public void setUp() throws Exception {
-
-        mockAuthenticationManager = mockery.mock(AuthenticationManager.class);
-        mockObjectEncoder = mockery.mock(ObjectEncoderDecoder.class);
-        
-        server = new ServerFacadeImpl(mockAuthenticationManager);
-        server.setEncoder(mockObjectEncoder);
-        server.init();
-
-        authenticationSession = IsisContext.getAuthenticationSession();
-
-        movieAdapter = system.createPersistentTestObject();
-        final Oid movieOid = movieAdapter.getOid();
-
-        movieData = new DummyReferenceData(movieOid, "none", movieAdapter.getVersion());
-
-        final TestProxySpecification spec = (TestProxySpecification) movieAdapter.getSpecification();
-        nameField = new TestProxyAssociation("director", system.getSpecification(String.class));
-        spec.setupFields(Arrays.asList( (ObjectAssociation)nameField ));
-
-        personAdapter = system.createPersistentTestObject();
-        final Oid personOid = personAdapter.getOid();
-
-        personData = new DummyReferenceData(personOid, "none", personAdapter.getVersion());
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.shutdown();
-    }
-
-    @Test
-    public void testClearAssociation() {
-        /*
-         * other tests for clear: - clear collection element - fails if unauthorised - fails if unavailable
-         * 
-         * could place all these clear test in one class; test other methods in other classes
-         */
-        IsisContext.getTransactionManager().startTransaction();
-        ClearAssociationRequest request = new ClearAssociationRequest(authenticationSession, "director", movieData, personData);
-		ClearAssociationResponse response = server.clearAssociation(request);
-		final ObjectData[] updatesData = response.getUpdates();
-        IsisContext.getTransactionManager().endTransaction();
-
-        nameField.assertFieldEmpty(movieAdapter);
-        assertEquals(0, updatesData.length);
-    }
-
-    @Test
-    public void testSetAssociation() {
-        IsisContext.getTransactionManager().startTransaction();
-        SetAssociationRequest request = new SetAssociationRequest(authenticationSession, "director", movieData, personData);
-        SetAssociationResponse response = server.setAssociation(request);
-		final ObjectData[] updates = response.getUpdates();
-        IsisContext.getTransactionManager().endTransaction();
-
-        nameField.assertField(movieAdapter, personAdapter.getObject());
-        assertEquals(0, updates.length);
-    }
-
-    @Test
-    public void testSetAssociationFailsWithNonCurrentTarget() {
-        // version should be different, causing concurrency exception
-        movieAdapter.setOptimisticLock(new TestProxyVersion(6));
-        try {
-        	SetAssociationRequest request = new SetAssociationRequest(authenticationSession, "director", movieData, personData);
-            server.setAssociation(request);
-            fail();
-        } catch (final ConcurrencyException expected) {}
-    }
-
-    @Test
-    public void testSetAssociationFailsWhenInvisible() {
-        nameField.setUpIsVisible(false);
-        try {
-            SetAssociationRequest request = new SetAssociationRequest(authenticationSession, "director", movieData, personData);
-			server.setAssociation(request);
-            fail();
-        } catch (final IsisException expected) {
-            assertEquals("can't modify field as not visible or editable", expected.getMessage());
-        }
-    }
-
-    @Test
-    public void testSetAssociationFailsWhenUnavailable() {
-        nameField.setUpIsUnusableFor(movieAdapter);
-        try {
-        	SetAssociationRequest request = new SetAssociationRequest(authenticationSession, "director", movieData, personData);
-            server.setAssociation(request);
-            fail();
-        } catch (final IsisException expected) {
-            assertEquals("can't modify field as not visible or editable", expected.getMessage());
-        }
-    }
-
-    @Test
-    public void testSetAssociationFailsWithNonCurrentAssociate() {
-        // version should be different, causing concurrency exception
-        personAdapter.setOptimisticLock(new TestProxyVersion(6));
-        try {
-        	SetAssociationRequest request = new SetAssociationRequest(authenticationSession, "director", movieData, personData);
-            server.setAssociation(request);
-            fail();
-        } catch (final ConcurrencyException expected) {}
-    }
-
-}
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(JMock.class)
+public class ServerFacadeImpl_AssociationTest extends ProxyJunit4TestCase {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private ServerFacadeImpl server;
+    private AuthenticationSession authenticationSession;
+    private ObjectAdapter movieAdapter;
+    private DummyReferenceData movieData;
+    private DummyReferenceData personData;
+    private TestProxyAssociation nameField;
+    private ObjectAdapter personAdapter;
+
+    private AuthenticationManager mockAuthenticationManager;
+    private ObjectEncoderDecoder mockObjectEncoder;
+
+    /*
+     * Testing the Distribution implementation ServerDistribution. This uses the encoder to unmarshall objects and then
+     * calls the persistor and reflector; all of which should be mocked.
+     */
+    @Before
+    public void setUp() throws Exception {
+
+        mockAuthenticationManager = mockery.mock(AuthenticationManager.class);
+        mockObjectEncoder = mockery.mock(ObjectEncoderDecoder.class);
+
+        server = new ServerFacadeImpl(mockAuthenticationManager);
+        server.setEncoder(mockObjectEncoder);
+        server.init();
+
+        authenticationSession = IsisContext.getAuthenticationSession();
+
+        movieAdapter = system.createPersistentTestObject();
+        final Oid movieOid = movieAdapter.getOid();
+
+        movieData = new DummyReferenceData(movieOid, "none", movieAdapter.getVersion());
+
+        final TestProxySpecification spec = (TestProxySpecification) movieAdapter.getSpecification();
+        nameField = new TestProxyAssociation("director", system.getSpecification(String.class));
+        spec.setupFields(Arrays.asList((ObjectAssociation) nameField));
+
+        personAdapter = system.createPersistentTestObject();
+        final Oid personOid = personAdapter.getOid();
+
+        personData = new DummyReferenceData(personOid, "none", personAdapter.getVersion());
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        system.shutdown();
+    }
+
+    @Test
+    public void testClearAssociation() {
+        /*
+         * other tests for clear: - clear collection element - fails if unauthorised - fails if unavailable
+         * 
+         * could place all these clear test in one class; test other methods in other classes
+         */
+        IsisContext.getTransactionManager().startTransaction();
+        final ClearAssociationRequest request =
+            new ClearAssociationRequest(authenticationSession, "director", movieData, personData);
+        final ClearAssociationResponse response = server.clearAssociation(request);
+        final ObjectData[] updatesData = response.getUpdates();
+        IsisContext.getTransactionManager().endTransaction();
+
+        nameField.assertFieldEmpty(movieAdapter);
+        assertEquals(0, updatesData.length);
+    }
+
+    @Test
+    public void testSetAssociation() {
+        IsisContext.getTransactionManager().startTransaction();
+        final SetAssociationRequest request =
+            new SetAssociationRequest(authenticationSession, "director", movieData, personData);
+        final SetAssociationResponse response = server.setAssociation(request);
+        final ObjectData[] updates = response.getUpdates();
+        IsisContext.getTransactionManager().endTransaction();
+
+        nameField.assertField(movieAdapter, personAdapter.getObject());
+        assertEquals(0, updates.length);
+    }
+
+    @Test
+    public void testSetAssociationFailsWithNonCurrentTarget() {
+        // version should be different, causing concurrency exception
+        movieAdapter.setOptimisticLock(new TestProxyVersion(6));
+        try {
+            final SetAssociationRequest request =
+                new SetAssociationRequest(authenticationSession, "director", movieData, personData);
+            server.setAssociation(request);
+            fail();
+        } catch (final ConcurrencyException expected) {
+        }
+    }
+
+    @Test
+    public void testSetAssociationFailsWhenInvisible() {
+        nameField.setUpIsVisible(false);
+        try {
+            final SetAssociationRequest request =
+                new SetAssociationRequest(authenticationSession, "director", movieData, personData);
+            server.setAssociation(request);
+            fail();
+        } catch (final IsisException expected) {
+            assertEquals("can't modify field as not visible or editable", expected.getMessage());
+        }
+    }
+
+    @Test
+    public void testSetAssociationFailsWhenUnavailable() {
+        nameField.setUpIsUnusableFor(movieAdapter);
+        try {
+            final SetAssociationRequest request =
+                new SetAssociationRequest(authenticationSession, "director", movieData, personData);
+            server.setAssociation(request);
+            fail();
+        } catch (final IsisException expected) {
+            assertEquals("can't modify field as not visible or editable", expected.getMessage());
+        }
+    }
+
+    @Test
+    public void testSetAssociationFailsWithNonCurrentAssociate() {
+        // version should be different, causing concurrency exception
+        personAdapter.setOptimisticLock(new TestProxyVersion(6));
+        try {
+            final SetAssociationRequest request =
+                new SetAssociationRequest(authenticationSession, "director", movieData, personData);
+            server.setAssociation(request);
+            fail();
+        } catch (final ConcurrencyException expected) {
+        }
+    }
+
+}

Modified: incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_ClientActionTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_ClientActionTest.java?rev=1098939&r1=1098938&r2=1098939&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_ClientActionTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_ClientActionTest.java Tue May  3 06:33:43 2011
@@ -17,13 +17,17 @@
  *  under the License.
  */
 
+package org.apache.isis.runtimes.dflt.remoting.common.server;
 
-package org.apache.isis.runtimes.dflt.remoting.common.server;
-
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
 import org.apache.isis.runtimes.dflt.remoting.common.client.transaction.ClientTransactionEvent;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyIdentityData;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyObjectData;
@@ -34,11 +38,6 @@ import org.apache.isis.runtimes.dflt.rem
 import org.apache.isis.runtimes.dflt.remoting.common.exchange.KnownObjectsRequest;
 import org.apache.isis.runtimes.dflt.remoting.common.facade.impl.ServerFacadeImpl;
 import org.apache.isis.runtimes.dflt.remoting.common.protocol.ObjectEncoderDecoder;
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.version.Version;
-import org.apache.isis.core.runtime.authentication.AuthenticationManager;
 import org.apache.isis.runtimes.dflt.runtime.persistence.ConcurrencyException;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyAdapter;
@@ -56,206 +55,195 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-
-
-@RunWith(JMock.class)
-public class ServerFacadeImpl_ClientActionTest  {
-
-
-    private Mockery mockery = new JUnit4Mockery();
-
-    private AuthenticationManager mockAuthenticationManager;
-    private ObjectEncoderDecoder mockEncoder;
-
-    private ServerFacadeImpl server;
-    private AuthenticationSession session;
-    private TestProxySystem system;
-
-    /*
-     * Testing the Distribution implementation ServerDistribution. This uses the encoder to unmarshall objects
-     * and then calls the persistor and reflector; all of which should be mocked.
-     */
-    @Before
-    public void setUp() throws Exception {
-        BasicConfigurator.configure();
-        LogManager.getRootLogger().setLevel(Level.OFF);
-
-        mockAuthenticationManager = mockery.mock(AuthenticationManager.class);
-        mockEncoder = mockery.mock(ObjectEncoderDecoder.class);
-
-        server = new ServerFacadeImpl(mockAuthenticationManager);
-        server.setEncoder(mockEncoder);
-
-        server.init();
-
-
-        system = new TestProxySystem();
-        system.init();
-
-        session = IsisContext.getAuthenticationSession();
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.shutdown();
-    }
-
-    @Test
-    public void testExecuteClientActionWithNoWork() {
-        
-        mockery.checking(new Expectations() {
-            {
-                one(mockEncoder).encodeClientActionResult(
-                        with(equalTo(new ObjectData[0])), 
-                        with(equalTo(new Version[0])), 
-                        with(equalTo(new ObjectData[0])));
-                will(returnValue(new ExecuteClientActionResponse(new ObjectData[0], new Version[0], null)));
-            }
-        });
-
-
-        ExecuteClientActionRequest request = new ExecuteClientActionRequest(session, new ReferenceData[0], new int[0]);
-        
-		// don't start xactn here, since within call.
-        final ExecuteClientActionResponse result = server.executeClientAction(request);
-
-        assertEquals(0, result.getPersisted().length);
-        assertEquals(0, result.getChanged().length);
-    }
-
-    @Test
-    public void testExecuteClientActionWhereObjectChanged() {
-        final ObjectAdapter adapter = system.createPersistentTestObject();
-
-        final DummyObjectData data = new DummyObjectData(adapter.getOid(), "none", true, new TestProxyVersion(1));
-
-        // prepare the update data to return
-        mockery.checking(new Expectations() {
-            {
-                one(mockEncoder).decode(data, new KnownObjectsRequest());
-                will(returnValue(adapter));
-                
-            }
-        });
-
-        // results returned in their own container
-        final ExecuteClientActionResponse results = new ExecuteClientActionResponse(new ObjectData[0], new Version[0], null);
-        mockery.checking(new Expectations() {
-            {
-                one(mockEncoder).encodeClientActionResult(
-                        with(equalTo(new ReferenceData[1])), 
-                        with(equalTo(new Version[] { new TestProxyVersion(2) })),
-                        with(equalTo(new ObjectData[0])));
-                will(returnValue(results));
-            }
-        });
-
-        ExecuteClientActionRequest request = 
-        	new ExecuteClientActionRequest(session, new ReferenceData[] { data }, new int[] { ClientTransactionEvent.CHANGE });
-		// don't start xactn here, since within call.
-        final ExecuteClientActionResponse result = 
-            server.executeClientAction(
-                    request);
-        final ObjectAdapter object = 
-            IsisContext.getPersistenceSession().loadObject(adapter.getOid(), adapter.getSpecification());
-        
-
-        assertEquals(new TestProxyVersion(2), object.getVersion());
-
-        assertEquals(results, result);
-    }
-
-
-    @Test
-    public void testExecuteClientActionWhereObjectMadePersistent() {
-        final ObjectAdapter adapter = system.createTransientTestObject();
-
-        final DummyObjectData data = new DummyObjectData(adapter.getOid(), "none", true, new TestProxyVersion(1));
-
-        // restore the object on the server
-        mockery.checking(new Expectations() {
-            {
-                one(mockEncoder).decode(data, new KnownObjectsRequest());
-                will(returnValue(adapter));
-                
-                one(mockEncoder).encodeIdentityData(adapter);
-                will(returnValue(null));
-            }
-        });
-
-        // return results
-        final ExecuteClientActionResponse results = new ExecuteClientActionResponse(new ObjectData[0], new Version[0], new ObjectData[0]);
-        mockery.checking(new Expectations() {
-            {
-                one(mockEncoder).encodeClientActionResult(
-                        with(equalTo(new ReferenceData[1])), 
-                        with(equalTo(new Version[1])), 
-                        with(equalTo(new ObjectData[0])));
-                will(returnValue(results));
-            }
-        });
-        
-        // don't start xactn here, since within call.
-
-        ExecuteClientActionRequest request = new ExecuteClientActionRequest(session, new ReferenceData[] { data }, new int[] { ClientTransactionEvent.ADD });
-		final ExecuteClientActionResponse response = 
-            server.executeClientAction(
-                    request);
-
-        final ObjectAdapter object = IsisContext.getPersistenceSession().loadObject(adapter.getOid(),
-                adapter.getSpecification());
-        
-
-        assertEquals(results, response);
-        assertEquals(adapter, object);
-        assertEquals(new TestProxyVersion(1), object.getVersion());
-    }
-
-    @Test
-    public void testExecuteClientActionFailsWithConcurrencyError() {
-        final ObjectAdapter adapter = system.createPersistentTestObject();
-        adapter.setOptimisticLock(new TestProxyVersion(7));
-
-        final Oid oid = adapter.getOid();
-        final DummyIdentityData identityData = new DummyIdentityData(oid, TestProxyAdapter.class.getName(),
-                new TestProxyVersion(6));
-
-        try {
-            ExecuteClientActionRequest request = new ExecuteClientActionRequest(
-            		new TestProxySession(), new ReferenceData[] { identityData }, new int[] { ClientTransactionEvent.DELETE });
-			server.executeClientAction(request);
-            fail();
-        } catch (final ConcurrencyException expected) {}
-    }
-
-    @Test
-    public void testExecuteClientActionWhereObjectDeleted() {
-        final ObjectAdapter adapter = system.createPersistentTestObject();
-
-        final Oid oid = adapter.getOid();
-        final DummyIdentityData identityData = new DummyIdentityData(oid, TestProxyAdapter.class.getName(),
-                new TestProxyVersion(1));
-
-        // return results
-        final ExecuteClientActionResponse results = new ExecuteClientActionResponse(new ObjectData[0], new Version[0], null);
-        mockery.checking(new Expectations() {
-            {
-                one(mockEncoder).encodeClientActionResult(
-                        with(equalTo(new ReferenceData[1])), 
-                        with(equalTo(new Version[1])), 
-                        with(equalTo(new ObjectData[0])));
-                will(returnValue(results));
-            }
-        });
-
-        // don't start xactn here, since within call.
-        ExecuteClientActionRequest request = 
-        	new ExecuteClientActionRequest(new TestProxySession(), new ReferenceData[] { identityData }, new int[] { ClientTransactionEvent.DELETE });
-		final ExecuteClientActionResponse result = 
-            server.executeClientAction(
-                    request);
-
-        assertEquals(results, result);
-    }
-
-}
+
+@RunWith(JMock.class)
+public class ServerFacadeImpl_ClientActionTest {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private AuthenticationManager mockAuthenticationManager;
+    private ObjectEncoderDecoder mockEncoder;
+
+    private ServerFacadeImpl server;
+    private AuthenticationSession session;
+    private TestProxySystem system;
+
+    /*
+     * Testing the Distribution implementation ServerDistribution. This uses the encoder to unmarshall objects and then
+     * calls the persistor and reflector; all of which should be mocked.
+     */
+    @Before
+    public void setUp() throws Exception {
+        BasicConfigurator.configure();
+        LogManager.getRootLogger().setLevel(Level.OFF);
+
+        mockAuthenticationManager = mockery.mock(AuthenticationManager.class);
+        mockEncoder = mockery.mock(ObjectEncoderDecoder.class);
+
+        server = new ServerFacadeImpl(mockAuthenticationManager);
+        server.setEncoder(mockEncoder);
+
+        server.init();
+
+        system = new TestProxySystem();
+        system.init();
+
+        session = IsisContext.getAuthenticationSession();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        system.shutdown();
+    }
+
+    @Test
+    public void testExecuteClientActionWithNoWork() {
+
+        mockery.checking(new Expectations() {
+            {
+                one(mockEncoder).encodeClientActionResult(with(equalTo(new ObjectData[0])),
+                    with(equalTo(new Version[0])), with(equalTo(new ObjectData[0])));
+                will(returnValue(new ExecuteClientActionResponse(new ObjectData[0], new Version[0], null)));
+            }
+        });
+
+        final ExecuteClientActionRequest request =
+            new ExecuteClientActionRequest(session, new ReferenceData[0], new int[0]);
+
+        // don't start xactn here, since within call.
+        final ExecuteClientActionResponse result = server.executeClientAction(request);
+
+        assertEquals(0, result.getPersisted().length);
+        assertEquals(0, result.getChanged().length);
+    }
+
+    @Test
+    public void testExecuteClientActionWhereObjectChanged() {
+        final ObjectAdapter adapter = system.createPersistentTestObject();
+
+        final DummyObjectData data = new DummyObjectData(adapter.getOid(), "none", true, new TestProxyVersion(1));
+
+        // prepare the update data to return
+        mockery.checking(new Expectations() {
+            {
+                one(mockEncoder).decode(data, new KnownObjectsRequest());
+                will(returnValue(adapter));
+
+            }
+        });
+
+        // results returned in their own container
+        final ExecuteClientActionResponse results =
+            new ExecuteClientActionResponse(new ObjectData[0], new Version[0], null);
+        mockery.checking(new Expectations() {
+            {
+                one(mockEncoder).encodeClientActionResult(with(equalTo(new ReferenceData[1])),
+                    with(equalTo(new Version[] { new TestProxyVersion(2) })), with(equalTo(new ObjectData[0])));
+                will(returnValue(results));
+            }
+        });
+
+        final ExecuteClientActionRequest request =
+            new ExecuteClientActionRequest(session, new ReferenceData[] { data },
+                new int[] { ClientTransactionEvent.CHANGE });
+        // don't start xactn here, since within call.
+        final ExecuteClientActionResponse result = server.executeClientAction(request);
+        final ObjectAdapter object =
+            IsisContext.getPersistenceSession().loadObject(adapter.getOid(), adapter.getSpecification());
+
+        assertEquals(new TestProxyVersion(2), object.getVersion());
+
+        assertEquals(results, result);
+    }
+
+    @Test
+    public void testExecuteClientActionWhereObjectMadePersistent() {
+        final ObjectAdapter adapter = system.createTransientTestObject();
+
+        final DummyObjectData data = new DummyObjectData(adapter.getOid(), "none", true, new TestProxyVersion(1));
+
+        // restore the object on the server
+        mockery.checking(new Expectations() {
+            {
+                one(mockEncoder).decode(data, new KnownObjectsRequest());
+                will(returnValue(adapter));
+
+                one(mockEncoder).encodeIdentityData(adapter);
+                will(returnValue(null));
+            }
+        });
+
+        // return results
+        final ExecuteClientActionResponse results =
+            new ExecuteClientActionResponse(new ObjectData[0], new Version[0], new ObjectData[0]);
+        mockery.checking(new Expectations() {
+            {
+                one(mockEncoder).encodeClientActionResult(with(equalTo(new ReferenceData[1])),
+                    with(equalTo(new Version[1])), with(equalTo(new ObjectData[0])));
+                will(returnValue(results));
+            }
+        });
+
+        // don't start xactn here, since within call.
+
+        final ExecuteClientActionRequest request =
+            new ExecuteClientActionRequest(session, new ReferenceData[] { data },
+                new int[] { ClientTransactionEvent.ADD });
+        final ExecuteClientActionResponse response = server.executeClientAction(request);
+
+        final ObjectAdapter object =
+            IsisContext.getPersistenceSession().loadObject(adapter.getOid(), adapter.getSpecification());
+
+        assertEquals(results, response);
+        assertEquals(adapter, object);
+        assertEquals(new TestProxyVersion(1), object.getVersion());
+    }
+
+    @Test
+    public void testExecuteClientActionFailsWithConcurrencyError() {
+        final ObjectAdapter adapter = system.createPersistentTestObject();
+        adapter.setOptimisticLock(new TestProxyVersion(7));
+
+        final Oid oid = adapter.getOid();
+        final DummyIdentityData identityData =
+            new DummyIdentityData(oid, TestProxyAdapter.class.getName(), new TestProxyVersion(6));
+
+        try {
+            final ExecuteClientActionRequest request =
+                new ExecuteClientActionRequest(new TestProxySession(), new ReferenceData[] { identityData },
+                    new int[] { ClientTransactionEvent.DELETE });
+            server.executeClientAction(request);
+            fail();
+        } catch (final ConcurrencyException expected) {
+        }
+    }
+
+    @Test
+    public void testExecuteClientActionWhereObjectDeleted() {
+        final ObjectAdapter adapter = system.createPersistentTestObject();
+
+        final Oid oid = adapter.getOid();
+        final DummyIdentityData identityData =
+            new DummyIdentityData(oid, TestProxyAdapter.class.getName(), new TestProxyVersion(1));
+
+        // return results
+        final ExecuteClientActionResponse results =
+            new ExecuteClientActionResponse(new ObjectData[0], new Version[0], null);
+        mockery.checking(new Expectations() {
+            {
+                one(mockEncoder).encodeClientActionResult(with(equalTo(new ReferenceData[1])),
+                    with(equalTo(new Version[1])), with(equalTo(new ObjectData[0])));
+                will(returnValue(results));
+            }
+        });
+
+        // don't start xactn here, since within call.
+        final ExecuteClientActionRequest request =
+            new ExecuteClientActionRequest(new TestProxySession(), new ReferenceData[] { identityData },
+                new int[] { ClientTransactionEvent.DELETE });
+        final ExecuteClientActionResponse result = server.executeClientAction(request);
+
+        assertEquals(results, result);
+    }
+
+}

Modified: incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_ParseableAssociationsTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_ParseableAssociationsTest.java?rev=1098939&r1=1098938&r2=1098939&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_ParseableAssociationsTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/remoting/common/src/test/java/org/apache/isis/runtimes/dflt/remoting/common/server/ServerFacadeImpl_ParseableAssociationsTest.java Tue May  3 06:33:43 2011
@@ -17,22 +17,22 @@
  *  under the License.
  */
 
+package org.apache.isis.runtimes.dflt.remoting.common.server;
 
-package org.apache.isis.runtimes.dflt.remoting.common.server;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 import java.util.Arrays;
 
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.core.metamodel.testspec.TestProxySpecification;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyEncodeableObjectData;
 import org.apache.isis.runtimes.dflt.remoting.common.data.DummyReferenceData;
 import org.apache.isis.runtimes.dflt.remoting.common.data.common.ObjectData;
@@ -43,181 +43,185 @@ import org.apache.isis.runtimes.dflt.rem
 import org.apache.isis.runtimes.dflt.remoting.common.facade.ServerFacade;
 import org.apache.isis.runtimes.dflt.remoting.common.facade.impl.ServerFacadeImpl;
 import org.apache.isis.runtimes.dflt.remoting.common.protocol.ObjectEncoderDecoder;
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facetapi.FacetHolder;
-import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
-import org.apache.isis.core.metamodel.testspec.TestProxySpecification;
-import org.apache.isis.core.runtime.authentication.AuthenticationManager;
 import org.apache.isis.runtimes.dflt.runtime.persistence.ConcurrencyException;
 import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.ProxyJunit4TestCase;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyAssociation;
 import org.apache.isis.runtimes.dflt.runtime.testsystem.TestProxyVersion;
-
-
-@RunWith(JMock.class)
-public class ServerFacadeImpl_ParseableAssociationsTest extends ProxyJunit4TestCase {
-
-    private Mockery mockery = new JUnit4Mockery();
-
-    private ServerFacadeImpl server;
-    private AuthenticationSession session;
-    private DummyReferenceData movieData;
-    private ObjectAdapter object;
-    private TestProxyAssociation nameField;
-
-    private AuthenticationManager mockAuthenticationManager;
-    private ObjectEncoderDecoder mockObjectEncoder;
-
-    /**
-     * Testing the {@link ServerFacadeImpl} implementation of {@link ServerFacade}.
-     *
-     * <p>
-     * This uses the encoder to unmarshall objects
-     * and then calls the persistor and reflector; all of which should be mocked.
-     */
-    @Before
-    public void setUp() throws Exception {
-
-        mockAuthenticationManager = mockery.mock(AuthenticationManager.class);
-        mockObjectEncoder = mockery.mock(ObjectEncoderDecoder.class);
-
-        server = new ServerFacadeImpl(mockAuthenticationManager);
-        server.setEncoder(mockObjectEncoder);
-        server.init();
-
-        object = system.createPersistentTestObject();
-
-        final TestProxySpecification spec = (TestProxySpecification) object.getSpecification();
-        nameField = new TestProxyAssociation("name", system.getSpecification(String.class));
-        spec.setupFields( Arrays.asList( (ObjectAssociation)nameField ));
-
-        movieData = new DummyReferenceData(object.getOid(), "none", new TestProxyVersion(1));
-
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        system.shutdown();
-    }
-
-    /**
-     * TODO: other tests for clear: - clear collection element - fails if unauthorised - fails if unavailable
-     *
-     * <p>
-     * could place all these clear test in one class; test other methods in other classes
-     */
-    @Test
-    public void testClearAssociation() {
-        IsisContext.getTransactionManager().startTransaction();
-        ClearValueRequest request = new ClearValueRequest(session, "name", movieData);
-		ClearValueResponse response = server.clearValue(request );
-		final ObjectData[] updatesData = response.getUpdates();
-        IsisContext.getTransactionManager().endTransaction();
-
-        nameField.assertFieldEmpty(object);
-        assertEquals(0, updatesData.length);
-    }
-
-    @Test
-    public void testSetValue() {
-        final TestProxySpecification specf = system.getSpecification(String.class);
-        specf.addFacet(new EncodableFacet() {
-            @Override
-            public String toEncodedString(final ObjectAdapter object) {
-                return null;
-            }
-
-            @Override
-            public ObjectAdapter fromEncodedString(final String encodedData) {
-                return getAdapterManager().adapterFor(encodedData);
-            }
-
-            @Override
-            public Class facetType() {
-                return EncodableFacet.class;
-            }
-
-            @Override
-            public FacetHolder getFacetHolder() {
-                return null;
-            }
-
-            @Override
-            public void setFacetHolder(final FacetHolder facetHolder) {}
-
-            @Override
-            public boolean alwaysReplace() {
-                return false;
-            }
-
-            @Override
-            public boolean isDerived() {
-            	return false;
-            }
-
-            @Override
-            public boolean isNoop() {
-                return false;
-            }
-        	@Override
-            public Facet getUnderlyingFacet() {
-        		return null;
-        	}
-        	@Override
-            public void setUnderlyingFacet(Facet underlyingFacet) {
-        		throw new UnsupportedOperationException();
-        	}
-
-        });
-
-        IsisContext.getTransactionManager().startTransaction();
-        SetValueRequest request = new SetValueRequest(session, "name", movieData, new DummyEncodeableObjectData("name of movie"));
-		SetValueResponse response = server.setValue(request);
-		final ObjectData[] updates = response.getUpdates();
-        IsisContext.getTransactionManager().endTransaction();
-
-        nameField.assertField(object, "name of movie");
-        assertEquals(0, updates.length);
-    }
-
-    @Test
-    public void testSetAssociationFailsWithNonCurrentTarget() {
-        try {
-            object.setOptimisticLock(new TestProxyVersion(2));
-            SetValueRequest request = new SetValueRequest(session, "name", movieData, new DummyEncodeableObjectData("name of movie"));
-			server.setValue(request);
-            fail();
-        } catch (final ConcurrencyException expected) {}
-    }
-
-    @Test
-    public void testSetAssociationFailsWhenInvisible() {
-        nameField.setUpIsVisible(false);
-        try {
-            SetValueRequest request = new SetValueRequest(session, "name", movieData, new DummyEncodeableObjectData("name of movie"));
-			server.setValue(request);
-            fail();
-        } catch (final IsisException expected) {
-            assertEquals("can't modify field as not visible or editable", expected.getMessage());
-        }
-    }
-
-    @Test
-    public void testSetAssociationFailsWhenUnavailable() {
-        nameField.setUpIsUnusableFor(object);
-        try {
-            SetValueRequest request = new SetValueRequest(session, "name", movieData, new DummyEncodeableObjectData("test data"));
-			server.setValue(request);
-            fail();
-        } catch (final IsisException expected) {
-            assertEquals("can't modify field as not visible or editable", expected.getMessage());
-        }
-    }
-
-
-}
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(JMock.class)
+public class ServerFacadeImpl_ParseableAssociationsTest extends ProxyJunit4TestCase {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private ServerFacadeImpl server;
+    private AuthenticationSession session;
+    private DummyReferenceData movieData;
+    private ObjectAdapter object;
+    private TestProxyAssociation nameField;
+
+    private AuthenticationManager mockAuthenticationManager;
+    private ObjectEncoderDecoder mockObjectEncoder;
+
+    /**
+     * Testing the {@link ServerFacadeImpl} implementation of {@link ServerFacade}.
+     * 
+     * <p>
+     * This uses the encoder to unmarshall objects and then calls the persistor and reflector; all of which should be
+     * mocked.
+     */
+    @Before
+    public void setUp() throws Exception {
+
+        mockAuthenticationManager = mockery.mock(AuthenticationManager.class);
+        mockObjectEncoder = mockery.mock(ObjectEncoderDecoder.class);
+
+        server = new ServerFacadeImpl(mockAuthenticationManager);
+        server.setEncoder(mockObjectEncoder);
+        server.init();
+
+        object = system.createPersistentTestObject();
+
+        final TestProxySpecification spec = (TestProxySpecification) object.getSpecification();
+        nameField = new TestProxyAssociation("name", system.getSpecification(String.class));
+        spec.setupFields(Arrays.asList((ObjectAssociation) nameField));
+
+        movieData = new DummyReferenceData(object.getOid(), "none", new TestProxyVersion(1));
+
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        system.shutdown();
+    }
+
+    /**
+     * TODO: other tests for clear: - clear collection element - fails if unauthorised - fails if unavailable
+     * 
+     * <p>
+     * could place all these clear test in one class; test other methods in other classes
+     */
+    @Test
+    public void testClearAssociation() {
+        IsisContext.getTransactionManager().startTransaction();
+        final ClearValueRequest request = new ClearValueRequest(session, "name", movieData);
+        final ClearValueResponse response = server.clearValue(request);
+        final ObjectData[] updatesData = response.getUpdates();
+        IsisContext.getTransactionManager().endTransaction();
+
+        nameField.assertFieldEmpty(object);
+        assertEquals(0, updatesData.length);
+    }
+
+    @Test
+    public void testSetValue() {
+        final TestProxySpecification specf = system.getSpecification(String.class);
+        specf.addFacet(new EncodableFacet() {
+            @Override
+            public String toEncodedString(final ObjectAdapter object) {
+                return null;
+            }
+
+            @Override
+            public ObjectAdapter fromEncodedString(final String encodedData) {
+                return getAdapterManager().adapterFor(encodedData);
+            }
+
+            @Override
+            public Class facetType() {
+                return EncodableFacet.class;
+            }
+
+            @Override
+            public FacetHolder getFacetHolder() {
+                return null;
+            }
+
+            @Override
+            public void setFacetHolder(final FacetHolder facetHolder) {
+            }
+
+            @Override
+            public boolean alwaysReplace() {
+                return false;
+            }
+
+            @Override
+            public boolean isDerived() {
+                return false;
+            }
+
+            @Override
+            public boolean isNoop() {
+                return false;
+            }
+
+            @Override
+            public Facet getUnderlyingFacet() {
+                return null;
+            }
+
+            @Override
+            public void setUnderlyingFacet(final Facet underlyingFacet) {
+                throw new UnsupportedOperationException();
+            }
+
+        });
+
+        IsisContext.getTransactionManager().startTransaction();
+        final SetValueRequest request =
+            new SetValueRequest(session, "name", movieData, new DummyEncodeableObjectData("name of movie"));
+        final SetValueResponse response = server.setValue(request);
+        final ObjectData[] updates = response.getUpdates();
+        IsisContext.getTransactionManager().endTransaction();
+
+        nameField.assertField(object, "name of movie");
+        assertEquals(0, updates.length);
+    }
+
+    @Test
+    public void testSetAssociationFailsWithNonCurrentTarget() {
+        try {
+            object.setOptimisticLock(new TestProxyVersion(2));
+            final SetValueRequest request =
+                new SetValueRequest(session, "name", movieData, new DummyEncodeableObjectData("name of movie"));
+            server.setValue(request);
+            fail();
+        } catch (final ConcurrencyException expected) {
+        }
+    }
+
+    @Test
+    public void testSetAssociationFailsWhenInvisible() {
+        nameField.setUpIsVisible(false);
+        try {
+            final SetValueRequest request =
+                new SetValueRequest(session, "name", movieData, new DummyEncodeableObjectData("name of movie"));
+            server.setValue(request);
+            fail();
+        } catch (final IsisException expected) {
+            assertEquals("can't modify field as not visible or editable", expected.getMessage());
+        }
+    }
+
+    @Test
+    public void testSetAssociationFailsWhenUnavailable() {
+        nameField.setUpIsUnusableFor(object);
+        try {
+            final SetValueRequest request =
+                new SetValueRequest(session, "name", movieData, new DummyEncodeableObjectData("test data"));
+            server.setValue(request);
+            fail();
+        } catch (final IsisException expected) {
+            assertEquals("can't modify field as not visible or editable", expected.getMessage());
+        }
+    }
+
+}



Mime
View raw message