You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2014/04/25 18:44:26 UTC
[1/3] ISIS-421: RO TCK tests and fixes
Repository: isis
Updated Branches:
refs/heads/master 964e252b9 -> 094379501
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJodaProperties_thenRepresentation_ok_TODO.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJodaProperties_thenRepresentation_ok_TODO.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJodaProperties_thenRepresentation_ok_TODO.java
deleted file mode 100644
index 62437af..0000000
--- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJodaProperties_thenRepresentation_ok_TODO.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.viewer.restfulobjects.tck.domainobject.oid;
-
-import static org.apache.isis.core.commons.matchers.IsisMatchers.matches;
-import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.assertThat;
-import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.isLink;
-import static org.hamcrest.CoreMatchers.*;
-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.util.Date;
-
-import org.joda.time.LocalDate;
-import org.joda.time.LocalDateTime;
-import org.joda.time.format.DateTimeFormat;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.commons.matchers.IsisMatchers;
-import org.apache.isis.core.webserver.WebServer;
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.Rel;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
-import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod;
-import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient;
-import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectMemberRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ScalarValueRepresentation;
-import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule;
-import org.apache.isis.viewer.restfulobjects.tck.Util;
-
-public class Get_givenEntityWithJodaProperties_thenRepresentation_ok_TODO {
-
- @Rule
- public IsisWebServerRule webServerRule = new IsisWebServerRule();
-
- protected RestfulClient client;
-
- private DomainObjectRepresentation domainObjectRepr;
-
- @Before
- public void setUp() throws Exception {
- final WebServer webServer = webServerRule.getWebServer();
- client = new RestfulClient(webServer.getBase());
- }
-
- @Ignore // to fix
- @Test
- public void thenMembers() throws Exception {
-
- // when
- final LinkRepresentation link = Util.serviceActionListInvokeFirstReference(client, "JodaValuedEntities");
- domainObjectRepr = client.follow(link).getEntity().as(DomainObjectRepresentation.class);
-
- // and then members (types)
- DomainObjectMemberRepresentation property;
- ScalarValueRepresentation scalarRepr;
-
- property = domainObjectRepr.getProperty("localDateProperty");
- assertThat(property.getMemberType(), is("property"));
- assertThat(property.getFormat(), is("date"));
- assertThat(property.getXIsisFormat(), is("jodalocaldate"));
- scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
- assertThat(scalarRepr.isString(), is(true));
- java.util.Date dateValue = scalarRepr.asDate();
- assertThat(dateValue, is(asDate("2008-03-21")));
-
- property = domainObjectRepr.getProperty("localDateTimeProperty");
- assertThat(property.getMemberType(), is("property"));
- assertThat(property.getFormat(), is("date-time"));
- assertThat(property.getXIsisFormat(), is("jodalocaldatetime"));
- scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
- assertThat(scalarRepr.isString(), is(true));
- java.util.Date dateTimeValue = scalarRepr.asDateTime();
- assertThat(dateTimeValue, is(not(nullValue())));
- assertThat(scalarRepr.asString(), IsisMatchers.startsWith("2009-04-29T13:45:22+0100"));
-
- // and then member types have links to details (selected ones inspected only)
- property = domainObjectRepr.getProperty("localDateProperty");
- assertThat(property.getLinkWithRel(Rel.DETAILS),
- isLink()
- .href(matches(".+\\/objects\\/JODA\\/\\d+\\/properties\\/localDateProperty"))
- .httpMethod(RestfulHttpMethod.GET)
- .type(RepresentationType.OBJECT_PROPERTY.getMediaType()));
-
- property = domainObjectRepr.getProperty("localDateTimeProperty");
- assertThat(property.getLinkWithRel(Rel.DETAILS),
- isLink()
- .href(matches(".+\\/objects\\/JODA\\/\\d+\\/properties\\/localDateTimeProperty"))
- .httpMethod(RestfulHttpMethod.GET)
- .type(RepresentationType.OBJECT_PROPERTY.getMediaType()));
- }
-
- private static Date asDate(final String text) {
- return new java.util.Date(JsonRepresentation.yyyyMMdd.parseDateTime(text).getMillis());
- }
-
- private static Date asDateTime(final String text) {
- return new java.util.Date(JsonRepresentation.yyyyMMddTHHmmssZ.parseDateTime(text).getMillis());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithPrimitiveProperties_thenRepresentation_ok.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithPrimitiveProperties_thenRepresentation_ok.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithPrimitiveProperties_thenRepresentation_ok.java
index 2cfcc1b..ed5977e 100644
--- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithPrimitiveProperties_thenRepresentation_ok.java
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithPrimitiveProperties_thenRepresentation_ok.java
@@ -77,7 +77,7 @@ public class Get_givenEntityWithPrimitiveProperties_thenRepresentation_ok {
property = domainObjectRepr.getProperty("byteProperty");
assertThat(property.getMemberType(), is("property"));
- assertThat(property.getFormat(), is(nullValue()));
+ assertThat(property.getFormat(), is("int"));
assertThat(property.getXIsisFormat(), is("byte"));
scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
assertThat(scalarRepr.isIntegralNumber(), is(true));
@@ -86,7 +86,7 @@ public class Get_givenEntityWithPrimitiveProperties_thenRepresentation_ok {
property = domainObjectRepr.getProperty("shortProperty");
assertThat(property.getMemberType(), is("property"));
- assertThat(property.getFormat(), is(nullValue()));
+ assertThat(property.getFormat(), is("int"));
assertThat(property.getXIsisFormat(), is("short"));
scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
assertThat(scalarRepr.isIntegralNumber(), is(true));
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithWrapperProperties_thenRepresentation_ok.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithWrapperProperties_thenRepresentation_ok.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithWrapperProperties_thenRepresentation_ok.java
index 8862ae4..b7cb2be 100644
--- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithWrapperProperties_thenRepresentation_ok.java
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithWrapperProperties_thenRepresentation_ok.java
@@ -18,19 +18,9 @@
*/
package org.apache.isis.viewer.restfulobjects.tck.domainobject.oid;
-import static org.apache.isis.core.commons.matchers.IsisMatchers.matches;
-import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.assertThat;
-import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.isLink;
-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 org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-
-import org.apache.isis.core.commons.matchers.IsisMatchers;
import org.apache.isis.core.webserver.WebServer;
import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation;
import org.apache.isis.viewer.restfulobjects.applib.Rel;
@@ -43,6 +33,13 @@ import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ScalarValueRep
import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule;
import org.apache.isis.viewer.restfulobjects.tck.Util;
+import static org.apache.isis.core.commons.matchers.IsisMatchers.matches;
+import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.assertThat;
+import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.isLink;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
public class Get_givenEntityWithWrapperProperties_thenRepresentation_ok {
@Rule
@@ -81,7 +78,7 @@ public class Get_givenEntityWithWrapperProperties_thenRepresentation_ok {
property = domainObjectRepr.getProperty("byteProperty");
assertThat(property.getMemberType(), is("property"));
- assertThat(property.getFormat(), is(nullValue()));
+ assertThat(property.getFormat(), is("int"));
assertThat(property.getXIsisFormat(), is("byte"));
scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
assertThat(scalarRepr.isIntegralNumber(), is(true));
@@ -90,7 +87,7 @@ public class Get_givenEntityWithWrapperProperties_thenRepresentation_ok {
property = domainObjectRepr.getProperty("shortProperty");
assertThat(property.getMemberType(), is("property"));
- assertThat(property.getFormat(), is(nullValue()));
+ assertThat(property.getFormat(), is("int"));
assertThat(property.getXIsisFormat(), is("short"));
scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
assertThat(scalarRepr.isIntegralNumber(), is(true));
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Put_whenArgsValid_thenMultiplePropertyUpdate.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Put_whenArgsValid_thenMultiplePropertyUpdate.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Put_whenArgsValid_thenMultiplePropertyUpdate.java
index bf3a828..5886833 100644
--- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Put_whenArgsValid_thenMultiplePropertyUpdate.java
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Put_whenArgsValid_thenMultiplePropertyUpdate.java
@@ -18,29 +18,22 @@
*/
package org.apache.isis.viewer.restfulobjects.tck.domainobject.oid;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertThat;
-
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.sql.Date;
-
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status.Family;
-
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.format.ISODateTimeFormat;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
-
import org.apache.isis.core.webserver.WebServer;
import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation;
@@ -48,11 +41,13 @@ import org.apache.isis.viewer.restfulobjects.applib.Rel;
import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient;
import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse;
import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode;
-import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectMemberRepresentation;
import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRepresentation;
import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectResource;
import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
public class Put_whenArgsValid_thenMultiplePropertyUpdate {
@Rule
@@ -126,10 +121,10 @@ public class Put_whenArgsValid_thenMultiplePropertyUpdate {
final BigDecimal bd = new BigDecimal("12345678901234567.789");
final BigInteger bi = new BigInteger("12345678901234567890");
- final java.sql.Date sqld = new java.sql.Date(114,4,1);
+ final java.sql.Date sqld = new java.sql.Date(new DateTime(2014,5,1, 0,0, DateTimeZone.UTC).getMillis());
final java.sql.Time sqlt = new java.sql.Time(13,0,0);
final java.sql.Timestamp sqlts = new java.sql.Timestamp(114,4,1,13,0,0,0);
- final java.util.Date d = new java.util.Date(114,4,1,13,0,0);
+ final java.util.Date d = new DateTime(2014,5,1, 11,45, DateTimeZone.UTC).toDate();
final String e = "ORANGE";
final String s = "Tangerine";
@@ -147,8 +142,7 @@ public class Put_whenArgsValid_thenMultiplePropertyUpdate {
final DomainObjectRepresentation afterResp = result.getEntity().as(DomainObjectRepresentation.class);
- // TODO: bigdecimal is being being truncated/converted to doubles...
- assertThat(afterResp.getProperty("bigDecimalProperty").getBigDecimalFromNumeric("value"), is(new BigDecimal(12345678901234568L)));
+ assertThat(afterResp.getProperty("bigDecimalProperty").getBigDecimal("value"), is(new BigDecimal("12345678901234567.789")));
assertThat(afterResp.getProperty("bigIntegerProperty").getBigInteger("value"), is(bi));
assertThat(afterResp.getProperty("javaSqlDateProperty").getDate("value"), is((java.util.Date)sqld));
assertThat(afterResp.getProperty("javaSqlTimeProperty").getTime("value"), is((java.util.Date)sqlt));
@@ -170,11 +164,11 @@ public class Put_whenArgsValid_thenMultiplePropertyUpdate {
final LocalDate ld = new LocalDate(2013,5,1);
final LocalDateTime ldt = new LocalDateTime(2013,2,1,14,15,0);
- final DateTime dt = new DateTime(2013,2,1,14,15,0);
+ final DateTime dt = new DateTime(2013,2,1,14,15,0, DateTimeZone.UTC);
final String s = "New string";
- argRepr.mapPut("localDateProperty.value", asIsoNoT(ld.toDate()));
- argRepr.mapPut("localDateTimeProperty.value", asIso(ldt.toDate()));
+ argRepr.mapPut("localDateProperty.value", "2013-05-01");
+ argRepr.mapPut("localDateTimeProperty.value", "2013-02-01T14:15:00Z");
argRepr.mapPut("dateTimeProperty.value", asIso(dt.toDate()));
argRepr.mapPut("stringProperty.value", s);
@@ -183,7 +177,7 @@ public class Put_whenArgsValid_thenMultiplePropertyUpdate {
final DomainObjectRepresentation afterResp = result.getEntity().as(DomainObjectRepresentation.class);
- assertThat(afterResp.getProperty("localDateProperty").getDate("value"), is(ld.toDate()));
+ assertThat(afterResp.getProperty("localDateProperty").getString("value"), is("2013-05-01")); // being a bit hacky here...
assertThat(afterResp.getProperty("localDateTimeProperty").getDateTime("value"), is(ldt.toDate()));
assertThat(afterResp.getProperty("dateTimeProperty").getDateTime("value"), is(dt.toDate()));
assertThat(afterResp.getProperty("stringProperty").getString("value"), is(s));
@@ -195,17 +189,16 @@ public class Put_whenArgsValid_thenMultiplePropertyUpdate {
}
private static String asIso(final org.joda.time.DateTime dt) {
- return ISODateTimeFormat.basicDateTimeNoMillis().print(dt);
+ return ISODateTimeFormat.dateTimeNoMillis().withZoneUTC().print(dt);
}
-
-
+
private static String asIsoNoT(final java.util.Date d) {
final org.joda.time.DateTime dt = new org.joda.time.DateTime(d.getTime());
return asIsoNoT(dt);
}
private static String asIsoNoT(final org.joda.time.DateTime dt) {
- return ISODateTimeFormat.basicDate().print(dt);
+ return ISODateTimeFormat.date().withZoneUTC().print(dt);
}
private static String asIsoOnlyT(final java.util.Date d) {
@@ -214,7 +207,7 @@ public class Put_whenArgsValid_thenMultiplePropertyUpdate {
}
private static String asIsoOnlyT(final org.joda.time.DateTime dt) {
- return ISODateTimeFormat.basicTime().print(dt);
+ return ISODateTimeFormat.timeNoMillis().withZoneUTC().print(dt);
}
private DomainObjectRepresentation getObjectRepr(final String domainType, final String instanceId) throws JsonParseException, JsonMappingException, IOException {
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/property/Put_whenArgValid_thenPropertyUpdated_ok.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/property/Put_whenArgValid_thenPropertyUpdated_ok.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/property/Put_whenArgValid_thenPropertyUpdated_ok.java
index 80e1306..ebd5cbf 100644
--- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/property/Put_whenArgValid_thenPropertyUpdated_ok.java
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/property/Put_whenArgValid_thenPropertyUpdated_ok.java
@@ -18,19 +18,15 @@
*/
package org.apache.isis.viewer.restfulobjects.tck.domainobject.oid.property;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
-
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status.Family;
-
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.format.ISODateTimeFormat;
@@ -38,7 +34,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-
import org.apache.isis.core.webserver.WebServer;
import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation;
@@ -50,6 +45,9 @@ import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRe
import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ObjectPropertyRepresentation;
import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
public class Put_whenArgValid_thenPropertyUpdated_ok {
@Rule
@@ -134,11 +132,10 @@ public class Put_whenArgValid_thenPropertyUpdated_ok {
public void jdkPropertiesUpdated() throws Exception {
// big decimal
- // TODO: bigdecimal is being being truncated/converted to doubles...
final BigDecimal bd = new BigDecimal("12345678901234567.789");
modifyLink = getObjectPropertyReprModifyLink("JDKV", "29", "bigDecimalProperty");
argRepr = modifyLink.getArguments().mapPut("value", bd);
- assertThat(followedRepr(modifyLink,argRepr).getBigDecimalFromNumeric("value"), is(new BigDecimal(12345678901234568L)));
+ assertThat(followedRepr(modifyLink,argRepr).getBigDecimal("value"), is(new BigDecimal("12345678901234567.789")));
// big integer
final BigInteger bi = new BigInteger("12345678901234567890");
@@ -147,7 +144,7 @@ public class Put_whenArgValid_thenPropertyUpdated_ok {
assertThat(followedRepr(modifyLink,argRepr).getBigInteger("value"), is(bi));
// java.sql.Date
- final java.sql.Date sqld = new java.sql.Date(114,4,1);
+ final java.sql.Date sqld = new java.sql.Date(new DateTime(2014,5,1, 0,0, DateTimeZone.UTC).getMillis());
modifyLink = getObjectPropertyReprModifyLink("JDKV", "29", "javaSqlDateProperty");
argRepr = modifyLink.getArguments().mapPut("value", asIsoNoT(sqld));
assertThat(followedRepr(modifyLink,argRepr).getDate("value"), is((java.util.Date)sqld));
@@ -191,9 +188,8 @@ public class Put_whenArgValid_thenPropertyUpdated_ok {
// LocalDate
final LocalDate ld = new LocalDate(2013,5,1);
modifyLink = getObjectPropertyReprModifyLink("JODA", "73", "localDateProperty");
- argRepr = modifyLink.getArguments().mapPut("value", asIsoNoT(ld.toDate()));
- assertThat(followedRepr(modifyLink,argRepr).getDate("value"), is(ld.toDate()));
-
+ argRepr = modifyLink.getArguments().mapPut("value", "2013-05-01");
+ assertThat(followedRepr(modifyLink,argRepr).getString("value"), is("2013-05-01")); // hacky
// LocalDateTime
final LocalDateTime ldt = new LocalDateTime(2013,2,1,14,15,0);
@@ -241,7 +237,7 @@ public class Put_whenArgValid_thenPropertyUpdated_ok {
}
private static String asIso(final org.joda.time.DateTime dt) {
- return ISODateTimeFormat.basicDateTimeNoMillis().print(dt);
+ return ISODateTimeFormat.basicDateTimeNoMillis().withZoneUTC().print(dt);
}
@@ -251,7 +247,7 @@ public class Put_whenArgValid_thenPropertyUpdated_ok {
}
private static String asIsoNoT(final org.joda.time.DateTime dt) {
- return ISODateTimeFormat.basicDate().print(dt);
+ return ISODateTimeFormat.basicDate().withZoneUTC().print(dt);
}
private static String asIsoOnlyT(final java.util.Date d) {
@@ -260,7 +256,7 @@ public class Put_whenArgValid_thenPropertyUpdated_ok {
}
private static String asIsoOnlyT(final org.joda.time.DateTime dt) {
- return ISODateTimeFormat.basicTime().print(dt);
+ return ISODateTimeFormat.basicTime().withZoneUTC().print(dt);
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/scalars/JdkValuedEntity.java
----------------------------------------------------------------------
diff --git a/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/scalars/JdkValuedEntity.java b/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/scalars/JdkValuedEntity.java
index 0f4b0dd..2bcf4b5 100644
--- a/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/scalars/JdkValuedEntity.java
+++ b/core/tck/tck-dom/src/main/java/org/apache/isis/core/tck/dom/scalars/JdkValuedEntity.java
@@ -118,7 +118,7 @@ public class JdkValuedEntity extends AbstractDomainObject {
// }}
- // {{ BigIntegerProperty
+ // {{ BigIntegerProperty (to hold values that are larger than a long)
private BigInteger bigIntegerProperty;
@Optional
@@ -133,7 +133,22 @@ public class JdkValuedEntity extends AbstractDomainObject {
// }}
- // {{ BigDecimalProperty
+ // {{ BigIntegerProperty2 (to hold values that can also fit into a long)
+ private BigInteger bigIntegerProperty2;
+
+ @Optional
+ @MemberOrder(sequence = "1")
+ public BigInteger getBigIntegerProperty2() {
+ return bigIntegerProperty2;
+ }
+
+ public void setBigIntegerProperty2(final BigInteger bigIntegerProperty2) {
+ this.bigIntegerProperty2 = bigIntegerProperty2;
+ }
+
+ // }}
+
+ // {{ BigDecimalProperty (to hold values that are larger than a double)
private BigDecimal bigDecimalProperty;
@Optional
@@ -149,6 +164,22 @@ public class JdkValuedEntity extends AbstractDomainObject {
// }}
+ // {{ BigDecimalProperty (to hold values that are larger than a double)
+ private BigDecimal bigDecimalProperty2;
+
+ @Optional
+ @MemberOrder(sequence = "1")
+ public BigDecimal getBigDecimalProperty2() {
+ return bigDecimalProperty2;
+ }
+
+ public void setBigDecimalProperty2(final BigDecimal bigDecimalProperty2) {
+ this.bigDecimalProperty2 = bigDecimalProperty2;
+ }
+
+ // }}
+
+
// {{ MyEnum (property)
private MyEnum myEnum;
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JdkValuedEntityFixture.java
----------------------------------------------------------------------
diff --git a/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JdkValuedEntityFixture.java b/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JdkValuedEntityFixture.java
index c0928ba..9d337a2 100644
--- a/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JdkValuedEntityFixture.java
+++ b/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JdkValuedEntityFixture.java
@@ -19,9 +19,17 @@
package org.apache.isis.core.tck.fixture.scalars;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Date;
+import javax.inject.Inject;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
import org.apache.isis.applib.fixtures.AbstractFixture;
import org.apache.isis.core.tck.dom.scalars.JdkValuedEntity;
import org.apache.isis.core.tck.dom.scalars.JdkValuedEntityRepository;
+import org.apache.isis.core.tck.dom.scalars.MyEnum;
public class JdkValuedEntityFixture extends AbstractFixture {
@@ -35,13 +43,39 @@ public class JdkValuedEntityFixture extends AbstractFixture {
}
private JdkValuedEntity createEntity() {
- return jdkValuesEntityRepository.newEntity();
+ final JdkValuedEntity entity = jdkValuesEntityRepository.newEntity();
+ entity.setBigDecimalProperty(new BigDecimal("12345678901234567890.1234567890"));
+ entity.setBigDecimalProperty2(new BigDecimal("123.45"));
+ entity.setBigIntegerProperty(new BigInteger("12345678901234567890"));
+ entity.setBigIntegerProperty2(new BigInteger("12345"));
+ entity.setJavaSqlDateProperty(asSqlDate("2014-04-24"));
+ entity.setJavaSqlTimeProperty(asSqlTime("1970-01-01T12:34:45Z"));
+ entity.setJavaSqlTimestampProperty(new Timestamp(1234567890));
+ entity.setJavaUtilDateProperty(asDateTime("2013-05-25T12:34:45Z"));
+ entity.setMyEnum(MyEnum.RED);
+ return entity;
}
- private JdkValuedEntityRepository jdkValuesEntityRepository;
+ private final static DateTimeFormatter yyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC();
+ private final static DateTimeFormatter yyyyMMddTHHmmssZ = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").withZoneUTC();
+
+ private static Date asDate(final String text) {
+ return new java.util.Date(yyyyMMdd.parseDateTime(text).getMillis());
+ }
+
+ private static Date asDateTime(final String text) {
+ return new java.util.Date(yyyyMMddTHHmmssZ.parseDateTime(text).getMillis());
+ }
- public void setJdkValuesEntityRepository(final JdkValuedEntityRepository jdkValuesEntityRepository) {
- this.jdkValuesEntityRepository = jdkValuesEntityRepository;
+ private static java.sql.Date asSqlDate(final String text) {
+ return new java.sql.Date(yyyyMMdd.parseDateTime(text).getMillis());
}
+ private static java.sql.Time asSqlTime(final String text) {
+ return new java.sql.Time(yyyyMMddTHHmmssZ.parseDateTime(text).getMillis());
+ }
+
+ @Inject
+ private JdkValuedEntityRepository jdkValuesEntityRepository;
+
}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JodaValuedEntityFixture.java
----------------------------------------------------------------------
diff --git a/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JodaValuedEntityFixture.java b/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JodaValuedEntityFixture.java
index 8ca8b37..42cb18b 100644
--- a/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JodaValuedEntityFixture.java
+++ b/core/tck/tck-fixture/src/main/java/org/apache/isis/core/tck/fixture/scalars/JodaValuedEntityFixture.java
@@ -20,9 +20,9 @@
package org.apache.isis.core.tck.fixture.scalars;
import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
-
import org.apache.isis.applib.fixtures.AbstractFixture;
import org.apache.isis.core.tck.dom.scalars.JodaValuedEntity;
import org.apache.isis.core.tck.dom.scalars.JodaValuedEntityRepository;
@@ -42,7 +42,7 @@ public class JodaValuedEntityFixture extends AbstractFixture {
final JodaValuedEntity jve = jodaValuesEntityRepository.newEntity();
jve.setLocalDateProperty(new LocalDate(2008,3,21));
jve.setLocalDateTimeProperty(new LocalDateTime(2009, 4, 29, 13, 45, 22));
- jve.setDateTimeProperty(new DateTime(2010, 3, 31, 9, 50, 43));
+ jve.setDateTimeProperty(new DateTime(2010, 3, 31, 9, 50, 43, DateTimeZone.UTC));
return jve;
}
[3/3] git commit: ISIS-421: RO TCK tests and fixes
Posted by da...@apache.org.
ISIS-421: RO TCK tests and fixes
mostly the JsonValueEncoder dealing with encoding/decoding to json of strings into primitives, wrappers, bigdecimal, biginteger and also (of course, everyone's favorite) dates.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/09437950
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/09437950
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/09437950
Branch: refs/heads/master
Commit: 09437950199579116d1afedeb95aa4438f58e8d8
Parents: 964e252
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Apr 25 17:44:13 2014 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Apr 25 17:44:13 2014 +0100
----------------------------------------------------------------------
.../applib/JsonRepresentation.java | 321 +++++++++++---
.../ScalarValueRepresentation.java | 3 +-
.../JsonRepresentationTest_getBigDecimal.java | 117 +++++
.../JsonRepresentationTest_getBigInteger.java | 84 ++--
.../JsonRepresentationTest_getDouble.java | 18 +-
.../applib/JsonRepresentationTest_size.java | 11 +-
.../applib/client/RestfulClientTest_follow.java | 132 ------
.../isis/viewer/restfulobjects/applib/map.json | 25 +-
.../domainobjects/DomainObjectReprRenderer.java | 3 +-
.../domainobjects/JsonValueEncoder.java | 346 ++++++++++-----
.../ObjectPropertyReprRenderer.java | 3 +-
.../domainobjects/ScalarValueReprRenderer.java | 5 +-
...onValueEncoderTest_appendValueAndFormat.java | 426 +++++++++++++++++++
.../JsonValueEncoderTest_asAdapter.java | 143 ++++---
.../JsonValueEncoderTest_asObject.java | 105 ++---
.../server/resources/DomainResourceHelper.java | 2 +-
...ontextTest_ensureCompatibleAcceptHeader.java | 33 +-
.../server/ResourceContextTest_getArg.java | 51 ++-
...WithJdkProperties_thenRepresentation_ok.java | 160 +++++++
...dkProperties_thenRepresentation_ok_TODO.java | 80 ----
...ithJodaProperties_thenRepresentation_ok.java | 122 ++++++
...daProperties_thenRepresentation_ok_TODO.java | 124 ------
...imitiveProperties_thenRepresentation_ok.java | 4 +-
...WrapperProperties_thenRepresentation_ok.java | 21 +-
...henArgsValid_thenMultiplePropertyUpdate.java | 37 +-
...Put_whenArgValid_thenPropertyUpdated_ok.java | 26 +-
.../core/tck/dom/scalars/JdkValuedEntity.java | 35 +-
.../fixture/scalars/JdkValuedEntityFixture.java | 42 +-
.../scalars/JodaValuedEntityFixture.java | 4 +-
29 files changed, 1720 insertions(+), 763 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentation.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentation.java b/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentation.java
index 009bf42..ac7fe0e 100644
--- a/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentation.java
+++ b/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentation.java
@@ -24,6 +24,8 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@@ -32,8 +34,9 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.*;
-import org.joda.time.format.DateTimeFormat;
+import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
import org.apache.isis.viewer.restfulobjects.applib.util.JsonNodeUtils;
import org.apache.isis.viewer.restfulobjects.applib.util.PathNode;
import org.apache.isis.viewer.restfulobjects.applib.util.UrlEncodingUtils;
@@ -44,6 +47,9 @@ import org.apache.isis.viewer.restfulobjects.applib.util.UrlEncodingUtils;
*/
public class JsonRepresentation {
+ private static final Pattern FORMAT_BIG_DECIMAL = Pattern.compile("big-decimal\\((\\d+),(\\d+)\\)");
+ private static final Pattern FORMAT_BIG_INTEGER = Pattern.compile("big-integer\\((\\d+)\\)");
+
public interface HasLinkToSelf {
public LinkRepresentation getSelf();
}
@@ -307,7 +313,7 @@ public class JsonRepresentation {
// getDate, asDate
// ///////////////////////////////////////////////////////////////////////
- public final static DateTimeFormatter yyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");
+ public final static DateTimeFormatter yyyyMMdd = ISODateTimeFormat.date().withZoneUTC();
public java.util.Date getDate(final String path) {
return getDate(path, getNode(path));
@@ -333,7 +339,7 @@ public class JsonRepresentation {
// getDateTime, asDateTime
// ///////////////////////////////////////////////////////////////////////
- public final static DateTimeFormatter yyyyMMddTHHmmssZ = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ");
+ public final static DateTimeFormatter yyyyMMddTHHmmssZ = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
public java.util.Date getDateTime(final String path) {
return getDateTime(path, getNode(path));
@@ -359,7 +365,7 @@ public class JsonRepresentation {
// getTime, asTime
// ///////////////////////////////////////////////////////////////////////
- public final static DateTimeFormatter _HHmmss = DateTimeFormat.forPattern("HH:mm:ss");
+ public final static DateTimeFormatter _HHmmss = ISODateTimeFormat.timeNoMillis().withZoneUTC();
public java.util.Date getTime(final String path) {
return getTime(path, getNode(path));
@@ -378,7 +384,8 @@ public class JsonRepresentation {
throw new IllegalArgumentException(formatExMsg(path, "is not a time"));
}
final String textValue = node.getTextValue();
- return new java.util.Date(_HHmmss.parseMillis(textValue));
+ final LocalTime localTime = _HHmmss.parseLocalTime(textValue + "Z");
+ return new java.util.Date(localTime.getMillisOfDay());
}
// ///////////////////////////////////////////////////////////////////////
@@ -423,9 +430,9 @@ public class JsonRepresentation {
}
// ///////////////////////////////////////////////////////////////////////
- // getByte, asByte
+ // isByte, getByte, asByte
// ///////////////////////////////////////////////////////////////////////
-
+
/**
* Use {@link #isIntegralNumber(String)} to test if number (it is not possible to check if a byte, however).
*/
@@ -599,10 +606,13 @@ public class JsonRepresentation {
return null;
}
checkValue(path, node, "a long");
- if (!node.isLong()) {
- throw new IllegalArgumentException(formatExMsg(path, "is not a long"));
+ if(node.isInt()) {
+ return Long.valueOf(node.getIntValue());
+ }
+ if(node.isLong()) {
+ return node.getLongValue();
}
- return node.getLongValue();
+ throw new IllegalArgumentException(formatExMsg(path, "is not a long"));
}
// ///////////////////////////////////////////////////////////////////////
@@ -610,7 +620,7 @@ public class JsonRepresentation {
// ///////////////////////////////////////////////////////////////////////
/**
- * Use {@link #isNumber(String)} to test if number (it is not possible to check if a float, however).
+ * Use {@link #isDecimal(String)} to test if a decimal value
*/
public Float getFloat(final String path) {
final JsonNode node = getNode(path);
@@ -637,18 +647,34 @@ public class JsonRepresentation {
// ///////////////////////////////////////////////////////////////////////
- // isDouble, getDouble, asDouble
+ // isDecimal, isDouble, getDouble, asDouble
// ///////////////////////////////////////////////////////////////////////
+ public boolean isDecimal(final String path) {
+ return isDecimal(getNode(path));
+ }
+
+ public boolean isDecimal() {
+ return isDecimal(asJsonNode());
+ }
+
+ /**
+ * @deprecated - use {@link #isDecimal(String)}
+ */
+ @Deprecated
public boolean isDouble(final String path) {
- return isDouble(getNode(path));
+ return isDecimal(path);
}
+ /**
+ * @deprecated - use {@link #isDecimal()}
+ */
+ @Deprecated
public boolean isDouble() {
- return isDouble(asJsonNode());
+ return isDecimal();
}
- private boolean isDouble(final JsonNode node) {
+ private boolean isDecimal(final JsonNode node) {
return !representsNull(node) && node.isValueNode() && node.isDouble();
}
@@ -691,33 +717,90 @@ public class JsonRepresentation {
}
private boolean isBigInteger(final JsonNode node) {
- return !representsNull(node) && node.isValueNode() && node.isBigInteger();
+ return !representsNull(node) && node.isValueNode() && (node.isBigInteger() || node.isLong() || node.isInt() || node.isTextual() && parseableAsBigInteger(node.getTextValue()));
+ }
+
+ private static boolean parseableAsBigInteger(String str) {
+ try {
+ new BigInteger(str);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
}
/**
* Use {@link #isBigInteger(String)} to check first, if required.
*/
public BigInteger getBigInteger(final String path) {
- final JsonNode node = getNode(path);
- return getBigInteger(path, node);
+ return getBigInteger(path, (String)null);
+ }
+
+ /**
+ * Use {@link #isBigInteger(String)} to check first, if required.
+ */
+ public BigInteger getBigInteger(final String path, final String formatRequested) {
+ final JsonNode node;
+ final String format;
+ if(formatRequested != null) {
+ node = getNode(path);
+ format = formatRequested;
+ } else {
+ final NodeAndFormat nodeAndFormat = getNodeAndFormat(path);
+ node = nodeAndFormat.node;
+ format = nodeAndFormat.format;
+ }
+ return getBigInteger(path, format, node);
}
/**
* Use {@link #isBigInteger()} to check first, if required.
*/
public BigInteger asBigInteger() {
- return getBigInteger(null, asJsonNode());
+ return asBigInteger(null);
+ }
+
+ public BigInteger asBigInteger(final String format) {
+ return getBigInteger(null, format, asJsonNode());
}
- private BigInteger getBigInteger(final String path, final JsonNode node) {
+ private BigInteger getBigInteger(final String path, final String format, final JsonNode node) {
if (representsNull(node)) {
return null;
}
- checkValue(path, node, "a biginteger");
- if (!node.isBigInteger()) {
- throw new IllegalArgumentException(formatExMsg(path, "is not a biginteger"));
+ final String requiredType = "a biginteger";
+ if(!isBigInteger(node)) {
+ throw new IllegalArgumentException(formatExMsg(path, "is not " + requiredType));
+ }
+ checkValue(path, node, requiredType);
+ final BigInteger bigInteger = getBigInteger(path, node);
+ if(format != null) {
+ final Matcher matcher = FORMAT_BIG_INTEGER.matcher(format);
+ if(matcher.matches()) {
+ final int precision = Integer.parseInt(matcher.group(1));
+ final BigInteger maxAllowed = BigInteger.TEN.pow(precision);
+ if(bigInteger.compareTo(maxAllowed) > 0) {
+ throw new IllegalArgumentException(String.format("Value '%s' larger than that allowed by format '%s'", bigInteger, format));
+ }
+ }
+ }
+ return bigInteger;
+ }
+
+ private BigInteger getBigInteger(String path, JsonNode node) {
+ if (node.isBigInteger()) {
+ return node.getBigIntegerValue();
+ }
+ if (node.isTextual()) {
+ return new BigInteger(node.getTextValue());
}
- return node.getBigIntegerValue();
+ if (node.isLong()) {
+ return BigInteger.valueOf(node.getLongValue());
+ }
+ if (node.isInt()) {
+ return BigInteger.valueOf(node.getIntValue());
+ }
+ throw new IllegalArgumentException(formatExMsg(path, "is not a biginteger, is not any other integral number, is not text parseable as a biginteger"));
}
// ///////////////////////////////////////////////////////////////////////
@@ -727,74 +810,95 @@ public class JsonRepresentation {
public boolean isBigDecimal(final String path) {
return isBigDecimal(getNode(path));
}
- public boolean isBigDecimalOrNumeric(final String path) {
- return isBigDecimalOrNumeric(getNode(path));
- }
public boolean isBigDecimal() {
return isBigDecimal(asJsonNode());
}
- public boolean isBigDecimalOrNumeric() {
- return isBigDecimalOrNumeric(asJsonNode());
- }
private boolean isBigDecimal(final JsonNode node) {
- return !representsNull(node) && node.isValueNode() && node.isBigDecimal();
+ return !representsNull(node) && node.isValueNode() && (node.isBigDecimal() || node.isDouble() || node.isLong() || node.isInt() || node.isBigInteger() || node.isTextual() && parseableAsBigDecimal(node.getTextValue()));
}
- private boolean isBigDecimalOrNumeric(final JsonNode node) {
- return !representsNull(node) && node.isValueNode() && (node.isBigDecimal() || node.isDouble() || node.isLong() || node.isInt() || node.isBigInteger());
+
+ private static boolean parseableAsBigDecimal(String str) {
+ try {
+ new BigDecimal(str);
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
}
/**
* Use {@link #isBigDecimal(String)} to check first, if required.
*/
public BigDecimal getBigDecimal(final String path) {
- final JsonNode node = getNode(path);
- return getBigDecimal(path, node);
+ return getBigDecimal(path, (String)null);
}
+
/**
* Use {@link #isBigDecimal(String)} to check first, if required.
*/
- public BigDecimal getBigDecimalFromNumeric(final String path) {
- final JsonNode node = getNode(path);
- return getBigDecimalFromNumeric(path, node);
+ public BigDecimal getBigDecimal(final String path, final String formatRequested) {
+ final JsonNode node;
+ final String format;
+ if(formatRequested != null) {
+ node = getNode(path);
+ format = formatRequested;
+ } else {
+ final NodeAndFormat nodeAndFormat = getNodeAndFormat(path);
+ node = nodeAndFormat.node;
+ format = nodeAndFormat.format;
+ }
+ return getBigDecimal(path, format, node);
}
/**
* Use {@link #isBigDecimal()} to check first, if required.
*/
public BigDecimal asBigDecimal() {
- return getBigDecimal(null, asJsonNode());
+ return asBigDecimal(null);
}
-
+
/**
- * Use {@link #isBigDecimalOrNumeric()} to check first, if required.
+ * Use {@link #isBigDecimal()} to check first, if required.
*/
- public BigDecimal asBigDecimalFromNumeric() {
- return getBigDecimalFromNumeric(null, asJsonNode());
+ public BigDecimal asBigDecimal(String format) {
+ return getBigDecimal(null, format, asJsonNode());
}
- private BigDecimal getBigDecimal(final String path, final JsonNode node) {
+ private BigDecimal getBigDecimal(final String path, final String format, final JsonNode node) {
if (representsNull(node)) {
return null;
}
- checkValue(path, node, "a bigdecimal");
- if (node.isBigDecimal()) {
- return node.getDecimalValue();
+ final String requiredType = "a bigdecimal";
+ if(!isBigDecimal(node)) {
+ throw new IllegalArgumentException(formatExMsg(path, "is not " + requiredType));
+ }
+ checkValue(path, node, requiredType);
+ final BigDecimal bigDecimal = getBigDecimal(path, node);
+ if(format != null) {
+ final Matcher matcher = FORMAT_BIG_DECIMAL.matcher(format);
+ if(matcher.matches()) {
+ final int precision = Integer.parseInt(matcher.group(1));
+ final int scale = Integer.parseInt(matcher.group(2));
+ final BigDecimal maxAllowed = BigDecimal.TEN.pow(precision-scale);
+ if(bigDecimal.compareTo(maxAllowed) > 0) {
+ throw new IllegalArgumentException(String.format("Value '%s' larger than that allowed by format '%s'", bigDecimal, format));
+ }
+ return bigDecimal.setScale(scale, BigDecimal.ROUND_HALF_EVEN);
+ }
}
- throw new IllegalArgumentException(formatExMsg(path, "is not a bigdecimal (or any other numeric)"));
+ return bigDecimal;
}
- private BigDecimal getBigDecimalFromNumeric(final String path, final JsonNode node) {
- if (representsNull(node)) {
- return null;
- }
- checkValue(path, node, "a bigdecimal");
+ private BigDecimal getBigDecimal(String path, JsonNode node) {
if (node.isBigDecimal()) {
return node.getDecimalValue();
}
+ if (node.isTextual()) {
+ return new BigDecimal(node.getTextValue());
+ }
if (node.isLong()) {
- // there will be rounding errors, most likely
return new BigDecimal(node.getLongValue());
}
if (node.isDouble()) {
@@ -802,16 +906,14 @@ public class JsonRepresentation {
return new BigDecimal(node.getDoubleValue());
}
if (node.isBigInteger()) {
- // there will be rounding errors, most likely
return new BigDecimal(node.getBigIntegerValue());
}
if (node.isInt()) {
- // there will be rounding errors, most likely
return new BigDecimal(node.getIntValue());
}
- throw new IllegalArgumentException(formatExMsg(path, "is not a bigdecimal (or any other numeric)"));
+ throw new IllegalArgumentException(formatExMsg(path, "is not a bigdecimal, is not any other numeric, is not text parseable as a bigdecimal"));
}
-
+
// ///////////////////////////////////////////////////////////////////////
// getString, isString, asString
@@ -1242,7 +1344,7 @@ public class JsonRepresentation {
}
final Path path = Path.parse(key);
final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
- node.put(path.getTail(), value != null? new POJONode(value): NullNode.getInstance() );
+ node.put(path.getTail(), value != null ? new POJONode(value) : NullNode.getInstance());
return this;
}
@@ -1285,7 +1387,23 @@ public class JsonRepresentation {
return this;
}
- public JsonRepresentation mapPut(final String key, final long value) {
+ public JsonRepresentation mapPut(final String key, final byte value) {
+ return mapPut(key, (int)value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final Byte value) {
+ return value != null ? mapPut(key, value.byteValue()) : mapPut(key, (Object) value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final short value) {
+ return mapPut(key, (int)value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final Short value) {
+ return value != null ? mapPut(key, value.shortValue()) : mapPut(key, (Object) value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final int value) {
if (!isMap()) {
throw new IllegalStateException("does not represent map");
}
@@ -1295,7 +1413,11 @@ public class JsonRepresentation {
return this;
}
- public JsonRepresentation mapPut(final String key, final int value) {
+ public JsonRepresentation mapPut(final String key, final Integer value) {
+ return value != null ? mapPut(key, value.intValue()) : mapPut(key, (Object) value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final long value) {
if (!isMap()) {
throw new IllegalStateException("does not represent map");
}
@@ -1305,7 +1427,11 @@ public class JsonRepresentation {
return this;
}
- public JsonRepresentation mapPut(final String key, final double value) {
+ public JsonRepresentation mapPut(final String key, final Long value) {
+ return value != null ? mapPut(key, value.longValue()) : mapPut(key, (Object) value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final float value) {
if (!isMap()) {
throw new IllegalStateException("does not represent map");
}
@@ -1315,7 +1441,11 @@ public class JsonRepresentation {
return this;
}
- public JsonRepresentation mapPut(final String key, final float value) {
+ public JsonRepresentation mapPut(final String key, final Float value) {
+ return value != null ? mapPut(key, value.floatValue()) : mapPut(key, (Object) value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final double value) {
if (!isMap()) {
throw new IllegalStateException("does not represent map");
}
@@ -1325,6 +1455,10 @@ public class JsonRepresentation {
return this;
}
+ public JsonRepresentation mapPut(final String key, final Double value) {
+ return value != null ? mapPut(key, value.doubleValue()) : mapPut(key, (Object) value);
+ }
+
public JsonRepresentation mapPut(final String key, final boolean value) {
if (!isMap()) {
throw new IllegalStateException("does not represent map");
@@ -1335,15 +1469,30 @@ public class JsonRepresentation {
return this;
}
+ public JsonRepresentation mapPut(final String key, final Boolean value) {
+ return value != null ? mapPut(key, value.booleanValue()) : mapPut(key, (Object) value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final char value) {
+ return mapPut(key, ""+value);
+ }
+
+ public JsonRepresentation mapPut(final String key, final Character value) {
+ return value != null ? mapPut(key, value.charValue()) : mapPut(key, (Object) value);
+ }
+
public JsonRepresentation mapPut(final String key, final BigInteger value) {
if (!isMap()) {
throw new IllegalStateException("does not represent map");
}
final Path path = Path.parse(key);
final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
- node.put(path.getTail(), value != null? new BigIntegerNode(value): NullNode.getInstance() );
+ if (value != null) {
+ node.put(path.getTail(), value.toString());
+ } else {
+ node.put(path.getTail(), NullNode.getInstance());
+ }
return this;
-
}
public JsonRepresentation mapPut(Iterable<Entry<String, JsonRepresentation>> entries) {
@@ -1364,7 +1513,11 @@ public class JsonRepresentation {
}
final Path path = Path.parse(key);
final ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
- node.put(path.getTail(), value != null? new DecimalNode(value): NullNode.getInstance() );
+ if (value != null) {
+ node.put(path.getTail(), value.toString());
+ } else {
+ node.put(path.getTail(), NullNode.getInstance());
+ }
return this;
}
@@ -1462,30 +1615,58 @@ public class JsonRepresentation {
}
private JsonNode getNode(final String path) {
+ return getNodeAndFormat(path).node;
+ }
+
+ private static class NodeAndFormat {
+ JsonNode node;
+ String format;
+ NodeAndFormat(JsonNode jsonNode, String format) {
+ node = jsonNode;
+ this.format = format;
+ }
+ }
+
+ /**
+ * Walks the path to the specified node, and also returns the value of 'format' in the parent node if present.
+ */
+ private NodeAndFormat getNodeAndFormat(final String path) {
JsonNode jsonNode = this.jsonNode;
final List<String> keys = PathNode.split(path);
+ String format = null;
for (final String key : keys) {
final PathNode pathNode = PathNode.parse(key);
if (!pathNode.getKey().isEmpty()) {
+ // grab format (if present) before moving down the path
+ format = getFormatValueIfAnyFrom(jsonNode);
jsonNode = jsonNode.path(pathNode.getKey());
} else {
// pathNode is criteria only; don't change jsonNode
}
if (jsonNode.isNull()) {
- return jsonNode;
+ return new NodeAndFormat(jsonNode, format);
}
if (!pathNode.hasCriteria()) {
continue;
}
if (!jsonNode.isArray()) {
- return NullNode.getInstance();
+ return new NodeAndFormat(NullNode.getInstance(), format);
}
+ // grab format (if present) before moving down the path
+ format = getFormatValueIfAnyFrom(jsonNode);
jsonNode = matching(jsonNode, pathNode);
if (jsonNode.isNull()) {
- return jsonNode;
+ return new NodeAndFormat(jsonNode, format);
}
}
- return jsonNode;
+ return new NodeAndFormat(jsonNode, format);
+ }
+
+ private String getFormatValueIfAnyFrom(JsonNode jsonNode) {
+ String format;
+ final JsonNode formatNode = jsonNode.get("format");
+ format = formatNode != null && formatNode.isTextual()? formatNode.getTextValue(): null;
+ return format;
}
private JsonNode matching(final JsonNode jsonNode, final PathNode pathNode) {
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/domainobjects/ScalarValueRepresentation.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/domainobjects/ScalarValueRepresentation.java b/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/domainobjects/ScalarValueRepresentation.java
index fec5c0b..6f102a8 100644
--- a/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/domainobjects/ScalarValueRepresentation.java
+++ b/component/viewer/restfulobjects/applib/src/main/java/org/apache/isis/viewer/restfulobjects/applib/domainobjects/ScalarValueRepresentation.java
@@ -18,8 +18,8 @@
*/
package org.apache.isis.viewer.restfulobjects.applib.domainobjects;
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
import org.codehaus.jackson.JsonNode;
+import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
public class ScalarValueRepresentation extends DomainRepresentation {
@@ -31,5 +31,4 @@ public class ScalarValueRepresentation extends DomainRepresentation {
return getRepresentation("value");
}
-
}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigDecimal.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigDecimal.java b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigDecimal.java
new file mode 100644
index 0000000..bcbe5bf
--- /dev/null
+++ b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigDecimal.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.viewer.restfulobjects.applib;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.apache.isis.viewer.restfulobjects.applib.JsonFixture.readJson;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class JsonRepresentationTest_getBigDecimal {
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private JsonRepresentation jsonRepresentation;
+
+ @Before
+ public void setUp() throws Exception {
+ jsonRepresentation = new JsonRepresentation(readJson("map.json"));
+ }
+
+ @Test
+ public void happyCase() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigDecimal("aBigDecimal"), is(new BigDecimal("12345678901234567890.1234")));
+ }
+
+ @Test
+ public void happyCaseForFormatJustFits() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigDecimal("aBigDecimal", "big-decimal(24,4)"), is(new BigDecimal("12345678901234567890.1234")));
+ }
+
+ @Test
+ public void invalidFormat() throws JsonParseException, JsonMappingException, IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Value '12345678901234567890.1234' larger than that allowed by format 'big-decimal(22,3)'");
+
+ assertThat(jsonRepresentation.getBigDecimal("aBigDecimal", "big-decimal(22,3)"), is(new BigDecimal("12345678901234567890")));
+ }
+
+ @Test
+ public void validFormattedFromPath() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigDecimal("yetAnotherSubMap.aFormattedBigDecimal.value"), is(new BigDecimal("123.45")));
+ }
+
+ @Test
+ public void invalidFormattedFromPath() throws JsonParseException, JsonMappingException, IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Value '123.45' larger than that allowed by format 'big-decimal(4,2)'");
+
+ jsonRepresentation.getBigDecimal("yetAnotherSubMap.anInvalidFormattedBigDecimal.value");
+ }
+
+ @Test
+ public void invalidFormattedFromPathButOverridden() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigDecimal("yetAnotherSubMap.anInvalidFormattedBigDecimal.value", "big-decimal(5,2)"), is(new BigDecimal("123.45")));
+ }
+
+ @Test
+ public void forNonExistent() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigDecimal("doesNotExist"), is(nullValue()));
+ }
+
+ @Test
+ public void forNonParseableString() throws JsonParseException, JsonMappingException, IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'aString' is not a bigdecimal");
+
+ jsonRepresentation.getBigDecimal("aString");
+ }
+
+ @Test
+ public void forMap() throws JsonParseException, JsonMappingException, IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'aSubMap' is not a bigdecimal");
+
+ jsonRepresentation.getBigDecimal("aSubMap");
+ }
+
+ @Test
+ public void forList() throws JsonParseException, JsonMappingException, IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'aSubList' is not a bigdecimal");
+
+ jsonRepresentation.getBigDecimal("aSubList");
+ }
+
+ @Test
+ public void forMultipartKey() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigDecimal("aSubMap.aBigDecimal"), is(new BigDecimal("12345678901234567890.1234")));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigInteger.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigInteger.java b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigInteger.java
index e7af049..def1cfb 100644
--- a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigInteger.java
+++ b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getBigInteger.java
@@ -18,22 +18,25 @@
*/
package org.apache.isis.viewer.restfulobjects.applib;
-import static org.apache.isis.viewer.restfulobjects.applib.JsonFixture.readJson;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
import java.io.IOException;
import java.math.BigInteger;
-
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.apache.isis.viewer.restfulobjects.applib.JsonFixture.readJson;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
public class JsonRepresentationTest_getBigInteger {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
private JsonRepresentation jsonRepresentation;
@Before
@@ -43,7 +46,38 @@ public class JsonRepresentationTest_getBigInteger {
@Test
public void happyCase() throws JsonParseException, JsonMappingException, IOException {
- assertThat(jsonRepresentation.getBigInteger("aBigInteger"), is(new BigInteger("12345678901234534132452342342789678234234")));
+ assertThat(jsonRepresentation.getBigInteger("aBigInteger"), is(new BigInteger("12345678901234567890")));
+ }
+
+ @Test
+ public void happyCaseForFormatJustFits() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigInteger("aBigInteger", "big-integer(20)"), is(new BigInteger("12345678901234567890")));
+ }
+
+ @Test
+ public void invalidFormat() throws JsonParseException, JsonMappingException, IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Value '12345678901234567890' larger than that allowed by format 'big-integer(19)'");
+
+ assertThat(jsonRepresentation.getBigInteger("aBigInteger", "big-integer(19)"), is(new BigInteger("12345678901234567890")));
+ }
+
+ @Test
+ public void validFormattedFromPath() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigInteger("yetAnotherSubMap.aFormattedBigInteger.value"), is(new BigInteger("123")));
+ }
+
+ @Test
+ public void invalidFormattedFromPath() throws JsonParseException, JsonMappingException, IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Value '123' larger than that allowed by format 'big-integer(2)'");
+
+ jsonRepresentation.getBigInteger("yetAnotherSubMap.anInvalidFormattedBigInteger.value");
+ }
+
+ @Test
+ public void invalidFormattedFromPathButOverridden() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.getBigInteger("yetAnotherSubMap.anInvalidFormattedBigInteger.value", "big-integer(3)"), is(new BigInteger("123")));
}
@Test
@@ -52,38 +86,32 @@ public class JsonRepresentationTest_getBigInteger {
}
@Test
- public void forValueButNot() throws JsonParseException, JsonMappingException, IOException {
- try {
- jsonRepresentation.getBigInteger("aString");
- fail();
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aString' is not a biginteger"));
- }
+ public void forNonParseableString() throws JsonParseException, JsonMappingException, IOException {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'aString' is not a biginteger");
+
+ jsonRepresentation.getBigInteger("aString");
}
@Test
public void forMap() throws JsonParseException, JsonMappingException, IOException {
- try {
- jsonRepresentation.getBigInteger("aSubMap");
- fail();
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aSubMap' is not a biginteger"));
- }
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'aSubMap' is not a biginteger");
+
+ jsonRepresentation.getBigInteger("aSubMap");
}
@Test
public void forList() throws JsonParseException, JsonMappingException, IOException {
- try {
- jsonRepresentation.getBigInteger("aSubList");
- fail();
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aSubList' is not a biginteger"));
- }
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("'aSubList' is not a biginteger");
+
+ jsonRepresentation.getBigInteger("aSubList");
}
@Test
public void forMultipartKey() throws JsonParseException, JsonMappingException, IOException {
- assertThat(jsonRepresentation.getDouble("aSubMap.aDouble"), is(12345678901234534.4567));
+ assertThat(jsonRepresentation.getBigInteger("aSubMap.aBigInteger"), is(new BigInteger("12345678901234567890")));
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getDouble.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getDouble.java b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getDouble.java
index 4809a6d..43a745e 100644
--- a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getDouble.java
+++ b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_getDouble.java
@@ -18,21 +18,25 @@
*/
package org.apache.isis.viewer.restfulobjects.applib;
-import static org.apache.isis.viewer.restfulobjects.applib.JsonFixture.readJson;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
import java.io.IOException;
-
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.apache.isis.viewer.restfulobjects.applib.JsonFixture.readJson;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
public class JsonRepresentationTest_getDouble {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
private JsonRepresentation jsonRepresentation;
@Before
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_size.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_size.java b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_size.java
index 967c6a9..3bcdb26 100644
--- a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_size.java
+++ b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/JsonRepresentationTest_size.java
@@ -18,16 +18,15 @@
*/
package org.apache.isis.viewer.restfulobjects.applib;
-import static org.apache.isis.viewer.restfulobjects.applib.JsonFixture.readJson;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
import java.io.IOException;
-
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.junit.Test;
+import static org.apache.isis.viewer.restfulobjects.applib.JsonFixture.readJson;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
public class JsonRepresentationTest_size {
private JsonRepresentation jsonRepresentation;
@@ -41,7 +40,7 @@ public class JsonRepresentationTest_size {
@Test
public void size_forNonEmptyMap() throws JsonParseException, JsonMappingException, IOException {
jsonRepresentation = new JsonRepresentation(readJson("map.json"));
- assertThat(jsonRepresentation.size(), is(15));
+ assertThat(jsonRepresentation.size(), is(16));
}
@Test
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/client/RestfulClientTest_follow.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/client/RestfulClientTest_follow.java b/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/client/RestfulClientTest_follow.java
deleted file mode 100644
index 8e0926a..0000000
--- a/component/viewer/restfulobjects/applib/src/test/java/org/apache/isis/viewer/restfulobjects/applib/client/RestfulClientTest_follow.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.viewer.restfulobjects.applib.client;
-
-import java.net.URI;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeMatcher;
-import org.jboss.resteasy.client.ClientExecutor;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.core.BaseClientResponse;
-import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
-import org.jboss.resteasy.specimpl.UriBuilderImpl;
-import org.jmock.Expectations;
-import org.jmock.auto.Mock;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
-import org.apache.isis.viewer.restfulobjects.applib.JsonFixture;
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation;
-
-public class RestfulClientTest_follow {
-
- @Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
-
- private final URI uri = URI.create("http://yadayada:8080");
-
- @Mock
- private ClientExecutor mockExecutor;
-
- @Mock
- private ClientRequest mockClientRequest;
-
- @Mock
- private BaseClientResponse<String> mockClientResponse;
-
- private JsonRepresentation jsonRepresentation;
-
- private RestfulClient client;
-
- @Before
- public void setUp() throws Exception {
- jsonRepresentation = new JsonRepresentation(JsonFixture.readJson("map.json"));
- client = new RestfulClient(uri, mockExecutor);
- }
-
- @Ignore("TODO")
- @Test
- public void follow_get() throws Exception {
- final LinkRepresentation link = jsonRepresentation.getLink("aLink");
-
- final String href = link.getHref();
-
- // when
- context.checking(new Expectations() {
- {
- one(mockExecutor).createRequest(with(any(UriBuilderImpl.class)));
- will(returnValue(mockClientRequest));
-
- one(mockExecutor).execute(mockClientRequest);
- will(returnValue(mockClientResponse));
-
- one(mockClientRequest).accept(MediaType.APPLICATION_JSON_TYPE);
- atLeast(1).of(mockClientRequest).setHttpMethod("GET");
-
- allowing(mockClientRequest).getHttpMethod();
- will(returnValue("GET"));
-
- oneOf(mockClientRequest).execute();
- will(returnValue(mockClientResponse));
-
- oneOf(mockClientResponse).setReturnType(String.class);
- allowing(mockClientResponse);
-
- final MultivaluedMap result = new MultivaluedMapImpl();
- result.put("Content-Type", "application/json");
- allowing(mockClientResponse).getMetadata();
- will(returnValue(result));
- }
-
- });
- final RestfulResponse<JsonRepresentation> response = client.follow(link);
-
- // then
- }
-
- private static Matcher<ClientRequest> requestToHref(final String href) {
- return new TypeSafeMatcher<ClientRequest>() {
-
- @Override
- public void describeTo(final Description description) {
- description.appendText("request to href: " + href);
- }
-
- @Override
- public boolean matchesSafely(final ClientRequest clientRequest) {
- try {
- return clientRequest.getUri().equals(href);
- } catch (final Exception e) {
- return false;
- }
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/applib/src/test/resources/org/apache/isis/viewer/restfulobjects/applib/map.json
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/applib/src/test/resources/org/apache/isis/viewer/restfulobjects/applib/map.json b/component/viewer/restfulobjects/applib/src/test/resources/org/apache/isis/viewer/restfulobjects/applib/map.json
index 2c9a7d1..d4f2d04 100644
--- a/component/viewer/restfulobjects/applib/src/test/resources/org/apache/isis/viewer/restfulobjects/applib/map.json
+++ b/component/viewer/restfulobjects/applib/src/test/resources/org/apache/isis/viewer/restfulobjects/applib/map.json
@@ -3,8 +3,8 @@
"aNull": null,
"aLong": 1234567890123,
"aDouble": 12345678901234534.3242,
- "aBigDecimal": 12345678901234534.3242,
- "aBigInteger": 12345678901234534132452342342789678234234,
+ "aBigDecimal": "12345678901234567890.1234",
+ "aBigInteger": "12345678901234567890",
"aBoolean": true,
"aLink": {
"href": "http://foo/bar",
@@ -20,13 +20,32 @@
"aBoolean": true,
"aLong": 1234567890456,
"aDouble": 12345678901234534.4567,
- "aBigInteger": 12345678901234534132452342342789678234234,
+ "aBigDecimal": "12345678901234567890.1234",
+ "aBigInteger": "12345678901234567890",
"aLink": {
"href": "http://foo/bar",
"method": "GET",
"rel": "someSubRel"
}
},
+ "yetAnotherSubMap": {
+ "aFormattedBigDecimal": {
+ "value":"123.45",
+ "format": "big-decimal(5,2)"
+ },
+ "anInvalidFormattedBigDecimal": {
+ "value":"123.45",
+ "format": "big-decimal(4,2)"
+ },
+ "aFormattedBigInteger": {
+ "value": "123",
+ "format": "big-integer(3)"
+ },
+ "anInvalidFormattedBigInteger": {
+ "value": "123",
+ "format": "big-integer(2)"
+ }
+ },
"aSubList": [
"a", "b", "c"
],
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/DomainObjectReprRenderer.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/DomainObjectReprRenderer.java b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/DomainObjectReprRenderer.java
index 49ef562..3bc4e51 100644
--- a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/DomainObjectReprRenderer.java
+++ b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/DomainObjectReprRenderer.java
@@ -351,7 +351,8 @@ public class DomainObjectReprRenderer extends ReprRendererAbstract<DomainObjectR
public static Object valueOrRef(final RendererContext resourceContext, final ObjectAdapter objectAdapter, final ObjectSpecification objectSpec) {
if(objectAdapter.isValue()) {
- return JsonValueEncoder.asObject(objectAdapter);
+ String format = null; // TODO
+ return JsonValueEncoder.asObject(objectAdapter, format);
}
final TitleFacet titleFacet = objectSpec.getFacet(TitleFacet.class);
final String title = titleFacet.title(objectAdapter, resourceContext.getLocalization());
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoder.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoder.java b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoder.java
index c3446b6..2afd9cd 100644
--- a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoder.java
+++ b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoder.java
@@ -49,6 +49,7 @@ import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
*/
public final class JsonValueEncoder {
+
private JsonValueEncoder(){}
@@ -79,13 +80,14 @@ public final class JsonValueEncoder {
/**
* The value, otherwise <tt>null</tt>.
*/
- public abstract ObjectAdapter asAdapter(JsonRepresentation repr);
+ public abstract ObjectAdapter asAdapter(JsonRepresentation repr, String format);
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- append(repr, objectAdapter, format, xIsisFormat);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ repr.mapPut("value", unwrapAsObjectElseNullNode(objectAdapter));
+ appendFormats(repr, this.format, this.xIsisFormat);
}
- public Object asObject(ObjectAdapter objectAdapter) {
+ public Object asObject(ObjectAdapter objectAdapter, String format) {
return objectAdapter.getObject();
}
}
@@ -102,27 +104,49 @@ public final class JsonValueEncoder {
static {
putConverter(new JsonValueConverter(null, "string", String.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isString()) {
return adapterFor(repr.asString());
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof String) {
+ final String str = (String) obj;
+ repr.mapPut("value", str);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
putConverter(new JsonValueConverter(null, "boolean", boolean.class, Boolean.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isBoolean()) {
return adapterFor(repr.asBoolean());
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof Boolean) {
+ final Boolean b = (Boolean) obj;
+ repr.mapPut("value", b);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
- putConverter(new JsonValueConverter(null, "byte", byte.class, Byte.class){
+ putConverter(new JsonValueConverter("int", "byte", byte.class, Byte.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isNumber()) {
return adapterFor(repr.asNumber().byteValue());
}
@@ -137,11 +161,22 @@ public final class JsonValueEncoder {
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof Byte) {
+ final Byte b = (Byte) obj;
+ repr.mapPut("value", b);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
- putConverter(new JsonValueConverter(null, "short", short.class, Short.class){
+ putConverter(new JsonValueConverter("int", "short", short.class, Short.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isNumber()) {
return adapterFor(repr.asNumber().shortValue());
}
@@ -156,11 +191,22 @@ public final class JsonValueEncoder {
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof Short) {
+ final Short s = (Short) obj;
+ repr.mapPut("value", s);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
putConverter(new JsonValueConverter("int", "int", int.class, Integer.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isInt()) {
return adapterFor(repr.asInt());
}
@@ -175,11 +221,22 @@ public final class JsonValueEncoder {
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof Integer) {
+ final Integer i = (Integer) obj;
+ repr.mapPut("value", i);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
putConverter(new JsonValueConverter("int", "long", long.class, Long.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isLong()) {
return adapterFor(repr.asLong());
}
@@ -194,11 +251,22 @@ public final class JsonValueEncoder {
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof Long) {
+ final Long l = (Long) obj;
+ repr.mapPut("value", l);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
putConverter(new JsonValueConverter("decimal", "float", float.class, Float.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isDouble()) {
return adapterFor((float)(double)repr.asDouble());
}
@@ -216,11 +284,22 @@ public final class JsonValueEncoder {
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof Float) {
+ final Float f = (Float) obj;
+ repr.mapPut("value", f);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
putConverter(new JsonValueConverter("decimal", "double", double.class, Double.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isDouble()) {
return adapterFor(repr.asDouble());
}
@@ -241,11 +320,22 @@ public final class JsonValueEncoder {
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof Double) {
+ final Double d = (Double) obj;
+ repr.mapPut("value", d);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
putConverter(new JsonValueConverter(null, "char", char.class, Character.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isString()) {
final String str = repr.asString();
if(str != null && str.length()>0) {
@@ -262,13 +352,27 @@ public final class JsonValueEncoder {
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof Character) {
+ final Character c = (Character) obj;
+ repr.mapPut("value", c);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, this.format, xIsisFormat);
+ }
});
- putConverter(new JsonValueConverter("int", "biginteger", BigInteger.class){
+ putConverter(new JsonValueConverter("big-integer", "javamathbiginteger", BigInteger.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
+ if (repr.isString()) {
+ return adapterFor(new BigInteger(repr.asString()));
+ }
if (repr.isBigInteger()) {
- return adapterFor(repr.asBigInteger());
+ return adapterFor(repr.asBigInteger(format));
}
if (repr.isLong()) {
return adapterFor(BigInteger.valueOf(repr.asLong()));
@@ -281,14 +385,27 @@ public final class JsonValueEncoder {
}
return null;
}
+ @Override
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof BigInteger) {
+ final BigInteger bi = (BigInteger) obj;
+ repr.mapPut("value", bi);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, format != null? format: this.format, xIsisFormat);
+ }
});
- putConverter(new JsonValueConverter("decimal", "bigdecimal", BigDecimal.class){
+ putConverter(new JsonValueConverter("big-decimal", "javamathbigdecimal", BigDecimal.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
- // TODO: if inferring a BigDecimal, need to get the scale from somewhere...
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
+ if (repr.isString()) {
+ return adapterFor(new BigDecimal(repr.asString()));
+ }
if (repr.isBigDecimal()) {
- return adapterFor(repr.asBigDecimal());
+ return adapterFor(repr.asBigDecimal(format));
}
if (repr.isBigInteger()) {
return adapterFor(new BigDecimal(repr.asBigInteger()));
@@ -305,21 +422,30 @@ public final class JsonValueEncoder {
return null;
}
@Override
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- super.appendValueAndFormat(objectAdapter, repr);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
+ if(obj instanceof BigDecimal) {
+ final BigDecimal bd = (BigDecimal) obj;
+ repr.mapPut("value", bd);
+ } else {
+ repr.mapPut("value", obj);
+ }
+ appendFormats(repr, format != null? format: this.format, xIsisFormat);
}
});
putConverter(new JsonValueConverter("date", "jodalocaldate", LocalDate.class){
+ // these formatters do NOT use withZoneUTC()
final List<DateTimeFormatter> formatters = Arrays.asList(
- JsonRepresentation.yyyyMMdd,
+ ISODateTimeFormat.date(),
+ ISODateTimeFormat.basicDate(),
DateTimeFormat.forPattern("yyyyMMdd"),
- ISODateTimeFormat.basicDate()
+ JsonRepresentation.yyyyMMdd
);
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isString()) {
final String dateStr = repr.asString();
for (DateTimeFormatter formatter : formatters) {
@@ -335,29 +461,31 @@ public final class JsonValueEncoder {
}
@Override
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- final Object obj = unwrap(objectAdapter);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
if(obj instanceof LocalDate) {
final LocalDate date = (LocalDate) obj;
final String dateStr = formatters.get(0).print(date.toDateTimeAtStartOfDay());
- append(repr, dateStr, format, xIsisFormat);
+ repr.mapPut("value", dateStr);
} else {
- append(repr, obj, format, xIsisFormat);
+ repr.mapPut("value", obj);
}
+ appendFormats(repr, this.format, xIsisFormat);
}
});
putConverter(new JsonValueConverter("date-time", "jodalocaldatetime", LocalDateTime.class){
-
+
final List<DateTimeFormatter> formatters = Arrays.asList(
- JsonRepresentation.yyyyMMddTHHmmssZ,
- DateTimeFormat.forPattern("yyyyMMdd'T'HHmmssZ"),
- ISODateTimeFormat.basicDateTimeNoMillis(),
- ISODateTimeFormat.basicDateTime()
+ ISODateTimeFormat.dateTimeNoMillis().withZoneUTC(),
+ ISODateTimeFormat.dateTime().withZoneUTC(),
+ ISODateTimeFormat.basicDateTimeNoMillis().withZoneUTC(),
+ ISODateTimeFormat.basicDateTime().withZoneUTC(),
+ JsonRepresentation.yyyyMMddTHHmmssZ.withZoneUTC()
);
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isString()) {
final String dateStr = repr.asString();
for (DateTimeFormatter formatter : formatters) {
@@ -373,29 +501,31 @@ public final class JsonValueEncoder {
}
@Override
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- final Object obj = unwrap(objectAdapter);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
if(obj instanceof LocalDateTime) {
final LocalDateTime date = (LocalDateTime) obj;
final String dateStr = formatters.get(0).print(date.toDateTime());
- append(repr, dateStr, format, xIsisFormat);
+ repr.mapPut("value", dateStr);
} else {
- append(repr, obj, format, xIsisFormat);
+ repr.mapPut("value", obj);
}
+ appendFormats(repr, this.format, xIsisFormat);
}
});
putConverter(new JsonValueConverter("date-time", "jodadatetime", DateTime.class){
final List<DateTimeFormatter> formatters = Arrays.asList(
- JsonRepresentation.yyyyMMddTHHmmssZ,
- DateTimeFormat.forPattern("yyyyMMdd'T'HHmmssZ"),
- ISODateTimeFormat.basicDateTimeNoMillis(),
- ISODateTimeFormat.basicDateTime()
+ ISODateTimeFormat.dateTimeNoMillis().withZoneUTC(),
+ ISODateTimeFormat.dateTime().withZoneUTC(),
+ ISODateTimeFormat.basicDateTimeNoMillis().withZoneUTC(),
+ ISODateTimeFormat.basicDateTime().withZoneUTC(),
+ JsonRepresentation.yyyyMMddTHHmmssZ.withZoneUTC()
);
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isString()) {
final String dateStr = repr.asString();
for (DateTimeFormatter formatter : formatters) {
@@ -411,28 +541,30 @@ public final class JsonValueEncoder {
}
@Override
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- final Object obj = unwrap(objectAdapter);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
if(obj instanceof DateTime) {
final DateTime date = (DateTime) obj;
final String dateStr = formatters.get(0).print(date.toDateTime());
- append(repr, dateStr, format, xIsisFormat);
+ repr.mapPut("value", dateStr);
} else {
- append(repr, obj, format, xIsisFormat);
+ repr.mapPut("value", obj);
}
+ appendFormats(repr, this.format, xIsisFormat);
}
});
- putConverter(new JsonValueConverter("date", "javautildate", java.util.Date.class){
+ putConverter(new JsonValueConverter("date-time", "javautildate", java.util.Date.class){
final List<DateTimeFormatter> formatters = Arrays.asList(
- JsonRepresentation.yyyyMMddTHHmmssZ,
- DateTimeFormat.forPattern("yyyyMMdd'T'HHmmssZ"),
- ISODateTimeFormat.basicDateTimeNoMillis(),
- ISODateTimeFormat.basicDateTime()
+ ISODateTimeFormat.dateTimeNoMillis().withZoneUTC(),
+ ISODateTimeFormat.dateTime().withZoneUTC(),
+ ISODateTimeFormat.basicDateTimeNoMillis().withZoneUTC(),
+ ISODateTimeFormat.basicDateTime().withZoneUTC(),
+ JsonRepresentation.yyyyMMddTHHmmssZ.withZoneUTC()
);
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isString()) {
final String dateStr = repr.asString();
for (DateTimeFormatter formatter : formatters) {
@@ -449,27 +581,29 @@ public final class JsonValueEncoder {
}
@Override
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- final Object obj = unwrap(objectAdapter);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
if(obj instanceof java.util.Date) {
final java.util.Date date = (java.util.Date) obj;
- final String dateStr = formatters.get(0).print(new DateTime(date));
- append(repr, dateStr, format, xIsisFormat);
+ final DateTimeFormatter dateTimeFormatter = formatters.get(0);
+ final String dateStr = dateTimeFormatter.print(new DateTime(date));
+ repr.mapPut("value", dateStr);
} else {
- append(repr, obj, format, xIsisFormat);
+ repr.mapPut("value", obj);
}
+ appendFormats(repr, this.format, xIsisFormat);
}
});
putConverter(new JsonValueConverter("date", "javasqldate", java.sql.Date.class){
final List<DateTimeFormatter> formatters = Arrays.asList(
- JsonRepresentation.yyyyMMdd,
- DateTimeFormat.forPattern("yyyyMMdd"),
- ISODateTimeFormat.basicDate()
- );
+ ISODateTimeFormat.date().withZoneUTC(),
+ ISODateTimeFormat.basicDate().withZoneUTC(),
+ JsonRepresentation.yyyyMMdd.withZoneUTC()
+ );
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isString()) {
final String dateStr = repr.asString();
for (DateTimeFormatter formatter : formatters) {
@@ -486,26 +620,29 @@ public final class JsonValueEncoder {
}
@Override
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- final Object obj = unwrap(objectAdapter);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
if(obj instanceof java.sql.Date) {
final java.sql.Date date = (java.sql.Date) obj;
final String dateStr = formatters.get(0).print(new DateTime(date));
- append(repr, dateStr, format, xIsisFormat);
+ repr.mapPut("value", dateStr);
} else {
- append(repr, obj, format, xIsisFormat);
+ repr.mapPut("value", obj);
}
+ appendFormats(repr, this.format, xIsisFormat);
}
});
- putConverter(new JsonValueConverter("date", "javasqltime", java.sql.Time.class){
+ putConverter(new JsonValueConverter("time", "javasqltime", java.sql.Time.class){
final List<DateTimeFormatter> formatters = Arrays.asList(
- JsonRepresentation._HHmmss,
- DateTimeFormat.forPattern("HHmmss"),
- ISODateTimeFormat.basicTime());
+ ISODateTimeFormat.hourMinuteSecond().withZoneUTC(),
+ ISODateTimeFormat.basicTimeNoMillis().withZoneUTC(),
+ ISODateTimeFormat.basicTime().withZoneUTC(),
+ JsonRepresentation._HHmmss.withZoneUTC()
+ );
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isString()) {
final String dateStr = repr.asString();
for (DateTimeFormatter formatter : formatters) {
@@ -522,22 +659,23 @@ public final class JsonValueEncoder {
}
@Override
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- final Object obj = unwrap(objectAdapter);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
if(obj instanceof java.sql.Time) {
final java.sql.Time date = (java.sql.Time) obj;
final String dateStr = formatters.get(0).print(new DateTime(date));
- append(repr, dateStr, format, xIsisFormat);
+ repr.mapPut("value", dateStr);
} else {
- append(repr, obj, format, xIsisFormat);
+ repr.mapPut("value", obj);
}
+ appendFormats(repr, this.format, xIsisFormat);
}
});
putConverter(new JsonValueConverter("utc-millisec", "javasqltimestamp", java.sql.Timestamp.class){
@Override
- public ObjectAdapter asAdapter(JsonRepresentation repr) {
+ public ObjectAdapter asAdapter(JsonRepresentation repr, String format) {
if (repr.isLong()) {
final Long millis = repr.asLong();
final java.sql.Timestamp parsedTimestamp = new java.sql.Timestamp(millis);
@@ -557,25 +695,29 @@ public final class JsonValueEncoder {
}
@Override
- public void appendValueAndFormat(ObjectAdapter objectAdapter, JsonRepresentation repr) {
- final Object obj = unwrap(objectAdapter);
+ public void appendValueAndFormat(ObjectAdapter objectAdapter, String format, JsonRepresentation repr) {
+ final Object obj = unwrapAsObjectElseNullNode(objectAdapter);
if(obj instanceof java.sql.Timestamp) {
final java.sql.Timestamp date = (java.sql.Timestamp) obj;
final long millisStr = date.getTime();
- append(repr, millisStr, format, xIsisFormat);
+ repr.mapPut("value", millisStr);
} else {
- append(repr, obj, format, xIsisFormat);
+ repr.mapPut("value", obj);
}
+ appendFormats(repr, this.format, xIsisFormat);
}
});
}
- public static ObjectAdapter asAdapter(final ObjectSpecification objectSpec, final JsonRepresentation argValueRepr) {
+ public static ObjectAdapter asAdapter(final ObjectSpecification objectSpec, final JsonRepresentation argValueRepr, final String format) {
if(argValueRepr == null) {
return null;
}
+ if (objectSpec == null) {
+ throw new IllegalArgumentException("ObjectSpecification is required");
+ }
if (!argValueRepr.isValue()) {
throw new IllegalArgumentException("Representation must be of a value");
}
@@ -597,7 +739,7 @@ public final class JsonValueEncoder {
throw new IllegalArgumentException("Unable to parse value");
}
- final ObjectAdapter asAdapter = jvc.asAdapter(argValueRepr);
+ final ObjectAdapter asAdapter = jvc.asAdapter(argValueRepr, format);
if(asAdapter != null) {
return asAdapter;
}
@@ -615,22 +757,23 @@ public final class JsonValueEncoder {
throw new IllegalArgumentException("Could not parse value '" + argValueRepr.asString() + "' as a " + objectSpec.getFullIdentifier());
}
- public static void appendValueAndFormat(ObjectSpecification objectSpec, ObjectAdapter objectAdapter, JsonRepresentation repr) {
+ public static void appendValueAndFormat(ObjectSpecification objectSpec, ObjectAdapter objectAdapter, JsonRepresentation repr, String format) {
final JsonValueConverter jvc = converterBySpec.get(objectSpec.getSpecId());
if(jvc != null) {
- jvc.appendValueAndFormat(objectAdapter, repr);
+ jvc.appendValueAndFormat(objectAdapter, format, repr);
} else {
final EncodableFacet encodableFacet = objectSpec.getFacet(EncodableFacet.class);
if (encodableFacet == null) {
throw new IllegalArgumentException("objectSpec expected to have EncodableFacet");
}
Object value = objectAdapter != null? encodableFacet.toEncodedString(objectAdapter): NullNode.getInstance();
- append(repr, value, "string", "string");
+ repr.mapPut("value", value);
+ appendFormats(repr, "string", "string");
}
}
- public static Object asObject(final ObjectAdapter objectAdapter) {
+ public static Object asObject(final ObjectAdapter objectAdapter, final String format) {
if (objectAdapter == null) {
throw new IllegalArgumentException("objectAdapter cannot be null");
}
@@ -638,7 +781,7 @@ public final class JsonValueEncoder {
final JsonValueConverter jvc = converterBySpec.get(objectSpec.getSpecId());
if(jvc != null) {
- return jvc.asObject(objectAdapter);
+ return jvc.asObject(objectAdapter, format);
}
// else
@@ -649,10 +792,8 @@ public final class JsonValueEncoder {
return encodableFacet.toEncodedString(objectAdapter);
}
-
- private static void append(JsonRepresentation repr, Object value, String format, String xIsisFormat) {
- repr.mapPut("value", value);
+ private static void appendFormats(JsonRepresentation repr, String format, String xIsisFormat) {
if(format != null) {
repr.mapPut("format", format);
}
@@ -661,11 +802,7 @@ public final class JsonValueEncoder {
}
}
- private static void append(JsonRepresentation repr, ObjectAdapter value, String format, String xIsisFormat) {
- append(repr, unwrap(value), format, xIsisFormat);
- }
-
- private static Object unwrap(ObjectAdapter objectAdapter) {
+ private static Object unwrapAsObjectElseNullNode(ObjectAdapter objectAdapter) {
return objectAdapter != null? objectAdapter.getObject(): NullNode.getInstance();
}
@@ -674,9 +811,16 @@ public final class JsonValueEncoder {
private static ObjectAdapter adapterFor(Object value) {
return getAdapterManager().adapterFor(value);
}
-
+
+ private static AdapterManager testAdapterManager;
+
+ // for testing purposes only
+ static void testSetAdapterManager(AdapterManager adapterManager) {
+ JsonValueEncoder.testAdapterManager = adapterManager;
+ }
+
public static AdapterManager getAdapterManager() {
- return IsisContext.getPersistenceSession().getAdapterManager();
+ return testAdapterManager != null? testAdapterManager: IsisContext.getPersistenceSession().getAdapterManager();
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ObjectPropertyReprRenderer.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ObjectPropertyReprRenderer.java b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ObjectPropertyReprRenderer.java
index c131991..37a123b 100644
--- a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ObjectPropertyReprRenderer.java
+++ b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ObjectPropertyReprRenderer.java
@@ -70,7 +70,8 @@ public class ObjectPropertyReprRenderer extends AbstractObjectMemberReprRenderer
final ValueFacet valueFacet = spec.getFacet(ValueFacet.class);
if (valueFacet != null) {
- JsonValueEncoder.appendValueAndFormat(spec, valueAdapter, representation);
+ String format = null; // TODO
+ JsonValueEncoder.appendValueAndFormat(spec, valueAdapter, representation, format);
return;
}
[2/3] ISIS-421: RO TCK tests and fixes
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ScalarValueReprRenderer.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ScalarValueReprRenderer.java b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ScalarValueReprRenderer.java
index 159765c..5aee110 100644
--- a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ScalarValueReprRenderer.java
+++ b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ScalarValueReprRenderer.java
@@ -17,13 +17,11 @@
package org.apache.isis.viewer.restfulobjects.rendering.domainobjects;
import javax.ws.rs.core.MediaType;
-
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
import org.apache.isis.viewer.restfulobjects.applib.Rel;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
import org.apache.isis.viewer.restfulobjects.rendering.LinkFollowSpecs;
import org.apache.isis.viewer.restfulobjects.rendering.RendererContext;
import org.apache.isis.viewer.restfulobjects.rendering.ReprRendererAbstract;
@@ -54,7 +52,8 @@ public class ScalarValueReprRenderer extends ReprRendererAbstract<ScalarValueRep
if (facet == null) {
throw ReprRendererException.create("Not an (encodable) value", objectAdapter.titleString());
}
- final Object value = JsonValueEncoder.asObject(objectAdapter);
+ String format = null; // TODO
+ final Object value = JsonValueEncoder.asObject(objectAdapter, format);
representation.mapPut("value", value);
return this;
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_appendValueAndFormat.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_appendValueAndFormat.java b/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_appendValueAndFormat.java
new file mode 100644
index 0000000..c9073ce
--- /dev/null
+++ b/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_appendValueAndFormat.java
@@ -0,0 +1,426 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.viewer.restfulobjects.rendering.domainobjects;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Date;
+import org.jmock.Expectations;
+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.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+@RunWith(JMock.class)
+public class JsonValueEncoderTest_appendValueAndFormat {
+
+ private final Mockery context = new JUnit4Mockery();
+
+ private JsonRepresentation representation;
+ private ObjectSpecification mockObjectSpec;
+ private EncodableFacet mockEncodableFacet;
+ private ObjectAdapter mockObjectAdapter;
+
+ private AdapterManager mockAdapterManager;
+
+ @Before
+ public void setUp() throws Exception {
+ mockObjectSpec = context.mock(ObjectSpecification.class);
+ mockEncodableFacet = context.mock(EncodableFacet.class);
+ mockObjectAdapter = context.mock(ObjectAdapter.class);
+ mockAdapterManager = context.mock(AdapterManager.class);
+
+ JsonValueEncoder.testSetAdapterManager(mockAdapterManager);
+
+ representation = JsonRepresentation.newMap();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ JsonValueEncoder.testSetAdapterManager(null);
+ }
+
+ @Test
+ public void whenString() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(String.class);
+ allowingObjectAdapterToReturn("aString");
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.getString("value"), is("aString"));
+
+ assertThat(representation.getString("format"), is(nullValue()));
+ assertThat(representation.getString("extensions.x-isis-format"), is("string"));
+ }
+
+ @Test
+ public void whenBooleanWrapper() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Boolean.class);
+ allowingObjectAdapterToReturn(Boolean.TRUE);
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isBoolean("value"), is(true));
+ assertThat(representation.getBoolean("value"), is(Boolean.TRUE));
+
+ assertThat(representation.getString("format"), is(nullValue()));
+ }
+
+ @Test
+ public void whenBooleanPrimitive() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(boolean.class);
+ allowingObjectAdapterToReturn(true);
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isBoolean("value"), is(true));
+ assertThat(representation.getBoolean("value"), is(true));
+
+ assertThat(representation.getString("format"), is(nullValue()));
+ }
+
+ @Test
+ public void whenByteWrapper() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Byte.class);
+ allowingObjectAdapterToReturn(Byte.valueOf((byte)123));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isIntegralNumber("value"), is(true));
+ assertThat(representation.getByte("value"), is(Byte.valueOf((byte)123)));
+
+ assertThat(representation.getString("format"), is("int"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("byte"));
+ }
+
+ @Test
+ public void whenBytePrimitive() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(byte.class);
+ allowingObjectAdapterToReturn((byte)123);
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isIntegralNumber("value"), is(true));
+ assertThat(representation.getByte("value"), is((byte)123));
+
+ assertThat(representation.getString("format"), is("int"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("byte"));
+ }
+
+ @Test
+ public void whenShortWrapper() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Short.class);
+ allowingObjectAdapterToReturn(Short.valueOf((short)12345));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isIntegralNumber("value"), is(true));
+ assertThat(representation.getShort("value"), is(Short.valueOf((short)12345)));
+
+ assertThat(representation.getString("format"), is("int"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("short"));
+ }
+
+ @Test
+ public void whenShortPrimitive() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(short.class);
+ allowingObjectAdapterToReturn((short)12345);
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isIntegralNumber("value"), is(true));
+ assertThat(representation.getShort("value"), is((short)12345));
+
+ assertThat(representation.getString("format"), is("int"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("short"));
+ }
+
+ @Test
+ public void whenIntWrapper() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Integer.class);
+ allowingObjectAdapterToReturn(Integer.valueOf(12345678));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isIntegralNumber("value"), is(true));
+ assertThat(representation.getInt("value"), is(Integer.valueOf(12345678)));
+
+ assertThat(representation.getString("format"), is("int"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("int"));
+ }
+
+ @Test
+ public void whenIntPrimitive() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(int.class);
+ allowingObjectAdapterToReturn(12345678);
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isIntegralNumber("value"), is(true));
+ assertThat(representation.getInt("value"), is(12345678));
+
+ assertThat(representation.getString("format"), is("int"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("int"));
+ }
+
+ @Test
+ public void whenLongWrapper() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Long.class);
+ allowingObjectAdapterToReturn(Long.valueOf(12345678901234L));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isIntegralNumber("value"), is(true));
+ assertThat(representation.getLong("value"), is(Long.valueOf(12345678901234L)));
+
+ assertThat(representation.getString("format"), is("int"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("long"));
+ }
+
+ @Test
+ public void whenLongPrimitive() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(long.class);
+ allowingObjectAdapterToReturn(12345678901234L);
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isIntegralNumber("value"), is(true));
+ assertThat(representation.getLong("value"), is(12345678901234L));
+
+ assertThat(representation.getString("format"), is("int"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("long"));
+ }
+
+ @Test
+ public void whenFloatWrapper() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Float.class);
+ allowingObjectAdapterToReturn(Float.valueOf((float)123.45));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isDecimal("value"), is(true));
+ assertThat(representation.getFloat("value"), is(Float.valueOf((float)123.45)));
+
+ assertThat(representation.getString("format"), is("decimal"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("float"));
+ }
+
+ @Test
+ public void whenFloatPrimitive() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Float.class);
+ allowingObjectAdapterToReturn((float)123.45);
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isDecimal("value"), is(true));
+ assertThat(representation.getFloat("value"), is((float)123.45));
+
+ assertThat(representation.getString("format"), is("decimal"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("float"));
+ }
+
+ @Test
+ public void whenDoubleWrapper() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Double.class);
+ allowingObjectAdapterToReturn(Double.valueOf(12345.6789));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isDecimal("value"), is(true));
+ assertThat(representation.getDouble("value"), is(Double.valueOf(12345.6789)));
+
+ assertThat(representation.getString("format"), is("decimal"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("double"));
+ }
+
+ @Test
+ public void whenDoublePrimitive() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(double.class);
+ allowingObjectAdapterToReturn(12345.6789);
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isDecimal("value"), is(true));
+ assertThat(representation.getDouble("value"), is(12345.6789));
+
+ assertThat(representation.getString("format"), is("decimal"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("double"));
+ }
+
+ @Test
+ public void whenCharWrapper() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(Character.class);
+ allowingObjectAdapterToReturn(Character.valueOf('a'));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.getChar("value"), is(Character.valueOf('a')));
+
+ assertThat(representation.getString("format"), is(nullValue()));
+ assertThat(representation.getString("extensions.x-isis-format"), is("char"));
+ }
+
+ @Test
+ public void whenCharPrimitive() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(char.class);
+ allowingObjectAdapterToReturn('a');
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.getChar("value"), is('a'));
+
+ assertThat(representation.getString("format"), is(nullValue()));
+ assertThat(representation.getString("extensions.x-isis-format"), is("char"));
+ }
+
+ @Test
+ public void whenJavaUtilDate() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(java.util.Date.class);
+ allowingObjectAdapterToReturn(asDateTime("2014-04-25T12:34:45Z"));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.getString("value"), is("2014-04-25T12:34:45Z"));
+
+ assertThat(representation.getString("format"), is("date-time"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("javautildate"));
+ }
+
+ @Test
+ public void whenJavaSqlDate() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(java.sql.Date.class);
+ allowingObjectAdapterToReturn(asSqlDate("2014-04-25"));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.getString("value"), is("2014-04-25"));
+
+ assertThat(representation.getString("format"), is("date"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("javasqldate"));
+ }
+
+ @Test
+ public void whenJodaDateTime() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(org.joda.time.DateTime.class);
+ allowingObjectAdapterToReturn(new org.joda.time.DateTime(asDateTime("2014-04-25T12:34:45Z")));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.getString("value"), is("2014-04-25T12:34:45Z"));
+
+ assertThat(representation.getString("format"), is("date-time"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("jodadatetime"));
+ }
+
+ @Test
+ public void whenJodaLocalDateTime() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(org.joda.time.LocalDateTime.class);
+ allowingObjectAdapterToReturn(new org.joda.time.LocalDateTime(asDateTime("2014-04-25T12:34:45Z")));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.getString("value"), is("2014-04-25T12:34:45Z"));
+
+ assertThat(representation.getString("format"), is("date-time"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("jodalocaldatetime"));
+ }
+
+ @Test
+ public void whenJodaLocalDate() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(org.joda.time.LocalDate.class);
+ allowingObjectAdapterToReturn(new org.joda.time.LocalDate(2014,4,25));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.getString("value"), is("2014-04-25"));
+
+ assertThat(representation.getString("format"), is("date"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("jodalocaldate"));
+ }
+
+ @Test
+ public void whenJavaSqlTimestamp() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(java.sql.Timestamp.class);
+ final long time = asDateTime("2014-04-25T12:34:45Z").getTime();
+ allowingObjectAdapterToReturn(new Timestamp(time));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, null);
+ assertThat(representation.isLong("value"), is(true));
+ assertThat(representation.getLong("value"), is(time));
+
+ assertThat(representation.getString("format"), is("utc-millisec"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("javasqltimestamp"));
+ }
+
+ @Test
+ public void whenBigInteger() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(BigInteger.class);
+ allowingObjectAdapterToReturn(new BigInteger("12345678901234567890"));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, "big-integer(22)");
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.isBigInteger("value"), is(true));
+ assertThat(representation.getBigInteger("value"), is(new BigInteger("12345678901234567890")));
+
+ assertThat(representation.getString("format"), is("big-integer(22)"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("javamathbiginteger"));
+ }
+
+ @Test
+ public void whenBigDecimal() throws Exception {
+ allowingObjectSpecToReturnSpecIdFor(BigDecimal.class);
+ allowingObjectAdapterToReturn(new BigDecimal("12345678901234567890.1234"));
+
+ JsonValueEncoder.appendValueAndFormat(mockObjectSpec, mockObjectAdapter, representation, "big-decimal(27,4)");
+ assertThat(representation.isString("value"), is(true));
+ assertThat(representation.isBigDecimal("value"), is(true));
+ assertThat(representation.getBigDecimal("value"), is(new BigDecimal("12345678901234567890.1234")));
+
+ assertThat(representation.getString("format"), is("big-decimal(27,4)"));
+ assertThat(representation.getString("extensions.x-isis-format"), is("javamathbigdecimal"));
+ }
+
+
+ private void allowingObjectSpecToReturnSpecIdFor(final Class<?> cls) {
+ context.checking(new Expectations() {
+ {
+ oneOf(mockObjectSpec).getSpecId();
+ will(returnValue(new ObjectSpecId(cls.getName())));
+ }
+ });
+ }
+
+ private void allowingObjectAdapterToReturn(final Object pojo) {
+ context.checking(new Expectations() {
+ {
+ oneOf(mockObjectAdapter).getObject();
+ will(returnValue(pojo));
+ }
+ });
+ }
+
+ private static java.sql.Date asSqlDate(final String text) {
+ return new java.sql.Date(JsonRepresentation.yyyyMMdd.parseDateTime(text).getMillis());
+ }
+
+ private static Date asDateTime(final String text) {
+ return new java.util.Date(JsonRepresentation.yyyyMMddTHHmmssZ.parseDateTime(text).getMillis());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java b/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
index 62a4847..f524e5a 100644
--- a/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
+++ b/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asAdapter.java
@@ -26,10 +26,12 @@ import org.jmock.Expectations;
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.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
import org.apache.isis.core.metamodel.facetapi.Facet;
import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
@@ -45,49 +47,58 @@ public class JsonValueEncoderTest_asAdapter {
private final Mockery context = new JUnit4Mockery();
- private JsonValueEncoder jsonValueEncoder;
private JsonRepresentation representation;
- private ObjectSpecification objectSpec;
+ private ObjectSpecification mockObjectSpec;
+ private EncodableFacet mockEncodableFacet;
+ private ObjectAdapter mockObjectAdapter;
- private EncodableFacet encodableFacet;
- private ObjectAdapter objectAdapter;
+ private AdapterManager mockAdapterManager;
@Before
public void setUp() throws Exception {
- objectSpec = context.mock(ObjectSpecification.class);
- encodableFacet = context.mock(EncodableFacet.class);
- objectAdapter = context.mock(ObjectAdapter.class);
+ mockObjectSpec = context.mock(ObjectSpecification.class);
+ mockEncodableFacet = context.mock(EncodableFacet.class);
+ mockObjectAdapter = context.mock(ObjectAdapter.class);
+ mockAdapterManager = context.mock(AdapterManager.class);
+
+ JsonValueEncoder.testSetAdapterManager(mockAdapterManager);
representation = new JsonRepresentation(TextNode.valueOf("aString"));
}
+ @After
+ public void tearDown() throws Exception {
+ JsonValueEncoder.testSetAdapterManager(null);
+ }
+
+
@Test(expected = IllegalArgumentException.class)
public void whenSpecIsNull() throws Exception {
- JsonValueEncoder.asAdapter(null, representation);
+ JsonValueEncoder.asAdapter(null, representation, null);
}
@Test
public void whenReprIsNull() throws Exception {
- assertThat(JsonValueEncoder.asAdapter(objectSpec, null), is(Matchers.nullValue()));
+ assertThat(JsonValueEncoder.asAdapter(mockObjectSpec, null, null), is(Matchers.nullValue()));
}
@Test(expected = IllegalArgumentException.class)
public void whenReprIsAnArray() throws Exception {
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- jsonValueEncoder.asAdapter(objectSpec, JsonRepresentation.newArray());
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
+ JsonValueEncoder.asAdapter(mockObjectSpec, JsonRepresentation.newArray(), null);
}
@Test(expected = IllegalArgumentException.class)
public void whenReprIsAMap() throws Exception {
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- assertNull(jsonValueEncoder.asAdapter(objectSpec, JsonRepresentation.newMap()));
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
+ assertNull(JsonValueEncoder.asAdapter(mockObjectSpec, JsonRepresentation.newMap(), null));
}
@Test(expected = IllegalArgumentException.class)
public void whenSpecDoesNotHaveAnEncodableFacet() throws Exception {
allowingObjectSpecHas(EncodableFacet.class, null);
- assertNull(jsonValueEncoder.asAdapter(objectSpec, representation));
+ assertNull(JsonValueEncoder.asAdapter(mockObjectSpec, representation, null));
}
@Test
@@ -102,39 +113,39 @@ public class JsonValueEncoderTest_asAdapter {
private void whenReprIsBoolean(final Class<?> correspondingClass) {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(correspondingClass);
final boolean value = true;
representation = new JsonRepresentation(BooleanNode.valueOf(value));
context.checking(new Expectations() {
{
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
+ oneOf(mockAdapterManager).adapterFor(value);
+ will(returnValue(mockObjectAdapter));
}
});
// when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
+ final ObjectAdapter adapter = JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
// then
- assertSame(objectAdapter, adapter);
+ assertSame(mockObjectAdapter, adapter);
}
@Test(expected = IllegalArgumentException.class)
public void whenObjectSpecIsBooleanButReprIsNot() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(boolean.class);
context.checking(new Expectations() {
{
- one(encodableFacet).fromEncodedString("aString");
+ one(mockEncodableFacet).fromEncodedString("aString");
will(throwException(new TextEntryParseException("'aString' cannot be parsed as a boolean value")));
}
});
// when
- jsonValueEncoder.asAdapter(objectSpec, representation);
+ JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
}
@Test
@@ -149,34 +160,34 @@ public class JsonValueEncoderTest_asAdapter {
private void whenReprIsInteger(final Class<?> correspondingClass) {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(correspondingClass);
final int value = 123;
representation = new JsonRepresentation(IntNode.valueOf(value));
context.checking(new Expectations() {
{
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
+ oneOf(mockAdapterManager).adapterFor(value);
+ will(returnValue(mockObjectAdapter));
}
});
// when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
+ final ObjectAdapter adapter = JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
// then
- assertSame(objectAdapter, adapter);
+ assertSame(mockObjectAdapter, adapter);
}
@Test(expected = IllegalArgumentException.class)
public void whenObjectSpecIsIntegerButReprIsNot() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(int.class);
representation = JsonRepresentation.newMap("foo", "bar");
// when
- jsonValueEncoder.asAdapter(objectSpec, representation);
+ JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
}
@Test
@@ -191,39 +202,39 @@ public class JsonValueEncoderTest_asAdapter {
private void whenReprIsLong(final Class<?> correspondingClass) {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(correspondingClass);
final long value = 1234567890L;
representation = new JsonRepresentation(LongNode.valueOf(value));
context.checking(new Expectations() {
{
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
+ oneOf(mockAdapterManager).adapterFor(value);
+ will(returnValue(mockObjectAdapter));
}
});
// when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
+ final ObjectAdapter adapter = JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
// then
- assertSame(objectAdapter, adapter);
+ assertSame(mockObjectAdapter, adapter);
}
@Test(expected = IllegalArgumentException.class)
public void whenObjectSpecIsLongButReprIsNot() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(long.class);
context.checking(new Expectations() {
{
- one(encodableFacet).fromEncodedString("aString");
+ one(mockEncodableFacet).fromEncodedString("aString");
will(throwException(new TextEntryParseException("'aString' cannot be parsed as a long value")));
}
});
// when
- jsonValueEncoder.asAdapter(objectSpec, representation);
+ JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
}
@Test
@@ -238,127 +249,127 @@ public class JsonValueEncoderTest_asAdapter {
private void whenReprIsDouble(final Class<?> correspondingClass) {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(correspondingClass);
final double value = 123.45;
representation = new JsonRepresentation(DoubleNode.valueOf(value));
context.checking(new Expectations() {
{
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
+ oneOf(mockAdapterManager).adapterFor(value);
+ will(returnValue(mockObjectAdapter));
}
});
// when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
+ final ObjectAdapter adapter = JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
// then
- assertSame(objectAdapter, adapter);
+ assertSame(mockObjectAdapter, adapter);
}
@Test(expected = IllegalArgumentException.class)
public void whenObjectSpecIsDoubleButReprIsNot() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(double.class);
representation = JsonRepresentation.newMap("foo", "bar");
// when
- jsonValueEncoder.asAdapter(objectSpec, representation);
+ JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
}
@Test
public void whenReprIsBigInteger() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(BigInteger.class);
final BigInteger value = BigInteger.valueOf(123);
representation = new JsonRepresentation(BigIntegerNode.valueOf(value));
context.checking(new Expectations() {
{
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
+ oneOf(mockAdapterManager).adapterFor(value);
+ will(returnValue(mockObjectAdapter));
}
});
// when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
+ final ObjectAdapter adapter = JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
// then
- assertSame(objectAdapter, adapter);
+ assertSame(mockObjectAdapter, adapter);
}
@Test(expected = IllegalArgumentException.class)
public void whenObjectSpecIsBigIntegerButReprIsNot() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(BigInteger.class);
representation = JsonRepresentation.newMap("foo", "bar");
// when
- jsonValueEncoder.asAdapter(objectSpec, representation);
+ JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
}
@Test
public void whenReprIsBigDecimal() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(BigDecimal.class);
final BigDecimal value = new BigDecimal("123234234.45612312343535");
representation = new JsonRepresentation(DecimalNode.valueOf(value));
context.checking(new Expectations() {
{
- oneOf(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
+ oneOf(mockAdapterManager).adapterFor(value);
+ will(returnValue(mockObjectAdapter));
}
});
// when
- final ObjectAdapter adapter = JsonValueEncoder.asAdapter(objectSpec, representation);
+ final ObjectAdapter adapter = JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
// then
- assertSame(objectAdapter, adapter);
+ assertSame(mockObjectAdapter, adapter);
}
@Test(expected = IllegalArgumentException.class)
public void whenObjectSpecIsBigDecimalButReprIsNot() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(BigDecimal.class);
representation = JsonRepresentation.newMap("foo", "bar");
// when
- jsonValueEncoder.asAdapter(objectSpec, representation);
+ JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
}
@Test
public void whenReprIsString() throws Exception {
// given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
allowingObjectSpecCorrespondingClassAndSpecIdIs(String.class);
representation = new JsonRepresentation(TextNode.valueOf("aString"));
context.checking(new Expectations() {
{
- one(encodableFacet).fromEncodedString("aString");
- will(returnValue(objectAdapter));
+ oneOf(mockAdapterManager).adapterFor("aString");
+ will(returnValue(mockObjectAdapter));
}
});
// when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
+ final ObjectAdapter adapter = JsonValueEncoder.asAdapter(mockObjectSpec, representation, null);
// then
- assertSame(objectAdapter, adapter);
+ assertSame(mockObjectAdapter, adapter);
}
private <T extends Facet> void allowingObjectSpecHas(final Class<T> facetClass, final T encodableFacet) {
context.checking(new Expectations() {
{
- allowing(objectSpec).getFacet(facetClass);
+ allowing(mockObjectSpec).getFacet(facetClass);
will(returnValue(encodableFacet));
}
});
@@ -367,10 +378,10 @@ public class JsonValueEncoderTest_asAdapter {
private void allowingObjectSpecCorrespondingClassAndSpecIdIs(final Class<?> result) {
context.checking(new Expectations() {
{
- allowing(objectSpec).getCorrespondingClass();
+ allowing(mockObjectSpec).getCorrespondingClass();
will(returnValue(result));
- allowing(objectSpec).getSpecId();
+ allowing(mockObjectSpec).getSpecId();
will(returnValue(ObjectSpecId.of(result.getName())));
}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asObject.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asObject.java b/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asObject.java
index d324744..8601bda 100644
--- a/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asObject.java
+++ b/component/viewer/restfulobjects/rendering/src/test/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/JsonValueEncoderTest_asObject.java
@@ -18,65 +18,67 @@
*/
package org.apache.isis.viewer.restfulobjects.rendering.domainobjects;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-
import java.math.BigDecimal;
import java.math.BigInteger;
-
import org.jmock.Expectations;
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.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
import org.apache.isis.core.metamodel.facetapi.Facet;
import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
import org.apache.isis.core.metamodel.spec.ObjectSpecId;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
@RunWith(JMock.class)
public class JsonValueEncoderTest_asObject {
private final Mockery context = new JUnit4Mockery();
- private JsonRepresentation representation;
- private ObjectAdapter objectAdapter;
- private ObjectSpecification objectSpec;
+ private ObjectAdapter mockObjectAdapter;
+ private ObjectSpecification mockObjectSpec;
+ private EncodableFacet mockEncodableFacet;
+ private AdapterManager mockAdapterManager;
- private EncodableFacet encodableFacet;
private Object encoded;
+ private JsonRepresentation representation;
+
@Before
public void setUp() throws Exception {
- objectAdapter = context.mock(ObjectAdapter.class);
- objectSpec = context.mock(ObjectSpecification.class);
+ mockObjectAdapter = context.mock(ObjectAdapter.class);
+ mockObjectSpec = context.mock(ObjectSpecification.class);
context.checking(new Expectations() {
{
- allowing(objectAdapter).getSpecification();
- will(returnValue(objectSpec));
+ allowing(mockObjectAdapter).getSpecification();
+ will(returnValue(mockObjectSpec));
}
});
- encodableFacet = context.mock(EncodableFacet.class);
+ mockEncodableFacet = context.mock(EncodableFacet.class);
+ mockAdapterManager = context.mock(AdapterManager.class);
+ JsonValueEncoder.testSetAdapterManager(mockAdapterManager);
encoded = new Object();
}
- @Test(expected = IllegalArgumentException.class)
- public void whenAdapterIsNull() throws Exception {
- JsonValueEncoder.asObject(null);
+ @After
+ public void tearDown() throws Exception {
+ JsonValueEncoder.testSetAdapterManager(null);
}
@Test(expected = IllegalArgumentException.class)
- public void whenObjectAdapterIsNotSpecialCaseAndSpecIsNotEncodable() throws Exception {
- allowingObjectSpecCorrespondingClassIs(String.class);
- allowingObjectSpecHas(EncodableFacet.class, null);
- JsonValueEncoder.asObject(objectAdapter);
+ public void whenAdapterIsNull() throws Exception {
+ JsonValueEncoder.asObject(null, null);
}
@Test
@@ -91,15 +93,15 @@ public class JsonValueEncoderTest_asObject {
private void whenBoolean(final Class<?> cls) {
allowingObjectSpecCorrespondingClassIs(cls);
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- never(encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
+ never(mockEncodableFacet);
context.checking(new Expectations() {
{
- one(objectAdapter).getObject();
+ one(mockObjectAdapter).getObject();
will(returnValue(true));
}
});
- assertEquals(true, JsonValueEncoder.asObject(objectAdapter));
+ assertEquals(true, JsonValueEncoder.asObject(mockObjectAdapter, null));
}
@Test
@@ -114,15 +116,15 @@ public class JsonValueEncoderTest_asObject {
private void whenInteger(final Class<?> cls) {
allowingObjectSpecCorrespondingClassIs(cls);
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- never(encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
+ never(mockEncodableFacet);
context.checking(new Expectations() {
{
- one(objectAdapter).getObject();
+ one(mockObjectAdapter).getObject();
will(returnValue(123));
}
});
- assertEquals(123, JsonValueEncoder.asObject(objectAdapter));
+ assertEquals(123, JsonValueEncoder.asObject(mockObjectAdapter, null));
}
@Test
@@ -137,15 +139,15 @@ public class JsonValueEncoderTest_asObject {
private void whenLong(final Class<?> cls) {
allowingObjectSpecCorrespondingClassIs(cls);
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- never(encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
+ never(mockEncodableFacet);
context.checking(new Expectations() {
{
- one(objectAdapter).getObject();
+ one(mockObjectAdapter).getObject();
will(returnValue(123456789L));
}
});
- assertEquals(123456789L, JsonValueEncoder.asObject(objectAdapter));
+ assertEquals(123456789L, JsonValueEncoder.asObject(mockObjectAdapter, null));
}
@Test
@@ -160,72 +162,73 @@ public class JsonValueEncoderTest_asObject {
private void whenDouble(final Class<?> cls) {
allowingObjectSpecCorrespondingClassIs(cls);
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- never(encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
+ never(mockEncodableFacet);
context.checking(new Expectations() {
{
- one(objectAdapter).getObject();
+ one(mockObjectAdapter).getObject();
will(returnValue(12345.6789));
}
});
- assertEquals(12345.6789, JsonValueEncoder.asObject(objectAdapter));
+ assertEquals(12345.6789, JsonValueEncoder.asObject(mockObjectAdapter, null));
}
@Test
public void whenBigInteger() throws Exception {
allowingObjectSpecCorrespondingClassIs(BigInteger.class);
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- never(encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
+ never(mockEncodableFacet);
final BigInteger value = new BigInteger("123456789012345");
context.checking(new Expectations() {
{
- one(objectAdapter).getObject();
+ one(mockObjectAdapter).getObject();
will(returnValue(value));
}
});
- assertEquals(value, JsonValueEncoder.asObject(objectAdapter));
+ assertEquals(value, JsonValueEncoder.asObject(mockObjectAdapter, null));
}
@Test
public void whenBigDecimal() throws Exception {
allowingObjectSpecCorrespondingClassIs(BigDecimal.class);
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- never(encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
+ never(mockEncodableFacet);
final BigDecimal value = new BigDecimal("1234567890.1234567890");
context.checking(new Expectations() {
{
- oneOf(objectAdapter).getObject();
+ oneOf(mockObjectAdapter).getObject();
will(returnValue(value));
}
});
- assertEquals(value, JsonValueEncoder.asObject(objectAdapter));
+ assertEquals(value, JsonValueEncoder.asObject(mockObjectAdapter, null));
}
@Test
public void whenString() throws Exception {
allowingObjectSpecCorrespondingClassIs(String.class);
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
+ allowingObjectSpecHas(EncodableFacet.class, mockEncodableFacet);
context.checking(new Expectations() {
{
- one(encodableFacet).toEncodedString(objectAdapter);
+ oneOf(mockObjectAdapter).getObject();
will(returnValue("encodedString"));
}
});
- assertSame("encodedString", JsonValueEncoder.asObject(objectAdapter));
+ final Object actual = JsonValueEncoder.asObject(mockObjectAdapter, null);
+ assertSame("encodedString", actual);
}
private void allowingObjectSpecCorrespondingClassIs(final Class<?> result) {
context.checking(new Expectations() {
{
- allowing(objectSpec).getCorrespondingClass();
+ allowing(mockObjectSpec).getCorrespondingClass();
will(returnValue(result));
}
});
context.checking(new Expectations() {
{
- allowing(objectSpec).getSpecId();
+ allowing(mockObjectSpec).getSpecId();
will(returnValue(new ObjectSpecId(result.getName())));
}
});
@@ -234,7 +237,7 @@ public class JsonValueEncoderTest_asObject {
private <T extends Facet> void allowingObjectSpecHas(final Class<T> facetClass, final T encodableFacet) {
context.checking(new Expectations() {
{
- allowing(objectSpec).getFacet(facetClass);
+ allowing(mockObjectSpec).getFacet(facetClass);
will(returnValue(encodableFacet));
}
});
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainResourceHelper.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainResourceHelper.java b/component/viewer/restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainResourceHelper.java
index eb5a685..c03e90d 100644
--- a/component/viewer/restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainResourceHelper.java
+++ b/component/viewer/restfulobjects/server/src/main/java/org/apache/isis/viewer/restfulobjects/server/resources/DomainResourceHelper.java
@@ -360,7 +360,7 @@ public final class DomainResourceHelper {
// value (encodable)
if (objectSpec.isEncodeable()) {
try {
- return JsonValueEncoder.asAdapter(objectSpec, argValueRepr);
+ return JsonValueEncoder.asAdapter(objectSpec, argValueRepr, null);
}catch(IllegalArgumentException ex) {
argRepr.mapPut("invalidReason", ex.getMessage());
throw ex;
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_ensureCompatibleAcceptHeader.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_ensureCompatibleAcceptHeader.java b/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_ensureCompatibleAcceptHeader.java
index a15381b..2f3a299 100644
--- a/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_ensureCompatibleAcceptHeader.java
+++ b/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_ensureCompatibleAcceptHeader.java
@@ -18,25 +18,24 @@
*/
package org.apache.isis.viewer.restfulobjects.server;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
-
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
-
+import com.google.common.collect.Maps;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Before;
import org.junit.Test;
-
import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
public class ResourceContextTest_ensureCompatibleAcceptHeader {
private HttpHeaders httpHeaders;
@@ -60,6 +59,7 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
public void noop() throws Exception {
final RepresentationType representationType = RepresentationType.HOME_PAGE;
givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(representationType.getMediaType()));
+ givenServletRequestParameterMapEmpty();
instantiateResourceContext(representationType);
}
@@ -68,6 +68,7 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
public void happyCase() throws Exception {
final RepresentationType representationType = RepresentationType.HOME_PAGE;
givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(representationType.getMediaType()));
+ givenServletRequestParameterMapEmpty();
instantiateResourceContext(representationType);
}
@@ -76,6 +77,7 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
public void acceptGenericAndProduceGeneric() throws Exception {
final RepresentationType representationType = RepresentationType.GENERIC;
givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(MediaType.APPLICATION_JSON_TYPE));
+ givenServletRequestParameterMapEmpty();
instantiateResourceContext(representationType);
}
@@ -84,6 +86,7 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
public void acceptGenericAndProduceSpecific() throws Exception {
final RepresentationType representationType = RepresentationType.HOME_PAGE;
givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(MediaType.APPLICATION_JSON_TYPE));
+ givenServletRequestParameterMapEmpty();
instantiateResourceContext(representationType);
}
@@ -92,6 +95,7 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
public void nonMatching() throws Exception {
final RepresentationType representationType = RepresentationType.HOME_PAGE;
givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(MediaType.APPLICATION_ATOM_XML_TYPE));
+ givenServletRequestParameterMapEmpty();
try {
instantiateResourceContext(representationType);
@@ -104,6 +108,7 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
public void nonMatchingProfile() throws Exception {
final RepresentationType representationType = RepresentationType.HOME_PAGE;
givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(RepresentationType.USER.getMediaType()));
+ givenServletRequestParameterMapEmpty();
try {
instantiateResourceContext(representationType);
@@ -116,6 +121,7 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
public void nonMatchingProfile_ignoreGeneric() throws Exception {
final RepresentationType representationType = RepresentationType.HOME_PAGE;
givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(RepresentationType.USER.getMediaType(), MediaType.APPLICATION_JSON_TYPE));
+ givenServletRequestParameterMapEmpty();
try {
instantiateResourceContext(representationType);
@@ -128,6 +134,7 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
public void emptyList_isOK() throws Exception {
final RepresentationType representationType = RepresentationType.HOME_PAGE;
givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList());
+ givenServletRequestParameterMapEmpty();
instantiateResourceContext(representationType);
}
@@ -135,14 +142,24 @@ public class ResourceContextTest_ensureCompatibleAcceptHeader {
private void givenHttpHeadersGetAcceptableMediaTypesReturns(final List<MediaType> mediaTypes) {
context.checking(new Expectations() {
{
- one(httpHeaders).getAcceptableMediaTypes();
+ oneOf(httpHeaders).getAcceptableMediaTypes();
will(returnValue(mediaTypes));
}
});
}
+ private void givenServletRequestParameterMapEmpty() {
+ final HashMap<Object, Object> parameterMap = Maps.newHashMap();
+ context.checking(new Expectations() {
+ {
+ oneOf(httpServletRequest).getParameterMap();
+ will(returnValue(parameterMap));
+ }
+ });
+ }
+
private ResourceContext instantiateResourceContext(final RepresentationType representationType) {
- return new ResourceContext(representationType, httpHeaders, null, null, null, (String)null, httpServletRequest, null, null, null, null, null, null, null, null);
+ return new ResourceContext(representationType, httpHeaders, null, null, null, null, httpServletRequest, null, null, null, null, null, null, null, null);
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_getArg.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_getArg.java b/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_getArg.java
index 0dfd93b..791212e 100644
--- a/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_getArg.java
+++ b/component/viewer/restfulobjects/server/src/test/java/org/apache/isis/viewer/restfulobjects/server/ResourceContextTest_getArg.java
@@ -18,16 +18,13 @@
*/
package org.apache.isis.viewer.restfulobjects.server;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertThat;
-
+import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
-
+import com.google.common.collect.Maps;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
import org.junit.Rule;
import org.junit.Test;
-
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
@@ -35,6 +32,9 @@ import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
import org.apache.isis.viewer.restfulobjects.applib.client.RestfulRequest.RequestParameter;
import org.apache.isis.viewer.restfulobjects.applib.util.UrlEncodingUtils;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
public class ResourceContextTest_getArg {
@Rule
@@ -45,18 +45,13 @@ public class ResourceContextTest_getArg {
@Mock
private ResourceContext resourceContext;
- private String queryString;
@Test
public void whenArgExists() throws Exception {
- queryString = UrlEncodingUtils.urlEncode(JsonRepresentation.newMap("x-ro-page", "123").asJsonNode());
+ final String queryString = UrlEncodingUtils.urlEncode(JsonRepresentation.newMap("x-ro-page", "123").asJsonNode());
+ givenServletRequestQueryString(queryString);
+ givenServletRequestParameterMapEmpty();
- context.checking(new Expectations() {
- {
- one(httpServletRequest).getQueryString();
- will(returnValue(queryString));
- }
- });
resourceContext = new ResourceContext(null, null, null, null, null, (String)null, httpServletRequest, null, null, null, null, null, null, null, null) {
@Override
void init(final RepresentationType representationType) {
@@ -69,14 +64,10 @@ public class ResourceContextTest_getArg {
@Test
public void whenArgDoesNotExist() throws Exception {
- queryString = UrlEncodingUtils.urlEncode(JsonRepresentation.newMap("xxx", "123").asJsonNode());
+ final String queryString = UrlEncodingUtils.urlEncode(JsonRepresentation.newMap("xxx", "123").asJsonNode());
+ givenServletRequestQueryString(queryString);
+ givenServletRequestParameterMapEmpty();
- context.checking(new Expectations() {
- {
- one(httpServletRequest).getQueryString();
- will(returnValue(queryString));
- }
- });
resourceContext = new ResourceContext(null, null, null, null, null, (String)null, httpServletRequest, null, null, null, null, null, null, null, null) {
@Override
void init(final RepresentationType representationType) {
@@ -87,4 +78,24 @@ public class ResourceContextTest_getArg {
assertThat(arg, equalTo(RequestParameter.PAGE.getDefault()));
}
+ private void givenServletRequestQueryString(final String queryString) {
+ context.checking(new Expectations() {
+ {
+ one(httpServletRequest).getQueryString();
+ will(returnValue(queryString));
+ }
+ });
+ }
+
+
+ private void givenServletRequestParameterMapEmpty() {
+ final HashMap<Object, Object> parameterMap = Maps.newHashMap();
+ context.checking(new Expectations() {
+ {
+ oneOf(httpServletRequest).getParameterMap();
+ will(returnValue(parameterMap));
+ }
+ });
+ }
+
}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJdkProperties_thenRepresentation_ok.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJdkProperties_thenRepresentation_ok.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJdkProperties_thenRepresentation_ok.java
new file mode 100644
index 0000000..4ccf999
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJdkProperties_thenRepresentation_ok.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.viewer.restfulobjects.tck.domainobject.oid;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.apache.isis.core.webserver.WebServer;
+import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
+import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation;
+import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient;
+import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse;
+import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectMemberRepresentation;
+import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRepresentation;
+import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ScalarValueRepresentation;
+import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule;
+import org.apache.isis.viewer.restfulobjects.tck.Util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class Get_givenEntityWithJdkProperties_thenRepresentation_ok {
+
+ @Rule
+ public IsisWebServerRule webServerRule = new IsisWebServerRule();
+
+ protected RestfulClient client;
+
+ private DomainObjectRepresentation domainObjectRepr;
+
+ @Before
+ public void setUp() throws Exception {
+ final WebServer webServer = webServerRule.getWebServer();
+ client = new RestfulClient(webServer.getBase());
+ }
+
+ @Test
+ public void thenMembers() throws Exception {
+
+ // when
+ final LinkRepresentation link = Util.serviceActionListInvokeFirstReference(client, "JdkValuedEntities");
+ final RestfulResponse<JsonRepresentation> restResp = client.follow(link);
+ final JsonRepresentation entityRepr = restResp.getEntity();
+ domainObjectRepr = entityRepr.as(DomainObjectRepresentation.class);
+
+ // and then members (types)
+ DomainObjectMemberRepresentation property;
+ ScalarValueRepresentation scalarRepr;
+
+ property = domainObjectRepr.getProperty("bigDecimalProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("big-decimal"));
+ assertThat(property.getXIsisFormat(), is("javamathbigdecimal"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ BigDecimal bigDecimal = scalarRepr.asBigDecimal(property.getFormat());
+ assertThat(bigDecimal, is(new BigDecimal("12345678901234567890.1234567890")));
+
+ property = domainObjectRepr.getProperty("bigDecimalProperty2");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("big-decimal"));
+ assertThat(property.getXIsisFormat(), is("javamathbigdecimal"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ BigDecimal bigDecimal2 = scalarRepr.asBigDecimal(property.getFormat());
+ assertThat(bigDecimal2, is(new BigDecimal("123.45")));
+
+ property = domainObjectRepr.getProperty("bigIntegerProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("big-integer"));
+ assertThat(property.getXIsisFormat(), is("javamathbiginteger"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ BigInteger bigInteger = scalarRepr.asBigInteger(property.getFormat());
+ assertThat(bigInteger, is(new BigInteger("12345678901234567890")));
+
+ property = domainObjectRepr.getProperty("bigIntegerProperty2");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("big-integer"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ BigInteger bigInteger2 = scalarRepr.asBigInteger(property.getFormat());
+ assertThat(bigInteger2, is(new BigInteger("12345")));
+
+ property = domainObjectRepr.getProperty("javaSqlDateProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("date"));
+ assertThat(property.getXIsisFormat(), is("javasqldate"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ assertThat(scalarRepr.asString(), is("2014-04-24"));
+ assertThat(scalarRepr.asDate(), is(asDate("2014-04-24")));
+
+ property = domainObjectRepr.getProperty("javaSqlTimeProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("time"));
+ assertThat(property.getXIsisFormat(), is("javasqltime"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ assertThat(scalarRepr.asString(), is("12:34:45"));
+ assertThat(scalarRepr.asTime(), is(asDateTime("1970-01-01T12:34:45Z")));
+
+ property = domainObjectRepr.getProperty("javaSqlTimestampProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("utc-millisec"));
+ assertThat(property.getXIsisFormat(), is("javasqltimestamp"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isInt() || scalarRepr.isLong(), is(true));
+ Long aLong = scalarRepr.asLong();
+ assertThat(aLong, is(new Long("1234567890")));
+
+ property = domainObjectRepr.getProperty("javaUtilDateProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("date-time"));
+ assertThat(property.getXIsisFormat(), is("javautildate"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ Date utilDate = scalarRepr.asDateTime();
+ assertThat(utilDate, is(asDateTime("2013-05-25T12:34:45Z")));
+ assertThat(scalarRepr.asString(), is("2013-05-25T12:34:45Z"));
+
+ property = domainObjectRepr.getProperty("myEnum");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("string"));
+ assertThat(property.getXIsisFormat(), is("string"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ String myEnumStr = scalarRepr.asString();
+ assertThat(myEnumStr, is("RED"));
+ }
+
+
+ private static Date asDate(final String text) {
+ return new java.util.Date(JsonRepresentation.yyyyMMdd.withZoneUTC().parseDateTime(text).getMillis());
+ }
+
+ private static Date asDateTime(final String text) {
+ return new java.util.Date(JsonRepresentation.yyyyMMddTHHmmssZ.withZoneUTC().parseDateTime(text).getMillis());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJdkProperties_thenRepresentation_ok_TODO.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJdkProperties_thenRepresentation_ok_TODO.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJdkProperties_thenRepresentation_ok_TODO.java
deleted file mode 100644
index f41872f..0000000
--- a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJdkProperties_thenRepresentation_ok_TODO.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.isis.viewer.restfulobjects.tck.domainobject.oid;
-
-import static org.apache.isis.core.commons.matchers.IsisMatchers.matches;
-import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.assertThat;
-import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.isLink;
-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 org.joda.time.LocalDate;
-import org.joda.time.LocalDateTime;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.commons.matchers.IsisMatchers;
-import org.apache.isis.core.webserver.WebServer;
-import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.Rel;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
-import org.apache.isis.viewer.restfulobjects.applib.RestfulHttpMethod;
-import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient;
-import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectMemberRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ScalarValueRepresentation;
-import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule;
-import org.apache.isis.viewer.restfulobjects.tck.Util;
-
-public class Get_givenEntityWithJdkProperties_thenRepresentation_ok_TODO {
-
- @Rule
- public IsisWebServerRule webServerRule = new IsisWebServerRule();
-
- protected RestfulClient client;
-
- private DomainObjectRepresentation domainObjectRepr;
-
- @Before
- public void setUp() throws Exception {
- final WebServer webServer = webServerRule.getWebServer();
- client = new RestfulClient(webServer.getBase());
- }
-
- @Ignore("TODO")
- @Test
- public void thenMembers() throws Exception {
-
- // when
- final LinkRepresentation link = Util.serviceActionListInvokeFirstReference(client, "JdkValuedEntities");
- domainObjectRepr = client.follow(link).getEntity().as(DomainObjectRepresentation.class);
-
- // and then members (types)
- DomainObjectMemberRepresentation property;
- ScalarValueRepresentation scalarRepr;
-
-
- // copy from Get_givenEntityWithPrimitiveProperties_thenRepresentation_ok
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/09437950/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJodaProperties_thenRepresentation_ok.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJodaProperties_thenRepresentation_ok.java b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJodaProperties_thenRepresentation_ok.java
new file mode 100644
index 0000000..e6b55d7
--- /dev/null
+++ b/component/viewer/restfulobjects/tck/src/test/java/org/apache/isis/viewer/restfulobjects/tck/domainobject/oid/Get_givenEntityWithJodaProperties_thenRepresentation_ok.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.viewer.restfulobjects.tck.domainobject.oid;
+
+import java.util.Date;
+import org.joda.time.LocalDateTime;
+import org.joda.time.format.ISODateTimeFormat;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.apache.isis.core.webserver.WebServer;
+import org.apache.isis.viewer.restfulobjects.applib.*;
+import org.apache.isis.viewer.restfulobjects.applib.client.RestfulClient;
+import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectMemberRepresentation;
+import org.apache.isis.viewer.restfulobjects.applib.domainobjects.DomainObjectRepresentation;
+import org.apache.isis.viewer.restfulobjects.applib.domainobjects.ScalarValueRepresentation;
+import org.apache.isis.viewer.restfulobjects.tck.IsisWebServerRule;
+import org.apache.isis.viewer.restfulobjects.tck.Util;
+
+import static org.apache.isis.core.commons.matchers.IsisMatchers.matches;
+import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.assertThat;
+import static org.apache.isis.viewer.restfulobjects.tck.RestfulMatchers.isLink;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class Get_givenEntityWithJodaProperties_thenRepresentation_ok {
+
+ @Rule
+ public IsisWebServerRule webServerRule = new IsisWebServerRule();
+
+ protected RestfulClient client;
+
+ private DomainObjectRepresentation domainObjectRepr;
+
+ @Before
+ public void setUp() throws Exception {
+ final WebServer webServer = webServerRule.getWebServer();
+ client = new RestfulClient(webServer.getBase());
+ }
+
+ @Test
+ public void thenMembers() throws Exception {
+
+ // when
+ final LinkRepresentation link = Util.serviceActionListInvokeFirstReference(client, "JodaValuedEntities");
+ domainObjectRepr = client.follow(link).getEntity().as(DomainObjectRepresentation.class);
+
+ // and then members (types)
+ DomainObjectMemberRepresentation property;
+ ScalarValueRepresentation scalarRepr;
+
+ property = domainObjectRepr.getProperty("dateTimeProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("date-time"));
+ assertThat(property.getXIsisFormat(), is("jodadatetime"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ assertThat(scalarRepr.asDateTime(), is(asDateTime("2010-03-31T09:50:43Z")));
+ assertThat(scalarRepr.asString(), is("2010-03-31T09:50:43Z"));
+
+ property = domainObjectRepr.getProperty("localDateProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("date"));
+ assertThat(property.getXIsisFormat(), is("jodalocaldate"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+ assertThat(scalarRepr.asDate(), is(asDate("2008-03-21")));
+ assertThat(scalarRepr.asString(), is("2008-03-21"));
+
+ property = domainObjectRepr.getProperty("localDateTimeProperty");
+ assertThat(property.getMemberType(), is("property"));
+ assertThat(property.getFormat(), is("date-time"));
+ assertThat(property.getXIsisFormat(), is("jodalocaldatetime"));
+ scalarRepr = property.getRepresentation("value").as(ScalarValueRepresentation.class);
+ assertThat(scalarRepr.isString(), is(true));
+
+ final LocalDateTime expected = new LocalDateTime(2009, 4, 29, 13, 45, 22);
+
+ assertThat(scalarRepr.asDateTime(), is(expected.toDate()));
+ assertThat(scalarRepr.asString(), is(ISODateTimeFormat.dateTimeNoMillis().withZoneUTC().print(expected.toDateTime())));
+
+ // and then member types have links to details (selected ones inspected only)
+ property = domainObjectRepr.getProperty("localDateProperty");
+ assertThat(property.getLinkWithRel(Rel.DETAILS),
+ isLink()
+ .href(matches(".+\\/objects\\/JODA\\/\\d+\\/properties\\/localDateProperty"))
+ .httpMethod(RestfulHttpMethod.GET)
+ .type(RepresentationType.OBJECT_PROPERTY.getMediaType()));
+
+ property = domainObjectRepr.getProperty("localDateTimeProperty");
+ assertThat(property.getLinkWithRel(Rel.DETAILS),
+ isLink()
+ .href(matches(".+\\/objects\\/JODA\\/\\d+\\/properties\\/localDateTimeProperty"))
+ .httpMethod(RestfulHttpMethod.GET)
+ .type(RepresentationType.OBJECT_PROPERTY.getMediaType()));
+ }
+
+ private static Date asDate(final String text) {
+ return new java.util.Date(JsonRepresentation.yyyyMMdd.withZoneUTC().parseDateTime(text).getMillis());
+ }
+
+ private static Date asDateTime(final String text) {
+ return new java.util.Date(JsonRepresentation.yyyyMMddTHHmmssZ.withZoneUTC().parseDateTime(text).getMillis());
+ }
+
+}