ISIS-953: enhancements to FixtureScript.ExecutionContext Also: - refactoring the todoapp and simpleapp to use FixtureScripts, lookup(...), and using composite fixtures.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/75735601 Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/75735601 Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/75735601 Branch: refs/heads/master Commit: 75735601cd62234d9b5e0c531de5622ab07be2be Parents: 0d9b74a Author: Dan Haywood <d...@haywood-associates.co.uk> Authored: Tue Nov 18 11:31:10 2014 +0100 Committer: Dan Haywood <d...@haywood-associates.co.uk> Committed: Tue Nov 18 11:31:10 2014 +0100 ---------------------------------------------------------------------- .../applib/fixturescripts/FixtureScript.java | 56 ++++++ .../fixturescripts/ExecutionContextTest.java | 174 +++++++++++++++++++ .../ExecutionContextTest_roundUp.java | 39 ----- .../src/main/java/dom/simple/SimpleObject.java | 1 + .../fixture/simple/SimpleObjectsFixture.java | 56 ------ .../simple/SimpleObjectsFixturesService.java | 4 +- .../simple/objects/SimpleObjectAbstract.java | 36 ++++ .../simple/objects/SimpleObjectForBar.java | 31 ++++ .../simple/objects/SimpleObjectForBaz.java | 31 ++++ .../simple/objects/SimpleObjectForFoo.java | 31 ++++ .../simple/scenario/SimpleObjectsFixture.java | 45 +++++ .../integration/glue/CatalogOfFixturesGlue.java | 2 +- .../tests/smoke/SimpleObjectTest.java | 82 +++++++++ .../tests/smoke/SimpleObjectsTest.java | 148 ++++++++++++++++ .../SimpleObjectsTest_listAll_and_create.java | 66 ------- .../src/main/webapp/WEB-INF/isis.properties | 2 +- .../fixture/todo/ToDoItemsFixturesService.java | 15 +- .../integtests/ToDoItemsIntegTestFixture.java | 4 +- .../complete/ToDoItemCompleteAbstract.java | 70 ++++++++ .../complete/ToDoItemCompleteForBuyStamps.java | 35 ++++ .../ToDoItemCompleteForWriteBlogPost.java | 36 ++++ .../todo/items/create/ToDoItemAbstract.java | 69 ++++++++ .../todo/items/create/ToDoItemForBuyBread.java | 37 ++++ .../todo/items/create/ToDoItemForBuyMilk.java | 37 ++++ .../todo/items/create/ToDoItemForBuyStamps.java | 39 +++++ .../todo/items/create/ToDoItemForMowLawn.java | 37 ++++ .../create/ToDoItemForOrganizeBrownBag.java | 37 ++++ .../items/create/ToDoItemForPickUpLaundry.java | 37 ++++ .../items/create/ToDoItemForSharpenKnives.java | 37 ++++ .../create/ToDoItemForStageIsisRelease.java | 37 ++++ .../ToDoItemForSubmitConferenceSession.java | 37 ++++ .../items/create/ToDoItemForVacuumHouse.java | 37 ++++ .../items/create/ToDoItemForWriteBlogPost.java | 39 +++++ .../items/create/ToDoItemForWriteToPenPal.java | 37 ++++ .../todo/items/delete/ToDoItemsDelete.java | 53 ++++++ .../todo/scenarios/DeleteToDoItemsFor.java | 36 ---- .../todo/scenarios/DeleteToDoItemsForSven.java | 30 ---- ...teToDoItemsAndCompleteSeveralForCurrent.java | 30 ---- .../todo/scenarios/RecreateToDoItemsFor.java | 36 ---- .../scenarios/RecreateToDoItemsForDick.java | 29 ---- .../todo/scenarios/RecreateToDoItemsForJoe.java | 29 ---- .../scenarios/RecreateToDoItemsForSven.java | 29 ---- .../todo/scenarios/ToDoItemsRecreate.java | 81 +++++++++ .../ToDoItemsRecreateAndCompleteSeveral.java | 60 +++++++ ...oItemsRecreateAndCompleteSeveralForDick.java | 28 +++ ...DoItemsRecreateAndCompleteSeveralForJoe.java | 28 +++ .../scenarios/ToDoItemsRecreateForSven.java | 29 ++++ .../fixture/todo/simple/ToDoItemsDelete.java | 53 ------ .../fixture/todo/simple/ToDoItemsRecreate.java | 95 ---------- .../ToDoItemsRecreateAndCompleteSeveral.java | 72 -------- .../src/main/java/fixture/todo/simple/Util.java | 36 ---- .../src/main/java/fixture/todo/util/Util.java | 32 ++++ .../tests/ToDoItemContributionsIntegTest.java | 5 +- .../integration/tests/ToDoItemIntegTest.java | 3 +- .../src/main/webapp/WEB-INF/isis.properties | 2 +- 55 files changed, 1628 insertions(+), 649 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java ---------------------------------------------------------------------- diff --git a/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java b/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java index 97832a3..4c0b22a 100644 --- a/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java +++ b/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java @@ -18,12 +18,17 @@ */ package org.apache.isis.applib.fixturescripts; +import java.io.IOException; import java.io.PrintStream; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; +import com.google.common.io.CharSource; import org.apache.isis.applib.AbstractViewModel; import org.apache.isis.applib.DomainObjectContainer; import org.apache.isis.applib.annotation.Hidden; @@ -253,20 +258,69 @@ public abstract class FixtureScript } }; + private static Pattern keyEqualsValuePattern = Pattern.compile("([^=]*)=(.*)"); private final String parameters; private final FixtureScripts fixtureScripts; private final FixtureResultList fixtureResultList; + private final Map<String, String> parameterMap; + ; public ExecutionContext(final String parameters, final FixtureScripts fixtureScripts) { this.fixtureScripts = fixtureScripts; fixtureResultList = new FixtureResultList(fixtureScripts, this); this.parameters = parameters; + this.parameterMap = asKeyValueMap(parameters); + } + + public static Map<String, String> asKeyValueMap(String parameters) { + Map<String,String> keyValues = Maps.newLinkedHashMap(); + if(parameters != null) { + try { + final ImmutableList<String> lines = CharSource.wrap(parameters).readLines(); + for (String line : lines) { + if (line == null) { + continue; + } + final Matcher matcher = keyEqualsValuePattern.matcher(line); + if (matcher.matches()) { + keyValues.put(matcher.group(1).trim(), matcher.group(2).trim()); + } + } + } catch (IOException e) { + // ignore, shouldn't happen + } + } + return keyValues; } public String getParameters() { return parameters; } + + public String getParameter(String parameterName) { + return getParameterMap().get(parameterName); + } + + public Map<String,String> getParameterMap() { + return Collections.unmodifiableMap(parameterMap); + } + + public void setParameterIfNotPresent(String parameterName, String parameterValue) { + if(parameterName == null) { + throw new IllegalArgumentException("parameterName required"); + } + if(parameterValue == null) { + // ignore + return; + } + if(parameterMap.containsKey(parameterName)) { + // ignore; the supplies parameters take precedence + return; + } + parameterMap.put(parameterName, parameterValue); + } + public List<FixtureResult> getResults() { return fixtureResultList.getResults(); } @@ -285,6 +339,7 @@ public abstract class FixtureScript return fixtureResultList.lookup(key, cls); } + static enum As { EXEC, SKIP } /** @@ -396,6 +451,7 @@ public abstract class FixtureScript return executionContext.lookup(key, cls); } + /** * Optional hook to validate parameters. */ http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionContextTest.java ---------------------------------------------------------------------- diff --git a/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionContextTest.java b/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionContextTest.java new file mode 100644 index 0000000..fdbf192 --- /dev/null +++ b/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionContextTest.java @@ -0,0 +1,174 @@ +package org.apache.isis.applib.fixturescripts; + +import java.util.Map; +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +public class ExecutionContextTest { + + public static class AsKeyValueMap extends ExecutionContextTest { + + @Test + public void happyCase() throws Exception { + final Map<String, String> map = FixtureScript.ExecutionContext.asKeyValueMap("foo=bar\nbop=baz"); + assertThat(map.size(), is(2)); + + assertThat(map.get("foo"), is("bar")); + assertThat(map.get("bop"), is("baz")); + } + + @Test + public void givenNull() throws Exception { + final Map<String, String> map = FixtureScript.ExecutionContext.asKeyValueMap(null); + assertThat(map.size(), is(0)); + } + + @Test + public void givenEmpty() throws Exception { + final Map<String, String> map = FixtureScript.ExecutionContext.asKeyValueMap(""); + assertThat(map.size(), is(0)); + } + + @Test + public void trim() throws Exception { + + final Map<String, String> map = FixtureScript.ExecutionContext.asKeyValueMap(" foo=bar\nbop=baz \n bip = bap "); + assertThat(map.size(), is(3)); + + assertThat(map.get("foo"), is("bar")); + assertThat(map.get("bop"), is("baz")); + assertThat(map.get("bip"), is("bap")); + } + + @Test + public void malformed() throws Exception { + final Map<String, String> map = FixtureScript.ExecutionContext.asKeyValueMap("abcde"); + assertThat(map.size(), is(0)); + } + + @Test + public void partiallyMalformed() throws Exception { + final Map<String, String> map = FixtureScript.ExecutionContext.asKeyValueMap("foo=bar\nabcde\nbop=baz"); + assertThat(map.size(), is(2)); + + assertThat(map.get("foo"), is("bar")); + assertThat(map.get("bop"), is("baz")); + } + } + + + public static class GetParameter extends ExecutionContextTest { + + @Test + public void happyCase() throws Exception { + final FixtureScript.ExecutionContext executionContext = new FixtureScript.ExecutionContext("foo=bar\nbop=baz", null); + + final Map<String, String> map = executionContext.getParameterMap(); + assertThat(map.size(), is(2)); + + assertThat(map.get("foo"), is("bar")); + assertThat(map.get("bop"), is("baz")); + + assertThat(executionContext.getParameter("foo"), is("bar")); + assertThat(executionContext.getParameter("bop"), is("baz")); + + } + + @Test + public void givenNull() throws Exception { + final FixtureScript.ExecutionContext executionContext = new FixtureScript.ExecutionContext(null, null); + final Map<String, String> map = executionContext.getParameterMap(); + assertThat(map.size(), is(0)); + + assertThat(executionContext.getParameter("foo"), is(nullValue())); + } + + @Test + public void givenEmpty() throws Exception { + final FixtureScript.ExecutionContext executionContext = new FixtureScript.ExecutionContext("", null); + final Map<String, String> map = executionContext.getParameterMap(); + assertThat(map.size(), is(0)); + + assertThat(executionContext.getParameter("foo"), is(nullValue())); + } + + @Test + public void malformed() throws Exception { + final FixtureScript.ExecutionContext executionContext = new FixtureScript.ExecutionContext("abcde", null); + final Map<String, String> map = executionContext.getParameterMap(); + assertThat(map.size(), is(0)); + + assertThat(executionContext.getParameter("foo"), is(nullValue())); + } + + @Test + public void partiallyMalformed() throws Exception { + final FixtureScript.ExecutionContext executionContext = new FixtureScript.ExecutionContext("foo=bar\nabcde\nbop=baz", null); + + final Map<String, String> map = executionContext.getParameterMap(); + assertThat(map.size(), is(2)); + + assertThat(map.get("foo"), is("bar")); + assertThat(map.get("bop"), is("baz")); + + assertThat(executionContext.getParameter("foo"), is("bar")); + assertThat(executionContext.getParameter("bop"), is("baz")); + } + + @Test + public void trim() throws Exception { + final FixtureScript.ExecutionContext executionContext = new FixtureScript.ExecutionContext(" foo=bar\nbop=baz \n bip = bap ", null); + + final Map<String, String> map = executionContext.getParameterMap(); + assertThat(map.size(), is(3)); + + assertThat(map.get("foo"), is("bar")); + assertThat(map.get("bop"), is("baz")); + assertThat(map.get("bip"), is("bap")); + + assertThat(executionContext.getParameter("foo"), is("bar")); + assertThat(executionContext.getParameter("bop"), is("baz")); + assertThat(executionContext.getParameter("bip"), is("bap")); + } + + } + public static class SetParameterIfNotPresent extends ExecutionContextTest { + + @Test + public void whenNotPresent() throws Exception { + final FixtureScript.ExecutionContext executionContext = new FixtureScript.ExecutionContext(null, null); + executionContext.setParameterIfNotPresent("foo", "bar"); + + assertThat(executionContext.getParameter("foo"), is("bar")); + } + + @Test + public void whenPresent() throws Exception { + final FixtureScript.ExecutionContext executionContext = new FixtureScript.ExecutionContext("foo=bop\n", null); + executionContext.setParameterIfNotPresent("foo", "bar"); + + assertThat(executionContext.getParameter("foo"), is("bop")); + } + + } + + public static class RoundUp extends ExecutionContextTest { + + @Test + public void happyCase() throws Exception { + Assert.assertThat(FixtureScript.ExecutionContext.roundup(5, 20), Matchers.is(20)); + Assert.assertThat(FixtureScript.ExecutionContext.roundup(19, 20), Matchers.is(20)); + Assert.assertThat(FixtureScript.ExecutionContext.roundup(20, 20), Matchers.is(40)); + Assert.assertThat(FixtureScript.ExecutionContext.roundup(21, 20), Matchers.is(40)); + Assert.assertThat(FixtureScript.ExecutionContext.roundup(39, 20), Matchers.is(40)); + Assert.assertThat(FixtureScript.ExecutionContext.roundup(40, 20), Matchers.is(60)); + } + + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionContextTest_roundUp.java ---------------------------------------------------------------------- diff --git a/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionContextTest_roundUp.java b/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionContextTest_roundUp.java deleted file mode 100644 index 82ac787..0000000 --- a/core/applib/src/test/java/org/apache/isis/applib/fixturescripts/ExecutionContextTest_roundUp.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.isis.applib.fixturescripts; - -import org.junit.Assert; -import org.junit.Test; - -import static org.hamcrest.Matchers.is; - -public class ExecutionContextTest_roundUp { - - @Test - public void happyCase() throws Exception { - Assert.assertThat(FixtureScript.ExecutionContext.roundup(5, 20), is(20)); - Assert.assertThat(FixtureScript.ExecutionContext.roundup(19, 20), is(20)); - Assert.assertThat(FixtureScript.ExecutionContext.roundup(20, 20), is(40)); - Assert.assertThat(FixtureScript.ExecutionContext.roundup(21, 20), is(40)); - Assert.assertThat(FixtureScript.ExecutionContext.roundup(39, 20), is(40)); - Assert.assertThat(FixtureScript.ExecutionContext.roundup(40, 20), is(60)); - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/dom/src/main/java/dom/simple/SimpleObject.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/dom/src/main/java/dom/simple/SimpleObject.java b/example/application/simpleapp/dom/src/main/java/dom/simple/SimpleObject.java index a5f8e43..74cef09 100644 --- a/example/application/simpleapp/dom/src/main/java/dom/simple/SimpleObject.java +++ b/example/application/simpleapp/dom/src/main/java/dom/simple/SimpleObject.java @@ -34,6 +34,7 @@ import org.apache.isis.applib.util.ObjectContracts; @javax.jdo.annotations.Version( strategy=VersionStrategy.VERSION_NUMBER, column="version") +@javax.jdo.annotations.Unique(name="SimpleObject_name_UNQ", members = {"name"}) @ObjectType("SIMPLE") @Bookmarkable public class SimpleObject implements Comparable<SimpleObject> { http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixture.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixture.java b/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixture.java deleted file mode 100644 index 7be750b..0000000 --- a/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixture.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package fixture.simple; - -import dom.simple.SimpleObject; -import dom.simple.SimpleObjects; - -import org.apache.isis.applib.fixturescripts.FixtureScript; - -public class SimpleObjectsFixture extends FixtureScript { - - public SimpleObjectsFixture() { - withDiscoverability(Discoverability.DISCOVERABLE); - } - - @Override - protected void execute(ExecutionContext executionContext) { - - // prereqs - executeChild(new SimpleObjectsTearDownFixture(), executionContext); - - // create - create("Foo", executionContext); - create("Bar", executionContext); - create("Baz", executionContext); - } - - // ////////////////////////////////////// - - private SimpleObject create(final String name, ExecutionContext executionContext) { - return executionContext.add(this, simpleObjects.create(name)); - } - - // ////////////////////////////////////// - - @javax.inject.Inject - private SimpleObjects simpleObjects; - -} http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java b/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java index fcb6c49..7868d3c 100644 --- a/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java +++ b/example/application/simpleapp/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java @@ -18,6 +18,8 @@ */ package fixture.simple; +import fixture.simple.scenario.SimpleObjectsFixture; + import java.util.List; import org.apache.isis.applib.annotation.DomainService; import org.apache.isis.applib.annotation.MemberOrder; @@ -39,7 +41,7 @@ public class SimpleObjectsFixturesService extends FixtureScripts { super("fixture.simple"); } - //@Override // compatibility with core 1.5.0 + @Override public FixtureScript default0RunFixtureScript() { return findFixtureScriptFor(SimpleFixtureScript.class); } http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectAbstract.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectAbstract.java b/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectAbstract.java new file mode 100644 index 0000000..d72578e --- /dev/null +++ b/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectAbstract.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 fixture.simple.objects; + +import dom.simple.SimpleObject; +import dom.simple.SimpleObjects; + +import org.apache.isis.applib.fixturescripts.FixtureScript; + +public abstract class SimpleObjectAbstract extends FixtureScript { + + protected SimpleObject create(final String name, ExecutionContext executionContext) { + return executionContext.add(this, simpleObjects.create(name)); + } + + @javax.inject.Inject + private SimpleObjects simpleObjects; + +} http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBar.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBar.java b/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBar.java new file mode 100644 index 0000000..a59aea4 --- /dev/null +++ b/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBar.java @@ -0,0 +1,31 @@ +/* + * 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 fixture.simple.objects; + +public class SimpleObjectForBar extends SimpleObjectAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + create("Bar", executionContext); + } + + +} http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBaz.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBaz.java b/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBaz.java new file mode 100644 index 0000000..b71baeb --- /dev/null +++ b/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBaz.java @@ -0,0 +1,31 @@ +/* + * 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 fixture.simple.objects; + +public class SimpleObjectForBaz extends SimpleObjectAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + create("Baz", executionContext); + } + + +} http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForFoo.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForFoo.java b/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForFoo.java new file mode 100644 index 0000000..fa3d488 --- /dev/null +++ b/example/application/simpleapp/fixture/src/main/java/fixture/simple/objects/SimpleObjectForFoo.java @@ -0,0 +1,31 @@ +/* + * 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 fixture.simple.objects; + +public class SimpleObjectForFoo extends SimpleObjectAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + create("Foo", executionContext); + } + + +} http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/fixture/src/main/java/fixture/simple/scenario/SimpleObjectsFixture.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/fixture/src/main/java/fixture/simple/scenario/SimpleObjectsFixture.java b/example/application/simpleapp/fixture/src/main/java/fixture/simple/scenario/SimpleObjectsFixture.java new file mode 100644 index 0000000..12582e6 --- /dev/null +++ b/example/application/simpleapp/fixture/src/main/java/fixture/simple/scenario/SimpleObjectsFixture.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 fixture.simple.scenario; + +import fixture.simple.SimpleObjectsTearDownFixture; +import fixture.simple.objects.SimpleObjectForBar; +import fixture.simple.objects.SimpleObjectForBaz; +import fixture.simple.objects.SimpleObjectForFoo; + +import org.apache.isis.applib.fixturescripts.FixtureScript; + +public class SimpleObjectsFixture extends FixtureScript { + + public SimpleObjectsFixture() { + withDiscoverability(Discoverability.DISCOVERABLE); + } + + @Override + protected void execute(ExecutionContext executionContext) { + + executeChild(new SimpleObjectsTearDownFixture(), executionContext); + + executeChild(new SimpleObjectForFoo(), executionContext); + executeChild(new SimpleObjectForBar(), executionContext); + executeChild(new SimpleObjectForBaz(), executionContext); + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java b/example/application/simpleapp/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java index b499e85..508a3a0 100644 --- a/example/application/simpleapp/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java +++ b/example/application/simpleapp/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java @@ -18,7 +18,7 @@ package integration.glue; import cucumber.api.java.Before; import dom.simple.SimpleObject; -import fixture.simple.SimpleObjectsFixture; +import fixture.simple.scenario.SimpleObjectsFixture; import org.apache.isis.core.specsupport.scenarios.InMemoryDB; import org.apache.isis.core.specsupport.specs.CukeGlueAbstract; http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectTest.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectTest.java b/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectTest.java new file mode 100644 index 0000000..13e24f9 --- /dev/null +++ b/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectTest.java @@ -0,0 +1,82 @@ +/* + * 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.smoke; + +import dom.simple.SimpleObject; +import dom.simple.SimpleObjects; +import fixture.simple.scenario.SimpleObjectsFixture; +import fixture.simple.SimpleObjectsTearDownFixture; +import integration.tests.SimpleAppIntegTest; + +import javax.inject.Inject; +import org.junit.Test; +import org.apache.isis.applib.fixturescripts.FixtureScript; +import org.apache.isis.applib.fixturescripts.FixtureScripts; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +public class SimpleObjectTest extends SimpleAppIntegTest { + + @Inject + FixtureScripts fixtureScripts; + @Inject + SimpleObjects simpleObjects; + + FixtureScript fixtureScript; + + public static class Name extends SimpleObjectTest { + + @Test + public void exists() throws Exception { + + // given + fixtureScript = new SimpleObjectsFixture(); + fixtureScripts.runFixtureScript(fixtureScript, null); + + final SimpleObject simpleObjectPojo = + fixtureScript.lookup("simple-objects-fixture/simple-object-for-foo/item-1", SimpleObject.class); + + // when + assertThat(simpleObjectPojo, is(not(nullValue()))); + final SimpleObject simpleObjectWrapped = wrap(simpleObjectPojo); + + // then + assertThat(simpleObjectWrapped.getName(), is("Foo")); + } + + @Test + public void doesNotExist() throws Exception { + + // given + fixtureScript = new SimpleObjectsTearDownFixture(); + fixtureScripts.runFixtureScript(fixtureScript, null); + + // when + SimpleObject simpleObjectPojo = fixtureScript.lookup("non-existent", SimpleObject.class); + + // then + assertThat(simpleObjectPojo, is(nullValue())); + + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest.java b/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest.java new file mode 100644 index 0000000..3963c8c --- /dev/null +++ b/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest.java @@ -0,0 +1,148 @@ +/* + * 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.smoke; + +import dom.simple.SimpleObject; +import dom.simple.SimpleObjects; +import fixture.simple.scenario.SimpleObjectsFixture; +import fixture.simple.SimpleObjectsTearDownFixture; +import integration.tests.SimpleAppIntegTest; + +import java.sql.SQLIntegrityConstraintViolationException; +import java.util.List; +import javax.inject.Inject; +import com.google.common.base.Throwables; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.apache.isis.applib.fixturescripts.FixtureScript; +import org.apache.isis.applib.fixturescripts.FixtureScripts; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class SimpleObjectsTest extends SimpleAppIntegTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Inject + FixtureScripts fixtureScripts; + @Inject + SimpleObjects simpleObjects; + + FixtureScript fixtureScript; + + public static class ListAll extends SimpleObjectsTest { + + @Test + public void happyCase() throws Exception { + + // given + fixtureScript = new SimpleObjectsFixture(); + fixtureScripts.runFixtureScript(fixtureScript, null); + nextTransaction(); + + // when + final List<SimpleObject> all = wrap(simpleObjects).listAll(); + + // then + assertThat(all.size(), is(3)); + + SimpleObject simpleObject = wrap(all.get(0)); + assertThat(simpleObject.getName(), is("Foo")); + } + + @Test + public void whenNone() throws Exception { + + // given + fixtureScript = new SimpleObjectsTearDownFixture(); + fixtureScripts.runFixtureScript(fixtureScript, null); + nextTransaction(); + + // when + final List<SimpleObject> all = wrap(simpleObjects).listAll(); + + // then + assertThat(all.size(), is(0)); + } + } + + public static class Create extends SimpleObjectsTest { + + @Test + public void happyCase() throws Exception { + + // given + fixtureScript = new SimpleObjectsTearDownFixture(); + fixtureScripts.runFixtureScript(fixtureScript, null); + nextTransaction(); + + // when + wrap(simpleObjects).create("Faz"); + + // then + final List<SimpleObject> all = wrap(simpleObjects).listAll(); + assertThat(all.size(), is(1)); + } + + @Test + public void whenAlreadyExists() throws Exception { + + // given + fixtureScript = new SimpleObjectsTearDownFixture(); + fixtureScripts.runFixtureScript(fixtureScript, null); + nextTransaction(); + wrap(simpleObjects).create("Faz"); + nextTransaction(); + + // then + expectedException.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class)); + + // when + wrap(simpleObjects).create("Faz"); + nextTransaction(); + } + + private static Matcher<? extends Throwable> causalChainContains(final Class<?> cls) { + return new TypeSafeMatcher<Throwable>() { + @Override + protected boolean matchesSafely(Throwable item) { + final List<Throwable> causalChain = Throwables.getCausalChain(item); + for (Throwable throwable : causalChain) { + if(cls.isAssignableFrom(throwable.getClass())){ + return true; + } + } + return false; + } + + @Override + public void describeTo(Description description) { + description.appendText("exception with causal chain containing " + cls.getSimpleName()); + } + }; + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest_listAll_and_create.java ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest_listAll_and_create.java b/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest_listAll_and_create.java deleted file mode 100644 index c2146e5..0000000 --- a/example/application/simpleapp/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest_listAll_and_create.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package integration.tests.smoke; - -import dom.simple.SimpleObject; -import dom.simple.SimpleObjects; -import fixture.simple.SimpleObjectsFixture; -import integration.tests.SimpleAppIntegTest; - -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 SimpleObjectsTest_listAll_and_create extends SimpleAppIntegTest { - - @Before - public void setUpData() throws Exception { - scenarioExecution().install(new SimpleObjectsFixture()); - } - - @Inject - private SimpleObjects simpleObjects; - - @Test - public void listAll() throws Exception { - - final List<SimpleObject> all = wrap(simpleObjects).listAll(); - assertThat(all.size(), is(3)); - - SimpleObject simpleObject = wrap(all.get(0)); - assertThat(simpleObject.getName(), is("Foo")); - } - - @Test - public void create() throws Exception { - - // when - wrap(simpleObjects).create("Faz"); - nextTransaction(); - - // then - final List<SimpleObject> all = wrap(simpleObjects).listAll(); - assertThat(all.size(), is(4)); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/simpleapp/webapp/src/main/webapp/WEB-INF/isis.properties ---------------------------------------------------------------------- diff --git a/example/application/simpleapp/webapp/src/main/webapp/WEB-INF/isis.properties b/example/application/simpleapp/webapp/src/main/webapp/WEB-INF/isis.properties index 87cce22..54bf51c 100644 --- a/example/application/simpleapp/webapp/src/main/webapp/WEB-INF/isis.properties +++ b/example/application/simpleapp/webapp/src/main/webapp/WEB-INF/isis.properties @@ -154,7 +154,7 @@ isis.services = \ # in-memory object store, the fixtures are installed on every run. For other # object stores, they are used only when the object store is first initialized. # -isis.fixtures=fixture.simple.SimpleObjectsFixture +isis.fixtures=fixture.simple.scenario.SimpleObjectsFixture # http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java index 137e12a..053cebe 100644 --- a/example/application/todoapp/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/ToDoItemsFixturesService.java @@ -18,7 +18,7 @@ */ package fixture.todo; -import fixture.todo.scenarios.RecreateToDoItemsAndCompleteSeveralForCurrent; +import fixture.todo.scenarios.ToDoItemsRecreateAndCompleteSeveral; import java.util.List; import org.apache.isis.applib.annotation.CssClassFa; @@ -36,7 +36,7 @@ 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 +@Named("Prototyping") @DomainService(menuOrder = "40.1") public class ToDoItemsFixturesService extends FixtureScripts { @@ -46,13 +46,18 @@ public class ToDoItemsFixturesService extends FixtureScripts { @CssClassFa("fa fa-bolt") @Override - public List<FixtureResult> runFixtureScript(FixtureScript fixtureScript, @Named("Parameters") @DescribedAs("Script-specific parameters (if any). The format depends on the script implementation (eg key=value, CSV, JSON, XML etc)") @MultiLine(numberOfLines = 10) @Optional String parameters) { + public List<FixtureResult> runFixtureScript( + final FixtureScript fixtureScript, + final @Named("Parameters") @DescribedAs("Script-specific parameters (key=value) ") + @MultiLine(numberOfLines = 10) + @Optional + String parameters) { return super.runFixtureScript(fixtureScript, parameters); } @Override public FixtureScript default0RunFixtureScript() { - return findFixtureScriptFor(RecreateToDoItemsAndCompleteSeveralForCurrent.class); + return findFixtureScriptFor(ToDoItemsRecreateAndCompleteSeveral.class); } /** @@ -71,7 +76,7 @@ public class ToDoItemsFixturesService extends FixtureScripts { @CssClassFa("fa fa-list") @MemberOrder(sequence="20") public Object recreateToDoItemsReturnFirst() { - final List<FixtureResult> run = findFixtureScriptFor(RecreateToDoItemsAndCompleteSeveralForCurrent.class).run(null); + final List<FixtureResult> run = findFixtureScriptFor(ToDoItemsRecreateAndCompleteSeveral.class).run(null); return run.get(0).getObject(); } } http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/integtests/ToDoItemsIntegTestFixture.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/integtests/ToDoItemsIntegTestFixture.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/integtests/ToDoItemsIntegTestFixture.java index c076a6a..6953e3f 100644 --- a/example/application/todoapp/fixture/src/main/java/fixture/todo/integtests/ToDoItemsIntegTestFixture.java +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/integtests/ToDoItemsIntegTestFixture.java @@ -19,7 +19,7 @@ package fixture.todo.integtests; -import fixture.todo.simple.ToDoItemsRecreateAndCompleteSeveral; +import fixture.todo.scenarios.ToDoItemsRecreateAndCompleteSeveral; import org.apache.isis.applib.fixturescripts.FixtureScript; @@ -34,7 +34,7 @@ public class ToDoItemsIntegTestFixture extends FixtureScript { @Override protected void execute(ExecutionContext executionContext) { - executeChild(new ToDoItemsRecreateAndCompleteSeveral(null), executionContext); + executeChild(new ToDoItemsRecreateAndCompleteSeveral(), executionContext); } } http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteAbstract.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteAbstract.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteAbstract.java new file mode 100644 index 0000000..1d6271c --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteAbstract.java @@ -0,0 +1,70 @@ +/* + * 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 fixture.todo.items.actions.complete; + +import dom.todo.ToDoItem; + +import java.util.Collection; +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; +import org.apache.isis.applib.fixturescripts.FixtureScript; + +public abstract class ToDoItemCompleteAbstract extends FixtureScript { + + @Override + protected void execute(ExecutionContext executionContext) { + validateParameters(executionContext); + + + } + + /** + * Subclasses should call from within {@link #execute(org.apache.isis.applib.fixturescripts.FixtureScript.ExecutionContext)}. + */ + protected void validateParameters(ExecutionContext executionContext) { + final String ownedBy = executionContext.getParameter("ownedBy"); + if(ownedBy == null) { + throw new IllegalArgumentException("'ownedBy' must be specified"); + } + } + + /** + * Looks up item from repository, and completes. + */ + protected void complete(final String description, final ExecutionContext executionContext) { + String ownedBy = executionContext.getParameter("ownedBy"); + final ToDoItem toDoItem = findToDoItem(description, ownedBy); + toDoItem.setComplete(true); + executionContext.add(this, toDoItem); + } + + + private ToDoItem findToDoItem(final String description, final String ownedBy) { + final Collection<ToDoItem> filtered = Collections2.filter(getContainer().allInstances(ToDoItem.class), new Predicate<ToDoItem>() { + @Override + public boolean apply(ToDoItem input) { + return Objects.equal(description, input.getDescription()) && + Objects.equal(ownedBy, input.getOwnedBy()); + } + }); + return filtered.isEmpty()? null: filtered.iterator().next(); + } + //endregion +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteForBuyStamps.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteForBuyStamps.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteForBuyStamps.java new file mode 100644 index 0000000..0d29846 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteForBuyStamps.java @@ -0,0 +1,35 @@ +/* + * 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 fixture.todo.items.actions.complete; + +import fixture.todo.items.create.ToDoItemForBuyStamps; + +public class ToDoItemCompleteForBuyStamps extends ToDoItemCompleteAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + // prereqs + executeChild(new ToDoItemForBuyStamps(), executionContext); + + // this fixture + complete(ToDoItemForBuyStamps.DESCRIPTION, executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteForWriteBlogPost.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteForWriteBlogPost.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteForWriteBlogPost.java new file mode 100644 index 0000000..8db5d90 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/actions/complete/ToDoItemCompleteForWriteBlogPost.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 fixture.todo.items.actions.complete; + +import fixture.todo.items.create.ToDoItemForWriteBlogPost; + +public class ToDoItemCompleteForWriteBlogPost extends ToDoItemCompleteAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + // prereqs + executeChild(new ToDoItemForWriteBlogPost(), executionContext); + + // this fixture + complete(ToDoItemForWriteBlogPost.DESCRIPTION, executionContext); + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemAbstract.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemAbstract.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemAbstract.java new file mode 100644 index 0000000..16bc2ea --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemAbstract.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 fixture.todo.items.create; + +import dom.todo.ToDoItem; +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; +import dom.todo.ToDoItems; + +import java.math.BigDecimal; +import org.joda.time.LocalDate; +import org.apache.isis.applib.fixturescripts.FixtureScript; +import org.apache.isis.applib.services.clock.ClockService; + +public abstract class ToDoItemAbstract extends FixtureScript { + + protected ToDoItem createToDoItem( + final String description, + final Category category, final Subcategory subcategory, + final LocalDate dueBy, + final BigDecimal cost, + final ExecutionContext executionContext) { + + // validate parameters + final String ownedBy = executionContext.getParameter("ownedBy"); + if(ownedBy == null) { + throw new IllegalArgumentException("'ownedBy' must be specified"); + } + + // execute + ToDoItem newToDo = toDoItems.newToDo( + description, category, subcategory, ownedBy, dueBy, cost); + return executionContext.add(this, newToDo); + } + + protected LocalDate nowPlusDays(int days) { + return clockService.now().plusDays(days); + } + + protected BigDecimal BD(String str) { + return new BigDecimal(str); + } + + //region > injected services + @javax.inject.Inject + private ToDoItems toDoItems; + + @javax.inject.Inject + protected ClockService clockService; + //endregion + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyBread.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyBread.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyBread.java new file mode 100644 index 0000000..0bcde45 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyBread.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForBuyBread extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Buy bread", + Category.Domestic, Subcategory.Shopping, + nowPlusDays(0), + BD("1.75"), + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyMilk.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyMilk.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyMilk.java new file mode 100644 index 0000000..da6d25e --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyMilk.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForBuyMilk extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Buy milk", + Category.Domestic, Subcategory.Shopping, + nowPlusDays(0), + BD("0.75"), + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyStamps.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyStamps.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyStamps.java new file mode 100644 index 0000000..4c6fb70 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForBuyStamps.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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForBuyStamps extends ToDoItemAbstract { + + public static final String DESCRIPTION = "Buy stamps"; + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + DESCRIPTION, + Category.Domestic, Subcategory.Shopping, + nowPlusDays(0), + BD("10.00"), + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForMowLawn.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForMowLawn.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForMowLawn.java new file mode 100644 index 0000000..daf4e2e --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForMowLawn.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForMowLawn extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Mow lawn", + Category.Domestic, Subcategory.Garden, + nowPlusDays(6), + null, + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForOrganizeBrownBag.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForOrganizeBrownBag.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForOrganizeBrownBag.java new file mode 100644 index 0000000..d4c01a7 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForOrganizeBrownBag.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForOrganizeBrownBag extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Organize brown bag", + Category.Professional, Subcategory.Consulting, + nowPlusDays(14), + null, + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForPickUpLaundry.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForPickUpLaundry.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForPickUpLaundry.java new file mode 100644 index 0000000..5d9a309 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForPickUpLaundry.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForPickUpLaundry extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Pick up laundry", + Category.Domestic, Subcategory.Chores, + nowPlusDays(6), + BD("7.50"), + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForSharpenKnives.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForSharpenKnives.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForSharpenKnives.java new file mode 100644 index 0000000..c850993 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForSharpenKnives.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForSharpenKnives extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Sharpen knives", + Category.Domestic, Subcategory.Chores, + nowPlusDays(14), + null, + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForStageIsisRelease.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForStageIsisRelease.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForStageIsisRelease.java new file mode 100644 index 0000000..d9544ab --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForStageIsisRelease.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForStageIsisRelease extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Stage Isis release", + Category.Professional, Subcategory.OpenSource, + null, + null, + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForSubmitConferenceSession.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForSubmitConferenceSession.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForSubmitConferenceSession.java new file mode 100644 index 0000000..86e7177 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForSubmitConferenceSession.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForSubmitConferenceSession extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Submit conference session", + Category.Professional, Subcategory.Education, + nowPlusDays(21), + null, + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForVacuumHouse.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForVacuumHouse.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForVacuumHouse.java new file mode 100644 index 0000000..64f4ab4 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForVacuumHouse.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForVacuumHouse extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Vacuum house", + Category.Domestic, Subcategory.Housework, + nowPlusDays(3), + null, + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForWriteBlogPost.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForWriteBlogPost.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForWriteBlogPost.java new file mode 100644 index 0000000..8d912ad --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForWriteBlogPost.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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForWriteBlogPost extends ToDoItemAbstract { + + public static final String DESCRIPTION = "Write blog post"; + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + DESCRIPTION, + Category.Professional, Subcategory.Marketing, + nowPlusDays(7), + null, + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForWriteToPenPal.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForWriteToPenPal.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForWriteToPenPal.java new file mode 100644 index 0000000..eb495a2 --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/create/ToDoItemForWriteToPenPal.java @@ -0,0 +1,37 @@ +/* + * 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 fixture.todo.items.create; + +import dom.todo.ToDoItem.Category; +import dom.todo.ToDoItem.Subcategory; + +public class ToDoItemForWriteToPenPal extends ToDoItemAbstract { + + @Override + protected void execute(ExecutionContext executionContext) { + + createToDoItem( + "Write to penpal", + Category.Other, Subcategory.Other, + null, + null, + executionContext); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/items/delete/ToDoItemsDelete.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/items/delete/ToDoItemsDelete.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/delete/ToDoItemsDelete.java new file mode 100644 index 0000000..d83f80a --- /dev/null +++ b/example/application/todoapp/fixture/src/main/java/fixture/todo/items/delete/ToDoItemsDelete.java @@ -0,0 +1,53 @@ +/* + * 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 fixture.todo.items.delete; + +import org.apache.isis.applib.fixturescripts.FixtureScript; +import org.apache.isis.applib.services.jdosupport.IsisJdoSupport; + +public class ToDoItemsDelete extends FixtureScript { + + //region > ownedBy (optional) + private String ownedBy; + + public String getOwnedBy() { + return ownedBy; + } + + public void setOwnedBy(String ownedBy) { + this.ownedBy = ownedBy; + } + //endregion + + //region > execute + protected void execute(ExecutionContext executionContext) { + + final String ownedBy = executionContext.getParameter("ownedBy"); + + isisJdoSupport.executeUpdate("delete from \"ToDoItem\" where \"ownedBy\" = '" + ownedBy + "'"); + } + + //endregion + + //region > injected services + @javax.inject.Inject + private IsisJdoSupport isisJdoSupport; + //endregion + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/isis/blob/75735601/example/application/todoapp/fixture/src/main/java/fixture/todo/scenarios/DeleteToDoItemsFor.java ---------------------------------------------------------------------- diff --git a/example/application/todoapp/fixture/src/main/java/fixture/todo/scenarios/DeleteToDoItemsFor.java b/example/application/todoapp/fixture/src/main/java/fixture/todo/scenarios/DeleteToDoItemsFor.java deleted file mode 100644 index b07271c..0000000 --- a/example/application/todoapp/fixture/src/main/java/fixture/todo/scenarios/DeleteToDoItemsFor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package fixture.todo.scenarios; - -import fixture.todo.simple.ToDoItemsDelete; - -import com.google.common.base.Strings; - -public class DeleteToDoItemsFor extends ToDoItemsDelete { - - public DeleteToDoItemsFor() { - super(null); - withDiscoverability(Discoverability.DISCOVERABLE); - } - - @Override - public String validateRun(final String parameters) { - return Strings.isNullOrEmpty(parameters) ? "Specify the owner of the ToDoItems to be deleted" : null; - } -} \ No newline at end of file