incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1165139 [3/3] - in /incubator/isis/trunk/framework: core/commons/src/main/java/org/apache/isis/core/commons/lang/ runtimes/dflt/webserver/src/main/java/org/apache/isis/runtimes/dflt/webserver/ viewer/json/json-applib/src/main/java/org/apac...
Date Mon, 05 Sep 2011 00:38:23 GMT
Copied: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceServerside.java
(from r1164046, incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceImpl.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceServerside.java?p2=incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceServerside.java&p1=incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceImpl.java&r1=1164046&r2=1165139&rev=1165139&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceImpl.java
(original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/user/UserResourceServerside.java
Mon Sep  5 00:38:21 2011
@@ -23,18 +23,18 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.apache.isis.viewer.json.applib.user.UserResource;
-import org.apache.isis.viewer.json.viewer.RepContext;
+import org.apache.isis.viewer.json.viewer.ResourceContext;
 import org.apache.isis.viewer.json.viewer.resources.ResourceAbstract;
 
-public class UserResourceImpl extends ResourceAbstract implements UserResource {
+public class UserResourceServerside extends ResourceAbstract implements UserResource {
 
     @Override
     @Produces({ MediaType.APPLICATION_JSON })
     public Response user() {
         init();
         
-        RepContext repContext = getResourceContext().repContext();
-        UserRepBuilder builder = UserRepBuilder.newBuilder(repContext, getAuthenticationSession());
+        ResourceContext resourceContext = getResourceContext();
+        UserRepBuilder builder = UserRepBuilder.newBuilder(resourceContext).withAuthenticationSession(getAuthenticationSession());
         return responseOfOk(jsonRepresentionFrom(builder));
     }
 

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstractTest_jsonFor.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstractTest_jsonFor.java?rev=1165139&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstractTest_jsonFor.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/resources/ResourceAbstractTest_jsonFor.java
Mon Sep  5 00:38:21 2011
@@ -0,0 +1,65 @@
+package org.apache.isis.viewer.json.viewer.resources;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.viewer.json.applib.JsonRepresentation;
+import org.apache.isis.viewer.json.applib.util.JsonMapper;
+import org.junit.Test;
+
+public class ResourceAbstractTest_jsonFor {
+
+    @Test
+    public void simpleNoMessage() throws Exception {
+        // given
+        Exception ex = new Exception();
+
+        // when
+        String jsonFor = ResourceAbstract.jsonFor(ex);
+        assertThat(jsonFor, is(not(nullValue())));
+        JsonRepresentation jsonRepr = JsonMapper.instance().read(jsonFor, JsonRepresentation.class);
+        
+        // then
+        assertThat(jsonRepr.getString("message"), is(nullValue()));
+        assertThat(jsonRepr.getArray("stackTrace"), is(not(nullValue())));
+        assertThat(jsonRepr.getArray("stackTrace").arraySize(), is(greaterThan(0)));
+        assertThat(jsonRepr.getRepresentation("causedBy"), is(nullValue()));
+    }
+
+    @Test
+    public void withMessage() throws Exception {
+        // given
+        Exception ex = new Exception("foobar");
+        
+        // when
+        String jsonFor = ResourceAbstract.jsonFor(ex);
+        assertThat(jsonFor, is(not(nullValue())));
+        JsonRepresentation jsonRepr = JsonMapper.instance().read(jsonFor, JsonRepresentation.class);
+        
+        // then
+        assertThat(jsonRepr.getString("message"), is(ex.getMessage()));
+    }
+
+    @Test
+    public void withCause() throws Exception {
+        // given
+        Exception cause = new Exception("barfoo");
+        Exception ex = new Exception("foobar", cause);
+        
+        // when
+        String jsonFor = ResourceAbstract.jsonFor(ex);
+        assertThat(jsonFor, is(not(nullValue())));
+        JsonRepresentation jsonRepr = JsonMapper.instance().read(jsonFor, JsonRepresentation.class);
+        
+        // then
+        assertThat(jsonRepr.getString("message"), is(ex.getMessage()));
+        JsonRepresentation causedByRepr = jsonRepr.getRepresentation("causedBy");
+        assertThat(causedByRepr, is(not(nullValue())));
+        assertThat(causedByRepr.getString("message"), is(cause.getMessage()));
+    }
+
+
+}

Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/util/RepresentationTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/util/RepresentationTypeTest.java?rev=1165139&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/util/RepresentationTypeTest.java
(added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/test/java/org/apache/isis/viewer/json/viewer/util/RepresentationTypeTest.java
Mon Sep  5 00:38:21 2011
@@ -0,0 +1,18 @@
+package org.apache.isis.viewer.json.viewer.util;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.viewer.json.viewer.resources.RepresentationType;
+import org.junit.Test;
+
+
+public class RepresentationTypeTest {
+
+	@Test
+	public void getName() throws Exception {
+	    assertThat(RepresentationType.DOMAIN_ACTION.getName(), is("domainAction"));
+	    assertThat(RepresentationType.LIST.getName(), is("list"));
+	}
+
+
+}



Mime
View raw message