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:27 UTC
[2/3] ISIS-421: RO TCK tests and fixes
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());
+ }
+
+}