You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2014/08/13 00:23:12 UTC
[12/21] ISIS-839: updating todoapp archetype
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/pom.xml
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/pom.xml b/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/pom.xml
index 1872775..d75a856 100644
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/pom.xml
+++ b/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/pom.xml
@@ -26,7 +26,7 @@
</parent>
<artifactId>${artifactId}</artifactId>
- <name>Quickstart Wicket/Restful/JDO Fixtures</name>
+ <name>ToDo App Fixtures</name>
<dependencies>
<dependency>
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java b/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java
index 38676d4..da1c7c3 100644
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java
+++ b/example/archetype/todoapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java
@@ -24,6 +24,7 @@ package fixture.todo;
import fixture.todo.scenarios.RecreateToDoItemsAndCompleteSeveralForCurrent;
import java.util.List;
+import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.MemberOrder;
import org.apache.isis.applib.annotation.Named;
import org.apache.isis.applib.annotation.Prototype;
@@ -35,12 +36,18 @@ import org.apache.isis.applib.fixturescripts.FixtureScripts;
* Enables fixtures to be installed from the application.
*/
@Named("Prototyping") // has the effect of defining a "Prototyping" menu item
+@DomainService(menuOrder = "40.1")
public class ToDoItemsFixturesService extends FixtureScripts {
public ToDoItemsFixturesService() {
super("fixture.todo");
}
+ //@Override // compatibility with core 1.5.0
+ public FixtureScript default0RunFixtureScript() {
+ return findFixtureScriptFor(RecreateToDoItemsAndCompleteSeveralForCurrent.class);
+ }
+
/**
* Raising visibility to <tt>public</tt> so that choices are available for first param
* of {@link ${symbol_pound}runFixtureScript(FixtureScript, String)}.
@@ -50,6 +57,9 @@ public class ToDoItemsFixturesService extends FixtureScripts {
return super.choices0RunFixtureScript();
}
+ // //////////////////////////////////////
+
+
@Prototype
@MemberOrder(sequence="20")
public Object recreateToDoItemsForCurrentAndReturnFirst() {
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/pom.xml
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/pom.xml b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/pom.xml
index 93dbfee..ddd276f 100644
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/pom.xml
+++ b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/pom.xml
@@ -26,7 +26,7 @@
</parent>
<artifactId>${artifactId}</artifactId>
- <name>Quickstart Wicket/Restful/JDO Integration Tests</name>
+ <name>ToDo App Integration Tests</name>
<build>
<testResources>
@@ -72,12 +72,12 @@
</dependency>
<dependency>
- <groupId>org.apache.isis.core</groupId>
- <artifactId>isis-core-wrapper</artifactId>
+ <groupId>org.apache.isis.module</groupId>
+ <artifactId>isis-module-wrapper</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.isis.objectstore</groupId>
- <artifactId>isis-objectstore-jdo-datanucleus</artifactId>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-objectstore-jdo-datanucleus</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/ToDoSystemInitializer.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/ToDoSystemInitializer.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/ToDoSystemInitializer.java
index f0f0cdf..70adfb8 100644
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/ToDoSystemInitializer.java
+++ b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/ToDoSystemInitializer.java
@@ -19,25 +19,10 @@
*/
package integration;
-import app.ToDoItemAnalysis;
-import dom.todo.ToDoItemContributions;
-import dom.todo.ToDoItemSubscriptions;
-import dom.todo.ToDoItems;
-import fixture.todo.ToDoItemsFixturesService;
-
-import org.apache.isis.applib.annotation.Bulk;
-import org.apache.isis.applib.services.classdiscovery.ClassDiscoveryServiceUsingReflections;
-import org.apache.isis.applib.services.clock.ClockService;
-import org.apache.isis.applib.services.queryresultscache.QueryResultsCache;
import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.integtestsupport.IsisSystemForTest;
-import org.apache.isis.core.metamodel.services.bookmarks.BookmarkServiceDefault;
-import org.apache.isis.core.runtime.services.memento.MementoServiceDefault;
-import org.apache.isis.core.wrapper.WrapperFactoryDefault;
import org.apache.isis.objectstore.jdo.datanucleus.DataNucleusPersistenceMechanismInstaller;
import org.apache.isis.objectstore.jdo.datanucleus.IsisConfigurationForJdoIntegTests;
-import org.apache.isis.objectstore.jdo.datanucleus.service.eventbus.EventBusServiceJdo;
-import org.apache.isis.objectstore.jdo.datanucleus.service.support.IsisJdoSupportImpl;
/**
* Holds an instance of an {@link IsisSystemForTest} as a {@link ThreadLocal} on the current thread,
@@ -59,27 +44,23 @@ public class ToDoSystemInitializer {
private static class ToDoSystemBuilder extends IsisSystemForTest.Builder {
public ToDoSystemBuilder() {
- //withFixtures( ... reference data fixtures ...); // if we had any...
withLoggingAt(org.apache.log4j.Level.INFO);
with(testConfiguration());
with(new DataNucleusPersistenceMechanismInstaller());
-
- withServices(
- new ToDoItems(),
- new ToDoItemAnalysis(),
- new ToDoItemContributions(),
- new ToDoItemsFixturesService(),
- new ClassDiscoveryServiceUsingReflections(),
- new ToDoItemSubscriptions(),
- new WrapperFactoryDefault(),
- new IsisJdoSupportImpl(),
- new Bulk.InteractionContext(),
- new EventBusServiceJdo(),
- new QueryResultsCache(),
- new MementoServiceDefault(),
- new BookmarkServiceDefault(),
- new ClockService()
- );
+
+ // services annotated with @DomainService
+ withServicesIn("app"
+ ,"dom.todo"
+ ,"fixture.todo"
+ ,"webapp.admin"
+ ,"webapp.prototyping"
+ ,"org.apache.isis.core.wrapper"
+ ,"org.apache.isis.applib"
+ ,"org.apache.isis.core.metamodel.services"
+ ,"org.apache.isis.core.runtime.services"
+ ,"org.apache.isis.objectstore.jdo.datanucleus.service.support" // IsisJdoSupportImpl
+ ,"org.apache.isis.objectstore.jdo.datanucleus.service.eventbus" // EventBusServiceJdo
+ );
}
private static IsisConfiguration testConfiguration() {
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/AbstractToDoIntegTest.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/AbstractToDoIntegTest.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/AbstractToDoIntegTest.java
new file mode 100644
index 0000000..f6625d1
--- /dev/null
+++ b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/AbstractToDoIntegTest.java
@@ -0,0 +1,41 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * 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 integration.tests;
+
+import integration.ToDoSystemInitializer;
+
+import org.junit.BeforeClass;
+import org.apache.isis.core.integtestsupport.IntegrationTestAbstract;
+import org.apache.isis.core.integtestsupport.scenarios.ScenarioExecutionForIntegration;
+
+public abstract class AbstractToDoIntegTest extends IntegrationTestAbstract {
+
+ @BeforeClass
+ public static void initClass() {
+ org.apache.log4j.PropertyConfigurator.configure("logging.properties");
+ ToDoSystemInitializer.initIsft();
+
+ // instantiating will install onto ThreadLocal
+ new ScenarioExecutionForIntegration();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoIntegTest.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoIntegTest.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoIntegTest.java
deleted file mode 100644
index ce12615..0000000
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoIntegTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*
- * 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 integration.tests;
-
-import integration.ToDoSystemInitializer;
-
-import org.junit.BeforeClass;
-import org.apache.isis.core.integtestsupport.IntegrationTestAbstract;
-import org.apache.isis.core.integtestsupport.scenarios.ScenarioExecutionForIntegration;
-
-public abstract class ToDoIntegTest extends IntegrationTestAbstract {
-
- @BeforeClass
- public static void initClass() {
- org.apache.log4j.PropertyConfigurator.configure("logging.properties");
- ToDoSystemInitializer.initIsft();
-
- // instantiating will install onto ThreadLocal
- new ScenarioExecutionForIntegration();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemContributionsIntegTest.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemContributionsIntegTest.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemContributionsIntegTest.java
new file mode 100644
index 0000000..c1b59ed
--- /dev/null
+++ b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemContributionsIntegTest.java
@@ -0,0 +1,152 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * 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 integration.tests;
+
+import dom.todo.ToDoItem;
+import dom.todo.ToDoItemContributions;
+import dom.todo.ToDoItems;
+import fixture.todo.integtests.ToDoItemsIntegTestFixture;
+
+import java.util.List;
+import javax.inject.Inject;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public abstract class ToDoItemContributionsIntegTest extends AbstractToDoIntegTest {
+
+ @Before
+ public void setUpData() throws Exception {
+ scenarioExecution().install(new ToDoItemsIntegTestFixture().withTracing());
+ }
+
+ @Inject
+ ToDoItems toDoItems;
+ @Inject
+ ToDoItemContributions toDoItemContributions;
+
+ ToDoItemContributions toDoItemContributionsWrapped;
+ ToDoItem toDoItem;
+
+ @Before
+ public void setUp() throws Exception {
+ final List<ToDoItem> all = toDoItems.notYetComplete();
+ toDoItem = wrap(all.get(0));
+
+ toDoItemContributionsWrapped = wrap(toDoItemContributions);
+ }
+
+ public static class Actions {
+ public static class UpdateCategory extends ToDoItemContributionsIntegTest {
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // when
+ toDoItemContributionsWrapped.updateCategory(toDoItem, ToDoItem.Category.Professional, ToDoItem.Subcategory.Consulting);
+
+ // then
+ assertThat(toDoItem.getCategory(), is(ToDoItem.Category.Professional));
+ assertThat(toDoItem.getSubcategory(), is(ToDoItem.Subcategory.Consulting));
+
+ // when
+ toDoItemContributionsWrapped.updateCategory(toDoItem, ToDoItem.Category.Domestic, ToDoItem.Subcategory.Chores);
+
+ // then
+ assertThat(toDoItem.getCategory(), is(ToDoItem.Category.Domestic));
+ assertThat(toDoItem.getSubcategory(), is(ToDoItem.Subcategory.Chores));
+ }
+
+
+ @Test
+ public void categoryCannotBeNull() throws Exception {
+
+ // when, then
+ expectedExceptions.expectMessage("'Category' is mandatory");
+ toDoItemContributionsWrapped.updateCategory(toDoItem, null, ToDoItem.Subcategory.Chores);
+ }
+
+ @Test
+ public void subcategoryCanBeNull() throws Exception {
+
+ // when, then
+ toDoItemContributionsWrapped.updateCategory(toDoItem, ToDoItem.Category.Professional, null);
+ }
+
+ @Test
+ public void subcategoryMustBelongToCategory() throws Exception {
+
+ // when, then
+ expectedExceptions.expectMessage(containsString("Invalid subcategory"));
+ toDoItemContributionsWrapped.updateCategory(toDoItem, ToDoItem.Category.Professional, ToDoItem.Subcategory.Chores);
+ }
+ }
+
+ public static class SimilarTo extends ToDoItemContributionsIntegTest {
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // when
+ List<ToDoItem> similarItems = toDoItemContributionsWrapped.similarTo(toDoItem);
+
+ // then
+ assertThat(similarItems.size(), is(6));
+ }
+
+ }
+ }
+
+ public static class Properties {
+ public static class Priority extends ToDoItemContributionsIntegTest {
+
+ private List<ToDoItem> notYetComplete;
+
+ @Before
+ public void setUp() throws Exception {
+ notYetComplete = wrap(toDoItems).notYetComplete();
+ }
+
+ @Test
+ public void happyCase() throws Exception {
+ assertPriority(0, 1);
+ assertPriority(1, 2);
+ assertPriority(2, 4);
+ assertPriority(3, 6);
+ assertPriority(4, 5);
+ assertPriority(5, 7);
+ assertPriority(6, 9);
+ assertPriority(7, 8);
+ assertPriority(8, 3);
+ assertPriority(9, 10);
+ }
+
+ private void assertPriority(final int n, final int priority) {
+ assertThat(toDoItemContributions.relativePriority(notYetComplete.get(n)), is(Integer.valueOf(priority)));
+ }
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemIntegTest.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemIntegTest.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemIntegTest.java
new file mode 100644
index 0000000..447070e
--- /dev/null
+++ b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemIntegTest.java
@@ -0,0 +1,1040 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * 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 integration.tests;
+
+import dom.todo.ToDoItem;
+import dom.todo.ToDoItemSubscriptions;
+import dom.todo.ToDoItems;
+import fixture.todo.integtests.ToDoItemsIntegTestFixture;
+
+import java.math.BigDecimal;
+import java.nio.charset.Charset;
+import java.util.EventObject;
+import java.util.List;
+import javax.activation.MimeType;
+import javax.inject.Inject;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.jmock.Expectations;
+import org.jmock.Sequence;
+import org.jmock.auto.Mock;
+import org.joda.time.LocalDate;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.isis.applib.NonRecoverableException;
+import org.apache.isis.applib.RecoverableException;
+import org.apache.isis.applib.clock.Clock;
+import org.apache.isis.applib.services.clock.ClockService;
+import org.apache.isis.applib.services.eventbus.*;
+import org.apache.isis.applib.value.Blob;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class ToDoItemIntegTest extends AbstractToDoIntegTest {
+
+ @Before
+ public void setUpData() throws Exception {
+ scenarioExecution().install(new ToDoItemsIntegTestFixture());
+ }
+
+ @Inject
+ ToDoItems toDoItems;
+ @Inject
+ ToDoItemSubscriptions toDoItemSubscriptions;
+
+ ToDoItem toDoItem;
+
+ @Before
+ public void setUp() throws Exception {
+ final List<ToDoItem> all = toDoItems.notYetComplete();
+ toDoItem = wrap(all.get(0));
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ toDoItemSubscriptions.reset();
+ }
+
+
+ public static class Title extends ToDoItemIntegTest {
+
+ private LocalDate dueBy;
+
+ @Before
+ public void setUp() throws Exception {
+ final List<ToDoItem> all = wrap(toDoItems).notYetComplete();
+ toDoItem = wrap(all.get(0));
+
+ dueBy = toDoItem.getDueBy();
+ }
+
+
+ @Test
+ public void includesDescription() throws Exception {
+
+ // given
+ assertThat(container().titleOf(toDoItem), containsString("Buy bread due by"));
+
+ // when
+ unwrap(toDoItem).setDescription("Buy bread and butter");
+
+ // then
+ assertThat(container().titleOf(toDoItem), containsString("Buy bread and butter due by"));
+ }
+
+ @Test
+ public void includesDueDateIfAny() throws Exception {
+
+ // given
+ assertThat(container().titleOf(toDoItem), containsString("due by " + dueBy.toString("yyyy-MM-dd")));
+
+ // when
+ final LocalDate fiveDaysFromNow = Clock.getTimeAsLocalDate().plusDays(5);
+ unwrap(toDoItem).setDueBy(fiveDaysFromNow);
+
+ // then
+ assertThat(container().titleOf(toDoItem), containsString("due by " + fiveDaysFromNow.toString("yyyy-MM-dd")));
+ }
+
+
+ @Test
+ public void ignoresDueDateIfNone() throws Exception {
+
+ // when
+ // (since wrapped, will call clearDueBy)
+ toDoItem.setDueBy(null);
+
+ // then
+ assertThat(container().titleOf(toDoItem), not(containsString("due by")));
+ }
+
+ @Test
+ public void usesWhetherCompleted() throws Exception {
+
+ // given
+ assertThat(container().titleOf(toDoItem), not(containsString("Completed!")));
+
+ // when
+ toDoItem.completed();
+
+ // then
+ assertThat(container().titleOf(toDoItem), not(containsString("due by")));
+ assertThat(container().titleOf(toDoItem), containsString("Buy bread - Completed!"));
+ }
+ }
+
+ public static class Actions {
+
+ public static class Completed extends ToDoItemIntegTest {
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // given
+ assertThat(toDoItem.isComplete(), is(false));
+
+ // when
+ toDoItem.completed();
+
+ // then
+ assertThat(toDoItem.isComplete(), is(true));
+ }
+
+ @Test
+ public void cannotCompleteIfAlreadyCompleted() throws Exception {
+
+ // given
+ unwrap(toDoItem).setComplete(true);
+
+ // when, then should fail
+ expectedExceptions.expectMessage("Already completed");
+ toDoItem.completed();
+
+ // and then
+ final EventObject ev = toDoItemSubscriptions.mostRecentlyReceivedEvent(EventObject.class);
+ assertThat(ev, is(nullValue()));
+ }
+
+
+ @Test
+ public void cannotSetPropertyDirectly() throws Exception {
+
+ // given
+
+ // when, then should fail
+ expectedExceptions.expectMessage("Always disabled");
+ toDoItem.setComplete(true);
+
+ // and then
+ final EventObject ev = toDoItemSubscriptions.mostRecentlyReceivedEvent(EventObject.class);
+ assertThat(ev, is(nullValue()));
+ }
+
+ @Test
+ public void subscriberReceivesEvents() throws Exception {
+
+ // given
+ toDoItemSubscriptions.reset();
+ assertThat(toDoItemSubscriptions.getSubscriberBehaviour(), is(ToDoItemSubscriptions.Behaviour.AnyExecuteAccept));
+ assertThat(unwrap(toDoItem).isComplete(), is(false));
+
+ // when
+ toDoItem.completed();
+
+ // then
+ assertThat(unwrap(toDoItem).isComplete(), is(true));
+
+ // and then
+ final List<ToDoItem.CompletedEvent> receivedEvents = toDoItemSubscriptions.receivedEvents(ToDoItem.CompletedEvent.class);
+
+ // hide, disable, validate, executing, executed
+ // sent to both the general on(ActionInteractionEvent ev)
+ // and also the specific on(final ToDoItem.CompletedEvent ev)
+ assertThat(receivedEvents.size(), is(5*2));
+ final ToDoItem.CompletedEvent ev = receivedEvents.get(0);
+
+ ToDoItem source = ev.getSource();
+ assertThat(source, is(equalTo(unwrap(toDoItem))));
+ assertThat(ev.getIdentifier().getMemberName(), is("completed"));
+ }
+
+ @Test
+ public void subscriberVetoesEventWithRecoverableException() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithRecoverableException);
+
+ // then
+ expectedExceptions.expect(RecoverableException.class);
+
+ // when
+ toDoItem.completed();
+ }
+
+ @Test
+ public void subscriberVetoesEventWithNonRecoverableException() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithNonRecoverableException);
+
+ // then
+ expectedExceptions.expect(NonRecoverableException.class);
+
+ // when
+ toDoItem.completed();
+ }
+
+ @Test
+ public void subscriberThrowingOtherExceptionIsIgnored() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithOtherException);
+
+ // when
+ toDoItem.completed();
+
+ // then
+ // (no expectedExceptions setup, expect to continue)
+ assertTrue(true);
+ }
+
+ }
+
+ /**
+ * This test demonstrates how a single service can be replaced, eg to use a mock.
+ */
+ public static class Completed_withMockService extends ToDoItemIntegTest {
+
+ private EventBusService originalEventBusService;
+ @Mock
+ private EventBusService mockEventBusService;
+
+ @Before
+ public void setUpMockEventBusService() throws Exception {
+ originalEventBusService = scenarioExecution().service(EventBusService.class);
+
+ context.checking(new Expectations() {{
+ ignoring(mockEventBusService).register(with(any(Object.class)));
+ ignoring(mockEventBusService).unregister(with(any(Object.class)));
+ }});
+
+ scenarioExecution().replaceService(originalEventBusService, mockEventBusService);
+ scenarioExecution().closeSession();
+ scenarioExecution().openSession();
+ }
+
+ @After
+ public void reinstateOriginalEventBusService() throws Exception {
+ scenarioExecution().replaceService(mockEventBusService, originalEventBusService);
+ }
+
+ @Test
+ public void raisesEvent() throws Exception {
+
+ final Sequence busRulesThenExec = context.sequence("busRulesThenExec");
+ // then
+ context.checking(new Expectations() {{
+ oneOf(mockEventBusService).post(with(completedEvent(AbstractInteractionEvent.Phase.HIDE)));
+ inSequence(busRulesThenExec);
+ oneOf(mockEventBusService).post(with(completedEvent(AbstractInteractionEvent.Phase.DISABLE)));
+ inSequence(busRulesThenExec);
+ oneOf(mockEventBusService).post(with(completedEvent(AbstractInteractionEvent.Phase.VALIDATE)));
+ inSequence(busRulesThenExec);
+ oneOf(mockEventBusService).post(with(completedEvent(AbstractInteractionEvent.Phase.EXECUTING)));
+ inSequence(busRulesThenExec);
+ oneOf(mockEventBusService).post(with(completedEvent(AbstractInteractionEvent.Phase.EXECUTED)));
+ inSequence(busRulesThenExec);
+ }});
+
+ // when
+ toDoItem.completed();
+ }
+
+ private Matcher<Object> completedEvent(final AbstractInteractionEvent.Phase phase) {
+ return new TypeSafeMatcher<Object>() {
+ @Override
+ protected boolean matchesSafely(Object item) {
+ if (!(item instanceof ToDoItem.CompletedEvent)) {
+ return false;
+ }
+
+ final ToDoItem.CompletedEvent completedEvent = (ToDoItem.CompletedEvent) item;
+ return completedEvent.getPhase() == phase;
+
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(" instance of a ToDoItem.CompletedEvent, " + phase);
+ }
+ };
+ }
+ }
+
+
+ public static class Duplicate extends ToDoItemIntegTest {
+
+ ToDoItem duplicateToDoItem;
+
+ @Inject
+ private ClockService clockService;
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // given
+ final LocalDate todaysDate = clockService.now();
+ toDoItem.setDueBy(todaysDate);
+ toDoItem.updateCost(new BigDecimal("123.45"));
+
+ duplicateToDoItem = toDoItem.duplicate(
+ unwrap(toDoItem).default0Duplicate(),
+ unwrap(toDoItem).default1Duplicate(),
+ unwrap(toDoItem).default2Duplicate(),
+ unwrap(toDoItem).default3Duplicate(),
+ new BigDecimal("987.65"));
+
+ // then
+ assertThat(duplicateToDoItem.getDescription(), is(toDoItem.getDescription() + " - Copy"));
+ assertThat(duplicateToDoItem.getCategory(), is(toDoItem.getCategory()));
+ assertThat(duplicateToDoItem.getDueBy(), is(todaysDate));
+ assertThat(duplicateToDoItem.getCost(), is(new BigDecimal("987.65")));
+ }
+ }
+
+ public static class NotYetCompleted extends ToDoItemIntegTest {
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // given
+ unwrap(toDoItem).setComplete(true);
+
+ // when
+ toDoItem.notYetCompleted();
+
+ // then
+ assertThat(toDoItem.isComplete(), is(false));
+ }
+
+ @Test
+ public void cannotUndoIfNotYetCompleted() throws Exception {
+
+ // given
+ assertThat(toDoItem.isComplete(), is(false));
+
+ // when, then should fail
+ expectedExceptions.expectMessage("Not yet completed");
+ toDoItem.notYetCompleted();
+ }
+
+ /**
+ * Even though {@link dom.todo.ToDoItem${symbol_pound}notYetCompleted()} is not annotated with
+ * {@link org.apache.isis.applib.annotation.ActionInteraction}, an event is still raised.
+ */
+ @Test
+ public void subscriberReceivesEvent() throws Exception {
+
+ // given
+ assertThat(toDoItemSubscriptions.getSubscriberBehaviour(), is(ToDoItemSubscriptions.Behaviour.AnyExecuteAccept));
+ unwrap(toDoItem).setComplete(true);
+
+ // when
+ toDoItem.notYetCompleted();
+
+ // then
+ assertThat(unwrap(toDoItem).isComplete(), is(false));
+
+ // and then
+ final ActionInteractionEvent<ToDoItem> ev = toDoItemSubscriptions.mostRecentlyReceivedEvent(ActionInteractionEvent.class);
+ assertThat(ev, is(not(nullValue())));
+
+ ToDoItem source = ev.getSource();
+ assertThat(source, is(equalTo(unwrap(toDoItem))));
+ assertThat(ev.getIdentifier().getMemberName(), is("notYetCompleted"));
+ }
+ }
+ }
+
+ public static class Collections {
+
+ public static class Dependencies {
+ public static class Add extends ToDoItemIntegTest {
+
+ private ToDoItem otherToDoItem;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ final List<ToDoItem> items = wrap(toDoItems).notYetComplete();
+ otherToDoItem = wrap(items.get(1));
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ unwrap(toDoItem).getDependencies().clear();
+ super.tearDown();
+ }
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // given
+ assertThat(toDoItem.getDependencies().size(), is(0));
+
+ // when
+ toDoItem.add(otherToDoItem);
+
+ // then
+ assertThat(toDoItem.getDependencies().size(), is(1));
+ assertThat(toDoItem.getDependencies().first(), is(unwrap(otherToDoItem)));
+ }
+
+
+ @Test
+ public void cannotDependOnSelf() throws Exception {
+
+ // then
+ expectedExceptions.expectMessage("Can't set up a dependency to self");
+
+ // when
+ toDoItem.add(toDoItem);
+ }
+
+ @Test
+ public void cannotAddIfComplete() throws Exception {
+
+ // given
+ unwrap(toDoItem).setComplete(true);
+
+ // then
+ expectedExceptions.expectMessage("Cannot add dependencies for items that are complete");
+
+ // when
+ toDoItem.add(otherToDoItem);
+ }
+
+
+ @Test
+ public void subscriberReceivesEvent() throws Exception {
+
+ // given
+ toDoItemSubscriptions.reset();
+
+ // when
+ toDoItem.add(otherToDoItem);
+
+ // then received events
+ @SuppressWarnings("unchecked")
+ final List<EventObject> receivedEvents = toDoItemSubscriptions.receivedEvents();
+
+ assertThat(receivedEvents.size(), is(7));
+ assertThat(receivedEvents.get(0) instanceof ActionInteractionEvent, is(true)); // ToDoItem${symbol_pound}add() executed
+ assertThat(receivedEvents.get(1) instanceof CollectionInteractionEvent, is(true)); // ToDoItem${symbol_pound}dependencies add, executed
+ assertThat(receivedEvents.get(2) instanceof CollectionInteractionEvent, is(true)); // ToDoItem${symbol_pound}dependencies add, executing
+ assertThat(receivedEvents.get(3) instanceof ActionInteractionEvent, is(true)); // ToDoItem${symbol_pound}add executing
+ assertThat(receivedEvents.get(4) instanceof ActionInteractionEvent, is(true)); // ToDoItem${symbol_pound}add validate
+ assertThat(receivedEvents.get(5) instanceof ActionInteractionEvent, is(true)); // ToDoItem${symbol_pound}add disable
+ assertThat(receivedEvents.get(6) instanceof ActionInteractionEvent, is(true)); // ToDoItem${symbol_pound}add hide
+
+ // inspect the collection interaction (posted programmatically in ToDoItem${symbol_pound}add)
+ final CollectionInteractionEvent<ToDoItem,ToDoItem> ciEv = (CollectionInteractionEvent<ToDoItem, ToDoItem>) toDoItemSubscriptions.mostRecentlyReceivedEvent(CollectionInteractionEvent.class);
+ assertThat(ciEv, is(notNullValue()));
+
+ assertThat(ciEv.getSource(), is(equalTo(unwrap(toDoItem))));
+ assertThat(ciEv.getIdentifier().getMemberName(), is("dependencies"));
+ assertThat(ciEv.getOf(), is(CollectionInteractionEvent.Of.ADD_TO));
+ assertThat(ciEv.getValue(), is(unwrap(otherToDoItem)));
+
+ // inspect the action interaction (posted declaratively by framework)
+ final ActionInteractionEvent<ToDoItem> aiEv = (ActionInteractionEvent<ToDoItem>) toDoItemSubscriptions.mostRecentlyReceivedEvent(ActionInteractionEvent.class);
+ assertThat(aiEv, is(notNullValue()));
+
+ assertThat(aiEv.getSource(), is(equalTo(unwrap(toDoItem))));
+ assertThat(aiEv.getIdentifier().getMemberName(), is("add"));
+ assertThat(aiEv.getArguments().size(), is(1));
+ assertThat(aiEv.getArguments().get(0), is(unwrap((Object)otherToDoItem)));
+ assertThat(aiEv.getCommand(), is(notNullValue()));
+ }
+
+ @Test
+ public void subscriberVetoesEventWithRecoverableException() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithRecoverableException);
+
+ // then
+ expectedExceptions.expect(RecoverableException.class);
+
+ // when
+ toDoItem.add(otherToDoItem);
+ }
+
+ @Test
+ public void subscriberVetoesEventWithNonRecoverableException() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithNonRecoverableException);
+
+ // then
+ expectedExceptions.expect(NonRecoverableException.class);
+
+ // when
+ toDoItem.add(otherToDoItem);
+ }
+
+ @Test
+ public void subscriberThrowingOtherExceptionIsIgnored() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithOtherException);
+
+ // when
+ toDoItem.add(otherToDoItem);
+
+ // then
+ // (no expectedExceptions setup, expect to continue)
+ assertTrue(true);
+ }
+ }
+ public static class Remove extends ToDoItemIntegTest {
+
+ private ToDoItem otherToDoItem;
+ private ToDoItem yetAnotherToDoItem;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ final List<ToDoItem> items = wrap(toDoItems).notYetComplete();
+ otherToDoItem = wrap(items.get(1));
+ yetAnotherToDoItem = wrap(items.get(2));
+
+ toDoItem.add(otherToDoItem);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ unwrap(toDoItem).getDependencies().clear();
+ super.tearDown();
+ }
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // given
+ assertThat(toDoItem.getDependencies().size(), is(1));
+
+ // when
+ toDoItem.remove(otherToDoItem);
+
+ // then
+ assertThat(toDoItem.getDependencies().size(), is(0));
+ }
+
+
+ @Test
+ public void cannotRemoveItemIfNotADependency() throws Exception {
+
+ // then
+ expectedExceptions.expectMessage("Not a dependency");
+
+ // when
+ toDoItem.remove(yetAnotherToDoItem);
+ }
+
+ @Test
+ public void cannotRemoveDependencyIfComplete() throws Exception {
+
+ // given
+ unwrap(toDoItem).setComplete(true);
+
+ // then
+ expectedExceptions.expectMessage("Cannot remove dependencies for items that are complete");
+
+ // when
+ toDoItem.remove(otherToDoItem);
+ }
+
+ @Test
+ public void subscriberVetoesEventWithRecoverableException() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithRecoverableException);
+
+ // then
+ expectedExceptions.expect(RecoverableException.class);
+
+ // when
+ toDoItem.remove(otherToDoItem);
+ }
+
+ @Test
+ public void subscriberVetoesEventWithNonRecoverableException() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithNonRecoverableException);
+
+ // then
+ expectedExceptions.expect(NonRecoverableException.class);
+
+ // when
+ toDoItem.remove(otherToDoItem);
+ }
+
+ @Test
+ public void subscriberThrowingOtherExceptionIsIgnored() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithOtherException);
+
+ // when
+ toDoItem.remove(otherToDoItem);
+
+ // then
+ // (no expectedExceptions setup, expect to continue)
+ assertTrue(true);
+ }
+ }
+ }
+
+ }
+
+ public static class Properties {
+
+ public static class Attachment extends ToDoItemIntegTest {
+
+ @Test
+ public void happyCase() throws Exception {
+
+ byte[] bytes = "{${symbol_escape}"foo${symbol_escape}": ${symbol_escape}"bar${symbol_escape}"}".getBytes(Charset.forName("UTF-8"));
+ final Blob newAttachment = new Blob("myfile.json", new MimeType("application/json"), bytes);
+
+ // when
+ toDoItem.setAttachment(newAttachment);
+
+ // then
+ assertThat(toDoItem.getAttachment(), is(newAttachment));
+ }
+
+ @Test
+ public void canBeNull() throws Exception {
+
+ // when
+ toDoItem.setAttachment((Blob)null);
+
+ // then
+ assertThat(toDoItem.getAttachment(), is((Blob)null));
+ }
+ }
+
+ public static class Category extends ToDoItemIntegTest {
+
+ @Test
+ public void cannotModify() throws Exception {
+
+ // when, then
+ expectedExceptions.expectMessage(containsString("Reason: Use action to update both category and subcategory."));
+ toDoItem.setCategory(ToDoItem.Category.Professional);
+ }
+ }
+
+ public static class Cost extends ToDoItemIntegTest {
+
+ private BigDecimal cost;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ cost = toDoItem.getCost();
+ }
+
+ @Test
+ public void happyCaseUsingProperty() throws Exception {
+
+ final BigDecimal newCost = new BigDecimal("123.45");
+
+ // when
+ toDoItem.updateCost(newCost);
+
+ // then
+ assertThat(toDoItem.getCost(), is(newCost));
+ }
+
+ @Test
+ public void happyCaseUsingAction() throws Exception {
+
+ final BigDecimal newCost = new BigDecimal("123.45");
+
+ // when
+ toDoItem.updateCost(newCost);
+
+ // then
+ assertThat(toDoItem.getCost(), is(newCost));
+ }
+
+ @Test
+ public void canBeNull() throws Exception {
+
+ // when
+ toDoItem.updateCost((BigDecimal)null);
+
+ // then
+ assertThat(toDoItem.getCost(), is((BigDecimal)null));
+ }
+
+ @Test
+ public void defaultForAction() throws Exception {
+
+ // then
+ assertThat(unwrap(toDoItem).default0UpdateCost(), is(cost));
+ }
+
+ }
+
+ public static class Description extends ToDoItemIntegTest {
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // given
+ assertThat(toDoItem.getDescription(), is("Buy bread"));
+
+ // when
+ toDoItem.setDescription("Buy bread and butter");
+
+ // then
+ assertThat(toDoItem.getDescription(), is("Buy bread and butter"));
+ }
+
+
+ @Test
+ public void failsRegex() throws Exception {
+
+ // when
+ expectedExceptions.expectMessage("Doesn't match pattern");
+ toDoItem.setDescription("exclamation marks are not allowed!!!");
+ }
+
+ @Test
+ public void cannotBeNull() throws Exception {
+
+ // when, then
+ expectedExceptions.expectMessage("Mandatory");
+ toDoItem.setDescription(null);
+ }
+
+ @Test
+ public void cannotUseModify() throws Exception {
+
+ expectedExceptions.expectMessage("Cannot invoke supporting method for 'Description'; use only property accessor/mutator");
+
+ // given
+ assertThat(toDoItem.getDescription(), is("Buy bread"));
+
+ // when
+ toDoItem.modifyDescription("Buy bread and butter");
+
+ // then
+ assertThat(toDoItem.getDescription(), is("Buy bread"));
+ }
+
+ @Test
+ public void cannotUseClear() throws Exception {
+
+ expectedExceptions.expectMessage("Cannot invoke supporting method for 'Description'; use only property accessor/mutator");
+
+ // given
+ assertThat(toDoItem.getDescription(), is("Buy bread"));
+
+ // when
+ toDoItem.clearDescription();
+
+ // then
+ assertThat(toDoItem.getDescription(), is("Buy bread"));
+ }
+
+
+ @Test
+ public void onlyJustShortEnough() throws Exception {
+
+ // when, then
+ toDoItem.setDescription(characters(100));
+ }
+
+ @Test
+ public void tooLong() throws Exception {
+
+ // then
+ expectedExceptions.expectMessage("The value proposed exceeds the maximum length of 100");
+
+ // when
+ toDoItem.setDescription(characters(101));
+ }
+
+
+ @Test
+ public void subscriberReceivesEvent() throws Exception {
+
+ // given
+ assertThat(toDoItemSubscriptions.getSubscriberBehaviour(), is(ToDoItemSubscriptions.Behaviour.AnyExecuteAccept));
+ assertThat(toDoItem.getDescription(), is("Buy bread"));
+
+ // when
+ toDoItem.setDescription("Buy bread and butter");
+
+ // then published and received
+ @SuppressWarnings("unchecked")
+ final PropertyInteractionEvent<ToDoItem,String> ev = toDoItemSubscriptions.mostRecentlyReceivedEvent(PropertyInteractionEvent.class);
+ assertThat(ev, is(not(nullValue())));
+
+ ToDoItem source = ev.getSource();
+ assertThat(source, is(equalTo(unwrap(toDoItem))));
+ assertThat(ev.getIdentifier().getMemberName(), is("description"));
+ assertThat(ev.getOldValue(), is("Buy bread"));
+ assertThat(ev.getNewValue(), is("Buy bread and butter"));
+ }
+
+ @Test
+ public void subscriberVetoesEventWithRecoverableException() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithRecoverableException);
+
+ // then
+ expectedExceptions.expect(RecoverableException.class);
+
+ // when
+ toDoItem.setDescription("Buy bread and butter");
+ }
+
+
+ @Test
+ public void subscriberVetoesEventWithNonRecoverableException() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithNonRecoverableException);
+
+ // then
+ expectedExceptions.expect(NonRecoverableException.class);
+
+ // when
+ toDoItem.setDescription("Buy bread and butter");
+ }
+
+
+ @Test
+ public void subscriberThrowingOtherExceptionIsIgnored() throws Exception {
+
+ // given
+ toDoItemSubscriptions.subscriberBehaviour(null, ToDoItemSubscriptions.Behaviour.AnyExecuteVetoWithOtherException);
+
+ // when
+ toDoItem.setDescription("Buy bread and butter");
+
+ // then
+ // (no expectedExceptions setup, expect to continue)
+ assertTrue(true);
+ }
+
+
+ private static String characters(final int n) {
+ StringBuffer buf = new StringBuffer();
+ for(int i=0; i<n; i++) {
+ buf.append("a");
+ }
+ return buf.toString();
+ }
+ }
+
+ public static class DueBy extends ToDoItemIntegTest {
+
+ @Inject
+ private ClockService clockService;
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // when
+ final LocalDate fiveDaysFromNow = clockService.now().plusDays(5);
+ toDoItem.setDueBy(fiveDaysFromNow);
+
+ // then
+ assertThat(toDoItem.getDueBy(), is(fiveDaysFromNow));
+ }
+
+
+ @Test
+ public void canBeNull() throws Exception {
+
+ // when
+ toDoItem.setDueBy((LocalDate)null);
+
+ // then
+ assertThat(toDoItem.getDueBy(), is((LocalDate)null));
+ }
+
+ @Test
+ public void canBeUpToSixDaysInPast() throws Exception {
+
+ final LocalDate nowAsLocalDate = clockService.now();
+ final LocalDate sixDaysAgo = nowAsLocalDate.plusDays(-5);
+
+ // when
+ toDoItem.setDueBy(sixDaysAgo);
+
+ // then
+ assertThat(toDoItem.getDueBy(), is(sixDaysAgo));
+ }
+
+
+ @Test
+ public void cannotBeMoreThanSixDaysInPast() throws Exception {
+
+ final LocalDate sevenDaysAgo = Clock.getTimeAsLocalDate().plusDays(-7);
+
+ // when, then
+ expectedExceptions.expectMessage("Due by date cannot be more than one week old");
+ toDoItem.setDueBy(sevenDaysAgo);
+ }
+ }
+
+ public static class Notes extends ToDoItemIntegTest {
+
+ @Test
+ public void happyCase() throws Exception {
+
+ final String newNotes = "Lorem ipsum yada yada";
+
+ // when
+ toDoItem.setNotes(newNotes);
+
+ // then
+ assertThat(toDoItem.getNotes(), is(newNotes));
+ }
+
+ @Test
+ public void canBeNull() throws Exception {
+
+ // when
+ toDoItem.setNotes((String)null);
+
+ // then
+ assertThat(toDoItem.getNotes(), is((String)null));
+ }
+
+ @Test
+ public void suscriberReceivedDefaultEvent() throws Exception {
+
+ final String newNotes = "Lorem ipsum yada yada";
+
+ // when
+ toDoItem.setNotes(newNotes);
+
+ // then
+ assertThat(unwrap(toDoItem).getNotes(), is(newNotes));
+
+ // and then receive the default event.
+ @SuppressWarnings("unchecked")
+ final PropertyInteractionEvent.Default ev = toDoItemSubscriptions.mostRecentlyReceivedEvent(PropertyInteractionEvent.Default.class);
+ assertThat(ev, is(notNullValue()));
+
+ assertThat(ev.getSource(), is((Object)unwrap(toDoItem)));
+ assertThat(ev.getNewValue(), is((Object)newNotes));
+ }
+
+
+ }
+
+ public static class OwnedBy extends ToDoItemIntegTest {
+
+ @Test
+ public void cannotModify() throws Exception {
+
+ // when, then
+ expectedExceptions.expectMessage("Always hidden");
+ toDoItem.setOwnedBy("other");
+ }
+
+
+ }
+
+ public static class Subcategory extends ToDoItemIntegTest {
+
+ @Test
+ public void cannotModify() throws Exception {
+
+ // when, then
+ expectedExceptions.expectMessage(containsString("Reason: Use action to update both category and subcategory."));
+ toDoItem.setSubcategory(ToDoItem.Subcategory.Chores);
+ }
+ }
+
+ }
+
+
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemsIntegTest.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemsIntegTest.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemsIntegTest.java
new file mode 100644
index 0000000..c95e9c0
--- /dev/null
+++ b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/ToDoItemsIntegTest.java
@@ -0,0 +1,116 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * 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 integration.tests;
+
+import dom.todo.ToDoItem;
+import dom.todo.ToDoItems;
+import fixture.todo.integtests.ToDoItemsIntegTestFixture;
+
+import java.util.List;
+import javax.inject.Inject;
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class ToDoItemsIntegTest extends AbstractToDoIntegTest {
+
+ @Inject
+ ToDoItems toDoItems;
+
+ public static class Finders extends ToDoItemsIntegTest {
+
+ @Before
+ public void setUpData() throws Exception {
+ scenarioExecution().install(new ToDoItemsIntegTestFixture());
+ }
+
+ private int notYetCompletedSize;
+ private int completedSize;
+
+ @Before
+ public void setUp() throws Exception {
+ final List<ToDoItem> notYetCompleteItems = wrap(toDoItems).notYetComplete();
+ final List<ToDoItem> completedItems = wrap(toDoItems).complete();
+
+ notYetCompletedSize = notYetCompleteItems.size();
+ completedSize = completedItems.size();
+
+ assertThat(notYetCompletedSize, is(Matchers.greaterThan(5)));
+ }
+
+ @Test
+ public void complete_and_notYetComplete() throws Exception {
+
+ // given
+ List<ToDoItem> notYetCompleteItems = wrap(service(ToDoItems.class)).notYetComplete();
+ final ToDoItem toDoItem = wrap(notYetCompleteItems.get(0));
+
+ // when
+ toDoItem.completed();
+
+ // then
+ assertThat(wrap(service(ToDoItems.class)).notYetComplete().size(), is(notYetCompletedSize-1));
+ assertThat(wrap(service(ToDoItems.class)).complete().size(), is(completedSize+1));
+
+ // and when
+ toDoItem.notYetCompleted();
+
+ // then
+ assertThat(wrap(service(ToDoItems.class)).notYetComplete().size(), is(notYetCompletedSize));
+ assertThat(wrap(service(ToDoItems.class)).complete().size(), is(completedSize));
+ }
+ }
+
+ public static class NewToDo_and_Delete extends ToDoItemsIntegTest {
+
+ @Before
+ public void setUpData() throws Exception {
+ // none
+ }
+
+ @Test
+ public void happyCase() throws Exception {
+
+ // given
+ int size = wrap(toDoItems).notYetComplete().size();
+
+ // when
+ final ToDoItem newToDo = toDoItems.newToDo("new todo", ToDoItem.Category.Professional, ToDoItem.Subcategory.OpenSource, null, null);
+
+ // then
+ assertThat(newToDo.getDescription(), is("new todo"));
+ assertThat(newToDo.getCategory(), is(ToDoItem.Category.Professional));
+ assertThat(wrap(service(ToDoItems.class)).notYetComplete().size(), is(size+1));
+
+ // when
+ newToDo.delete();
+
+ // then
+ assertThat(wrap(service(ToDoItems.class)).notYetComplete().size(), is(size));
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemContributionsTest_updateCategory.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemContributionsTest_updateCategory.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemContributionsTest_updateCategory.java
deleted file mode 100644
index 9fd3683..0000000
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemContributionsTest_updateCategory.java
+++ /dev/null
@@ -1,106 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*
- * 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 integration.tests.actions;
-
-import dom.todo.ToDoItem;
-import dom.todo.ToDoItem.Category;
-import dom.todo.ToDoItem.Subcategory;
-import dom.todo.ToDoItemContributions;
-import dom.todo.ToDoItems;
-import fixture.todo.integtests.ToDoItemsIntegTestFixture;
-import integration.tests.ToDoIntegTest;
-
-import java.util.List;
-import javax.inject.Inject;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class ToDoItemContributionsTest_updateCategory extends ToDoIntegTest {
-
- @Before
- public void setUpData() throws Exception {
- scenarioExecution().install(new ToDoItemsIntegTestFixture().withTracing());
- }
-
- @Inject
- private ToDoItems toDoItems;
- @Inject
- private ToDoItemContributions toDoItemContributions;
-
- private ToDoItemContributions toDoItemContributionsWrapper;
- private ToDoItem toDoItem;
-
- @Before
- public void setUp() throws Exception {
- final List<ToDoItem> all = toDoItems.notYetComplete();
- toDoItem = wrap(all.get(0));
-
- toDoItemContributionsWrapper = wrap(toDoItemContributions);
- }
-
- @Test
- public void happyCase() throws Exception {
-
- // when
- toDoItemContributionsWrapper.updateCategory(toDoItem, Category.Professional, Subcategory.Consulting);
-
- // then
- assertThat(toDoItem.getCategory(), is(Category.Professional));
- assertThat(toDoItem.getSubcategory(), is(Subcategory.Consulting));
-
- // when
- toDoItemContributionsWrapper.updateCategory(toDoItem, Category.Domestic, Subcategory.Chores);
-
- // then
- assertThat(toDoItem.getCategory(), is(Category.Domestic));
- assertThat(toDoItem.getSubcategory(), is(Subcategory.Chores));
- }
-
-
- @Test
- public void categoryCannotBeNull() throws Exception {
-
- // when, then
- expectedExceptions.expectMessage("'Category' is mandatory");
- toDoItemContributionsWrapper.updateCategory(toDoItem, null, Subcategory.Chores);
- }
-
- @Test
- public void subcategoryCanBeNull() throws Exception {
-
- // when, then
- toDoItemContributionsWrapper.updateCategory(toDoItem, Category.Professional, null);
- }
-
- @Test
- public void subcategoryMustBelongToCategory() throws Exception {
-
- // when, then
- expectedExceptions.expectMessage(containsString("Invalid subcategory"));
- toDoItemContributionsWrapper.updateCategory(toDoItem, Category.Professional, Subcategory.Chores);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_completed.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_completed.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_completed.java
deleted file mode 100644
index 98e5ee8..0000000
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_completed.java
+++ /dev/null
@@ -1,174 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*
- * 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 integration.tests.actions;
-
-import dom.todo.ToDoItem;
-import dom.todo.ToDoItemSubscriptions;
-import dom.todo.ToDoItems;
-import fixture.todo.integtests.ToDoItemsIntegTestFixture;
-import integration.tests.ToDoIntegTest;
-
-import java.util.EventObject;
-import java.util.List;
-import javax.inject.Inject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.isis.applib.NonRecoverableException;
-import org.apache.isis.applib.RecoverableException;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public class ToDoItemTest_completed extends ToDoIntegTest {
-
- @Before
- public void setUpData() throws Exception {
- scenarioExecution().install(new ToDoItemsIntegTestFixture());
- }
-
- @Inject
- private ToDoItems toDoItems;
- @Inject
- private ToDoItemSubscriptions toDoItemSubscriptions;
-
- private ToDoItem toDoItem;
-
- @Before
- public void setUp() throws Exception {
- final List<ToDoItem> all = toDoItems.notYetComplete();
- toDoItem = wrap(all.get(0));
- }
-
- @After
- public void tearDown() throws Exception {
- toDoItemSubscriptions.reset();
- }
-
- @Test
- public void happyCase() throws Exception {
-
- // given
- assertThat(toDoItem.isComplete(), is(false));
-
- // when
- toDoItem.completed();
-
- // then
- assertThat(toDoItem.isComplete(), is(true));
- }
-
- @Test
- public void cannotCompleteIfAlreadyCompleted() throws Exception {
-
- // given
- unwrap(toDoItem).setComplete(true);
-
- // when, then should fail
- expectedExceptions.expectMessage("Already completed");
- toDoItem.completed();
-
- // and then
- final EventObject ev = toDoItemSubscriptions.mostRecentlyReceivedEvent(EventObject.class);
- assertThat(ev, is(nullValue()));
- }
-
-
- @Test
- public void cannotSetPropertyDirectly() throws Exception {
-
- // given
-
- // when, then should fail
- expectedExceptions.expectMessage("Always disabled");
- toDoItem.setComplete(true);
-
- // and then
- final EventObject ev = toDoItemSubscriptions.mostRecentlyReceivedEvent(EventObject.class);
- assertThat(ev, is(nullValue()));
- }
-
- @Test
- public void subscriberReceivesEvent() throws Exception {
-
- // given
- assertThat(toDoItemSubscriptions.getSubscriberBehaviour(), is(ToDoItemSubscriptions.Behaviour.AcceptEvents));
- assertThat(toDoItem.isComplete(), is(false));
-
- // when
- toDoItem.completed();
-
- // then
- assertThat(toDoItem.isComplete(), is(true));
-
- // and then
- final ToDoItem.CompletedEvent ev = toDoItemSubscriptions.mostRecentlyReceivedEvent(ToDoItem.CompletedEvent.class);
- assertThat(ev, is(not(nullValue())));
-
- ToDoItem source = ev.getSource();
- assertThat(source, is(equalTo(unwrap(toDoItem))));
- assertThat(ev.getIdentifier().getMemberName(), is("completed"));
- }
-
- @Test
- public void subscriberVetoesEventWithRecoverableException() throws Exception {
-
- // given
- toDoItemSubscriptions.subscriberBehaviour(ToDoItemSubscriptions.Behaviour.RejectEventsWithRecoverableException);
-
- // then
- expectedExceptions.expect(RecoverableException.class);
-
- // when
- toDoItem.completed();
- }
-
- @Test
- public void subscriberVetoesEventWithNonRecoverableException() throws Exception {
-
- // given
- toDoItemSubscriptions.subscriberBehaviour(ToDoItemSubscriptions.Behaviour.RejectEventsWithNonRecoverableException);
-
- // then
- expectedExceptions.expect(NonRecoverableException.class);
-
- // when
- toDoItem.completed();
- }
-
- @Test
- public void subscriberThrowingOtherExceptionIsIgnored() throws Exception {
-
- // given
- toDoItemSubscriptions.subscriberBehaviour(ToDoItemSubscriptions.Behaviour.ThrowOtherException);
-
- // when
- toDoItem.completed();
-
- // then
- // (no expectedExceptions setup, expect to continue)
- assertTrue(true);
- }
-
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_duplicate.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_duplicate.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_duplicate.java
deleted file mode 100644
index e959918..0000000
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_duplicate.java
+++ /dev/null
@@ -1,83 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*
- * 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 integration.tests.actions;
-
-import dom.todo.ToDoItem;
-import dom.todo.ToDoItems;
-import fixture.todo.integtests.ToDoItemsIntegTestFixture;
-import integration.tests.ToDoIntegTest;
-
-import java.math.BigDecimal;
-import java.util.List;
-import javax.inject.Inject;
-import org.joda.time.LocalDate;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.isis.applib.services.clock.ClockService;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class ToDoItemTest_duplicate extends ToDoIntegTest {
-
- @Before
- public void setUpData() throws Exception {
- scenarioExecution().install(new ToDoItemsIntegTestFixture());
- }
-
- @Inject
- private ToDoItems toDoItems;
- @Inject
- private ClockService clockService;
-
- private ToDoItem toDoItem;
- private ToDoItem duplicateToDoItem;
-
- @Before
- public void setUp() throws Exception {
- final List<ToDoItem> all = wrap(toDoItems).notYetComplete();
- toDoItem = wrap(all.get(0));
- }
-
- @Test
- public void happyCase() throws Exception {
-
- // given
- final LocalDate todaysDate = clockService.now();
- toDoItem.setDueBy(todaysDate);
- toDoItem.updateCost(new BigDecimal("123.45"));
-
- duplicateToDoItem = toDoItem.duplicate(
- unwrap(toDoItem).default0Duplicate(),
- unwrap(toDoItem).default1Duplicate(),
- unwrap(toDoItem).default2Duplicate(),
- unwrap(toDoItem).default3Duplicate(),
- new BigDecimal("987.65"));
-
- // then
- assertThat(duplicateToDoItem.getDescription(), is(toDoItem.getDescription() + " - Copy"));
- assertThat(duplicateToDoItem.getCategory(), is(toDoItem.getCategory()));
- assertThat(duplicateToDoItem.getDueBy(), is(todaysDate));
- assertThat(duplicateToDoItem.getCost(), is(new BigDecimal("987.65")));
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_notYetCompleted.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_notYetCompleted.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_notYetCompleted.java
deleted file mode 100644
index 47ff7d8..0000000
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/actions/ToDoItemTest_notYetCompleted.java
+++ /dev/null
@@ -1,79 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*
- * 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 integration.tests.actions;
-
-import dom.todo.ToDoItem;
-import dom.todo.ToDoItems;
-import fixture.todo.integtests.ToDoItemsIntegTestFixture;
-import integration.tests.ToDoIntegTest;
-
-import java.util.List;
-import javax.inject.Inject;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class ToDoItemTest_notYetCompleted extends ToDoIntegTest {
-
- @Before
- public void setUpData() throws Exception {
- scenarioExecution().install(new ToDoItemsIntegTestFixture());
- }
-
- @Inject
- private ToDoItems toDoItems;
-
- private ToDoItem toDoItem;
-
- @Before
- public void setUp() throws Exception {
- final List<ToDoItem> all = wrap(toDoItems).notYetComplete();
- toDoItem = wrap(all.get(0));
- }
-
- @Test
- public void happyCase() throws Exception {
-
- // given
- unwrap(toDoItem).setComplete(true);
-
- // when
- toDoItem.notYetCompleted();
-
- // then
- assertThat(toDoItem.isComplete(), is(false));
- }
-
- @Test
- public void cannotUndoIfNotYetCompleted() throws Exception {
-
- // given
- assertThat(toDoItem.isComplete(), is(false));
-
- // when, then should fail
- expectedExceptions.expectMessage("Not yet completed");
- toDoItem.notYetCompleted();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/04e8ba20/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/colls/ToDoItemContributionsTest_similarTo.java
----------------------------------------------------------------------
diff --git a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/colls/ToDoItemContributionsTest_similarTo.java b/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/colls/ToDoItemContributionsTest_similarTo.java
deleted file mode 100644
index 451904a..0000000
--- a/example/archetype/todoapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/colls/ToDoItemContributionsTest_similarTo.java
+++ /dev/null
@@ -1,71 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*
- * 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 integration.tests.colls;
-
-import dom.todo.ToDoItem;
-import dom.todo.ToDoItemContributions;
-import dom.todo.ToDoItems;
-import fixture.todo.integtests.ToDoItemsIntegTestFixture;
-import integration.tests.ToDoIntegTest;
-
-import java.util.List;
-import javax.inject.Inject;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class ToDoItemContributionsTest_similarTo extends ToDoIntegTest {
-
- @Before
- public void setUpData() throws Exception {
- scenarioExecution().install(new ToDoItemsIntegTestFixture());
- }
-
- @Inject
- private ToDoItems toDoItems;
- @Inject
- private ToDoItemContributions toDoItemContributions;
-
- private ToDoItemContributions toDoItemContributionsWrapped;
- private ToDoItem toDoItem;
-
- @Before
- public void setUp() throws Exception {
- final List<ToDoItem> all = this.toDoItems.notYetComplete();
- toDoItem = wrap(all.get(0));
-
- toDoItemContributionsWrapped = wrap(toDoItemContributions);
- }
-
- @Test
- public void happyCase() throws Exception {
-
- // when
- List<ToDoItem> similarItems = toDoItemContributionsWrapped.similarTo(toDoItem);
-
- // then
- assertThat(similarItems.size(), is(6));
- }
-
-}
\ No newline at end of file