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 2012/12/05 00:41:12 UTC
[50/52] [partial] ISIS-188: consolidating isis-core
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DoubleValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DoubleValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DoubleValueSemanticsProviderTest.java
new file mode 100644
index 0000000..d8bf210
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DoubleValueSemanticsProviderTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.longs.DoubleWrapperValueSemanticsProvider;
+
+public class DoubleValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private Double doubleObj;
+
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.double");
+ will(returnValue(null));
+ }
+ });
+
+ holder = new FacetHolderImpl();
+ setValue(new DoubleWrapperValueSemanticsProvider(holder, mockConfiguration, mockContext));
+
+ doubleObj = new Double(32.5d);
+ allowMockAdapterToReturn(doubleObj);
+ }
+
+ @Test
+ public void testValue() {
+ assertEquals("32.5", getValue().displayTitleOf(doubleObj, (Localization) null));
+ }
+
+ @Test
+ public void testInvalidParse() throws Exception {
+ try {
+ getValue().parseTextEntry(null, "one", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("35,000,000", getValue().displayTitleOf(Double.valueOf(35000000.0), (Localization) null));
+ }
+
+ @Test
+ public void testParse() throws Exception {
+ final Object newValue = getValue().parseTextEntry(null, "120.56", null);
+ assertEquals(120.56, ((Double) newValue).doubleValue(), 0.0);
+ }
+
+ @Test
+ public void testParse2() throws Exception {
+ final Object newValue = getValue().parseTextEntry(null, "1,20.0", null);
+ assertEquals(120, ((Double) newValue).doubleValue(), 0.0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/FloatValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/FloatValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/FloatValueSemanticsProviderTest.java
new file mode 100644
index 0000000..b0f2745
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/FloatValueSemanticsProviderTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.floats.FloatValueSemanticsProviderAbstract;
+import org.apache.isis.core.progmodel.facets.value.floats.FloatWrapperValueSemanticsProvider;
+
+public class FloatValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private FloatValueSemanticsProviderAbstract value;
+ private Float float1;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.float");
+ will(returnValue(null));
+ }
+ });
+
+ float1 = new Float(32.5f);
+ allowMockAdapterToReturn(float1);
+
+ holder = new FacetHolderImpl();
+ setValue(value = new FloatWrapperValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testInvalidParse() throws Exception {
+ try {
+ value.parseTextEntry(null, "one", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("32.5", value.displayTitleOf(float1, (Localization) null));
+ }
+
+ @Test
+ public void testParse() throws Exception {
+ final Object parsed = value.parseTextEntry(null, "120.50", null);
+ assertEquals(120.5f, ((Float) parsed).floatValue(), 0.0);
+ }
+
+ @Test
+ public void testParseBadlyFormatedEntry() throws Exception {
+ final Object parsed = value.parseTextEntry(null, "1,20.0", null);
+ assertEquals(120.0f, ((Float) parsed).floatValue(), 0.0);
+ }
+
+ @Test
+ public void testEncode() throws Exception {
+ assertEquals("32.5", getEncodeableFacet().toEncodedString(createAdapter(float1)));
+ }
+
+ @Test
+ public void testDecode() throws Exception {
+ final Object restored = value.fromEncodedString("10.25");
+ assertEquals(10.25, ((Float) restored).floatValue(), 0.0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ImageValueSemanticsProviderAbstractTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ImageValueSemanticsProviderAbstractTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ImageValueSemanticsProviderAbstractTest.java
new file mode 100644
index 0000000..19e0f63
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ImageValueSemanticsProviderAbstractTest.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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+
+import java.awt.Image;
+
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.value.image.ImageValueSemanticsProviderAbstract;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+
+public class ImageValueSemanticsProviderAbstractTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
+
+ @Mock
+ private FacetHolder mockFacetHolder;
+
+ private TestImageSemanticsProvider adapter;
+
+ @Before
+ public void setUp() throws Exception {
+ adapter = new TestImageSemanticsProvider(mockFacetHolder);
+ }
+
+ @Test
+ public void testImageData() throws Exception {
+
+ final String data = adapter.toEncodedString(null);
+ final int[][] array = adapter.doRestore(data);
+
+ assertEquals(0xFF000000, array[0][0]);
+ assertEquals(0xFF3F218A, array[0][1]);
+ assertEquals(0xFF123456, array[0][3]);
+ assertEquals(0xFF7FFFFF, array[0][4]);
+ assertEquals(-0x7FFFFF, array[0][5]);
+ assertEquals(-0x700000, array[0][6]);
+ }
+}
+
+class TestImageSemanticsProvider extends ImageValueSemanticsProviderAbstract<int[][]> {
+
+ TestImageSemanticsProvider(final FacetHolder holder) {
+ super(holder, null, null, null);
+ }
+
+ @Override
+ protected int[][] getPixels(final Object object) {
+ final int[][] array = new int[10][10];
+ array[0][1] = 0x3F218A;
+ array[0][3] = 0x123456;
+ array[0][4] = 0x7FFFFF;
+ array[0][5] = -0x7FFFFF;
+ array[0][6] = -0x700000;
+ return array;
+ }
+
+ @Override
+ protected int[][] setPixels(final int[][] pixels) {
+ return pixels;
+ }
+
+ @Override
+ public int getHeight(final ObjectAdapter object) {
+ return 0;
+ }
+
+ @Override
+ public Image getImage(final ObjectAdapter object) {
+ return null;
+ }
+
+ @Override
+ public int getWidth(final ObjectAdapter object) {
+ return 0;
+ }
+
+ public ObjectAdapter setImage(final ObjectAdapter object, final Image image) {
+ return null;
+ }
+
+ @Override
+ public boolean isNoop() {
+ return false;
+ }
+
+ @Override
+ public ObjectAdapter createValue(final Image image) {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/IntValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/IntValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/IntValueSemanticsProviderTest.java
new file mode 100644
index 0000000..c077012
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/IntValueSemanticsProviderTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.integer.IntValueSemanticsProviderAbstract;
+import org.apache.isis.core.progmodel.facets.value.integer.IntWrapperValueSemanticsProvider;
+
+public class IntValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private IntValueSemanticsProviderAbstract value;
+ private Integer integer;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ integer = Integer.valueOf(32);
+ allowMockAdapterToReturn(integer);
+
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.int");
+ will(returnValue(null));
+ }
+ });
+
+ holder = new FacetHolderImpl();
+ setValue(value = new IntWrapperValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testInvalidParse() throws Exception {
+ try {
+ value.parseTextEntry(null, "one", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleString() {
+ assertEquals("32", value.displayTitleOf(integer, (Localization) null));
+ }
+
+ @Test
+ public void testParse() throws Exception {
+ final Object newValue = value.parseTextEntry(null, "120", null);
+ assertEquals(Integer.valueOf(120), newValue);
+ }
+
+ @Test
+ public void testParseOddlyFormedEntry() throws Exception {
+ final Object newValue = value.parseTextEntry(null, "1,20.0", null);
+ assertEquals(Integer.valueOf(120), newValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlDateValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlDateValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlDateValueSemanticsProviderTest.java
new file mode 100644
index 0000000..73132b6
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlDateValueSemanticsProviderTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.sql.Date;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.datesql.JavaSqlDateValueSemanticsProvider;
+
+public class JavaSqlDateValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private JavaSqlDateValueSemanticsProvider adapter;
+ private Date date;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.date");
+ will(returnValue(null));
+ }
+ });
+
+ TestClock.initialize();
+ date = new Date(0);
+ holder = new FacetHolderImpl();
+ setValue(adapter = new JavaSqlDateValueSemanticsProvider(holder, mockConfiguration, mockContext) {
+ @Override
+ protected String defaultFormat() {
+ return "iso";
+ }
+ });
+ }
+
+ @Test
+ public void testInvalidParse() throws Exception {
+ try {
+ adapter.parseTextEntry(null, "date", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("1970-01-01", adapter.displayTitleOf(date, (Localization) null));
+ }
+
+ @Test
+ public void testParse() throws Exception {
+ final Object newValue = adapter.parseTextEntry(null, "1/1/1980", null);
+
+ final Calendar calendar = Calendar.getInstance();
+ calendar.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
+ calendar.set(1980, 0, 1, 0, 0, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+
+ assertEquals(calendar.getTime(), newValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlTimeStampValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlTimeStampValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlTimeStampValueSemanticsProviderTest.java
new file mode 100644
index 0000000..ed9fcf0
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlTimeStampValueSemanticsProviderTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.sql.Timestamp;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.timestampsql.JavaSqlTimeStampValueSemanticsProvider;
+
+public class JavaSqlTimeStampValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private JavaSqlTimeStampValueSemanticsProvider adapter;
+ private Object timestamp;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.timestamp");
+ will(returnValue(null));
+ }
+ });
+
+ TestClock.initialize();
+ timestamp = new Timestamp(0);
+ holder = new FacetHolderImpl();
+ setValue(adapter = new JavaSqlTimeStampValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Override
+ public void testParseEmptyString() {
+ final Object parsed = adapter.parseTextEntry(null, "", null);
+ assertNull(parsed);
+ }
+
+ @Test
+ public void testTitle() {
+ assertEquals("01/01/70 00:00:00 UTC", adapter.titleString(timestamp, null));
+ }
+
+ @Test
+ public void testEncodesTimeStamp() {
+ final String encodedString = adapter.toEncodedString(timestamp);
+ assertEquals("19700101T000000000", encodedString);
+ }
+
+ @Test
+ public void testDecodesTimeStamp() {
+ final String encodedString = "19700101T000000000";
+ final Object restored = adapter.fromEncodedString(encodedString);
+ assertEquals(((Timestamp) timestamp).getTime(), ((Timestamp) restored).getTime());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlTimeValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlTimeValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlTimeValueSemanticsProviderTest.java
new file mode 100644
index 0000000..37494fd
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaSqlTimeValueSemanticsProviderTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.Time;
+import java.util.Calendar;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.timesql.JavaSqlTimeValueSemanticsProvider;
+
+public class JavaSqlTimeValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private Time twoOClock;
+ private JavaSqlTimeValueSemanticsProvider value;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.time");
+ will(returnValue(null));
+ }
+ });
+
+ final Calendar c = Calendar.getInstance();
+ // c.setTimeZone(TestClock.timeZone);
+
+ c.set(Calendar.MILLISECOND, 0);
+
+ c.set(Calendar.YEAR, 0);
+ c.set(Calendar.MONTH, 0);
+ c.set(Calendar.DAY_OF_MONTH, 0);
+
+ c.set(Calendar.HOUR_OF_DAY, 14);
+ c.set(Calendar.MINUTE, 0);
+ c.set(Calendar.SECOND, 0);
+
+ twoOClock = new Time(c.getTimeInMillis());
+
+ holder = new FacetHolderImpl();
+ setValue(value = new JavaSqlTimeValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testNewTime() {
+ final String asEncodedString = value.toEncodedString(twoOClock);
+ assertEquals("140000000", asEncodedString);
+ }
+
+ @Test
+ public void testAdd() {
+ final Object newValue = value.add(twoOClock, 0, 0, 0, 1, 15);
+ assertEquals("15:15:00", newValue.toString());
+ }
+
+ @Test
+ public void testAdd2() {
+ final Object newValue = value.add(twoOClock, 0, 0, 0, 0, 0);
+ assertEquals("14:00:00", newValue.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaUtilDateValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaUtilDateValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaUtilDateValueSemanticsProviderTest.java
new file mode 100644
index 0000000..3833e3f
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/JavaUtilDateValueSemanticsProviderTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.dateutil.JavaUtilDateValueSemanticsProvider;
+
+public class JavaUtilDateValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private java.util.Date date;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.datetime");
+ will(returnValue(null));
+ }
+ });
+
+ TestClock.initialize();
+ date = new java.util.Date(0);
+
+ holder = new FacetHolderImpl();
+ setValue(new JavaUtilDateValueSemanticsProvider(holder, mockConfiguration, mockContext) {
+ @Override
+ protected String defaultFormat() {
+ return "iso";
+ }
+ });
+ }
+
+ @Test
+ public void testInvalidParse() throws Exception {
+ try {
+ getValue().parseTextEntry(null, "invalid entry", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ /**
+ * Something rather bizarre here, that the epoch formats as 01:00 rather
+ * than 00:00. It's obviously because of some sort of timezone issue, but I
+ * don't know where that dependency is coming from.
+ */
+ @Test
+ public void testTitleOf() {
+ final String EXPECTED = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new java.util.Date(0));
+ assertEquals(EXPECTED, getValue().displayTitleOf(date, (Localization) null));
+ }
+
+ @Test
+ public void testParse() throws Exception {
+ final Object newValue = getValue().parseTextEntry(null, "1980-01-01 10:40", null);
+
+ final Calendar calendar = Calendar.getInstance();
+ calendar.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
+ calendar.set(1980, 0, 1, 10, 40, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+
+ assertEquals(calendar.getTime(), newValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/LongValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/LongValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/LongValueSemanticsProviderTest.java
new file mode 100644
index 0000000..a0a4066
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/LongValueSemanticsProviderTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.longs.LongValueSemanticsProviderAbstract;
+import org.apache.isis.core.progmodel.facets.value.longs.LongWrapperValueSemanticsProvider;
+
+public class LongValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private LongValueSemanticsProviderAbstract value;
+
+ private Object longObj;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ longObj = new Long(367322);
+ allowMockAdapterToReturn(longObj);
+ holder = new FacetHolderImpl();
+
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.long");
+ will(returnValue(null));
+ }
+ });
+
+ setValue(value = new LongWrapperValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testInvalidParse() throws Exception {
+ try {
+ value.parseTextEntry(null, "one", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testOutputAsString() {
+ assertEquals("367,322", value.displayTitleOf(longObj, (Localization) null));
+ }
+
+ @Test
+ public void testParse() throws Exception {
+ final Object parsed = value.parseTextEntry(null, "120", null);
+ assertEquals("120", parsed.toString());
+ }
+
+ @Test
+ public void testParseWithBadlyFormattedEntry() throws Exception {
+ final Object parsed = value.parseTextEntry(null, "1,20.0", null);
+ assertEquals("120", parsed.toString());
+ }
+
+ @Test
+ public void testEncode() throws Exception {
+ assertEquals("367322", value.toEncodedString(longObj));
+ }
+
+ @Test
+ public void test() throws Exception {
+ final Object parsed = value.fromEncodedString("234");
+ assertEquals("234", parsed.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/MoneyValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/MoneyValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/MoneyValueSemanticsProviderTest.java
new file mode 100644
index 0000000..2933b15
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/MoneyValueSemanticsProviderTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.Locale;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.money.MoneyValueSemanticsProvider;
+
+public class MoneyValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private static final String POUND_SYMBOL = "\u00A3";
+ private static final String EURO_SYMBOL = "\u20AC";
+ private MoneyValueSemanticsProvider adapter;
+ private Money originalMoney;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ Locale.setDefault(Locale.UK);
+ holder = new FacetHolderImpl();
+ setValue(adapter = new MoneyValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ private Money createMoney(final double amount, final String currency) {
+ return new Money(amount, currency);
+ }
+
+ @Test
+ public void testLocale() {
+ assertEquals(Locale.UK, Locale.getDefault());
+ }
+
+ @Test
+ public void testEncoding() {
+ originalMoney = new Money(10.5, "gbp");
+ final String data = adapter.toEncodedString(originalMoney);
+ assertEquals("10.5 GBP", data);
+ }
+
+ @Test
+ public void testDecoding() {
+ final Object restored = adapter.fromEncodedString("23.77 FFR");
+ final Money expected = new Money(23.77, "FFR");
+ assertEquals(expected, restored);
+ }
+
+ @Test
+ public void testTitleOfWithPounds() {
+ originalMoney = new Money(10.5, "gbp");
+ assertEquals(POUND_SYMBOL + "10.50", adapter.displayTitleOf(originalMoney, (Localization) null));
+ }
+
+ @Test
+ public void testTitleOfWithNonLocalCurrency() {
+ assertEquals("10.50 USD", adapter.displayTitleOf(createMoney(10.50, "usd"), (Localization) null));
+ }
+
+ @Test
+ public void testTitleWithUnknownCurrency() {
+ assertEquals("10.50 UNK", adapter.displayTitleOf(createMoney(10.50, "UNK"), (Localization) null));
+ }
+
+ @Test
+ public void testUserEntryWithCurrency() {
+ final Money money = createMoney(10.5, "gbp");
+ final Money parsed = adapter.parseTextEntry(money, "22.45 USD", null);
+ assertEquals(new Money(22.45, "usd"), parsed);
+ }
+
+ @Test
+ public void testNewUserEntryUsesPreviousCurrency() {
+ originalMoney = new Money(10.5, "gbp");
+ final Object parsed = adapter.parseTextEntry(originalMoney, "22.45", null);
+ assertEquals(new Money(22.45, "gbp"), parsed);
+ }
+
+ @Test
+ public void testReplacementEntryForDefaultCurrency() {
+ // MoneyValueSemanticsProvider adapter = new
+ // MoneyValueSemanticsProvider(new Money(10.3, "gbp"));
+ final Object parsed = adapter.parseTextEntry(originalMoney, POUND_SYMBOL + "80.90", null);
+ assertEquals(new Money(80.90, "gbp"), parsed);
+ }
+
+ @Test
+ public void testSpecifyingCurrencyInEntry() {
+ final Object parsed = adapter.parseTextEntry(originalMoney, "3021.50 EUr", null);
+ assertEquals("3,021.50 EUR", adapter.displayTitleOf(parsed, (Localization) null));
+ }
+
+ @Test
+ public void testUsingLocalCurrencySymbol() {
+ // MoneyValueSemanticsProvider adapter = new
+ // MoneyValueSemanticsProvider(new Money(0L, "gbp"));
+ final Object parsed = adapter.parseTextEntry(originalMoney, POUND_SYMBOL + "3021.50", null);
+ assertEquals(POUND_SYMBOL + "3,021.50", adapter.titleString(parsed, null));
+ }
+
+ @Test
+ public void testInvalidCurrencyCodeIsRejected() throws Exception {
+ try {
+ adapter.parseTextEntry(originalMoney, "3021.50 XYZ", null);
+ fail("invalid code accepted " + adapter);
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testInvalidCurrencySymbolIsRejected() throws Exception {
+ try {
+ adapter.parseTextEntry(originalMoney, EURO_SYMBOL + "3021.50", null);
+ fail("invalid code accepted " + adapter);
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testNewValueDefaultsToLocalCurrency() throws Exception {
+ final Money parsed = adapter.parseTextEntry(originalMoney, "3021.50", null);
+ assertEquals(POUND_SYMBOL + "3,021.50", adapter.displayTitleOf(parsed, (Localization) null));
+ }
+
+ @Test
+ public void testUnrelatedCurrencySymbolIsRejected() throws Exception {
+ final Money money = createMoney(1, "eur");
+ try {
+ adapter.parseTextEntry(money, "$3021.50", null);
+ fail("invalid code accepted " + adapter);
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PasswordValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PasswordValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PasswordValueSemanticsProviderTest.java
new file mode 100644
index 0000000..7b99b8c
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PasswordValueSemanticsProviderTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.value.Password;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.password.PasswordValueSemanticsProvider;
+
+public class PasswordValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private PasswordValueSemanticsProvider adapter;
+ private Object password;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ holder = new FacetHolderImpl();
+ setValue(adapter = new PasswordValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ password = new Password("secret");
+ }
+
+ @Test
+ public void testEncoding() {
+ assertEquals("secret", adapter.toEncodedString(password));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PercentageValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PercentageValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PercentageValueSemanticsProviderTest.java
new file mode 100644
index 0000000..2696e12
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PercentageValueSemanticsProviderTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.value.Percentage;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.percentage.PercentageValueSemanticsProvider;
+
+public class PercentageValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+ private PercentageValueSemanticsProvider adapter;
+ private Percentage percentage;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.percentage");
+ will(returnValue(null));
+ }
+ });
+
+ percentage = new Percentage(0.105f);
+ allowMockAdapterToReturn(percentage);
+
+ holder = new FacetHolderImpl();
+
+ setValue(adapter = new PercentageValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testAsEncodedString() {
+ final String encoded = getEncodeableFacet().toEncodedString(mockAdapter);
+ assertEquals("0.105", encoded);
+ }
+
+ @Test
+ public void testParseTextEntryWithNumber() {
+ final Percentage parsed = adapter.parseTextEntry(percentage, "21%", null);
+ assertEquals(new Percentage(0.21f), parsed);
+ }
+
+ @Test
+ public void testParseTextEntryWithNumberAndDecimalPoint() {
+ final Percentage parsed = adapter.parseTextEntry(percentage, "21.4%", null);
+ assertEquals(new Percentage(0.214f), parsed);
+ }
+
+ @Test
+ public void testParseTextEntryWithBlank() {
+ final Percentage parsed = adapter.parseTextEntry(percentage, "", null);
+ assertEquals(null, parsed);
+ }
+
+ @Test
+ public void testRestoreFromEncodedString() {
+ final Object restored = adapter.fromEncodedString("0.2134");
+ assertEquals(new Percentage(0.2134f), restored);
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("10%", adapter.displayTitleOf(percentage, (Localization) null));
+ }
+
+ @Test
+ public void testFloatValue() {
+ assertEquals(0.105f, adapter.floatValue(mockAdapter), 0.0f);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PolishMoneyValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PolishMoneyValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PolishMoneyValueSemanticsProviderTest.java
new file mode 100644
index 0000000..1bb9068
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/PolishMoneyValueSemanticsProviderTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.Locale;
+
+import org.jmock.integration.junit4.JMock;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.value.Money;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.money.MoneyValueSemanticsProvider;
+
+@Ignore
+// TODO once the sematics provide has a way to reset the formatters for the new
+// local then this test can be reinstated.
+@RunWith(JMock.class)
+public class PolishMoneyValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private static final String CURRENCY_SPACE = "\u00a0";
+ private static final String ZLOTYCH_SYMBOL = "\u007a\u0142";
+ private static final String EURO_SYMBOL = "\u20AC";
+ private MoneyValueSemanticsProvider adapter;
+ private Money originalMoney;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ Locale.setDefault(new Locale("pl", "PL"));
+ originalMoney = new Money(10.50, "pln");
+ holder = new FacetHolderImpl();
+ setValue(adapter = new MoneyValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ private Money createMoney(final double amount, final String currency) {
+ return new Money(amount, currency);
+ }
+
+ @Test
+ public void testLocale() {
+ assertEquals("PL", Locale.getDefault().getCountry());
+ assertEquals("pl", Locale.getDefault().getLanguage());
+ }
+
+ @Test
+ public void testEncoding() {
+ final String data = adapter.toEncodedString(originalMoney);
+ assertEquals("10.5 PLN", data);
+ }
+
+ @Test
+ public void testDecoding() {
+ final Object restored = adapter.fromEncodedString("23.77 FFR");
+ final Money expected = new Money(23.77, "FFR");
+ assertEquals(expected, restored);
+ }
+
+ @Test
+ public void testTitleOfWithZlotych() {
+ assertEquals("10,5 " + ZLOTYCH_SYMBOL, adapter.displayTitleOf(originalMoney, (Localization) null));
+ }
+
+ @Test
+ public void testTitleOfWithNonLocalCurrency() {
+ assertEquals("10,5 USD", adapter.displayTitleOf(createMoney(10.50, "usd"), (Localization) null));
+ }
+
+ @Test
+ public void testTitleWithUnknownCurrency() {
+ assertEquals("10,5 UNK", adapter.displayTitleOf(createMoney(10.50, "UNK"), (Localization) null));
+ }
+
+ @Test
+ public void testUserEntryWithCurrency() {
+ final Money money = createMoney(10.5, "gbp");
+ final Money parsed = adapter.parseTextEntry(money, "22,45 USD", null);
+ assertEquals(new Money(22.45, "usd"), parsed);
+ }
+
+ @Test
+ public void testUserEntryUsesPreviousCurrency() {
+ final Object parsed = adapter.parseTextEntry(originalMoney, "22,45", null);
+ assertEquals(new Money(22.45, "pln"), parsed);
+ }
+
+ @Test
+ public void testReplacementEntryForDefaultCurrency() {
+ final Object parsed = adapter.parseTextEntry(originalMoney, "80,90 " + ZLOTYCH_SYMBOL, null);
+ assertEquals(new Money(80.90, "pln"), parsed);
+ }
+
+ @Test
+ public void testSpecifyingCurrencyInEntry() {
+ final Object parsed = adapter.parseTextEntry(originalMoney, "3021,50 cad", null);
+ assertEquals("3" + CURRENCY_SPACE + "021,5 CAD", adapter.displayTitleOf(parsed, (Localization) null));
+ }
+
+ @Test
+ public void testUsingLocalCurrencySymbol() {
+ // MoneyValueSemanticsProvider adapter = new
+ // MoneyValueSemanticsProvider(new Money(0L, "gbp"));
+ final Object parsed = adapter.parseTextEntry(originalMoney, "3021,50 " + ZLOTYCH_SYMBOL, null);
+ assertEquals("3" + CURRENCY_SPACE + "021,5 " + ZLOTYCH_SYMBOL, adapter.titleString(parsed, (Localization) null));
+ }
+
+ @Test
+ public void testInvalidCurrencySuffixRejected() throws Exception {
+ final Object parsed = adapter.parseTextEntry(originalMoney, "3" + CURRENCY_SPACE + "021,50 Dm", null);
+ assertEquals("3" + CURRENCY_SPACE + "021,5 " + ZLOTYCH_SYMBOL, adapter.titleString(parsed, null));
+ }
+
+ @Test
+ public void testInvalidCurrencySymbolIsRejected() throws Exception {
+ try {
+ adapter.parseTextEntry(originalMoney, EURO_SYMBOL + "3021.50", null);
+ fail("invalid code accepted " + adapter);
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testNewValueDefaultsToLocalCurrency() throws Exception {
+ final Money parsed = adapter.parseTextEntry(originalMoney, "3021,50", null);
+ assertEquals("3" + CURRENCY_SPACE + "021,5 " + ZLOTYCH_SYMBOL, adapter.displayTitleOf(parsed, (Localization) null));
+ }
+
+ @Test
+ public void testUnrelatedCurrencySymbolIsRejected() throws Exception {
+ final Money money = createMoney(1, "eur");
+ try {
+ adapter.parseTextEntry(money, "$3021.50", null);
+ fail("invalid code accepted " + adapter);
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ShortValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ShortValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ShortValueSemanticsProviderTest.java
new file mode 100644
index 0000000..3b7ee24
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ShortValueSemanticsProviderTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseException;
+import org.apache.isis.core.progmodel.facets.value.shortint.ShortValueSemanticsProviderAbstract;
+import org.apache.isis.core.progmodel.facets.value.shortint.ShortWrapperValueSemanticsProvider;
+
+public class ShortValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private ShortValueSemanticsProviderAbstract value;
+ private Short short1;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.short");
+ will(returnValue(null));
+ }
+ });
+
+ short1 = Short.valueOf((short) 32);
+ allowMockAdapterToReturn(short1);
+
+ holder = new FacetHolderImpl();
+
+ setValue(value = new ShortWrapperValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testInvalidParse() throws Exception {
+ try {
+ value.parseTextEntry(null, "one", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleOfForPositiveValue() {
+ assertEquals("32", value.displayTitleOf(short1, (Localization) null));
+ }
+
+ @Test
+ public void testTitleOfForLargestNegativeValue() {
+ assertEquals("-128", value.displayTitleOf(Short.valueOf((short) -128), (Localization) null));
+ }
+
+ @Test
+ public void testParse() throws Exception {
+ final Object newValue = value.parseTextEntry(null, "120", null);
+ assertEquals(Short.valueOf((short) 120), newValue);
+ }
+
+ @Test
+ public void testParseOfOddEntry() throws Exception {
+ final Object newValue = value.parseTextEntry(null, "1,20.0", null);
+ assertEquals(Short.valueOf((short) 120), newValue);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/StringValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/StringValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/StringValueSemanticsProviderTest.java
new file mode 100644
index 0000000..fdb4b9e
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/StringValueSemanticsProviderTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.string.StringValueSemanticsProvider;
+
+public class StringValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private StringValueSemanticsProvider value;
+
+ private String string;
+
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ string = "text entry";
+ holder = new FacetHolderImpl();
+ setValue(value = new StringValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("text entry", value.displayTitleOf(string, (Localization) null));
+ }
+
+ @Test
+ public void testParse() throws Exception {
+ final Object parsed = value.parseTextEntry(null, "tRUe", null);
+ assertEquals("tRUe", parsed.toString());
+ }
+
+ @Test
+ public void testEncodeNormalString() throws Exception {
+ allowMockAdapterToReturn("/slash");
+ assertEquals("//slash", getEncodeableFacet().toEncodedString(mockAdapter));
+ }
+
+ @Test
+ public void testEncodeNULLString() throws Exception {
+ allowMockAdapterToReturn("NULL");
+ assertEquals("/NULL", getEncodeableFacet().toEncodedString(mockAdapter));
+ }
+
+ @Test
+ public void testRestore() throws Exception {
+ final Object parsed = value.fromEncodedString("//slash");
+ assertEquals("/slash", parsed.toString());
+ }
+
+ @Test
+ public void testRestoreNULLString() throws Exception {
+ final Object parsed = value.fromEncodedString("/NULL");
+ assertEquals("NULL", parsed.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TestClock.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TestClock.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TestClock.java
new file mode 100644
index 0000000..73fa1c6
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TestClock.java
@@ -0,0 +1,68 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.isis.applib.clock.Clock;
+
+public class TestClock extends Clock {
+
+ public static final TimeZone timeZone;
+
+ public static void initialize() {
+ new TestClock();
+
+ Locale.setDefault(Locale.UK);
+ TimeZone.setDefault(timeZone);
+ }
+
+ private TestClock() {
+ super();
+ }
+
+ static {
+ timeZone = TimeZone.getTimeZone("Etc/UTC");
+ }
+
+ /**
+ * Always return the time as 2003/8/17 21:30:25
+ */
+ @Override
+ protected long time() {
+ final Calendar c = Calendar.getInstance();
+ c.setTimeZone(timeZone);
+
+ c.set(Calendar.MILLISECOND, 0);
+
+ c.set(Calendar.YEAR, 2003);
+ c.set(Calendar.MONTH, 7);
+ c.set(Calendar.DAY_OF_MONTH, 17);
+
+ c.set(Calendar.HOUR_OF_DAY, 21);
+ c.set(Calendar.MINUTE, 30);
+ c.set(Calendar.SECOND, 25);
+
+ return c.getTime().getTime();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TimeStampValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TimeStampValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TimeStampValueSemanticsProviderTest.java
new file mode 100644
index 0000000..d39f548
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TimeStampValueSemanticsProviderTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.value.TimeStamp;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.timestamp.TimeStampValueSemanticsProvider;
+
+public class TimeStampValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private TimeStampValueSemanticsProvider adapter;
+ private Object timestamp;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.timestamp");
+ will(returnValue(null));
+ }
+ });
+
+ TestClock.initialize();
+ timestamp = new TimeStamp(0);
+ holder = new FacetHolderImpl();
+ setValue(adapter = new TimeStampValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Override
+ public void testParseEmptyString() {
+ final Object parsed = adapter.parseTextEntry(null, "", null);
+ assertNull(parsed);
+ }
+
+ @Test
+ public void testTitle() {
+ assertEquals("01/01/70 00:00:00 UTC", adapter.titleString(timestamp, null));
+ }
+
+ @Test
+ public void testEncodesTimeStamp() {
+ final String encodedString = adapter.toEncodedString(timestamp);
+ assertEquals("19700101T000000000", encodedString);
+ }
+
+ @Test
+ public void testDecodesTimeStamp() {
+ final String encodedString = "19700101T000000000";
+ final Object restored = adapter.fromEncodedString(encodedString);
+ assertEquals(((TimeStamp) timestamp).longValue(), ((TimeStamp) restored).longValue());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TimeValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TimeValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TimeValueSemanticsProviderTest.java
new file mode 100644
index 0000000..bc67d2f
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/TimeValueSemanticsProviderTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.apache.isis.applib.adapters.EncodingException;
+import org.apache.isis.applib.value.Time;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.time.TimeValueSemanticsProvider;
+
+public class TimeValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private TimeValueSemanticsProvider adapter;
+ private Time time;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.time");
+ will(returnValue(null));
+ }
+ });
+
+ TestClock.initialize();
+ time = new Time(8, 13);
+ holder = new FacetHolderImpl();
+ setValue(adapter = new TimeValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testTimeAsEncodedString() throws Exception {
+ assertEquals("081300000", adapter.toEncodedString(time));
+ }
+
+ @Test
+ public void testParseEntryOfHoursMinutesText() throws Exception {
+ final Object parsed = adapter.parseTextEntry(null, "8:30", null);
+ assertEquals(new Time(8, 30), parsed);
+ }
+
+ @Test
+ @Ignore
+ public void testParseEntryOfHoursMinutesSecondsText() throws Exception {
+ final Object parsed = adapter.parseTextEntry(null, "8:30:45", null);
+ // I can't get the text parser to parse HH:mm:ss before HH:mm!!
+ final Time expected = new Time(8, 30, 45);
+ assertEquals(expected, parsed);
+ }
+
+ @Test
+ public void testParseEntryOfHoursAfterTime() throws Exception {
+ final Object parsed = adapter.parseTextEntry(time, "+5H", null);
+ assertEquals(new Time(13, 13), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfHoursAfterNow() throws Exception {
+ final Object parsed = adapter.parseTextEntry(null, "+5H", null);
+ assertEquals(new Time(2, 30, 25), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfHoursBeforeTime() throws Exception {
+ final Object parsed = adapter.parseTextEntry(time, "-7H", null);
+ assertEquals(new Time(1, 13), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfHoursBeforeToNow() throws Exception {
+ final Object parsed = adapter.parseTextEntry(null, "-5H", null);
+ assertEquals(new Time(16, 30, 25), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfKeywordNow() throws Exception {
+ final Object parsed = adapter.parseTextEntry(time, "now", null);
+ assertEquals(new Time(), parsed);
+ }
+
+ @Test
+ public void testRestoreTime() throws Exception {
+ final Time expected = new Time(21, 30);
+ final Object parsed = adapter.fromEncodedString("213000000");
+ assertEquals(expected, parsed);
+ }
+
+ @Test
+ public void testRestoreOfInvalidDatal() throws Exception {
+ try {
+ adapter.fromEncodedString("two ten");
+ fail();
+ } catch (final EncodingException expected) {
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ValueSemanticsProviderAbstractTestCase.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ValueSemanticsProviderAbstractTestCase.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ValueSemanticsProviderAbstractTestCase.java
new file mode 100644
index 0000000..898cd4d
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ValueSemanticsProviderAbstractTestCase.java
@@ -0,0 +1,180 @@
+/*
+ * 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.core.progmodel.facets.value;
+
+import static org.apache.isis.core.testsupport.jmock.ReturnArgumentJMockAction.returnArgument;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.util.Locale;
+
+import org.jmock.Expectations;
+import org.jmock.auto.Mock;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.deployment.DeploymentCategory;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.facets.object.parseable.ParseableFacet;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.progmodel.facets.object.encodeable.EncodableFacetUsingEncoderDecoder;
+import org.apache.isis.core.progmodel.facets.object.parseable.ParseableFacetUsingParser;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderAndFacetAbstract;
+import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+
+public abstract class ValueSemanticsProviderAbstractTestCase {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private ValueSemanticsProviderAndFacetAbstract<?> valueSemanticsProvider;
+ private EncodableFacetUsingEncoderDecoder encodeableFacet;
+ private ParseableFacetUsingParser parseableFacet;
+
+ @Mock
+ protected FacetHolder mockFacetHolder;
+ @Mock
+ protected IsisConfiguration mockConfiguration;
+ @Mock
+ protected ValueSemanticsProviderContext mockContext;
+ @Mock
+ protected ServicesInjector mockDependencyInjector;
+ @Mock
+ protected AdapterManager mockAdapterManager;
+ @Mock
+ protected SpecificationLoaderSpi mockSpecificationLoader;
+ @Mock
+ protected AuthenticationSessionProvider mockAuthenticationSessionProvider;
+ @Mock
+ protected ObjectAdapter mockAdapter;
+
+ @Before
+ public void setUp() throws Exception {
+ Locale.setDefault(Locale.UK);
+
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString(with(any(String.class)), with(any(String.class)));
+ will(returnArgument(1));
+
+ allowing(mockConfiguration).getBoolean(with(any(String.class)), with(any(Boolean.class)));
+ will(returnArgument(1));
+
+ allowing(mockConfiguration).getString("isis.locale");
+ will(returnValue(null));
+
+ allowing(mockDependencyInjector).injectServicesInto(with(any(Object.class)));
+
+ never(mockAuthenticationSessionProvider);
+
+ never(mockAdapterManager);
+ }
+ });
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ context.assertIsSatisfied();
+ }
+
+ protected void allowMockAdapterToReturn(final Object pojo) {
+ context.checking(new Expectations() {
+ {
+ allowing(mockAdapter).getObject();
+ will(returnValue(pojo));
+ }
+ });
+ }
+
+ protected void setValue(final ValueSemanticsProviderAndFacetAbstract<?> value) {
+ this.valueSemanticsProvider = value;
+ this.encodeableFacet = new EncodableFacetUsingEncoderDecoder(value, mockFacetHolder, mockAdapterManager, mockDependencyInjector);
+ this.parseableFacet = new ParseableFacetUsingParser(value, mockFacetHolder, DeploymentCategory.PRODUCTION, mockAuthenticationSessionProvider, mockDependencyInjector, mockAdapterManager);
+ }
+
+ protected ValueSemanticsProviderAndFacetAbstract<?> getValue() {
+ return valueSemanticsProvider;
+ }
+
+ protected EncodableFacet getEncodeableFacet() {
+ return encodeableFacet;
+ }
+
+ protected ParseableFacet getParseableFacet() {
+ return parseableFacet;
+ }
+
+ protected ObjectAdapter createAdapter(final Object object) {
+ return mockAdapter;
+ }
+
+ @Test
+ public void testParseNull() throws Exception {
+ Assume.assumeThat(valueSemanticsProvider.getParser(), is(not(nullValue())));
+ try {
+ valueSemanticsProvider.parseTextEntry(null, null, null);
+ fail();
+ } catch (final IllegalArgumentException expected) {
+ }
+ }
+
+ @Test
+ public void testParseEmptyString() throws Exception {
+ Assume.assumeThat(valueSemanticsProvider.getParser(), is(not(nullValue())));
+
+ final Object newValue = valueSemanticsProvider.parseTextEntry(null, "", null);
+ assertNull(newValue);
+ }
+
+ @Test
+ public void testDecodeNULL() throws Exception {
+ Assume.assumeThat(valueSemanticsProvider.getEncoderDecoder(), is(not(nullValue())));
+
+ final Object newValue = encodeableFacet.fromEncodedString(EncodableFacetUsingEncoderDecoder.ENCODED_NULL);
+ assertNull(newValue);
+ }
+
+ @Test
+ public void testEmptyEncoding() {
+ Assume.assumeThat(valueSemanticsProvider.getEncoderDecoder(), is(not(nullValue())));
+
+ assertEquals(EncodableFacetUsingEncoderDecoder.ENCODED_NULL, encodeableFacet.toEncodedString(null));
+ }
+
+ @Test
+ public void testTitleOfForNullObject() {
+ assertEquals("", valueSemanticsProvider.displayTitleOf(null, (Localization) null));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/progmodels/dflt/ObjectReflectorDefaultTestAbstract.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/progmodels/dflt/ObjectReflectorDefaultTestAbstract.java b/framework/core/metamodel/src/test/java/org/apache/isis/progmodels/dflt/ObjectReflectorDefaultTestAbstract.java
new file mode 100644
index 0000000..4e32a72
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/progmodels/dflt/ObjectReflectorDefaultTestAbstract.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.progmodels.dflt;
+
+import java.util.HashSet;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jmock.Expectations;
+import org.jmock.auto.Mock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facetdecorator.FacetDecorator;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.describedas.DescribedAsFacet;
+import org.apache.isis.core.metamodel.facets.named.NamedFacet;
+import org.apache.isis.core.metamodel.facets.object.plural.PluralFacet;
+import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacet;
+import org.apache.isis.core.metamodel.runtimecontext.RuntimeContext;
+import org.apache.isis.core.metamodel.runtimecontext.noruntime.RuntimeContextNoRuntime;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault;
+import org.apache.isis.core.metamodel.specloader.classsubstitutor.ClassSubstitutorAbstract;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistryDefault;
+import org.apache.isis.core.metamodel.specloader.traverser.SpecificationTraverserDefault;
+import org.apache.isis.core.progmodel.layout.dflt.MemberLayoutArrangerDefault;
+import org.apache.isis.core.progmodel.metamodelvalidator.dflt.MetaModelValidatorDefault;
+import org.apache.isis.core.testsupport.jmock.InjectIntoJMockAction;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+
+public abstract class ObjectReflectorDefaultTestAbstract {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
+
+ private RuntimeContext runtimeContext;
+
+ @Mock
+ private IsisConfiguration mockConfiguration;
+
+ // is loaded by subclasses
+ protected ObjectSpecification specification;
+
+
+ @Before
+ public void setUp() throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).injectInto(with(anything()));
+ will(InjectIntoJMockAction.injectInto());
+
+ ignoring(mockConfiguration);
+ }
+ });
+
+ runtimeContext = new RuntimeContextNoRuntime();
+ final ObjectReflectorDefault reflector = new ObjectReflectorDefault(mockConfiguration, new ClassSubstitutorAbstract() {}, new CollectionTypeRegistryDefault(), new SpecificationTraverserDefault(), new MemberLayoutArrangerDefault(), new ProgrammingModelFacetsJava5(), new HashSet<FacetDecorator>(),
+ new MetaModelValidatorDefault());
+ reflector.setRuntimeContext(runtimeContext);
+ reflector.init();
+
+ specification = loadSpecification(reflector);
+ }
+
+ protected abstract ObjectSpecification loadSpecification(ObjectReflectorDefault reflector);
+
+ @Test
+ public void testCollectionFacet() throws Exception {
+ final Facet facet = specification.getFacet(CollectionFacet.class);
+ Assert.assertNull(facet);
+ }
+
+ @Test
+ public void testTypeOfFacet() throws Exception {
+ final TypeOfFacet facet = specification.getFacet(TypeOfFacet.class);
+ Assert.assertNull(facet);
+ }
+
+ @Test
+ public void testNamedFaced() throws Exception {
+ final Facet facet = specification.getFacet(NamedFacet.class);
+ Assert.assertNotNull(facet);
+ }
+
+ @Test
+ public void testPluralFaced() throws Exception {
+ final Facet facet = specification.getFacet(PluralFacet.class);
+ Assert.assertNotNull(facet);
+ }
+
+ @Test
+ public void testDescriptionFacet() throws Exception {
+ final Facet facet = specification.getFacet(DescribedAsFacet.class);
+ Assert.assertNotNull(facet);
+ }
+
+}