incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1154565 - in /incubator/isis/trunk/framework/viewer/json: json-applib/src/test/java/org/apache/isis/viewer/json/applib/ json-tck/src/test/java/ json-tck/src/test/java/org/apache/isis/viewer/json/tck/
Date Sat, 06 Aug 2011 18:15:23 GMT
Author: danhaywood
Date: Sat Aug  6 18:15:23 2011
New Revision: 1154565

URL: http://svn.apache.org/viewvc?rev=1154565&view=rev
Log:
ISIS-109: Json viewer tests

Added:
    incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulClientTest_follow.java
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.java
      - copied, changed from r1154100, incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/JsonViewerEndToEndTest.java
Removed:
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/JsonViewerEndToEndTest.java

Added: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulClientTest_follow.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulClientTest_follow.java?rev=1154565&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulClientTest_follow.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/RestfulClientTest_follow.java
Sat Aug  6 18:15:23 2011
@@ -0,0 +1,80 @@
+package org.apache.isis.viewer.json.applib;
+import java.net.URI;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.isis.viewer.json.applib.blocks.Link;
+import org.apache.isis.viewer.json.applib.blocks.Method;
+import org.jboss.resteasy.client.ClientExecutor;
+import org.jboss.resteasy.client.ClientRequest;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.client.core.BaseClientResponse;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.Sequence;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.jmock.lib.legacy.ClassImposteriser;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+@RunWith(JMock.class)
+public class RestfulClientTest_follow {
+
+    private Mockery context = new JUnit4Mockery() {{
+        setImposteriser(ClassImposteriser.INSTANCE);
+    }};
+    private RestfulClient client;
+    private URI uri;
+    private ClientExecutor mockExecutor;
+    private ClientRequest mockClientRequest;
+    private BaseClientResponse<String> mockClientResponse;
+
+    @SuppressWarnings("unchecked")
+    @Before
+    public void setUp() throws Exception {
+        mockExecutor = context.mock(ClientExecutor.class);
+        mockClientRequest = context.mock(ClientRequest.class);
+        mockClientResponse = context.mock(BaseClientResponse.class);
+        
+        uri = URI.create("http://yadayada:8080");
+        client = new RestfulClient(uri, mockExecutor);
+    }
+    
+    
+    @Test
+    public void follow_get() throws Exception {
+        // given
+        JsonRepresentation jsonRepresentation = new JsonRepresentation(JsonUtils.readJson("map.json"));
+        Link getLink = jsonRepresentation.getLink("aLink");
+
+        // when
+        final Sequence sequence = context.sequence("execution");
+        context.checking(new Expectations() {
+            {
+                one(mockExecutor).createRequest("http://foo/bar");
+                inSequence(sequence);
+                will(returnValue(mockClientRequest));
+                
+                one(mockClientRequest).setHttpMethod(Method.GET.name());
+                inSequence(sequence);
+                one(mockClientRequest).accept(MediaType.APPLICATION_JSON_TYPE);
+                inSequence(sequence);
+
+                one(mockExecutor).execute(mockClientRequest);
+                inSequence(sequence);
+                will(returnValue(mockClientResponse));
+                
+                one(mockClientResponse).setReturnType(String.class);
+                inSequence(sequence);
+            }
+        });
+        client.follow(getLink);
+        
+        // then
+    }
+
+}

Copied: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.java
(from r1154100, incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/JsonViewerEndToEndTest.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.java?p2=incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.java&p1=incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/JsonViewerEndToEndTest.java&r1=1154100&r2=1154565&rev=1154565&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/JsonViewerEndToEndTest.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.java
Sat Aug  6 18:15:23 2011
@@ -1,14 +1,12 @@
+package org.apache.isis.viewer.json.tck;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
-import java.net.URI;
-
 import javax.ws.rs.core.Response;
 
 import org.apache.isis.runtimes.dflt.webserver.WebServer;
-import org.apache.isis.viewer.json.applib.JsonRepresentation;
 import org.apache.isis.viewer.json.applib.RestfulClient;
 import org.apache.isis.viewer.json.applib.blocks.Method;
 import org.apache.isis.viewer.json.applib.domain.DomainObjectRepresentation;
@@ -18,14 +16,13 @@ import org.apache.isis.viewer.json.appli
 import org.apache.isis.viewer.json.applib.homepage.HomePageResource;
 import org.apache.isis.viewer.json.applib.util.HttpStatusCode;
 import org.apache.isis.viewer.json.applib.util.JsonResponse;
-import org.codehaus.jackson.JsonNode;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 
-public class JsonViewerEndToEndTest {
+public class ResourceRepresentationTest {
 
     @BeforeClass
     public static void setUpClass() throws Exception {
@@ -38,17 +35,17 @@ public class JsonViewerEndToEndTest {
         webServer.stop();
     }
 
-    private static WebServer webServer;
-    private RestfulClient client;
+    protected static WebServer webServer;
+    protected RestfulClient client;
 
     @Before
     public void setUp() throws Exception {
         client = new RestfulClient(webServer.getBase());
     }
-    
-    
+
+
     @Test
-    public void homePageResources() throws Exception {
+    public void homePageResource_returnsHomePageRepresentation() throws Exception {
         // given
         HomePageResource homePageResource = client.getHomePageResource();
         
@@ -68,24 +65,8 @@ public class JsonViewerEndToEndTest {
     }
 
     @Test
-    public void homePageResource_canMarshallToJsonNode() throws Exception {
-        // given
-        HomePageResource homePageResource = client.getHomePageResource();
-        
-        // when
-        Response resourcesResp = homePageResource.resources();
-        JsonResponse<JsonNode> homePageJsonResp = JsonResponse.of(resourcesResp, JsonNode.class);
-        
-        // then
-        assertThat(homePageJsonResp.getStatus(), is(HttpStatusCode.OK));
-        JsonNode homePage = homePageJsonResp.getEntity();
-
-        assertThat(homePage.isArray(), is(false));
-    }
-
-
-    @Test
     public void homePageResource_linksToServicesResource() throws Exception {
+        
         // given
         HomePageResource homePageResource = client.getHomePageResource();
 
@@ -107,9 +88,8 @@ public class JsonViewerEndToEndTest {
         assertThat(applibValuesEntityRepoRep, is(not(nullValue())));
     }
 
-
     @Test
-    public void servicesResource_canBeCalledDirectly() throws Exception {
+    public void servicesResource_returnsServicesRepresentation() throws Exception {
         // given
         ServicesResource servicesResource = client.getServicesResource();
         
@@ -125,61 +105,4 @@ public class JsonViewerEndToEndTest {
     }
 
 
-    @Test
-    public void jsonResponse_canFollow_usingGet() throws Exception {
-        // given
-        HomePageResource homePageResource = client.getHomePageResource();
-
-        // when
-        Response resourcesResp = homePageResource.resources();
-        JsonResponse<HomePageRepresentation> homePageJsonResp = JsonResponse.of(resourcesResp,
HomePageRepresentation.class);
-        
-        // then
-        HomePageRepresentation homePageRepr = homePageJsonResp.getEntity();
-        
-        // and when
-        Response servicesResp = client.follow(homePageRepr.getServices());
-        JsonResponse<ServicesRepresentation> servicesJsonResp = JsonResponse.of(servicesResp,
ServicesRepresentation.class);
-        
-        // then
-        assertThat(servicesJsonResp.getStatus(), is(HttpStatusCode.OK));
-        ServicesRepresentation servicesRepr = servicesJsonResp.getEntity();
-        
-        assertThat(servicesRepr, is(not(nullValue())));
-        assertThat(servicesRepr.get(0), is(not(nullValue())));
-    }
-
-    @Test
-    public void jsonRepresentation_deserializeFromMap() throws Exception {
-        // given
-        HomePageResource homePageResource = client.getHomePageResource();
-
-        // when
-        Response resourcesResp = homePageResource.resources();
-        JsonResponse<JsonRepresentation> homePageJsonResp = JsonResponse.of(resourcesResp,
JsonRepresentation.class);
-        
-        // then
-        assertThat(homePageJsonResp.getStatus(), is(HttpStatusCode.OK));
-        JsonRepresentation jsonRepr = homePageJsonResp.getEntity();
-
-        assertThat(jsonRepr, is(not(nullValue())));
-        assertThat(jsonRepr.getJsonNode().isArray(), is(false));
-    }
-
-    @Test
-    public void jsonRepresentation_deserializeFromList() throws Exception {
-        // given
-        ServicesResource servicesResource = client.getServicesResource();
-        
-        // when
-        Response servicesResp = servicesResource.services();
-        JsonResponse<JsonRepresentation> servicesJsonResp = JsonResponse.of(servicesResp,
JsonRepresentation.class);
-        
-        // then
-        JsonRepresentation jsonRepr = servicesJsonResp.getEntity();
-
-        assertThat(jsonRepr, is(not(nullValue())));
-        assertThat(jsonRepr.getJsonNode().isArray(), is(true));
-    }
-
 }



Mime
View raw message