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/06 11:10:35 UTC
[27/51] [partial] ISIS-188: moving modules into core
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/ContainedObjectTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/ContainedObjectTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/ContainedObjectTest.java
new file mode 100644
index 0000000..f638dc7
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/ContainedObjectTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.applib;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.security.UserMemento;
+
+public class ContainedObjectTest {
+
+ private DomainObjectContainer container;
+ private AbstractContainedObject object;
+ private Mockery context;
+
+ @Before
+ public void setUp() throws Exception {
+ context = new Mockery();
+ container = context.mock(DomainObjectContainer.class);
+ object = new AbstractContainedObject() {
+ };
+ object.setContainer(container);
+ }
+
+ @Test
+ public void testContainer() throws Exception {
+ assertEquals(container, object.getContainer());
+ }
+
+ @Test
+ public void testInformUser() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(container).informUser("message");
+ }
+ });
+
+ object.informUser("message");
+
+ context.assertIsSatisfied();
+ }
+
+ @Test
+ public void testWarnUser() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(container).warnUser("message");
+ }
+ });
+
+ object.warnUser("message");
+
+ context.assertIsSatisfied();
+ }
+
+ @Test
+ public void testRaiseError() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(container).raiseError("message");
+ }
+ });
+
+ object.raiseError("message");
+
+ context.assertIsSatisfied();
+ }
+
+ @Test
+ public void testGetUser() throws Exception {
+ final UserMemento memento = new UserMemento("Harry");
+ context.checking(new Expectations() {
+ {
+ one(container).getUser();
+ will(returnValue(memento));
+
+ }
+ });
+
+ final UserMemento user = object.getUser();
+ assertEquals(memento, user);
+
+ context.assertIsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/FactoryAndRepositoryTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/FactoryAndRepositoryTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/FactoryAndRepositoryTest.java
new file mode 100644
index 0000000..65683aa
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/FactoryAndRepositoryTest.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.applib;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(JMock.class)
+public class FactoryAndRepositoryTest {
+
+ public static class TestDomainObject {
+ }
+
+ private DomainObjectContainer container;
+ private AbstractFactoryAndRepository object;
+ private Mockery context;
+
+ @Before
+ public void setUp() throws Exception {
+ context = new Mockery();
+ container = context.mock(DomainObjectContainer.class);
+ object = new AbstractFactoryAndRepository() {
+ };
+ object.setContainer(container);
+ }
+
+ @Test
+ public void testContainer() throws Exception {
+ assertEquals(container, object.getContainer());
+ }
+
+ @Test
+ public void testInformUser() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(container).informUser("message");
+ }
+ });
+
+ object.informUser("message");
+ }
+
+ @Test
+ public void testWarnUser() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(container).warnUser("message");
+ }
+ });
+
+ object.warnUser("message");
+ }
+
+ @Test
+ public void testRaiseError() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(container).raiseError("message");
+ }
+ });
+
+ object.raiseError("message");
+ }
+
+ @Test
+ public void testAllInstances() throws Exception {
+ final List<Object> list = new ArrayList<Object>();
+ list.add(new TestDomainObject());
+ list.add(new TestDomainObject());
+ list.add(new TestDomainObject());
+
+ context.checking(new Expectations() {
+ {
+ one(container).allInstances(TestDomainObject.class);
+ will(returnValue(list));
+ }
+ });
+
+ final List<TestDomainObject> allInstances = object.allInstances(TestDomainObject.class);
+ assertThat(allInstances.size(), is(3));
+ assertThat(allInstances.get(0), notNullValue());
+ assertThat(allInstances.get(0), equalTo(list.get(0)));
+ assertThat(allInstances.get(1), equalTo(list.get(1)));
+ assertThat(allInstances.get(2), equalTo(list.get(2)));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/IdentifierTests.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/IdentifierTests.java b/framework/core/applib/src/test/java/org/apache/isis/applib/IdentifierTests.java
new file mode 100644
index 0000000..955f274
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/IdentifierTests.java
@@ -0,0 +1,69 @@
+/*
+ * 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.applib;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class IdentifierTests {
+
+ private Identifier identifier;
+
+ @Before
+ public void setUp() {
+ }
+
+ @Test
+ public void canInstantiateClassIdentifier() {
+ identifier = Identifier.classIdentifier(SomeDomainClass.class);
+ assertThat(identifier, is(not(nullValue())));
+ }
+
+ @Test
+ public void classIdentifierClassNameIsSet() {
+ final Class<?> domainClass = SomeDomainClass.class;
+ final String domainClassFullyQualifiedName = domainClass.getCanonicalName();
+ identifier = Identifier.classIdentifier(domainClass);
+ assertThat(identifier.getClassName(), is(domainClassFullyQualifiedName));
+ }
+
+ @Test
+ public void memberParameterNames() {
+ final Class<?> domainClass = SomeDomainClass.class;
+ identifier = Identifier.actionIdentifier(domainClass, "placeOrder", int.class, String.class);
+ assertThat(identifier.getMemberParameterNames(), is(Arrays.asList("int", "java.lang.String")));
+ }
+
+ @Test
+ public void paramsIdentityString() {
+ final Class<?> domainClass = SomeDomainClass.class;
+ identifier = Identifier.actionIdentifier(domainClass, "placeOrder", int.class, String.class, BigDecimal.class);
+ assertThat(identifier.toParmsIdentityString(), is("(int,java.lang.String,java.math.BigDecimal)"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/SomeDomainClass.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/SomeDomainClass.java b/framework/core/applib/src/test/java/org/apache/isis/applib/SomeDomainClass.java
new file mode 100644
index 0000000..568ae04
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/SomeDomainClass.java
@@ -0,0 +1,24 @@
+/*
+ * 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.applib;
+
+public class SomeDomainClass {
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/events/InteractionEventTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/events/InteractionEventTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/events/InteractionEventTest.java
new file mode 100644
index 0000000..1a6bf3d
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/events/InteractionEventTest.java
@@ -0,0 +1,149 @@
+/*
+ * 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.applib.events;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+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.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.isis.applib.Identifier;
+
+@RunWith(JMock.class)
+public class InteractionEventTest {
+
+ @SuppressWarnings("unused")
+ private final Mockery mockery = new JUnit4Mockery();
+
+ private InteractionEvent interactionEvent;
+
+ private Object source;
+ private Identifier identifier;
+
+ private Class<? extends InteractionEventTest> advisorClass;
+
+ @Before
+ public void setUp() {
+ source = new Object();
+ identifier = Identifier.actionIdentifier("CustomerOrder", "cancelOrder", new Class[] { String.class, boolean.class });
+ advisorClass = this.getClass();
+ }
+
+ @Test
+ public void getIdentifier() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ assertThat(interactionEvent.getIdentifier(), is(identifier));
+ }
+
+ @Test
+ public void getSource() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ assertThat(interactionEvent.getSource(), is(source));
+ }
+
+ @Test
+ public void getClassName() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ assertThat(interactionEvent.getClassName(), equalTo("CustomerOrder"));
+ }
+
+ @Test
+ public void getClassNaturalName() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ assertThat(interactionEvent.getClassNaturalName(), equalTo("Customer Order"));
+ }
+
+ @Test
+ public void getMember() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ assertThat(interactionEvent.getMemberName(), equalTo("cancelOrder"));
+ }
+
+ @Test
+ public void getMemberNaturalName() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ assertThat(interactionEvent.getMemberNaturalName(), equalTo("Cancel Order"));
+ }
+
+ @Test
+ public void shouldInitiallyNotVeto() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ assertThat(interactionEvent.isVeto(), is(false));
+ }
+
+ @Test
+ public void afterAdvisedShouldVeto() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ interactionEvent.advised("some reason", this.getClass());
+ assertThat(interactionEvent.isVeto(), is(true));
+ }
+
+ @Test
+ public void afterAdvisedShouldReturnReason() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ interactionEvent.advised("some reason", this.getClass());
+ assertThat(interactionEvent.isVeto(), is(true));
+ }
+
+ @Test
+ public void afterAdvisedShouldReturnAdvisorClass() {
+ interactionEvent = new InteractionEvent(source, identifier) {
+
+ private static final long serialVersionUID = 1L;
+ };
+ interactionEvent.advised("some reason", advisorClass);
+ assertEquals(interactionEvent.getAdvisorClass(), advisorClass);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/fixtures/FixtureClockInstantiationTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/fixtures/FixtureClockInstantiationTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/fixtures/FixtureClockInstantiationTest.java
new file mode 100644
index 0000000..f7ae7c6
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/fixtures/FixtureClockInstantiationTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.applib.fixtures;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.clock.Clock;
+
+public class FixtureClockInstantiationTest {
+
+ @Before
+ public void setUp() {
+
+ }
+
+ @Test
+ public void shouldSetupClockSingletonWithFixtureClockWhenInitialize() {
+ FixtureClock.initialize();
+ assertThat(Clock.getInstance(), is(instanceOf(FixtureClock.class)));
+ }
+
+ @Test
+ public void canInitializeFixtureClockMultipleTimesButAlwaysGetTheSameFixtureClock() {
+ final FixtureClock fixtureClock1 = FixtureClock.initialize();
+ final FixtureClock fixtureClock2 = FixtureClock.initialize();
+ assertThat(fixtureClock1, is(fixtureClock2));
+ }
+
+ @Test
+ public void canRemoveFixtureClock() {
+ FixtureClock.initialize();
+ assertThat(FixtureClock.remove(), is(true));
+ assertThat(FixtureClock.remove(), is(false)); // already removed.
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/spec/SpecificationAbstractTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/spec/SpecificationAbstractTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/spec/SpecificationAbstractTest.java
new file mode 100644
index 0000000..5650c20
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/spec/SpecificationAbstractTest.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.applib.spec;
+
+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.AbstractSpecification.Nullability;
+import org.apache.isis.applib.spec.AbstractSpecification.TypeChecking;
+
+public class SpecificationAbstractTest {
+
+ private static class SomeDomainObject {
+ }
+
+ private static class SomeOtherDomainObject {
+ }
+
+ private AbstractSpecification<SomeDomainObject> specAbstractSomeDomainObject;
+
+ @Test
+ public void shouldSatisfyByDefaultForNull() {
+ specAbstractSomeDomainObject = new AbstractSpecification<SomeDomainObject>() {
+ @Override
+ public String satisfiesSafely(final SomeDomainObject obj) {
+ return null;
+ }
+ };
+ assertThat(specAbstractSomeDomainObject.satisfies(null), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotSatisfyForNullIfConfiguredAsSuch() {
+ specAbstractSomeDomainObject = new AbstractSpecification<SomeDomainObject>(Nullability.ENSURE_NOT_NULL, TypeChecking.IGNORE_INCORRECT_TYPE) {
+ @Override
+ public String satisfiesSafely(final SomeDomainObject obj) {
+ return null;
+ }
+ };
+ assertThat(specAbstractSomeDomainObject.satisfies(null), is(not(nullValue())));
+ }
+
+ @Test
+ public void shouldSatisfyByDefaultForIncorrectType() {
+ specAbstractSomeDomainObject = new AbstractSpecification<SomeDomainObject>() {
+ @Override
+ public String satisfiesSafely(final SomeDomainObject obj) {
+ return null;
+ }
+ };
+ assertThat(specAbstractSomeDomainObject.satisfies(new SomeOtherDomainObject()), is(nullValue()));
+ }
+
+ @Test
+ public void shouldNotSatisfyForIncorrectTypeIfConfiguredAsSuch() {
+ specAbstractSomeDomainObject = new AbstractSpecification<SomeDomainObject>(Nullability.IGNORE_IF_NULL, TypeChecking.ENSURE_CORRECT_TYPE) {
+ @Override
+ public String satisfiesSafely(final SomeDomainObject obj) {
+ return null;
+ }
+ };
+ assertThat(specAbstractSomeDomainObject.satisfies(new SomeOtherDomainObject()), is(not(nullValue())));
+ }
+
+ @Test
+ public void shouldSatisfyForNonNullCorrectTypeIfConfiguredAsSuch() {
+ specAbstractSomeDomainObject = new AbstractSpecification<SomeDomainObject>(Nullability.ENSURE_NOT_NULL, TypeChecking.ENSURE_CORRECT_TYPE) {
+ @Override
+ public String satisfiesSafely(final SomeDomainObject obj) {
+ return null;
+ }
+ };
+ assertThat(specAbstractSomeDomainObject.satisfies(new SomeDomainObject()), is(nullValue()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/util/EnumsTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/util/EnumsTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/util/EnumsTest.java
new file mode 100644
index 0000000..d53328a
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/util/EnumsTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.applib.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+import org.apache.isis.applib.annotation.When;
+import org.apache.isis.applib.util.Enums;
+
+public class EnumsTest {
+
+ @Test
+ public void getFriendlyNameOf() {
+ assertThat(Enums.getFriendlyNameOf(When.ALWAYS), is("Always"));
+ assertThat(Enums.getFriendlyNameOf(When.ONCE_PERSISTED), is("Once Persisted"));
+ }
+
+ @Test
+ public void getEnumNameFromFriendly() {
+ assertThat(Enums.getEnumNameFromFriendly("Always"), is("ALWAYS"));
+ assertThat(Enums.getEnumNameFromFriendly("Once Persisted"), is("ONCE_PERSISTED"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/util/EnumsTest_converts.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/util/EnumsTest_converts.java b/framework/core/applib/src/test/java/org/apache/isis/applib/util/EnumsTest_converts.java
new file mode 100644
index 0000000..1d230a0
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/util/EnumsTest_converts.java
@@ -0,0 +1,45 @@
+/*
+ * 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.applib.util;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class EnumsTest_converts {
+
+ private static enum MyEnum {
+ CONTENT_TYPE, LAST_MODIFIED, WARNING, X_REPRESENTATION_TYPE, OBJECT_ACTION
+ }
+
+ @Test
+ public void converts() {
+ assertConverts(MyEnum.CONTENT_TYPE, "Content-Type", "contentType");
+ assertConverts(MyEnum.LAST_MODIFIED, "Last-Modified", "lastModified");
+ assertConverts(MyEnum.WARNING, "Warning", "warning");
+ assertConverts(MyEnum.X_REPRESENTATION_TYPE, "X-Representation-Type", "xRepresentationType");
+ }
+
+ protected void assertConverts(final Enum<?> someEnum, final String httpHeader, final String camelCase) {
+ assertThat(Enums.enumToHttpHeader(someEnum), is(httpHeader));
+ assertThat(Enums.enumToCamelCase(someEnum), is(camelCase));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/util/ReasonBufferTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/util/ReasonBufferTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/util/ReasonBufferTest.java
new file mode 100644
index 0000000..e08635e
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/util/ReasonBufferTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.applib.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ReasonBufferTest {
+ private ReasonBuffer reason;
+
+ @Before
+ public void setUp() {
+ reason = new ReasonBuffer();
+ }
+
+ @Test
+ public void testNoReasonReturnsNull() throws Exception {
+ assertEquals(null, reason.getReason());
+ }
+
+ @Test
+ public void testAReasonReturnsString() throws Exception {
+ reason.append("reason 1");
+ assertEquals("reason 1", reason.getReason());
+ }
+
+ @Test
+ public void testConditionalAppendWithTrue() {
+ reason.appendOnCondition(true, "reason 1");
+ assertEquals("reason 1", reason.getReason());
+ }
+
+ @Test
+ public void testConditionalAppendWithFalse() {
+ reason.appendOnCondition(false, "reason 1");
+ assertEquals(null, reason.getReason());
+ }
+
+ @Test
+ public void testAppendTwoReasons() {
+ reason.append("reason 1");
+ reason.append("reason 2");
+ assertEquals("reason 1; reason 2", reason.getReason());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/util/ReasonsTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/util/ReasonsTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/util/ReasonsTest.java
new file mode 100644
index 0000000..83ec09c
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/util/ReasonsTest.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.applib.util;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ReasonsTest {
+
+ @Test
+ public void testNoReasonReturnsNull() throws Exception {
+ assertThat(Reasons.coalesce(), is(nullValue()));
+ }
+
+ @Test
+ public void testSingleNullReturnsNull() throws Exception {
+ assertThat(Reasons.coalesce((String) null), is(nullValue()));
+ }
+
+ @Test
+ public void testSingleNonNullReturnsSame() throws Exception {
+ assertThat(Reasons.coalesce("yada"), is("yada"));
+ }
+
+ @Test
+ public void testNullThenNonNullReturnsLatter() throws Exception {
+ assertThat(Reasons.coalesce(null, "yada"), is("yada"));
+ }
+
+ @Test
+ public void testNotNullThenNonNullReturnsBothConcatenated() throws Exception {
+ assertThat(Reasons.coalesce("foobar", "yada"), is("foobar; yada"));
+ }
+
+ @Test
+ public void testNotNullThenNullBothFormer() throws Exception {
+ assertThat(Reasons.coalesce("foobar", null), is("foobar"));
+ }
+
+ @Test
+ public void testNullsAreSkippedThenNonNull() throws Exception {
+ assertThat(Reasons.coalesce("foobar", null, "yada"), is("foobar; yada"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/util/TitleBufferTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/util/TitleBufferTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/util/TitleBufferTest.java
new file mode 100644
index 0000000..dfa5019
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/util/TitleBufferTest.java
@@ -0,0 +1,291 @@
+/*
+ * 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.applib.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TitleBufferTest {
+
+ String companyName;
+ String name;
+ TitleTestObject objectWithEmptyTitle;
+ TitleTestObject objectWithNoTitle;
+ TitleTestObject objectWithTitle;
+
+ TitleBuffer t1;
+ TitleBuffer t2;
+ TitleBuffer t3;
+
+ @Before
+ public void setUp() {
+ name = "Fred";
+ t1 = new TitleBuffer(name);
+ t2 = new TitleBuffer();
+ companyName = "ABC Co.";
+ objectWithTitle = new TitleTestObject();
+ objectWithTitle.setupTitle(companyName);
+ objectWithNoTitle = new TitleTestObject();
+ objectWithEmptyTitle = new TitleTestObject();
+ objectWithEmptyTitle.setupTitle("");
+ t3 = new TitleBuffer("This is a long title");
+ }
+
+ @Test
+ public void testAppend() {
+ t1.append("");
+ assertEquals("add empty string", name, t1.toString());
+ t1.append("Smith");
+ name += (" " + "Smith");
+ assertEquals("append simple string", name, t1.toString());
+ t1.append(",", "");
+ assertEquals("append empty string with delimiter", name, t1.toString());
+ t1.append(",", null);
+ assertEquals("append null with delimiter", name, t1.toString());
+ t1.append(",", "Xyz Ltd.");
+ name += (", " + "Xyz Ltd.");
+ assertEquals("append string with delimiter", name, t1.toString());
+ }
+
+ @Test
+ public void testAppendEmptyStringLeavesBufferUnchanged() {
+ t1.append("");
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testAppendEmptyStringWithJoinerLeavesBufferUnchanged() {
+ t1.append(",", "");
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testAppendInt() {
+ final TitleBuffer t = new TitleBuffer();
+ t.append(123);
+ assertEquals("123", t.toString());
+ }
+
+ @Test
+ public void testAppendNull() {
+ t1.append(null);
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testAppendNullWithJoinerLeavesBufferUnchanged() {
+ t1.append(",", (Object) null);
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testAppendObjectsWithJoinerAddsTitleWithJoinerAndSpace() {
+ t1.append(",", objectWithTitle);
+ assertEquals(name + ", " + companyName, t1.toString());
+ }
+
+ @Test
+ public void testAppendObjectsWithJoinerOnlyAddsTitleWhenBufferEmpty() {
+ t2.append(",", objectWithTitle);
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testAppendObjectWhereDefaultNotNeeded() {
+ t1.append(objectWithTitle, "none");
+ assertEquals(name + " " + companyName, t1.toString());
+ }
+
+ @Test
+ public void testAppendObjectWhereDefaultUsedAsObjectHasEmptyTitle() {
+ t1.append(objectWithEmptyTitle, "none");
+ assertEquals(name + " " + "none", t1.toString());
+ }
+
+ @Test
+ public void testAppendObjectWhereDefaultUsedAsReferenceIsNull() {
+ t1.append((Object) null, "none");
+ assertEquals(name + " " + "none", t1.toString());
+ }
+
+ @Test
+ public void testAppendObjectWithEmptyTitleLeavesBufferUnchanged() {
+ t1.append(objectWithEmptyTitle);
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testAppendObjectWithNoTitleLeavesBufferUnchanged() {
+ t1.append(objectWithNoTitle);
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testAppendObjectWithTitleAddTitleWithSpace() {
+ t1.append(objectWithTitle);
+ assertEquals(name + " " + companyName, t1.toString());
+ }
+
+ @Test
+ public void testAppendStringAddStringWithSpace() {
+ t1.append("Smith");
+ assertEquals("Fred Smith", t1.toString());
+ }
+
+ @Test
+ public void testAppendStringToEmptyBufferAddsStringWithoutSpace() {
+ t2.append("Smith");
+ assertEquals("Smith", t2.toString());
+ }
+
+ @Test
+ public void testAppendStringWithJoinerAddsStringWithJoinerAndSpace() {
+ t1.append(",", "Smith");
+ assertEquals("Fred, Smith", t1.toString());
+ }
+
+ @Test
+ public void testAppendToBuffer() {
+ final TitleBuffer t = new TitleBuffer("123");
+ t.append("test");
+ assertEquals("123 test", t.toString());
+ }
+
+ @Test
+ public void testAppendToEmpty() {
+ final TitleBuffer t = new TitleBuffer();
+ t.append("test");
+ assertEquals("test", t.toString());
+ }
+
+ @Test
+ public void testAppendValue() {
+ final TitleTestObject s = new TitleTestObject();
+
+ t1.append(s);
+ assertEquals("append empty TextString", name, t1.toString());
+
+ //
+ t1.append(new TitleTestObject("square"));
+ assertEquals("append empty TextString", name + " " + "square", t1.toString());
+ }
+
+ @Test
+ public void testConcatEmptyStringLeavesBufferUnchanged() {
+ t1.concat("");
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testConcatObjects() {
+ t1.concat(objectWithTitle);
+ assertEquals(name + companyName, t1.toString());
+ }
+
+ @Test
+ public void testConcatObjectsWhereDefaultNotNeededAddsTitle() {
+ t1.concat(objectWithTitle, "none");
+ assertEquals(name + companyName, t1.toString());
+ }
+
+ @Test
+ public void testConcatObjectsWhereNoTitleAddDefaultTitle() {
+ t1.concat(objectWithNoTitle, "none");
+ assertEquals(name + "none", t1.toString());
+ }
+
+ @Test
+ public void testConcatObjectWhereNoTitleLeavesBufferUnchanged() {
+ t1.concat(objectWithNoTitle);
+ assertEquals(name, t1.toString());
+ }
+
+ @Test
+ public void testConcatObjectWhereTitleIsAdded() {
+ t1.concat(objectWithTitle);
+ assertEquals("FredABC Co.", t1.toString());
+ }
+
+ @Test
+ public void testConcatStringAddsString() {
+ t1.concat("Smith");
+ assertEquals("FredSmith", t1.toString());
+ }
+
+ @Test
+ public void testConstructorsWithObjectWhereDefaultIsNotNeeded() {
+ t1 = new TitleBuffer(objectWithTitle, "test");
+ assertEquals("ABC Co.", t1.toString());
+ }
+
+ @Test
+ public void testConstructorsWithObjectWhereDefaultIsUsedAsTitle() {
+ t1 = new TitleBuffer(objectWithNoTitle, "test");
+ assertEquals("test", t1.toString());
+ }
+
+ @Test
+ public void testConstructorWithObject() {
+ final TitleBuffer t = new TitleBuffer(objectWithTitle);
+ assertEquals("ABC Co.", t.toString());
+ }
+
+ @Test
+ public void testConstructorWithObjectWithNoTitle() {
+ final TitleBuffer t = new TitleBuffer(objectWithEmptyTitle);
+ assertEquals("", t.toString());
+ }
+
+ @Test
+ public void testConstructorWithString() {
+ final TitleBuffer t = new TitleBuffer("Test");
+ assertEquals("Test", t.toString());
+ }
+
+ @Test
+ public void testDefaultConstructor() {
+ final TitleBuffer t = new TitleBuffer();
+ assertEquals("", t.toString());
+ }
+
+ @Test
+ public void testTruncateHasNoEffectUntilTitleLongEnough() {
+ t3.truncate(5);
+ assertEquals("This is a long title", t3.toString());
+ }
+
+ @Test
+ public void testTruncateLimitsTitleLength() {
+ t3.truncate(3);
+ assertEquals("This is a...", t3.toString());
+ }
+
+ @Test
+ public void testTruncateMustBeAUsableLength() {
+ try {
+ t3.truncate(0);
+ fail("Exception expected");
+ } catch (final IllegalArgumentException ee) {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/util/TitleTestObject.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/util/TitleTestObject.java b/framework/core/applib/src/test/java/org/apache/isis/applib/util/TitleTestObject.java
new file mode 100644
index 0000000..e4d1e69
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/util/TitleTestObject.java
@@ -0,0 +1,45 @@
+/*
+ * 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.applib.util;
+
+class TitleTestObject {
+
+ private String title;
+
+ public TitleTestObject() {
+ }
+
+ public TitleTestObject(final String title) {
+ this.title = title;
+ }
+
+ public void setupTitle(final String title) {
+ this.title = title;
+ }
+
+ public String title() {
+ return title;
+ }
+
+ @Override
+ public String toString() {
+ return "xxx";
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/BlobTest_constructor.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/BlobTest_constructor.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/BlobTest_constructor.java
new file mode 100644
index 0000000..bc70e26
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/BlobTest_constructor.java
@@ -0,0 +1,36 @@
+/*
+ * 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.applib.value;
+
+import org.junit.Test;
+
+public class BlobTest_constructor {
+
+ @Test
+ public void happyCase() throws Exception {
+ new Blob("validName", "application", "xml", new byte[]{0,1});
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void name_cannotContainColon() throws Exception {
+ new Blob("with a colon : in it", "application", "xml", new byte[]{0,1});
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/ClobTest_constructor.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/ClobTest_constructor.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/ClobTest_constructor.java
new file mode 100644
index 0000000..8716964
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/ClobTest_constructor.java
@@ -0,0 +1,36 @@
+/*
+ * 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.applib.value;
+
+import org.junit.Test;
+
+public class ClobTest_constructor {
+
+ @Test
+ public void happyCase() throws Exception {
+ new Clob("validName", "application", "xml", "abc");
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void name_cannotContainColon() throws Exception {
+ new Clob("with a colon : in it", "application", "xml", "abc");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/ColorTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/ColorTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/ColorTest.java
new file mode 100644
index 0000000..a96fdb3
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/ColorTest.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.applib.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class ColorTest {
+ @Test
+ public void testToTitle() throws Exception {
+ assertEquals("Black", Color.BLACK.title());
+ assertEquals("White", Color.WHITE.title());
+ assertEquals("#FE231D", new Color(0xfe231D).title());
+ }
+
+ @Test
+ public void testIsLessThan() throws Exception {
+ assertTrue(Color.BLACK.isLessThan(Color.WHITE));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/DateTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/DateTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/DateTest.java
new file mode 100644
index 0000000..5ef6988
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/DateTest.java
@@ -0,0 +1,179 @@
+/*
+ * 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.applib.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class DateTest {
+
+ private Date actual;
+
+ @Before
+ public void setUp() throws Exception {
+ TestClock.initialize();
+ actual = new Date(2000, 3, 14);
+ }
+
+ @Test
+ public void testGetDay() {
+ assertEquals(14, actual.getDay());
+ }
+
+ @Test
+ public void testGetMonth() {
+ assertEquals(3, actual.getMonth());
+ }
+
+ @Test
+ public void testGetYear() {
+ assertEquals(2000, actual.getYear());
+ }
+
+ @Test
+ public void testAdd() {
+ final Date resultDate = actual.add(1, 2, 3);
+ assertEquals(17, resultDate.getDay());
+ assertEquals(5, resultDate.getMonth());
+ assertEquals(2001, resultDate.getYear());
+ }
+
+ @Test
+ public void testDate() {
+ actual = new Date(2001, 3, 7);
+ assertEquals("day", 7, actual.getDay());
+ assertEquals("month", 3, actual.getMonth());
+ assertEquals("year", 2001, actual.getYear());
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ assertTrue(actual.equals(actual));
+ assertTrue(new Date(2003, 8, 17).equals(new Date()));
+ assertTrue(actual.equals(new Date(2000, 3, 14)));
+ }
+
+ @Test
+ public void testIsLestThan() throws Exception {
+ assertFalse(new Date(2003, 8, 17).isLessThan(new Date(2003, 8, 17)));
+ assertTrue(new Date(2003, 8, 16).isLessThan(new Date(2003, 8, 17)));
+ }
+
+ @Test
+ public void testSameDayOfWeekAs() throws Exception {
+ assertTrue(new Date(2000, 2, 17).sameDayOfWeekAs(new Date(2003, 8, 7))); // Thursday
+ assertFalse(new Date(2000, 2, 15).sameDayOfWeekAs(new Date(2003, 8, 17))); // Tues
+ // &
+ }
+
+ @Test
+ public void testSameDayOfMonthAs() throws Exception {
+ assertTrue(new Date(2000, 2, 17).sameDayOfMonthAs(new Date(2003, 8, 17)));
+ assertFalse(new Date(2000, 2, 15).sameDayOfMonthAs(new Date(2003, 8, 17)));
+ }
+
+ @Test
+ public void testSameDayOfYearAs() throws Exception {
+ assertTrue(new Date(2001, 8, 17).sameDayOfYearAs(new Date(2003, 8, 17)));
+ assertTrue(new Date(1999, 3, 1).sameDayOfYearAs(new Date(2000, 2, 29))); // leap
+ // year
+ assertFalse(new Date(2001, 3, 1).sameDayOfYearAs(new Date(2000, 3, 2)));
+ }
+
+ @Test
+ public void testSameWeekAs() throws Exception {
+ assertFalse(new Date(2000, 2, 15).sameWeekAs(new Date(2000, 2, 12))); // Tue,
+ // week
+ // 7
+ // and
+ // Sat,
+ // week
+ // 6
+ assertTrue(new Date(2001, 2, 16).sameWeekAs(new Date(2002, 2, 11))); // Tue,
+ // week
+ // 7,
+ // and
+ // Thu,
+ // week
+ // 7
+ }
+
+ @Test
+ public void testSameMonthAs() throws Exception {
+ assertTrue(new Date(2000, 8, 15).sameMonthAs(new Date(2003, 8, 17)));
+ assertFalse(new Date(2003, 2, 17).sameMonthAs(new Date(2003, 8, 17)));
+ }
+
+ @Test
+ public void testSameYearAs() throws Exception {
+ assertTrue(new Date(2003, 2, 15).sameYearAs(new Date(2003, 8, 17)));
+ assertFalse(new Date(2000, 2, 15).sameYearAs(new Date(2003, 8, 17)));
+ }
+
+ @Test
+ public void testDateValue() {
+ final Date date = new Date(1970, 1, 1);
+ assertEquals(1970, date.getYear());
+ assertEquals(1, date.getMonth());
+ assertEquals(1, date.getDay());
+ final java.util.Date dateValue = date.dateValue();
+ final long time = dateValue.getTime();
+ assertEquals(1000 * 60 * 60 * 12 * 0, time);
+ }
+
+ @Test
+ public void testStartOfYear() {
+ assertEquals(new Date(2000, 1, 1), actual.startOfYear());
+ }
+
+ @Test
+ public void testStartOfMonth() {
+ assertEquals(new Date(2000, 3, 1), actual.startOfMonth());
+ }
+
+ @Test
+ public void testStartOfWeek() {
+ assertEquals(new Date(2000, 3, 13), actual.startOfWeek());
+ assertEquals(new Date(2000, 2, 28), new Date(2000, 3, 2).startOfWeek());
+ }
+
+ @Test
+ public void testEndOfMonth() {
+ assertEquals(new Date(2000, 2, 29), new Date(2000, 2, 2).endOfMonth());
+ assertEquals(new Date(2001, 2, 28), new Date(2001, 2, 2).endOfMonth());
+ }
+
+ @Test
+ public void testNewWithTodaysDate() {
+ final Date actual = new Date();
+ final Date expected = new Date(2003, 8, 17);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals("2000-03-14", actual.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/DateTimeTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/DateTimeTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/DateTimeTest.java
new file mode 100644
index 0000000..a79989a
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/DateTimeTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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.applib.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+// TODO review all date based classes - should we use factory and service to create and work with date type values?
+public class DateTimeTest {
+
+ private DateTime actual;
+ private int year, month, day, hour, minute;
+
+ @Before
+ public void setUp() throws Exception {
+ TestClock.initialize();
+ year = 2000;
+ month = 3;
+ day = 14;
+ hour = 10;
+ minute = 45;
+ actual = new DateTime(year, month, day, hour, minute);
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ @Test
+ public void testGetDay() {
+ assertEquals(14, actual.getDay());
+ }
+
+ @Test
+ public void testGetMonth() {
+ assertEquals(3, actual.getMonth());
+ }
+
+ @Test
+ public void testGetYear() {
+ assertEquals(2000, actual.getYear());
+ }
+
+ @Test
+ public void test24Hour() {
+ final DateTime dt = new DateTime(2006, 05, 07, 23, 59);
+ assertEquals("hour", 23, dt.getHour());
+ assertEquals("minute", 59, dt.getMinute());
+ }
+
+ @Test
+ public void testAdd() {
+ final DateTime resultDateTime = actual.add(1, 2, 3);
+ assertEquals(17, resultDateTime.getDay());
+ assertEquals(5, resultDateTime.getMonth());
+ assertEquals(2001, resultDateTime.getYear());
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ assertTrue(actual.equals(actual));
+ assertEquals(actual, new DateTime(2000, 3, 14, 10, 45));
+ assertTrue(new DateTime(2003, 8, 17).isSameDayAs(new DateTime()));
+ }
+
+ @Test
+ public void testIsLestThan() throws Exception {
+ assertFalse(new DateTime(2003, 8, 17).isLessThan(new DateTime(2003, 8, 17)));
+ assertTrue(new DateTime(2003, 8, 16).isLessThan(new DateTime(2003, 8, 17)));
+ }
+
+ @Test
+ public void testSameDayOfWeekAs() throws Exception {
+ assertTrue(new DateTime(2000, 2, 17).sameDayOfWeekAs(new DateTime(2003, 8, 7))); // Thursday
+ assertFalse(new DateTime(2000, 2, 15).sameDayOfWeekAs(new DateTime(2003, 8, 17))); // Tues
+ // &
+ }
+
+ @Test
+ public void testSameDayOfMonthAs() throws Exception {
+ assertTrue(new DateTime(2000, 2, 17).sameDayOfMonthAs(new DateTime(2003, 8, 17)));
+ assertFalse(new DateTime(2000, 2, 15).sameDayOfMonthAs(new DateTime(2003, 8, 17)));
+ }
+
+ @Test
+ public void testSameDayOfYearAs() throws Exception {
+ assertTrue(new DateTime(2001, 8, 17).sameDayOfYearAs(new DateTime(2003, 8, 17)));
+ assertTrue(new DateTime(1999, 3, 1).sameDayOfYearAs(new DateTime(2000, 2, 29))); // leap
+ // year
+ assertFalse(new DateTime(2001, 3, 1).sameDayOfYearAs(new DateTime(2000, 3, 2)));
+ }
+
+ @Test
+ public void testSameWeekAs() throws Exception {
+ assertFalse(new DateTime(2000, 2, 15).sameWeekAs(new DateTime(2000, 2, 12))); // Tue,
+ // week
+ // 7
+ // and
+ // Sat,
+ // week 6
+ assertTrue(new DateTime(2001, 2, 16).sameWeekAs(new DateTime(2002, 2, 11))); // Tue,
+ // week
+ // 7,
+ // and
+ // Thu,
+ // week 7
+ }
+
+ @Test
+ public void testSameMonthAs() throws Exception {
+ assertTrue(new DateTime(2000, 8, 15).sameMonthAs(new DateTime(2003, 8, 17)));
+ assertFalse(new DateTime(2003, 2, 17).sameMonthAs(new DateTime(2003, 8, 17)));
+ }
+
+ @Test
+ public void testSameYearAs() throws Exception {
+ assertTrue(new DateTime(2003, 2, 15).sameYearAs(new DateTime(2003, 8, 17)));
+ assertFalse(new DateTime(2000, 2, 15).sameYearAs(new DateTime(2003, 8, 17)));
+ }
+
+ @Test
+ public void testDateTimeValue() {
+ final DateTime date = new DateTime(1970, 1, 1, 0, 0, 0);
+ assertEquals(1970, date.getYear());
+ assertEquals(1, date.getMonth());
+ assertEquals(1, date.getDay());
+ final long time = date.millisSinceEpoch();
+ assertEquals(1000 * 60 * 60 * 24 * 0, time);
+
+ final long jtime = date.dateValue().getTime();
+ assertEquals(1000 * 60 * 60 * 24 * 0, jtime);
+
+ }
+
+ @Test
+ public void testStartOfYear() {
+ assertEquals(new DateTime(2000, 1, 1, hour, minute), actual.startOfYear());
+ }
+
+ @Test
+ public void testStartOfMonth() {
+ assertEquals(new DateTime(2000, 3, 1, hour, minute), actual.startOfMonth());
+ }
+
+ @Test
+ public void testStartOfWeek() {
+ assertEquals(new DateTime(2000, 3, 13, hour, minute), actual.startOfWeek());
+ assertEquals(new DateTime(2000, 2, 28), new DateTime(2000, 3, 2).startOfWeek());
+ }
+
+ @Test
+ public void testNewWithTodaysDateTime() {
+ final DateTime actual = new DateTime();
+ final DateTime expected = new DateTime(2003, 8, 17);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals("2000-03-14 10:45", actual.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/MoneyTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/MoneyTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/MoneyTest.java
new file mode 100644
index 0000000..daa5172
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/MoneyTest.java
@@ -0,0 +1,232 @@
+/*
+ * 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.applib.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.math.BigDecimal;
+
+import org.junit.Test;
+
+public class MoneyTest {
+
+ @Test
+ public void testAdd() {
+ final Money m1 = new Money(110, "pds");
+ final Money m2 = new Money(220, "pds");
+ final Money m3 = m1.add(m2);
+ assertEquals(330.0, m3.doubleValue(), 0.0);
+ }
+
+ @Test
+ public void testAddWithCents() {
+ final Money m1 = new Money(110.10, "pds");
+ final Money m2 = new Money(220.50, "pds");
+ final Money m3 = m1.add(m2);
+ assertEquals(330.60, m3.doubleValue(), 0.0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testAddThrowsExceptionForDifferentCurrencies() {
+ final Money m1 = new Money(100, "pds");
+ final Money m2 = new Money(200, "uds");
+
+ m1.add(m2);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testDoubleConstructorExpectsCurrencyToBeSpecified() {
+ new Money(100.50, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testLongConstructorExpectsCurrencyToBeSpecified() {
+ new Money(100L, null);
+ }
+
+ @Test
+ public void testCreateFromDouble() {
+ final Money m1 = new Money(100.50, "pds");
+ assertEquals("100.50", m1.getAmount().toString());
+ assertEquals(100.50, m1.doubleValue(), 0.0);
+ }
+
+ @Test
+ public void testDouble() {
+ final Money m1 = new Money(100, "pds");
+ assertEquals(100.0, m1.doubleValue(), 0.0);
+ }
+
+ @Test
+ public void testDoubleConstructor() {
+ final Money m1 = new Money(100.15, "pds");
+ assertEquals(100.15, m1.doubleValue(), 0.0);
+ }
+
+ @Test
+ public void testDoubleRoundingDown() {
+ final Money m1 = new Money(100.154, "pds");
+ assertEquals(100.15, m1.doubleValue(), 0.0);
+ }
+
+ @Test
+ public void testDoubleRoundingUp() {
+ final Money m1 = new Money(100.156, "pds");
+ assertEquals(100.16, m1.doubleValue(), 0.0);
+ }
+
+ @Test
+ public void testEqualsObject() {
+ final Money m1 = new Money(100.25, "pds");
+ final Money m2 = new Money(100.25, "pds");
+ assertTrue(m1.equals(m2));
+ }
+
+ @Test
+ public void testEqualsObjectFailsWithDifferentAmounts() {
+ final Money m1 = new Money(100, "pds");
+ final Money m2 = new Money(101, "pds");
+ assertFalse(m1.equals(m2));
+ }
+
+ @Test
+ public void testEqualsObjectFailsWithDifferentCurrencies() {
+ final Money m1 = new Money(100, "pds");
+ final Money m2 = new Money(100, "usd");
+ assertFalse(m1.equals(m2));
+ }
+
+ @Test
+ public void testGetAmount() {
+ final Money m1 = new Money(100, "pds");
+ assertEquals(BigDecimal.valueOf(10000, 2), m1.getAmount());
+ }
+
+ @Test
+ public void testHasSameCurrency() {
+ final Money m1 = new Money(100, "pds");
+ final Money m2 = new Money(200, "pds");
+ final Money m3 = new Money(200, "usd");
+ assertTrue(m1.hasSameCurrency(m2));
+ assertFalse(m1.hasSameCurrency(m3));
+ }
+
+ @Test
+ public void testIsEqualTo() {
+ final Money m1 = new Money(100, "pds");
+ final Money m2 = new Money(100, "pds");
+ assertTrue(m1.isEqualTo(m2));
+ }
+
+ @Test
+ public void testIsEqualToFailsWithDifferentAmount() {
+ final Money m1 = new Money(100, "pds");
+ final Money m2 = new Money(101, "pds");
+ assertFalse(m1.isEqualTo(m2));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testIsEqualToThrowsExceptionWithDifferentCurrencies() {
+ final Money m1 = new Money(100, "pds");
+ final Money m2 = new Money(100, "usd");
+
+ m1.isEqualTo(m2);
+ }
+
+ @Test
+ public void testIsGreaterThanZero() {
+ final Money m1 = new Money(1, "usd");
+ assertTrue(m1.isGreaterThanZero());
+ }
+
+ @Test
+ public void testIsGreaterThanZeroFailsWhenZero() {
+ final Money m1 = new Money(0, "usd");
+ assertFalse(m1.isGreaterThanZero());
+ }
+
+ @Test
+ public void testIsLessThan() {
+ final Money m1 = new Money(98, "pds");
+ final Money m2 = new Money(100, "pds");
+ assertTrue(m1.isLessThan(m2));
+ }
+
+ @Test
+ public void testIsLessThanFails() {
+ final Money m1 = new Money(98, "pds");
+ final Money m2 = new Money(100, "pds");
+ assertFalse(m2.isLessThan(m1));
+ }
+
+ @Test
+ public void testIsLessThanZero() {
+ final Money m1 = new Money(-1, "usd");
+ assertTrue(m1.isLessThanZero());
+ }
+
+ @Test
+ public void testIsLessThanZeroFailsWhenZero() {
+ final Money m1 = new Money(0, "usd");
+ assertFalse(m1.isLessThanZero());
+ }
+
+ public void testIsLessThrowsExceptionWithDifferentCurrencies() {
+ final Money m1 = new Money(98, "pds");
+ final Money m2 = new Money(100, "usd");
+ try {
+ m2.isLessThan(m1);
+ fail();
+ } catch (final IllegalArgumentException expected) {
+ }
+ }
+
+ @Test
+ public void testIsZero() {
+ final Money m1 = new Money(0, "usd");
+ assertTrue(m1.isZero());
+ }
+
+ @Test
+ public void testIsZeroFailsWhenPositive() {
+ final Money m1 = new Money(1, "usd");
+ assertFalse(m1.isZero());
+ }
+
+ @Test
+ public void testSubtract() {
+ final Money m1 = new Money(300, "pds");
+ final Money m2 = new Money(100, "pds");
+ final Money m3 = m1.subtract(m2);
+ assertEquals(200.0, m3.doubleValue(), 0.0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSubtractThrowsExceptionForDifferentCurrencies() {
+ final Money m1 = new Money(100, "pds");
+ final Money m2 = new Money(200, "uds");
+
+ m1.subtract(m2);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/PasswordTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/PasswordTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/PasswordTest.java
new file mode 100644
index 0000000..80fb305
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/PasswordTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.applib.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class PasswordTest {
+ @Test
+ public void testCheckPassword() {
+ final Password password = new Password("secret");
+ assertFalse(password.checkPassword(""));
+ assertFalse(password.checkPassword("SECRET"));
+ assertTrue(password.checkPassword("secret"));
+ }
+
+ @Test
+ public void testTitleObscuresPassword() {
+ Password password = new Password("secret");
+ assertEquals("******", password.toString());
+
+ password = new Password("a very very very long password");
+ assertEquals("********************", password.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/PercentageTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/PercentageTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/PercentageTest.java
new file mode 100644
index 0000000..e518c24
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/PercentageTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.applib.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class PercentageTest {
+ Percentage p1;
+ Percentage p2;
+ Percentage p3;
+
+ @Before
+ public void setUp() throws Exception {
+ p1 = new Percentage(10.5f);
+ p2 = new Percentage(10.5f);
+ p3 = new Percentage(12.0f);
+ }
+
+ @Test
+ public void testEquals() {
+ assertEquals(p1, p2);
+ assertNotSame(p1, p2);
+ assertFalse(p1.equals(p3));
+ }
+
+ @Test
+ public void testAddFloat() {
+ final Percentage p4 = p1.add(10.0f);
+ assertEquals(20.5f, p4.floatValue(), 0.0f);
+ }
+
+ @Test
+ public void testAddPercentage() {
+ final Percentage p4 = p1.add(p3);
+ assertEquals(22.5f, p4.floatValue(), 0.0f);
+ }
+
+ @Test
+ public void testIsEqualTo() {
+ assertTrue(p1.isEqualTo(p2));
+ assertFalse(p1.isEqualTo(p3));
+ }
+
+ @Test
+ public void testIsLessThan() {
+ assertTrue(p1.isLessThan(p3));
+ assertFalse(p3.isLessThan(p1));
+ assertFalse(p1.isLessThan(p1));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/TestClock.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/TestClock.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/TestClock.java
new file mode 100644
index 0000000..43bb8cf
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/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.applib.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/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/TimeStampTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/TimeStampTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/TimeStampTest.java
new file mode 100644
index 0000000..e897f6f
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/TimeStampTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.applib.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TimeStampTest {
+
+ private TimeStamp timeStamp;
+
+ @Before
+ public void setUp() throws Exception {
+ TestClock.initialize();
+ timeStamp = new TimeStamp();
+ }
+
+ @Test
+ public void testCreatesToClocksTime() {
+ assertEquals(1061155825000L, timeStamp.longValue());
+ }
+
+ @Test
+ public void testEqualsTo() {
+ final TimeStamp timeStamp2 = new TimeStamp();
+ assertFalse(timeStamp2 == timeStamp);
+
+ assertTrue(timeStamp.isEqualTo(timeStamp2));
+ assertTrue(timeStamp2.isEqualTo(timeStamp));
+ }
+
+ @Test
+ public void testLessThan() {
+ final TimeStamp timeStamp2 = new TimeStamp(1061155825050L);
+
+ assertTrue(timeStamp.isLessThan(timeStamp2));
+ assertFalse(timeStamp2.isLessThan(timeStamp));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/applib/src/test/java/org/apache/isis/applib/value/TimeTest.java
----------------------------------------------------------------------
diff --git a/framework/core/applib/src/test/java/org/apache/isis/applib/value/TimeTest.java b/framework/core/applib/src/test/java/org/apache/isis/applib/value/TimeTest.java
new file mode 100644
index 0000000..41cafca
--- /dev/null
+++ b/framework/core/applib/src/test/java/org/apache/isis/applib/value/TimeTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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.applib.value;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TimeTest {
+ public static void main(final String[] args) {
+ final Date date = new Date(3600000 * 14);
+
+ Locale.setDefault(Locale.KOREA);
+ Locale.setDefault(Locale.US);
+ Locale.setDefault(Locale.FRANCE);
+
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
+ TimeZone.setDefault(TimeZone.getTimeZone("Europe/Paris"));
+
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
+ final DateFormat format = DateFormat.getDateTimeInstance();
+
+ System.out.println(date.toString());
+ System.out.println(format.format(date));
+ }
+
+ private Time time;
+
+ @Before
+ public void setUp() throws Exception {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ TestClock.initialize();
+ time = new Time(13, 14);
+ }
+
+ @Test
+ public void testAdd() {
+ final Time result = time.add(2, 3);
+ assertEquals(17, result.getMinute());
+ assertEquals(15, result.getHour());
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ assertTrue(time.equals(time));
+ assertTrue(time.equals(new Time(13, 14)));
+ assertTrue(new Time(13, 14).equals(time));
+ }
+
+ @Test
+ public void testGetHour() {
+ assertEquals(13, time.getHour());
+ }
+
+ @Test
+ public void testGetMinute() {
+ assertEquals(14, time.getMinute());
+ }
+
+ @Test
+ public void testIsLestThan() throws Exception {
+ assertFalse(new Time(8, 17).isLessThan(new Time(8, 17)));
+ assertTrue(new Time(8, 16).isLessThan(new Time(8, 17)));
+ }
+
+ @Test
+ public void testNewWithCurrentTime() {
+ final Time expected = new Time(21, 30, 25);
+ final Time actual = new Time(); // Clock actually has 21:30:25
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testSameHourAs() throws Exception {
+ assertTrue(new Time(8, 17).sameHourAs(new Time(8, 7)));
+ assertFalse(new Time(2, 15).sameHourAs(new Time(8, 17)));
+ }
+
+ @Test
+ public void testSameMinuteAs() throws Exception {
+ assertTrue(new Time(2, 17).sameMinuteAs(new Time(8, 17)));
+ assertFalse(new Time(2, 15).sameMinuteAs(new Time(8, 17)));
+ }
+
+ @Test
+ public void testStartOfHour() {
+ assertEquals(new Time(13, 00), time.onTheHour());
+ }
+
+ @Test
+ public void testTitle() {
+ assertEquals("13:14", time.titleString());
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals("13:14:00", time.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/bytecode-cglib/NOTICE
----------------------------------------------------------------------
diff --git a/framework/core/bytecode-cglib/NOTICE b/framework/core/bytecode-cglib/NOTICE
new file mode 100644
index 0000000..d391f54
--- /dev/null
+++ b/framework/core/bytecode-cglib/NOTICE
@@ -0,0 +1,7 @@
+Apache Isis
+Copyright 2010-2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+