isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1154757 - in /incubator/isis/trunk/framework: core/commons/src/main/java/org/apache/isis/core/commons/matchers/ viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ viewer/json/json-applib/src/main/java/org/apac...
Date Sun, 07 Aug 2011 20:04:04 GMT
Author: danhaywood
Date: Sun Aug  7 20:04:04 2011
New Revision: 1154757

URL: http://svn.apache.org/viewvc?rev=1154757&view=rev
Log:
ISIS-109: more tests for resource representations

Added:
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserRepresentation.java
Modified:
    incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/matchers/IsisMatchers.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectRepresentation.java
    incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesRepresentation.java
    incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.java

Modified: incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/matchers/IsisMatchers.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/matchers/IsisMatchers.java?rev=1154757&r1=1154756&r2=1154757&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/matchers/IsisMatchers.java
(original)
+++ incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/matchers/IsisMatchers.java
Sun Aug  7 20:04:04 2011
@@ -210,4 +210,19 @@ public final class IsisMatchers {
         };
     }
 
+    public static Matcher<String> matches(final String regex) {
+        return new TypeSafeMatcher<String>() {
+    
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("string matching " + regex);
+            }
+    
+            @Override
+            public boolean matchesSafely(String str) {
+                return str.matches(regex);
+            }
+        };
+    }
+
 }

Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectRepresentation.java?rev=1154757&r1=1154756&r2=1154757&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectRepresentation.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/DomainObjectRepresentation.java
Sun Aug  7 20:04:04 2011
@@ -1,6 +1,13 @@
 package org.apache.isis.viewer.json.applib.domain;
 
+import org.apache.isis.viewer.json.applib.JsonRepresentation;
+import org.codehaus.jackson.JsonNode;
 
-public class DomainObjectRepresentation {
+
+public class DomainObjectRepresentation extends JsonRepresentation {
+
+    public DomainObjectRepresentation(JsonNode jsonNode) {
+        super(jsonNode);
+    }
 
 }

Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesRepresentation.java?rev=1154757&r1=1154756&r2=1154757&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesRepresentation.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/domain/ServicesRepresentation.java
Sun Aug  7 20:04:04 2011
@@ -8,7 +8,6 @@ public class ServicesRepresentation exte
 
     public ServicesRepresentation(JsonNode jsonNode) {
         super(jsonNode);
-        // TODO Auto-generated constructor stub
     }
     
 }

Added: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserRepresentation.java?rev=1154757&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserRepresentation.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/user/UserRepresentation.java
Sun Aug  7 20:04:04 2011
@@ -0,0 +1,13 @@
+package org.apache.isis.viewer.json.applib.user;
+
+import org.apache.isis.viewer.json.applib.JsonRepresentation;
+import org.codehaus.jackson.JsonNode;
+
+
+public class UserRepresentation extends JsonRepresentation {
+
+    public UserRepresentation(JsonNode jsonNode) {
+        super(jsonNode);
+    }
+    
+}

Modified: incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.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?rev=1154757&r1=1154756&r2=1154757&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-tck/src/test/java/org/apache/isis/viewer/json/tck/ResourceRepresentationTest.java
Sun Aug  7 20:04:04 2011
@@ -1,14 +1,16 @@
 package org.apache.isis.viewer.json.tck;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
+
+import static org.hamcrest.CoreMatchers.*;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
+import static org.apache.isis.core.commons.matchers.IsisMatchers.*;
 
 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.Link;
 import org.apache.isis.viewer.json.applib.blocks.Method;
 import org.apache.isis.viewer.json.applib.domain.DomainObjectRepresentation;
 import org.apache.isis.viewer.json.applib.domain.DomainObjectResource;
@@ -16,11 +18,13 @@ import org.apache.isis.viewer.json.appli
 import org.apache.isis.viewer.json.applib.domain.ServicesResource;
 import org.apache.isis.viewer.json.applib.homepage.HomePageRepresentation;
 import org.apache.isis.viewer.json.applib.homepage.HomePageResource;
+import org.apache.isis.viewer.json.applib.user.UserRepresentation;
 import org.apache.isis.viewer.json.applib.util.HttpStatusCode;
 import org.apache.isis.viewer.json.applib.util.JsonResponse;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 
@@ -60,6 +64,9 @@ public class ResourceRepresentationTest 
         
         HomePageRepresentation homePageRepr = homePageJsonResp.getEntity();
         assertThat(homePageRepr, is(not(nullValue())));
+        assertThat(homePageRepr.isMap(), is(true));
+        
+        assertThat(homePageRepr.getUser(), is(not(nullValue())));
         assertThat(homePageRepr.getUser().getMethod(), is(Method.GET));
         
         assertThat(homePageRepr.getServices(), is(not(nullValue())));
@@ -90,8 +97,35 @@ public class ResourceRepresentationTest 
         assertThat(applibValuesEntityRepoRep, is(not(nullValue())));
     }
 
+    @Ignore("not yet implemented")
+    @Test
+    public void homePageResource_linksToUserResource() 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 userResp = client.follow(homePageRepr.getUser());
+        JsonResponse<UserRepresentation> userJsonResp = JsonResponse.of(userResp, UserRepresentation.class);
+        
+        // then
+        UserRepresentation userRepr = userJsonResp.getEntity();
+
+        assertThat(userRepr, is(not(nullValue())));
+        assertThat(userRepr.isMap(), is(true));
+    }
+
+    
     @Test
     public void servicesResource_returnsServicesRepresentation() throws Exception {
+        
         // given
         ServicesResource servicesResource = client.getServicesResource();
         
@@ -101,11 +135,57 @@ public class ResourceRepresentationTest 
         
         // then
         ServicesRepresentation servicesRepr = servicesJsonResp.getEntity();
+
+        assertThat(servicesRepr, is(not(nullValue())));
+        assertThat(servicesRepr.isArray(), is(true));
+        assertThat(servicesRepr.size(), is(4));
+
+        JsonRepresentation repoRepr = servicesRepr.elementAt(0);
+        assertThat(repoRepr, is(not(nullValue())));
+        
+        assertThat(repoRepr.getString("title"), is("ApplibValues"));
+        
+        Link repoObjLink = repoRepr.getLink("link");
+        assertThat(repoObjLink.getRel(), is("object"));
+        assertThat(repoObjLink.getHref(), matches("http://localhost:\\d+/objects/OID:1"));
+        
+        Link repoTypeLink = repoRepr.getLink("type");
+        assertThat(repoTypeLink.getRel(), is("type"));
+        assertThat(repoTypeLink.getHref(), matches("http://localhost:\\d+/types/application/vnd.org.apache.isis.tck.objstore.dflt.scalars.ApplibValuesEntityRepositoryDefault\\+json"));
+
+        Link repoIconLink = repoRepr.getLink("icon");
+        assertThat(repoIconLink.getRel(), is("icon"));
+        assertThat(repoIconLink.getHref(), matches("http://localhost:\\d+/images/null.png"));
+    }
+
+
+    @Test
+    public void servicesResource_linksToDomainObjectResourceForService() throws Exception
{
         
-        JsonRepresentation applibValuesEntityRepoRep = servicesRepr.elementAt(0);
-        assertThat(applibValuesEntityRepoRep, is(not(nullValue())));
+        // given
+        ServicesResource servicesResource = client.getServicesResource();
+        
+        // when
+        Response servicesResp = servicesResource.services();
+        JsonResponse<ServicesRepresentation> servicesJsonResp = JsonResponse.of(servicesResp,
ServicesRepresentation.class);
+        
+        // then
+        ServicesRepresentation servicesRepr = servicesJsonResp.getEntity();
+
+        JsonRepresentation repoRepr = servicesRepr.elementAt(0);
+        Link repoObjLink = repoRepr.getLink("link");
+
+        // and when
+        Response repoFollowResp = client.follow(repoObjLink);
+        JsonResponse<DomainObjectRepresentation> repoFollowJsonResp = JsonResponse.of(repoFollowResp,
DomainObjectRepresentation.class);
+        
+        // then
+        DomainObjectRepresentation domainObjectRepr = repoFollowJsonResp.getEntity();
+        Link domainObjectReprLink = domainObjectRepr.getLink("_self.link");
+        assertThat(domainObjectReprLink, is(repoObjLink));
     }
 
+
     @Test
     public void domainObjectResource_returnsDomainObjectRepresentation() throws Exception
{
         // given
@@ -117,12 +197,13 @@ public class ResourceRepresentationTest 
         
         // then
         DomainObjectRepresentation domainObjectRepr = domainObjectJsonResp.getEntity();
+        Link link = domainObjectRepr.getLink("_self.link");
+        assertThat(link.getRel(), is("object"));
+        assertThat(link.getHref(), matches(".+objects/OID:1"));
     }
 
+
     
-    
-    
-}
 //{
 //    "_self" : {
 //      "link" : {
@@ -188,3 +269,7 @@ public class ResourceRepresentationTest 
 //      }
 //    }
 //  }
+
+    
+}
+    
\ No newline at end of file



Mime
View raw message