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
[49/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/propparam/specification/SpecificationNotTests.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationNotTests.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationNotTests.java
new file mode 100644
index 0000000..25573c5
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationNotTests.java
@@ -0,0 +1,62 @@
+/*
+ * 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.propparam.specification;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+import org.apache.isis.applib.spec.Specification;
+import org.apache.isis.applib.spec.SpecificationNot;
+
+public class SpecificationNotTests {
+
+ private final Specification alwaysSatisfied = new SpecificationAlwaysSatisfied();
+ private final Specification neverSatisfied = new SpecificationNeverSatisfied();
+
+ @Test
+ public void notSatisfiedIfUnderlyingIs() {
+ class MySpecNot extends SpecificationNot {
+ public MySpecNot() {
+ super(alwaysSatisfied);
+ }
+ }
+ ;
+ final Specification mySpecOr = new MySpecNot();
+ assertThat(mySpecOr.satisfies(null), is(not(nullValue())));
+ assertThat(mySpecOr.satisfies(null), is("not satisfied"));
+ }
+
+ @Test
+ public void satisfiedIfUnderlyingIsNot() {
+ class MySpecNot extends SpecificationNot {
+ public MySpecNot() {
+ super(neverSatisfied);
+ }
+ }
+ ;
+ final Specification mySpecOr = new MySpecNot();
+ assertThat(mySpecOr.satisfies(null), is(nullValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationOrTests.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationOrTests.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationOrTests.java
new file mode 100644
index 0000000..41d74e1
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationOrTests.java
@@ -0,0 +1,110 @@
+/*
+ * 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.propparam.specification;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+import org.apache.isis.applib.spec.Specification;
+import org.apache.isis.applib.spec.SpecificationOr;
+
+public class SpecificationOrTests {
+
+ private final Specification alwaysSatisfied = new SpecificationAlwaysSatisfied();
+ private final Specification neverSatisfied = new SpecificationNeverSatisfied();
+
+ @Test
+ public void satisfiedIfNone() {
+ class MySpecOr extends SpecificationOr {
+ public MySpecOr() {
+ }
+ }
+ ;
+ final Specification mySpecOr = new MySpecOr();
+ assertThat(mySpecOr.satisfies(null), is(nullValue()));
+ }
+
+ @Test
+ public void satisfiedIfOneAndOkay() {
+ class MySpecOr extends SpecificationOr {
+ public MySpecOr() {
+ super(alwaysSatisfied);
+ }
+ }
+ ;
+ final Specification mySpecOr = new MySpecOr();
+ assertThat(mySpecOr.satisfies(null), is(nullValue()));
+ }
+
+ @Test
+ public void notSatisfiedIfOneAndNotOkay() {
+ class MySpecOr extends SpecificationOr {
+ public MySpecOr() {
+ super(neverSatisfied);
+ }
+ }
+ ;
+ final Specification mySpecOr = new MySpecOr();
+ assertThat(mySpecOr.satisfies(null), is(not(nullValue())));
+ assertThat(mySpecOr.satisfies(null), is("not satisfied"));
+ }
+
+ @Test
+ public void satisfiedIfTwoAndOneIsNotOkay() {
+ class MySpecOr extends SpecificationOr {
+ public MySpecOr() {
+ super(alwaysSatisfied, neverSatisfied);
+ }
+ }
+ ;
+ final Specification mySpecOr = new MySpecOr();
+ assertThat(mySpecOr.satisfies(null), is(nullValue()));
+ }
+
+ @Test
+ public void satisfiedIfTwoAndBothAreOkay() {
+ class MySpecOr extends SpecificationOr {
+ public MySpecOr() {
+ super(alwaysSatisfied, alwaysSatisfied);
+ }
+ }
+ ;
+ final Specification mySpecOr = new MySpecOr();
+ assertThat(mySpecOr.satisfies(null), is(nullValue()));
+ }
+
+ @Test
+ public void notSatisfiedIfTwoAndBothAreNotOkayWithConcatenatedReason() {
+ class MySpecOr extends SpecificationOr {
+ public MySpecOr() {
+ super(neverSatisfied, neverSatisfied);
+ }
+ }
+ ;
+ final Specification mySpecOr = new MySpecOr();
+ assertThat(mySpecOr.satisfies(null), is(not(nullValue())));
+ assertThat(mySpecOr.satisfies(null), is("not satisfied; not satisfied"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationRequiresFirstLetterToBeUpperCase.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationRequiresFirstLetterToBeUpperCase.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationRequiresFirstLetterToBeUpperCase.java
new file mode 100644
index 0000000..d44d010
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/SpecificationRequiresFirstLetterToBeUpperCase.java
@@ -0,0 +1,39 @@
+/*
+ * 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.propparam.specification;
+
+import org.apache.isis.applib.spec.Specification;
+
+public class SpecificationRequiresFirstLetterToBeUpperCase implements Specification {
+
+ @Override
+ public String satisfies(final Object obj) {
+ if (!(obj instanceof String)) {
+ return null;
+ }
+ final String str = (String) obj;
+ if (str.length() < 0) {
+ return "Must contain at least one letter";
+ }
+ final char firstLetter = str.charAt(0);
+ return Character.isUpperCase(firstLetter) ? null : "Must start with upper case";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/Utils.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/Utils.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/Utils.java
new file mode 100644
index 0000000..7c93f5f
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/specification/Utils.java
@@ -0,0 +1,40 @@
+/*
+ * 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.propparam.specification;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.isis.applib.spec.Specification;
+
+public final class Utils {
+
+ private Utils() {
+ }
+
+ @SuppressWarnings("serial")
+ public static List<Specification> listOf(final Specification specification) {
+ return new ArrayList<Specification>() {
+ {
+ add(specification);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/typicallength/TypicalLengthAnnotationFacetFactoryTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/typicallength/TypicalLengthAnnotationFacetFactoryTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/typicallength/TypicalLengthAnnotationFacetFactoryTest.java
new file mode 100644
index 0000000..74f2332
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/typicallength/TypicalLengthAnnotationFacetFactoryTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.propparam.typicallength;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.annotation.TypicalLength;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessMethodContext;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessParameterContext;
+import org.apache.isis.core.metamodel.facets.typicallen.TypicalLengthFacet;
+import org.apache.isis.core.progmodel.facets.AbstractFacetFactoryTest;
+import org.apache.isis.core.progmodel.facets.param.typicallen.annotation.TypicalLengthAnnotationOnParameterFacetFactory;
+import org.apache.isis.core.progmodel.facets.param.typicallen.annotation.TypicalLengthFacetAnnotationOnParameter;
+import org.apache.isis.core.progmodel.facets.properties.typicallen.annotation.TypicalLengthAnnotationOnPropertyFacetFactory;
+import org.apache.isis.core.progmodel.facets.properties.typicallen.annotation.TypicalLengthFacetAnnotationOnProperty;
+
+public class TypicalLengthAnnotationFacetFactoryTest extends AbstractFacetFactoryTest {
+
+ public void testTypicalLengthAnnotationPickedUpOnProperty() {
+ final TypicalLengthAnnotationOnPropertyFacetFactory facetFactory = new TypicalLengthAnnotationOnPropertyFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ @TypicalLength(30)
+ public String getFirstName() {
+ return null;
+ }
+ }
+ final Method method = findMethod(Customer.class, "getFirstName");
+
+ facetFactory.process(new ProcessMethodContext(Customer.class, method, methodRemover, facetedMethod));
+
+ final Facet facet = facetedMethod.getFacet(TypicalLengthFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof TypicalLengthFacetAnnotationOnProperty);
+ final TypicalLengthFacetAnnotationOnProperty typicalLengthFacetAnnotation = (TypicalLengthFacetAnnotationOnProperty) facet;
+ assertEquals(30, typicalLengthFacetAnnotation.value());
+ }
+
+ public void testTypicalLengthAnnotationPickedUpOnActionParameter() {
+ final TypicalLengthAnnotationOnParameterFacetFactory facetFactory = new TypicalLengthAnnotationOnParameterFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ public void someAction(@TypicalLength(20) final int foo) {
+ }
+ }
+ final Method method = findMethod(Customer.class, "someAction", new Class[] { int.class });
+
+ facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter));
+
+ final Facet facet = facetedMethodParameter.getFacet(TypicalLengthFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof TypicalLengthFacetAnnotationOnParameter);
+ final TypicalLengthFacetAnnotationOnParameter typicalLengthFacetAnnotation = (TypicalLengthFacetAnnotationOnParameter) facet;
+ assertEquals(20, typicalLengthFacetAnnotation.value());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mandatory/OptionalAnnotationFacetFactoryTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mandatory/OptionalAnnotationFacetFactoryTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mandatory/OptionalAnnotationFacetFactoryTest.java
new file mode 100644
index 0000000..cc1f18d
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mandatory/OptionalAnnotationFacetFactoryTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.propparam.validate.mandatory;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.annotation.Optional;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessMethodContext;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessParameterContext;
+import org.apache.isis.core.metamodel.facets.mandatory.MandatoryFacet;
+import org.apache.isis.core.progmodel.facets.AbstractFacetFactoryTest;
+import org.apache.isis.core.progmodel.facets.param.mandatory.annotation.MandatoryFacetInvertedByOptionalForParameter;
+import org.apache.isis.core.progmodel.facets.param.mandatory.annotation.OptionalAnnotationForParameterFacetFactory;
+import org.apache.isis.core.progmodel.facets.properties.mandatory.annotation.MandatoryFacetInvertedByOptionalForProperty;
+import org.apache.isis.core.progmodel.facets.properties.mandatory.annotation.OptionalAnnotationForPropertyFacetFactory;
+
+public class OptionalAnnotationFacetFactoryTest extends AbstractFacetFactoryTest {
+
+ public void testOptionalAnnotationPickedUpOnProperty() {
+ final OptionalAnnotationForPropertyFacetFactory facetFactory = new OptionalAnnotationForPropertyFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ @Optional
+ public String getFirstName() {
+ return null;
+ }
+ }
+ final Method method = findMethod(Customer.class, "getFirstName");
+
+ facetFactory.process(new ProcessMethodContext(Customer.class, method, methodRemover, facetedMethod));
+
+ final Facet facet = facetedMethod.getFacet(MandatoryFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof MandatoryFacetInvertedByOptionalForProperty);
+ }
+
+ public void testOptionalAnnotationPickedUpOnActionParameter() {
+ final OptionalAnnotationForParameterFacetFactory facetFactory = new OptionalAnnotationForParameterFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ public void someAction(@Optional final String foo) {
+ }
+ }
+ final Method method = findMethod(Customer.class, "someAction", new Class[] { String.class });
+
+ facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter));
+
+ final Facet facet = facetedMethodParameter.getFacet(MandatoryFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof MandatoryFacetInvertedByOptionalForParameter);
+ }
+
+ public void testOptionalAnnotationIgnoredForPrimitiveOnProperty() {
+ final OptionalAnnotationForPropertyFacetFactory facetFactory = new OptionalAnnotationForPropertyFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ @Optional
+ public int getNumberOfOrders() {
+ return 0;
+ }
+ }
+ final Method method = findMethod(Customer.class, "getNumberOfOrders");
+
+ facetFactory.process(new ProcessMethodContext(Customer.class, method, methodRemover, facetedMethod));
+
+ assertNull(facetedMethod.getFacet(MandatoryFacet.class));
+ }
+
+ public void testOptionalAnnotationIgnoredForPrimitiveOnActionParameter() {
+ final OptionalAnnotationForParameterFacetFactory facetFactory = new OptionalAnnotationForParameterFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ public void someAction(@Optional final int foo) {
+ }
+ }
+ final Method method = findMethod(Customer.class, "someAction", new Class[] { int.class });
+
+ facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter));
+
+ assertNull(facetedMethod.getFacet(MandatoryFacet.class));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mask/MaskAnnotationFacetFactoryTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mask/MaskAnnotationFacetFactoryTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mask/MaskAnnotationFacetFactoryTest.java
new file mode 100644
index 0000000..d9869f4
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mask/MaskAnnotationFacetFactoryTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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.propparam.validate.mask;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.annotation.Mask;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessClassContext;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessMethodContext;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessParameterContext;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.testspec.ObjectSpecificationStub;
+import org.apache.isis.core.progmodel.facets.AbstractFacetFactoryTest;
+import org.apache.isis.core.progmodel.facets.object.mask.MaskFacet;
+import org.apache.isis.core.progmodel.facets.object.mask.annotation.MaskAnnotationForTypeFacetFactory;
+import org.apache.isis.core.progmodel.facets.object.mask.annotation.MaskFacetAnnotationForType;
+import org.apache.isis.core.progmodel.facets.param.validate.maskannot.MaskAnnotationForParameterFacetFactory;
+import org.apache.isis.core.progmodel.facets.param.validate.maskannot.MaskFacetAnnotationForParameter;
+import org.apache.isis.core.progmodel.facets.properties.validate.maskannot.MaskAnnotationForPropertyFacetFactory;
+import org.apache.isis.core.progmodel.facets.properties.validate.maskannot.MaskFacetAnnotationForProperty;
+
+public class MaskAnnotationFacetFactoryTest extends AbstractFacetFactoryTest {
+
+ private final ObjectSpecification customerNoSpec = new ObjectSpecificationStub(String.class);
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ reflector.setLoadSpecificationStringReturn(customerNoSpec);
+ }
+
+ public void testMaskAnnotationPickedUpOnClass() {
+ final MaskAnnotationForTypeFacetFactory facetFactory = new MaskAnnotationForTypeFacetFactory();
+ facetFactory.setSpecificationLookup(reflector);
+
+ @Mask("###")
+ class Customer {
+ }
+ facetFactory.process(new ProcessClassContext(Customer.class, methodRemover, facetedMethod));
+
+ final Facet facet = facetedMethod.getFacet(MaskFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof MaskFacetAnnotationForType);
+ final MaskFacetAnnotationForType maskFacet = (MaskFacetAnnotationForType) facet;
+ assertEquals("###", maskFacet.value());
+ }
+
+ public void testMaskAnnotationPickedUpOnProperty() {
+ final MaskAnnotationForPropertyFacetFactory facetFactory = new MaskAnnotationForPropertyFacetFactory();
+ facetFactory.setSpecificationLookup(reflector);
+
+ class Customer {
+ @SuppressWarnings("unused")
+ @Mask("###")
+ public String getFirstName() {
+ return null;
+ }
+ }
+ final Method method = findMethod(Customer.class, "getFirstName");
+
+ facetFactory.process(new ProcessMethodContext(Customer.class, method, methodRemover, facetedMethod));
+
+ final Facet facet = facetedMethod.getFacet(MaskFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof MaskFacetAnnotationForProperty);
+ final MaskFacetAnnotationForProperty maskFacet = (MaskFacetAnnotationForProperty) facet;
+ assertEquals("###", maskFacet.value());
+ }
+
+ public void testMaskAnnotationPickedUpOnActionParameter() {
+ final MaskAnnotationForParameterFacetFactory facetFactory = new MaskAnnotationForParameterFacetFactory();
+ facetFactory.setSpecificationLookup(reflector);
+
+ class Customer {
+ @SuppressWarnings("unused")
+ public void someAction(@Mask("###") final String foo) {
+ }
+ }
+ final Method method = findMethod(Customer.class, "someAction", new Class[] { String.class });
+
+ facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter));
+
+ final Facet facet = facetedMethodParameter.getFacet(MaskFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof MaskFacetAnnotationForParameter);
+ final MaskFacetAnnotationForParameter maskFacet = (MaskFacetAnnotationForParameter) facet;
+ assertEquals("###", maskFacet.value());
+ }
+
+ public void testMaskAnnotationNotIgnoredForNonStringsProperty() {
+ final MaskAnnotationForPropertyFacetFactory facetFactory = new MaskAnnotationForPropertyFacetFactory();
+ facetFactory.setSpecificationLookup(reflector);
+
+ class Customer {
+ @SuppressWarnings("unused")
+ @Mask("###")
+ public int getNumberOfOrders() {
+ return 0;
+ }
+ }
+ final Method method = findMethod(Customer.class, "getNumberOfOrders");
+
+ facetFactory.process(new ProcessMethodContext(Customer.class, method, methodRemover, facetedMethod));
+
+ assertNotNull(facetedMethod.getFacet(MaskFacet.class));
+ }
+
+ public void testMaskAnnotationNotIgnoredForPrimitiveOnActionParameter() {
+ final MaskAnnotationForParameterFacetFactory facetFactory = new MaskAnnotationForParameterFacetFactory();
+ facetFactory.setSpecificationLookup(reflector);
+
+ class Customer {
+ @SuppressWarnings("unused")
+ public void someAction(@Mask("###") final int foo) {
+ }
+ }
+ final Method method = findMethod(Customer.class, "someAction", new Class[] { int.class });
+
+ facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter));
+
+ assertNotNull(facetedMethodParameter.getFacet(MaskFacet.class));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mask/MaskEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mask/MaskEvaluatorTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mask/MaskEvaluatorTest.java
new file mode 100644
index 0000000..5df727a
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/mask/MaskEvaluatorTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.propparam.validate.mask;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Locale;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import org.apache.isis.core.progmodel.facets.object.mask.MaskEvaluator;
+
+@RunWith(Parameterized.class)
+public class MaskEvaluatorTest {
+
+ @Parameters
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] { { "AAA", "aby", true }, { "A", "A", true }, { "A", "Z", true }, { "A", "a", true }, { "A", "z", true }, { "A", "0", true }, { "A", "9", true }, { "A", "@", false }, { "A", "~", false }, { "a", "A", true }, { "a", "Z", true }, { "a", "a", true },
+ { "a", "z", true }, { "a", "0", true }, { "a", "9", true }, { "a", " ", true }, { "a", "~", false }, { "9", "z", false }, { "9", "0", true }, { "9", "9", true }, { "9", " ", true }, { "9", "~", false }, { "&", "A", true }, { "&", "Z", true }, { "&", "a", true }, { "&", "z", true },
+ { "&", "9", false }, { "?", "A", true }, { "?", "Z", true }, { "?", "a", true }, { "?", "z", true }, { "U", "A", true }, { "U", "Z", true }, { "U", "a", false }, { "L", "a", true }, { "L", "z", true }, { "L", "A", false }, { "#", "0", true }, { "#", "9", true }, { "#", "X", false },
+ { "#", "#", false }, { ",", ",", true },
+ // {".", "X", false}, // TODO: failing so commented out
+ { ":", ":", true }, { ":", "X", false }, { "/", "/", true }, { "/", "X", false }, { "##", "23", true },
+ // {"##.#", "23.3", true}, // TODO: failing so commented out
+ });
+ }
+
+ private Locale previousLocale = Locale.getDefault();
+
+ @Before
+ public void setUp() {
+ previousLocale = Locale.getDefault();
+ Locale.setDefault(Locale.ENGLISH);
+ }
+
+ @After
+ public void tearDown() {
+ Locale.setDefault(previousLocale);
+ }
+
+ private final String mask;
+ private final String proposed;
+ private final boolean expected;
+
+ public MaskEvaluatorTest(final String mask, final String proposed, final boolean expected) {
+ this.mask = mask;
+ this.proposed = proposed;
+ this.expected = expected;
+ }
+
+ @Test
+ public void all() {
+ assertThat(new MaskEvaluator(mask).evaluate(proposed), is(expected));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/regex/RegExAnnotationFacetFactoryTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/regex/RegExAnnotationFacetFactoryTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/regex/RegExAnnotationFacetFactoryTest.java
new file mode 100644
index 0000000..bed6ab1
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/regex/RegExAnnotationFacetFactoryTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.propparam.validate.regex;
+
+import java.lang.reflect.Method;
+
+import org.apache.isis.applib.annotation.RegEx;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessClassContext;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessMethodContext;
+import org.apache.isis.core.metamodel.facets.FacetFactory.ProcessParameterContext;
+import org.apache.isis.core.progmodel.facets.AbstractFacetFactoryTest;
+import org.apache.isis.core.progmodel.facets.object.regex.RegExFacet;
+import org.apache.isis.core.progmodel.facets.object.regex.annotation.RegExFacetAnnotationForType;
+import org.apache.isis.core.progmodel.facets.object.regex.annotation.RegExFacetAnnotationForTypeFacetFactory;
+import org.apache.isis.core.progmodel.facets.param.validate.regexannot.RegExFacetAnnotationForParameter;
+import org.apache.isis.core.progmodel.facets.param.validate.regexannot.RegExFacetAnnotationForParameterFacetFactory;
+import org.apache.isis.core.progmodel.facets.properties.validate.regexannot.RegExFacetAnnotationForProperty;
+import org.apache.isis.core.progmodel.facets.properties.validate.regexannot.RegExFacetAnnotationForPropertyFacetFactory;
+
+public class RegExAnnotationFacetFactoryTest extends AbstractFacetFactoryTest {
+
+ public void testRegExAnnotationPickedUpOnClass() {
+ final RegExFacetAnnotationForTypeFacetFactory facetFactory = new RegExFacetAnnotationForTypeFacetFactory();
+
+ @RegEx(validation = "^A.*", caseSensitive = false)
+ class Customer {
+ }
+ facetFactory.process(new ProcessClassContext(Customer.class, methodRemover, facetedMethod));
+
+ final Facet facet = facetedMethod.getFacet(RegExFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof RegExFacetAnnotationForType);
+ final RegExFacetAnnotationForType regExFacet = (RegExFacetAnnotationForType) facet;
+ assertEquals("^A.*", regExFacet.validation());
+ assertEquals(false, regExFacet.caseSensitive());
+ }
+
+ public void testRegExAnnotationPickedUpOnProperty() {
+ final RegExFacetAnnotationForPropertyFacetFactory facetFactory = new RegExFacetAnnotationForPropertyFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ @RegEx(validation = "^A.*", caseSensitive = false)
+ public String getFirstName() {
+ return null;
+ }
+ }
+ final Method method = findMethod(Customer.class, "getFirstName");
+
+ facetFactory.process(new ProcessMethodContext(Customer.class, method, methodRemover, facetedMethod));
+
+ final Facet facet = facetedMethod.getFacet(RegExFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof RegExFacetAnnotationForProperty);
+ final RegExFacetAnnotationForProperty regExFacet = (RegExFacetAnnotationForProperty) facet;
+ assertEquals("^A.*", regExFacet.validation());
+ assertEquals(false, regExFacet.caseSensitive());
+ }
+
+ public void testRegExAnnotationPickedUpOnActionParameter() {
+ final RegExFacetAnnotationForParameterFacetFactory facetFactory = new RegExFacetAnnotationForParameterFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ public void someAction(@RegEx(validation = "^A.*", caseSensitive = false) final String foo) {
+ }
+ }
+ final Method method = findMethod(Customer.class, "someAction", new Class[] { String.class });
+
+ facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter));
+
+ final Facet facet = facetedMethodParameter.getFacet(RegExFacet.class);
+ assertNotNull(facet);
+ assertTrue(facet instanceof RegExFacetAnnotationForParameter);
+ final RegExFacetAnnotationForParameter regExFacet = (RegExFacetAnnotationForParameter) facet;
+ assertEquals("^A.*", regExFacet.validation());
+ assertEquals(false, regExFacet.caseSensitive());
+ }
+
+ public void testRegExAnnotationIgnoredForNonStringsProperty() {
+ final RegExFacetAnnotationForParameterFacetFactory facetFactory = new RegExFacetAnnotationForParameterFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ @RegEx(validation = "^A.*", caseSensitive = false)
+ public int getNumberOfOrders() {
+ return 0;
+ }
+ }
+ final Method method = findMethod(Customer.class, "getNumberOfOrders");
+
+ facetFactory.process(new ProcessMethodContext(Customer.class, method, methodRemover, facetedMethod));
+
+ assertNull(facetedMethod.getFacet(RegExFacet.class));
+ }
+
+ public void testRegExAnnotationIgnoredForPrimitiveOnActionParameter() {
+ final RegExFacetAnnotationForParameterFacetFactory facetFactory = new RegExFacetAnnotationForParameterFacetFactory();
+
+ class Customer {
+ @SuppressWarnings("unused")
+ public void someAction(@RegEx(validation = "^A.*", caseSensitive = false) final int foo) {
+ }
+ }
+ final Method method = findMethod(Customer.class, "someAction", new Class[] { int.class });
+
+ facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter));
+
+ assertNull(facetedMethod.getFacet(RegExFacet.class));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/regex/RegExFacetAnnotationTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/regex/RegExFacetAnnotationTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/regex/RegExFacetAnnotationTest.java
new file mode 100644
index 0000000..c08b5dc
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/propparam/validate/regex/RegExFacetAnnotationTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.propparam.validate.regex;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+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.facetapi.FacetHolder;
+import org.apache.isis.core.progmodel.facets.object.regex.annotation.RegExFacetAnnotationForType;
+
+@RunWith(JMock.class)
+public class RegExFacetAnnotationTest {
+
+ private final Mockery context = new JUnit4Mockery();
+
+ private RegExFacetAnnotationForType regExFacetAnnotationForType;
+ private FacetHolder facetHolder;
+
+ @Before
+ public void setUp() throws Exception {
+ facetHolder = context.mock(FacetHolder.class);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ facetHolder = null;
+ regExFacetAnnotationForType = null;
+ }
+
+ @Test
+ public void shouldBeAbleToInstantiate() {
+ regExFacetAnnotationForType = new RegExFacetAnnotationForType(".*", "", true, facetHolder);
+ }
+
+ @Test
+ public void shouldAllowDotStar() {
+ regExFacetAnnotationForType = new RegExFacetAnnotationForType(".*", "", true, facetHolder);
+ assertThat(regExFacetAnnotationForType.doesNotMatch("abc"), equalTo(false)); // ie
+ // does
+ // match
+ }
+
+ @Test
+ public void shouldAllowWhenCaseSensitive() {
+ regExFacetAnnotationForType = new RegExFacetAnnotationForType("^abc$", "", true, facetHolder);
+ assertThat(regExFacetAnnotationForType.doesNotMatch("abc"), equalTo(false)); // ie
+ // does
+ // match
+ }
+
+ @Test
+ public void shouldAllowWhenCaseInsensitive() {
+ regExFacetAnnotationForType = new RegExFacetAnnotationForType("^abc$", "", false, facetHolder);
+ assertThat(regExFacetAnnotationForType.doesNotMatch("ABC"), equalTo(false)); // ie
+ // does
+ // match
+ }
+
+ @Test
+ public void shouldDisallowWhenCaseSensitive() {
+ regExFacetAnnotationForType = new RegExFacetAnnotationForType("^abc$", "", true, facetHolder);
+ assertThat(regExFacetAnnotationForType.doesNotMatch("abC"), equalTo(true));
+ }
+
+ @Test
+ public void shouldDisallowWhenCaseInsensitive() {
+ regExFacetAnnotationForType = new RegExFacetAnnotationForType("^abc$", "", false, facetHolder);
+ assertThat(regExFacetAnnotationForType.doesNotMatch("aBd"), equalTo(true));
+ }
+
+ @Test
+ public void shouldReformat() {
+ regExFacetAnnotationForType = new RegExFacetAnnotationForType("^([0-9]{2})([0-9]{2})([0-9]{2})$", "$1-$2-$3", false, facetHolder);
+ assertThat(regExFacetAnnotationForType.doesNotMatch("123456"), equalTo(false));
+ assertThat(regExFacetAnnotationForType.format("123456"), equalTo("12-34-56"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BigDecimalValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BigDecimalValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BigDecimalValueSemanticsProviderTest.java
new file mode 100644
index 0000000..69a61ce
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BigDecimalValueSemanticsProviderTest.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 java.math.BigDecimal;
+
+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.bigdecimal.BigDecimalValueSemanticsProvider;
+
+public class BigDecimalValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private BigDecimalValueSemanticsProvider value;
+ private BigDecimal bigDecimal;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.decimal");
+ will(returnValue(null));
+ }
+ });
+
+ bigDecimal = new BigDecimal("34132.199");
+ allowMockAdapterToReturn(bigDecimal);
+ holder = new FacetHolderImpl();
+
+ setValue(value = new BigDecimalValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testParseValidString() throws Exception {
+ final Object newValue = value.parseTextEntry(null, "2142342334", null);
+ assertEquals(new BigDecimal(2142342334L), newValue);
+ }
+
+ @Test
+ public void testParseInvalidString() throws Exception {
+ try {
+ value.parseTextEntry(null, "214xxx2342334", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("34,132.199", value.displayTitleOf(bigDecimal, (Localization) null));
+ }
+
+ @Test
+ public void testEncode() {
+ assertEquals("34132.199", value.toEncodedString(bigDecimal));
+ }
+
+ @Test
+ public void testDecode() throws Exception {
+ final Object newValue = value.fromEncodedString("4322.89991");
+ assertEquals(new BigDecimal("4322.89991"), 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/BigIntValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BigIntValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BigIntValueSemanticsProviderTest.java
new file mode 100644
index 0000000..64b536b
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BigIntValueSemanticsProviderTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.math.BigInteger;
+
+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.biginteger.BigIntegerValueSemanticsProvider;
+
+public class BigIntValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private BigInteger bigInt;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ bigInt = new BigInteger("132199");
+ allowMockAdapterToReturn(bigInt);
+
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.int");
+ will(returnValue(null));
+ }
+ });
+
+ holder = new FacetHolderImpl();
+ setValue(new BigIntegerValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testParseValidString() throws Exception {
+ final Object newValue = getValue().parseTextEntry(null, "2142342334", null);
+ assertEquals(new BigInteger("2142342334"), newValue);
+ }
+
+ @Test
+ public void testParseInvalidString() throws Exception {
+ try {
+ getValue().parseTextEntry(null, "214xxx2342334", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitle() throws Exception {
+ assertEquals("132,199", getValue().displayTitleOf(bigInt, (Localization) null));
+ }
+
+ @Test
+ public void testEncode() throws Exception {
+ assertEquals("132199", getValue().toEncodedString(bigInt));
+ }
+
+ @Test
+ public void testDecode() throws Exception {
+ final Object newValue = getValue().fromEncodedString("432289991");
+ assertEquals(new BigInteger("432289991"), 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/BlobValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BlobValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BlobValueSemanticsProviderTest.java
new file mode 100644
index 0000000..0f66141
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BlobValueSemanticsProviderTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.value.Blob;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.blobs.BlobValueSemanticsProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BlobValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private BlobValueSemanticsProvider value;
+ private Blob blob;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ blob = new Blob("myfile1.docx", "application", "vnd.ms-word", new byte[]{1,2,3,4});
+ allowMockAdapterToReturn(blob);
+ holder = new FacetHolderImpl();
+
+ setValue(value = new BlobValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("myfile1.docx", value.displayTitleOf(blob, (Localization) null));
+ }
+
+ @Test
+ public void testEncode_and_decode() {
+ String encoded = value.toEncodedString(blob);
+ assertEquals("myfile1.docx:application/vnd.ms-word:AQIDBA==", encoded);
+ Blob decoded = value.fromEncodedString(encoded);
+ assertThat(decoded.getName(), is("myfile1.docx"));
+ assertThat(decoded.getMimeType().getPrimaryType(), is("application"));
+ assertThat(decoded.getMimeType().getSubType(), is("vnd.ms-word"));
+ assertThat(decoded.getBytes().length, is(4));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BooleanValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BooleanValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BooleanValueSemanticsProviderTest.java
new file mode 100644
index 0000000..e86fb8b
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/BooleanValueSemanticsProviderTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.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.booleans.BooleanValueSemanticsProviderAbstract;
+import org.apache.isis.core.progmodel.facets.value.booleans.BooleanWrapperValueSemanticsProvider;
+
+public class BooleanValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private BooleanValueSemanticsProviderAbstract value;
+
+ private Object booleanObj;
+ private FacetHolder facetHolder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ booleanObj = Boolean.valueOf(true);
+ facetHolder = new FacetHolderImpl();
+ setValue(value = new BooleanWrapperValueSemanticsProvider(facetHolder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testParseFalseString() throws Exception {
+ final Object parsed = value.parseTextEntry(null, "faLSe", null);
+ assertEquals(Boolean.valueOf(false), parsed);
+ }
+
+ @Test
+ public void testParseStringWithPrecedingSpace() throws Exception {
+ final Object parsed = value.parseTextEntry(null, " false", null);
+ assertEquals(Boolean.valueOf(false), parsed);
+ }
+
+ @Test
+ public void testParseStringWithTrailingSpace() throws Exception {
+ final Object parsed = value.parseTextEntry(null, " false", null);
+ assertEquals(Boolean.valueOf(false), parsed);
+ }
+
+ @Test
+ public void testParseTrueString() throws Exception {
+ final Object parsed = value.parseTextEntry(null, "TRue", null);
+ assertEquals(Boolean.valueOf(true), parsed);
+ }
+
+ @Test
+ public void testParseInvalidString() throws Exception {
+ try {
+ value.parseTextEntry(null, "yes", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitle() throws Exception {
+ assertEquals("True", value.displayTitleOf(booleanObj, (Localization) null));
+ }
+
+ @Test
+ public void testTitleWhenNotSet() throws Exception {
+ assertEquals("", value.titleString(null, null));
+ }
+
+ @Test
+ public void testEncode() throws Exception {
+ assertEquals("T", value.toEncodedString(booleanObj));
+ }
+
+ @Test
+ public void testDecode() throws Exception {
+ final Object parsed = value.fromEncodedString("T");
+ assertEquals(Boolean.valueOf(true), parsed);
+ }
+
+ @Test
+ public void testIsSet() {
+ allowMockAdapterToReturn(Boolean.valueOf(true));
+ assertEquals(true, value.isSet(mockAdapter));
+ }
+
+ @Test
+ public void testIsNotSet() {
+ allowMockAdapterToReturn(Boolean.valueOf(false));
+ assertEquals(false, value.isSet(mockAdapter));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ByteValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ByteValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ByteValueSemanticsProviderTest.java
new file mode 100644
index 0000000..ece06ba
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ByteValueSemanticsProviderTest.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.bytes.ByteValueSemanticsProviderAbstract;
+import org.apache.isis.core.progmodel.facets.value.bytes.ByteWrapperValueSemanticsProvider;
+
+public class ByteValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private ByteValueSemanticsProviderAbstract value;
+
+ private Byte byteObj;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ byteObj = Byte.valueOf((byte) 102);
+ allowMockAdapterToReturn(byteObj);
+ holder = new FacetHolderImpl();
+
+ context.checking(new Expectations() {
+ {
+ allowing(mockConfiguration).getString("isis.value.format.byte");
+ will(returnValue(null));
+ }
+ });
+
+ setValue(value = new ByteWrapperValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testParseValidString() throws Exception {
+ final Object parsed = value.parseTextEntry(null, "21", null);
+ assertEquals(Byte.valueOf((byte) 21), parsed);
+ }
+
+ @Test
+ public void testParseInvalidString() throws Exception {
+ try {
+ value.parseTextEntry(null, "xs21z4xxx23", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleOf() throws Exception {
+ assertEquals("102", value.displayTitleOf(byteObj, (Localization) null));
+ }
+
+ @Test
+ public void testEncode() throws Exception {
+ assertEquals("102", value.toEncodedString(byteObj));
+ }
+
+ @Test
+ public void testDecode() throws Exception {
+ final Object parsed = value.fromEncodedString("-91");
+ assertEquals(Byte.valueOf((byte) -91), parsed);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/CharacterValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/CharacterValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/CharacterValueSemanticsProviderTest.java
new file mode 100644
index 0000000..2dbc3c1
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/CharacterValueSemanticsProviderTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.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.InvalidEntryException;
+import org.apache.isis.core.progmodel.facets.value.chars.CharValueSemanticsProviderAbstract;
+import org.apache.isis.core.progmodel.facets.value.chars.CharWrapperValueSemanticsProvider;
+
+public class CharacterValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private CharValueSemanticsProviderAbstract value;
+
+ private Character character;
+
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ character = Character.valueOf('r');
+ holder = new FacetHolderImpl();
+ setValue(value = new CharWrapperValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testParseLongString() throws Exception {
+ try {
+ value.parseTextEntry(null, "one", null);
+ fail();
+ } catch (final InvalidEntryException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("r", value.displayTitleOf(character, (Localization) null));
+ }
+
+ @Test
+ public void testValidParse() throws Exception {
+ final Object parse = value.parseTextEntry(null, "t", null);
+ assertEquals(Character.valueOf('t'), parse);
+ }
+
+ @Test
+ public void testEncode() throws Exception {
+ assertEquals("r", value.toEncodedString(character));
+ }
+
+ @Test
+ public void testDecode() throws Exception {
+ final Object restore = value.fromEncodedString("Y");
+ assertEquals(Character.valueOf('Y'), restore);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ClobValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ClobValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ClobValueSemanticsProviderTest.java
new file mode 100644
index 0000000..94c8ba5
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ClobValueSemanticsProviderTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.value.Clob;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.clobs.ClobValueSemanticsProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ClobValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private ClobValueSemanticsProvider value;
+ private Clob clob;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ clob = new Clob("myfile1.xml", "application", "xml", "abcdef");
+ allowMockAdapterToReturn(clob);
+ holder = new FacetHolderImpl();
+
+ setValue(value = new ClobValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("myfile1.xml", value.displayTitleOf(clob, (Localization) null));
+ }
+
+ @Test
+ public void testEncode_and_decode() {
+ String encoded = value.toEncodedString(clob);
+ assertEquals("myfile1.xml:application/xml:abcdef", encoded);
+ Clob decoded = value.fromEncodedString(encoded);
+ assertThat(decoded.getName(), is("myfile1.xml"));
+ assertThat(decoded.getMimeType().getPrimaryType(), is("application"));
+ assertThat(decoded.getMimeType().getSubType(), is("xml"));
+ assertThat(decoded.getChars(), is((CharSequence)"abcdef"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ColorValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ColorValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ColorValueSemanticsProviderTest.java
new file mode 100644
index 0000000..c9c4255
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/ColorValueSemanticsProviderTest.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 org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.applib.value.Color;
+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.color.ColorValueSemanticsProvider;
+
+public class ColorValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private ColorValueSemanticsProvider value;
+ private Color color;
+ private FacetHolder holder;
+
+ @Before
+ public void setUpObjects() throws Exception {
+ color = new Color(0x3366ff);
+ allowMockAdapterToReturn(color);
+ holder = new FacetHolderImpl();
+
+ setValue(value = new ColorValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testParseValidString() throws Exception {
+ final Object newValue = value.parseTextEntry(null, "#3366fF", null);
+ assertEquals(color, newValue);
+ }
+
+ @Test
+ public void testParseInvalidString() throws Exception {
+ try {
+ value.parseTextEntry(null, "red", null);
+ fail();
+ } catch (final TextEntryParseException expected) {
+ }
+ }
+
+ @Test
+ public void testTitleOf() {
+ assertEquals("#3366FF", value.displayTitleOf(color, (Localization) null));
+ }
+
+ @Test
+ public void testTitleOfBlack() {
+ assertEquals("Black", value.displayTitleOf(new Color(0), (Localization) null));
+ }
+
+ @Test
+ public void testTitleOfWhite() {
+ assertEquals("White", value.displayTitleOf(new Color(0xffffff), (Localization) null));
+ }
+
+ @Test
+ public void testEncode() {
+ assertEquals("3366ff", value.toEncodedString(color));
+ }
+
+ @Test
+ public void testDecode() throws Exception {
+ final Object newValue = value.fromEncodedString("3366ff");
+ assertEquals(color, 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/DateTimeValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DateTimeValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DateTimeValueSemanticsProviderTest.java
new file mode 100644
index 0000000..dbf8f71
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DateTimeValueSemanticsProviderTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.DateTime;
+import org.apache.isis.core.metamodel.facetapi.FacetHolder;
+import org.apache.isis.core.metamodel.facetapi.FacetHolderImpl;
+import org.apache.isis.core.progmodel.facets.value.datetime.DateTimeValueSemanticsProvider;
+
+public class DateTimeValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private DateTimeValueSemanticsProvider adapter;
+ 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();
+ holder = new FacetHolderImpl();
+ setValue(adapter = new DateTimeValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testNow() {
+ assertEntry("now", 2003, 8, 17, 21, 30, 25);
+ }
+
+ @Test
+ public void testToday() {
+ assertEntry("today", 2003, 8, 17, 21, 30, 25);
+ }
+
+ @Test
+ public void testEntryWithShortFormat() {
+ final String entry = "21/5/07 10:30";
+ final int year = 2007;
+ final int month = 5;
+ final int day = 21;
+ final int hour = 10;
+ final int minute = 30;
+ assertEntry(entry, year, month, day, hour, minute, 0);
+
+ // assertEquals("21-May-2007 10:30", adapter.titleString(null));
+ }
+
+ private void assertEntry(final String entry, final int year, final int month, final int day, final int hour, final int minute, final int second) {
+ final Object object = adapter.parseTextEntry(null, entry, null);
+ assertEquals(new DateTime(year, month, day, hour, minute, second), object);
+ }
+
+ @Test
+ public void testEntryWithMediumFormat() {
+ assertEntry("21-May-2007 10:30", 2007, 5, 21, 10, 30, 0);
+ }
+
+ @Test
+ public void testEntryWithShortISOFormat() {
+ assertEntry("20070521T1030", 2007, 5, 21, 10, 30, 0);
+ }
+
+ @Test
+ public void testEntryWithLongISOFormat() {
+ assertEntry("2007-05-21 10:30", 2007, 5, 21, 10, 30, 0);
+ }
+
+ @Test
+ public void testEntryWithLongISOFormatAndSeconds() {
+ assertEntry("2007-05-21 10:30:40", 2007, 5, 21, 10, 30, 40);
+ }
+
+ @Test
+ public void testEmptyClears() {
+ assertNull(adapter.parseTextEntry(null, "", null));
+ }
+
+ @Test
+ public void testAddDayAndMonth() {
+ assertEntry("+1d 1m", 2003, 9, 18, 21, 30, 25);
+ }
+
+ @Test
+ public void testSubtractDayAndMonth() {
+ assertEntry("-1d 1m", 2003, 7, 16, 21, 30, 25);
+ }
+
+ @Test
+ public void testAddOneDay() {
+ assertEntry("+1d", 2003, 8, 18, 21, 30, 25);
+ }
+
+ @Test
+ public void testSubtractOneDay() {
+ assertEntry("-1d", 2003, 8, 16, 21, 30, 25);
+ }
+
+ @Test
+ public void testAddOneMonth() {
+ assertEntry("+1m", 2003, 9, 17, 21, 30, 25);
+ }
+
+ @Test
+ public void testAddOneYear() {
+ assertEntry("+1y", 2004, 8, 17, 21, 30, 25);
+ }
+
+ @Test
+ public void testAddOneHour() {
+ assertEntry("+1H", 2003, 8, 17, 22, 30, 25);
+ }
+
+ @Test
+ public void testAddOneMinute() {
+ assertEntry("+1M", 2003, 8, 17, 21, 31, 25);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/e4735c72/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DateValueSemanticsProviderTest.java
----------------------------------------------------------------------
diff --git a/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DateValueSemanticsProviderTest.java b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DateValueSemanticsProviderTest.java
new file mode 100644
index 0000000..5c89a99
--- /dev/null
+++ b/framework/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/value/DateValueSemanticsProviderTest.java
@@ -0,0 +1,154 @@
+/*
+ * 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.adapters.EncodingException;
+import org.apache.isis.applib.value.Date;
+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.date.DateValueSemanticsProvider;
+
+public class DateValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
+
+ private DateValueSemanticsProvider 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(2001, 2, 4);
+ holder = new FacetHolderImpl();
+ setValue(adapter = new DateValueSemanticsProvider(holder, mockConfiguration, mockContext));
+ }
+
+ @Test
+ public void testDateAsEncodedString() throws Exception {
+ assertEquals("20010204", adapter.toEncodedString(date));
+ }
+
+ @Test
+ public void testParseEntryOfDaysAfterDate() throws Exception {
+ final Date parsed = adapter.parseTextEntry(date, "+7", null);
+ assertEquals(new Date(2001, 2, 11), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfDaysAfterToToday() throws Exception {
+ final Date parsed = adapter.parseTextEntry(null, "+5", null);
+ assertEquals(new Date(2003, 8, 22), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfDaysBeforeDate() throws Exception {
+ final Date parsed = adapter.parseTextEntry(date, "-7", null);
+ assertEquals(new Date(2001, 1, 28), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfDaysBeforeToToday() throws Exception {
+ final Date parsed = adapter.parseTextEntry(null, "-5", null);
+ assertEquals(new Date(2003, 8, 12), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfKeywordToday() throws Exception {
+ final Date parsed = adapter.parseTextEntry(date, "today", null);
+ assertEquals(new Date(2003, 8, 17), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfWeeksAfterDate() throws Exception {
+ final Date parsed = adapter.parseTextEntry(date, "+3w", null);
+ assertEquals(new Date(2001, 2, 25), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfWeeksAfterToToday() throws Exception {
+ final Date parsed = adapter.parseTextEntry(null, "+4w", null);
+ assertEquals(new Date(2003, 9, 14), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfWeeksBeforeDate() throws Exception {
+ final Date parsed = adapter.parseTextEntry(date, "-3w", null);
+ assertEquals(new Date(2001, 1, 14), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfWeeksBeforeToToday() throws Exception {
+ final Date parsed = adapter.parseTextEntry(null, "-4w", null);
+ assertEquals(new Date(2003, 7, 20), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfMonthsAfterDate() throws Exception {
+ final Date parsed = adapter.parseTextEntry(date, "+3m", null);
+ assertEquals(new Date(2001, 5, 4), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfMonthsAfterToToday() throws Exception {
+ final Date parsed = adapter.parseTextEntry(null, "+4m", null);
+ assertEquals(new Date(2003, 12, 17), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfMonthsBeforeDate() throws Exception {
+ final Date parsed = adapter.parseTextEntry(date, "-3m", null);
+ assertEquals(new Date(2000, 11, 4), parsed);
+ }
+
+ @Test
+ public void testParseEntryOfMonthsBeforeToToday() throws Exception {
+ final Date parsed = adapter.parseTextEntry(null, "-4m", null);
+ assertEquals(new Date(2003, 4, 17), parsed);
+ }
+
+ @Test(expected = TextEntryParseException.class)
+ public void illegalEntry() throws Exception {
+ adapter.parseTextEntry(null, "xxx", null);
+ }
+
+ @Test
+ public void testRestoreOfInvalidDatal() throws Exception {
+ try {
+ adapter.fromEncodedString("2003may12");
+ fail();
+ } catch (final EncodingException expected) {
+ }
+ }
+
+}