ISIS-928: recreating simpleapp archetype
Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/1be98510 Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/1be98510 Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/1be98510 Branch: refs/heads/master Commit: 1be985101aec8cc1f7f9e6720e16a84777aa004f Parents: 4e7dde9 Author: Dan Haywood <[email protected]> Authored: Tue Nov 18 12:15:45 2014 +0100 Committer: Dan Haywood <[email protected]> Committed: Tue Nov 18 12:15:45 2014 +0100 ---------------------------------------------------------------------- .../src/main/java/dom/simple/SimpleObject.java | 1 + .../test/java/dom/simple/SimpleObjectTest.java | 54 +++++++ .../java/dom/simple/SimpleObjectTest_name.java | 51 ------- .../test/java/dom/simple/SimpleObjectsTest.java | 105 +++++++++++++ .../dom/simple/SimpleObjectsTest_create.java | 77 ---------- .../dom/simple/SimpleObjectsTest_listAll.java | 72 --------- .../fixture/simple/SimpleObjectsFixture.java | 59 -------- .../simple/SimpleObjectsFixturesService.java | 4 +- .../simple/objects/SimpleObjectAbstract.java | 39 +++++ .../simple/objects/SimpleObjectForBar.java | 34 +++++ .../simple/objects/SimpleObjectForBaz.java | 34 +++++ .../simple/objects/SimpleObjectForFoo.java | 34 +++++ .../simple/scenario/SimpleObjectsFixture.java | 48 ++++++ .../integration/glue/CatalogOfFixturesGlue.java | 2 +- .../tests/smoke/SimpleObjectTest.java | 85 +++++++++++ .../tests/smoke/SimpleObjectsTest.java | 151 +++++++++++++++++++ .../SimpleObjectsTest_listAll_and_create.java | 69 --------- .../src/main/webapp/WEB-INF/isis.properties | 2 +- .../projects/basic/archetype.properties | 2 +- 19 files changed, 591 insertions(+), 332 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/main/java/dom/simple/SimpleObject.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/main/java/dom/simple/SimpleObject.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/main/java/dom/simple/SimpleObject.java index 5e1fc3e..473de9d 100644 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/main/java/dom/simple/SimpleObject.java +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/main/java/dom/simple/SimpleObject.java @@ -37,6 +37,7 @@ import org.apache.isis.applib.util.ObjectContracts; @javax.jdo.annotations.Version( strategy=VersionStrategy.VERSION_NUMBER, column="version") [email protected](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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectTest.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectTest.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectTest.java new file mode 100644 index 0000000..48bdc1f --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectTest.java @@ -0,0 +1,54 @@ +#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 dom.simple; + +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +public class SimpleObjectTest { + + SimpleObject simpleObject; + + @Before + public void setUp() throws Exception { + simpleObject = new SimpleObject(); + } + + public static class Name extends SimpleObjectTest { + + @Test + public void happyCase() throws Exception { + // given + String name = "Foobar"; + assertThat(simpleObject.getName(), is(nullValue())); + + // when + simpleObject.setName(name); + + // then + assertThat(simpleObject.getName(), is(name)); + } + } + +} http://git-wip-us.apache.org/repos/asf/isis/blob/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectTest_name.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectTest_name.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectTest_name.java deleted file mode 100644 index f1749ef..0000000 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectTest_name.java +++ /dev/null @@ -1,51 +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 dom.simple; - -import org.junit.Before; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; - -public class SimpleObjectTest_name { - - private SimpleObject simpleObject; - - @Before - public void setUp() throws Exception { - simpleObject = new SimpleObject(); - } - - @Test - public void happyCase() throws Exception { - // given - String name = "Foobar"; - assertThat(simpleObject.getName(), is(nullValue())); - - // when - simpleObject.setName(name); - - // then - assertThat(simpleObject.getName(), is(name)); - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest.java new file mode 100644 index 0000000..bdac1bd --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest.java @@ -0,0 +1,105 @@ +#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 dom.simple; + +import java.util.List; +import com.google.common.collect.Lists; +import org.jmock.Expectations; +import org.jmock.Sequence; +import org.jmock.auto.Mock; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.apache.isis.applib.DomainObjectContainer; +import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2; +import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class SimpleObjectsTest { + + @Rule + public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); + + @Mock + DomainObjectContainer mockContainer; + + SimpleObjects simpleObjects; + + @Before + public void setUp() throws Exception { + simpleObjects = new SimpleObjects(); + simpleObjects.container = mockContainer; + } + + public static class Create extends SimpleObjectsTest { + + @Test + public void happyCase() throws Exception { + + // given + final SimpleObject simpleObject = new SimpleObject(); + + final Sequence seq = context.sequence("create"); + context.checking(new Expectations() { + { + oneOf(mockContainer).newTransientInstance(SimpleObject.class); + inSequence(seq); + will(returnValue(simpleObject)); + + oneOf(mockContainer).persistIfNotAlready(simpleObject); + inSequence(seq); + } + }); + + // when + final SimpleObject obj = simpleObjects.create("Foobar"); + + // then + assertThat(obj, is(simpleObject)); + assertThat(obj.getName(), is("Foobar")); + } + + } + + public static class ListAll extends SimpleObjectsTest { + + @Test + public void happyCase() throws Exception { + + // given + final List<SimpleObject> all = Lists.newArrayList(); + + context.checking(new Expectations() { + { + oneOf(mockContainer).allInstances(SimpleObject.class); + will(returnValue(all)); + } + }); + + // when + final List<SimpleObject> list = simpleObjects.listAll(); + + // then + assertThat(list, is(all)); + } + } +} http://git-wip-us.apache.org/repos/asf/isis/blob/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest_create.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest_create.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest_create.java deleted file mode 100644 index 7995839..0000000 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest_create.java +++ /dev/null @@ -1,77 +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 dom.simple; - -import org.jmock.Expectations; -import org.jmock.Sequence; -import org.jmock.auto.Mock; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.apache.isis.applib.DomainObjectContainer; -import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2; -import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class SimpleObjectsTest_create { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private DomainObjectContainer mockContainer; - - private SimpleObjects simpleObjects; - - @Before - public void setUp() throws Exception { - simpleObjects = new SimpleObjects(); - simpleObjects.container = mockContainer; - } - - @Test - public void happyCase() throws Exception { - - // given - final SimpleObject simpleObject = new SimpleObject(); - - final Sequence seq = context.sequence("create"); - context.checking(new Expectations() { - { - oneOf(mockContainer).newTransientInstance(SimpleObject.class); - inSequence(seq); - will(returnValue(simpleObject)); - - oneOf(mockContainer).persistIfNotAlready(simpleObject); - inSequence(seq); - } - }); - - // when - final SimpleObject obj = simpleObjects.create("Foobar"); - - // then - assertThat(obj, is(simpleObject)); - assertThat(obj.getName(), is("Foobar")); - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest_listAll.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest_listAll.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest_listAll.java deleted file mode 100644 index b3fd77e..0000000 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/dom/src/test/java/dom/simple/SimpleObjectsTest_listAll.java +++ /dev/null @@ -1,72 +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 dom.simple; - -import java.util.List; -import com.google.common.collect.Lists; -import org.jmock.Expectations; -import org.jmock.auto.Mock; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.apache.isis.applib.DomainObjectContainer; -import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2; -import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class SimpleObjectsTest_listAll { - - @Rule - public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); - - @Mock - private DomainObjectContainer mockContainer; - - private SimpleObjects simpleObjects; - - @Before - public void setUp() throws Exception { - simpleObjects = new SimpleObjects(); - simpleObjects.container = mockContainer; - } - - @Test - public void happyCase() throws Exception { - - // given - final List<SimpleObject> all = Lists.newArrayList(); - - context.checking(new Expectations() { - { - oneOf(mockContainer).allInstances(SimpleObject.class); - will(returnValue(all)); - } - }); - - // when - final List<SimpleObject> list = simpleObjects.listAll(); - - // then - assertThat(list, is(all)); - } - -} http://git-wip-us.apache.org/repos/asf/isis/blob/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixture.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixture.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixture.java deleted file mode 100644 index bb3287e..0000000 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixture.java +++ /dev/null @@ -1,59 +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 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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java index fb69258..5852a31 100644 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/SimpleObjectsFixturesService.java @@ -21,6 +21,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; @@ -42,7 +44,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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectAbstract.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectAbstract.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectAbstract.java new file mode 100644 index 0000000..8f282ec --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectAbstract.java @@ -0,0 +1,39 @@ +#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 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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBar.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBar.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBar.java new file mode 100644 index 0000000..dab0f43 --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBar.java @@ -0,0 +1,34 @@ +#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 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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBaz.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBaz.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBaz.java new file mode 100644 index 0000000..ae968cb --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForBaz.java @@ -0,0 +1,34 @@ +#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 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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForFoo.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForFoo.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForFoo.java new file mode 100644 index 0000000..6aa9af8 --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/objects/SimpleObjectForFoo.java @@ -0,0 +1,34 @@ +#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 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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/scenario/SimpleObjectsFixture.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/scenario/SimpleObjectsFixture.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/scenario/SimpleObjectsFixture.java new file mode 100644 index 0000000..f067114 --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/fixture/src/main/java/fixture/simple/scenario/SimpleObjectsFixture.java @@ -0,0 +1,48 @@ +#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 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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java index c09082e..10a8163 100644 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/glue/CatalogOfFixturesGlue.java @@ -21,7 +21,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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectTest.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectTest.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectTest.java new file mode 100644 index 0000000..66e7d2d --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectTest.java @@ -0,0 +1,85 @@ +#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.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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest.java new file mode 100644 index 0000000..5be937e --- /dev/null +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest.java @@ -0,0 +1,151 @@ +#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.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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest_listAll_and_create.java ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest_listAll_and_create.java b/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest_listAll_and_create.java deleted file mode 100644 index fbe949d..0000000 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/integtests/src/test/java/integration/tests/smoke/SimpleObjectsTest_listAll_and_create.java +++ /dev/null @@ -1,69 +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.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/1be98510/example/archetype/simpleapp/src/main/resources/archetype-resources/webapp/src/main/webapp/WEB-INF/isis.properties ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/main/resources/archetype-resources/webapp/src/main/webapp/WEB-INF/isis.properties b/example/archetype/simpleapp/src/main/resources/archetype-resources/webapp/src/main/webapp/WEB-INF/isis.properties index af65eca..db13b88 100644 --- a/example/archetype/simpleapp/src/main/resources/archetype-resources/webapp/src/main/webapp/WEB-INF/isis.properties +++ b/example/archetype/simpleapp/src/main/resources/archetype-resources/webapp/src/main/webapp/WEB-INF/isis.properties @@ -157,7 +157,7 @@ ${symbol_pound} Fixtures are used to seed the object store with an initial set o ${symbol_pound} in-memory object store, the fixtures are installed on every run. For other ${symbol_pound} object stores, they are used only when the object store is first initialized. ${symbol_pound} -isis.fixtures=fixture.simple.SimpleObjectsFixture +isis.fixtures=fixture.simple.scenario.SimpleObjectsFixture ${symbol_pound} http://git-wip-us.apache.org/repos/asf/isis/blob/1be98510/example/archetype/simpleapp/src/test/resources/projects/basic/archetype.properties ---------------------------------------------------------------------- diff --git a/example/archetype/simpleapp/src/test/resources/projects/basic/archetype.properties b/example/archetype/simpleapp/src/test/resources/projects/basic/archetype.properties index 1046b2e..8d6ce03 100644 --- a/example/archetype/simpleapp/src/test/resources/projects/basic/archetype.properties +++ b/example/archetype/simpleapp/src/test/resources/projects/basic/archetype.properties @@ -1,4 +1,4 @@ -#Sat Nov 15 10:29:53 GMT 2014 +#Tue Nov 18 12:15:39 CET 2014 package=it.pkg version=0.1-SNAPSHOT groupId=archetype.it
