You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/05/25 09:55:53 UTC
[2/4] git commit: ISIS-406: adding integration tests to the todo
example app.
ISIS-406: adding integration tests to the todo example app.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/a55c76ba
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/a55c76ba
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/a55c76ba
Branch: refs/heads/master
Commit: a55c76ba690ca1fc68107f5ca3e41d29851c2aab
Parents: c0ab239
Author: Dan Haywood <da...@apache.org>
Authored: Fri May 24 09:33:21 2013 +0100
Committer: Dan Haywood <da...@apache.org>
Committed: Sat May 25 07:56:50 2013 +0100
----------------------------------------------------------------------
.../application/claims/viewer-wicket/.gitignore | 1 +
.../dom/src/main/java/dom/todo/ToDoItem.java | 1 -
.../integtests/pom.xml | 67 +++++++
.../test/java/integtests/AbstractIntegTest.java | 141 +++++++++++++++
.../test/java/integtests/ToDoItemIntegTest.java | 97 ++++++++++
5 files changed, 306 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/a55c76ba/example/application/claims/viewer-wicket/.gitignore
----------------------------------------------------------------------
diff --git a/example/application/claims/viewer-wicket/.gitignore b/example/application/claims/viewer-wicket/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/example/application/claims/viewer-wicket/.gitignore
@@ -0,0 +1 @@
+/target
http://git-wip-us.apache.org/repos/asf/isis/blob/a55c76ba/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
index 6ae4124..950b321 100644
--- a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
+++ b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
@@ -54,7 +54,6 @@ import org.apache.isis.applib.annotation.PublishedObject;
import org.apache.isis.applib.annotation.RegEx;
import org.apache.isis.applib.annotation.Render;
import org.apache.isis.applib.annotation.Render.Type;
-import org.apache.isis.applib.annotation.RenderedAsDayBefore;
import org.apache.isis.applib.annotation.Where;
import org.apache.isis.applib.clock.Clock;
import org.apache.isis.applib.filter.Filter;
http://git-wip-us.apache.org/repos/asf/isis/blob/a55c76ba/example/application/quickstart_wicket_restful_jdo/integtests/pom.xml
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/integtests/pom.xml b/example/application/quickstart_wicket_restful_jdo/integtests/pom.xml
new file mode 100644
index 0000000..27a0e5d
--- /dev/null
+++ b/example/application/quickstart_wicket_restful_jdo/integtests/pom.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis.example.application</groupId>
+ <artifactId>quickstart_wicket_restful_jdo</artifactId>
+ <version>1.0.3-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>quickstart_wicket_restful_jdo-integtests</artifactId>
+ <name>Quickstart Wicket/Restful/JDO Integration Tests</name>
+
+ <dependencies>
+
+ <!-- other modules in this project -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>quickstart_wicket_restful_jdo-fixture</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>quickstart_wicket_restful_jdo-objstore-jdo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-unittestsupport</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-integtestsupport</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.isis.core</groupId>
+ <artifactId>isis-core-wrapper</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ </dependency>
+
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/a55c76ba/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integtests/AbstractIntegTest.java
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integtests/AbstractIntegTest.java b/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integtests/AbstractIntegTest.java
new file mode 100644
index 0000000..44510bd
--- /dev/null
+++ b/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integtests/AbstractIntegTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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 integtests;
+
+import dom.todo.ToDoItems;
+import fixture.todo.ToDoItemsFixture;
+import objstore.jdo.todo.ToDoItemsJdo;
+
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.MethodRule;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+import org.apache.isis.applib.services.wrapper.WrapperFactory;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.integtestsupport.IsisSystemForTest;
+import org.apache.isis.core.wrapper.WrapperFactoryDefault;
+import org.apache.isis.objectstore.jdo.datanucleus.DataNucleusObjectStore;
+import org.apache.isis.objectstore.jdo.datanucleus.DataNucleusPersistenceMechanismInstaller;
+import org.apache.isis.objectstore.jdo.service.RegisterEntities;
+
+public class AbstractIntegTest {
+
+ protected ToDoItems toDoItems;
+ protected WrapperFactory wrapperFactory;
+
+ @Rule
+ public IsisSystemForTestRule rule = new IsisSystemForTestRule();
+
+ /**
+ * Same running system returned for all tests, set up with {@link ToDoItemsFixture}.
+ *
+ * <p>
+ * The database is NOT reset between tests.
+ */
+ public IsisSystemForTest getIsft() {
+ return rule.getIsisSystemForTest();
+ }
+
+ @Before
+ public void init() {
+ toDoItems = getIsft().getService(ToDoItemsJdo.class);
+ wrapperFactory = getIsft().getService(WrapperFactoryDefault.class);
+ }
+
+ protected <T> T wrap(T obj) {
+ return wrapperFactory.wrap(obj);
+ }
+
+
+ ////////////////////////////////////////////////////////////////
+ // Boilerplate
+ ////////////////////////////////////////////////////////////////
+
+ @BeforeClass
+ public static void initClass() {
+ BasicConfigurator.configure();
+ }
+
+ private static class ToDoIntegTestBuilder extends IsisSystemForTest.Builder {
+
+ public ToDoIntegTestBuilder() {
+ withFixtures(new ToDoItemsFixture());
+ withLoggingAt(Level.INFO);
+ with(testConfiguration());
+ with(new DataNucleusPersistenceMechanismInstaller());
+ withServices(
+ new ToDoItemsJdo(),
+ new WrapperFactoryDefault(),
+ new RegisterEntities()
+ );
+ }
+
+ private IsisConfiguration testConfiguration() {
+ final IsisConfigurationDefault testConfiguration = new IsisConfigurationDefault();
+
+ testConfiguration.add("isis.persistor.datanucleus.RegisterEntities.packagePrefix", "dom");
+ testConfiguration.add("isis.persistor.datanucleus.impl.javax.jdo.option.ConnectionURL", "jdbc:hsqldb:mem:test");
+
+ testConfiguration.add("isis.persistor.datanucleus.impl.datanucleus.defaultInheritanceStrategy", "TABLE_PER_CLASS");
+ testConfiguration.add(DataNucleusObjectStore.INSTALL_FIXTURES_KEY , "true");
+
+ testConfiguration.add("isis.persistor.datanucleus.impl.datanucleus.cache.level2.type","none");
+
+ return testConfiguration;
+ }
+ }
+
+ private static class IsisSystemForTestRule implements MethodRule {
+ private static ThreadLocal<IsisSystemForTest> ISFT = new ThreadLocal<IsisSystemForTest>() {
+ @Override
+ protected IsisSystemForTest initialValue() {
+ return new ToDoIntegTestBuilder().build().setUpSystem();
+ };
+ };
+
+ public IsisSystemForTest getIsisSystemForTest() {
+ // reuse same system for all calls.
+ return ISFT.get();
+ }
+
+ @Override
+ public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
+ final IsisSystemForTest isft = getIsisSystemForTest(); // creates and starts running if required
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ isft.beginTran();
+ base.evaluate();
+ // if an exception is thrown by any test, then we don't attempt to cleanup (eg by calling bounceSystem)#
+ // because - in any case - we only ever install the fixtures once for ALL of the tests.
+ // therefore, just fix the first test that fails and don't worry about any other test failures beyond that
+ // (fix them up one by one)
+ isft.commitTran();
+ }
+ };
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/a55c76ba/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integtests/ToDoItemIntegTest.java
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integtests/ToDoItemIntegTest.java b/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integtests/ToDoItemIntegTest.java
new file mode 100644
index 0000000..5aab2d8
--- /dev/null
+++ b/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integtests/ToDoItemIntegTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package integtests;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import dom.todo.ToDoItem;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import org.apache.isis.applib.services.wrapper.DisabledException;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class ToDoItemIntegTest extends AbstractIntegTest {
+
+ @Test
+ public void t01_findNotYetCompleted() throws Exception {
+ final List<ToDoItem> all = wrap(toDoItems).notYetComplete();
+ assertThat(all.size(), is(5));
+ }
+
+ @Test
+ public void t02_update() throws Exception {
+ // given
+ final List<ToDoItem> all = wrap(toDoItems).notYetComplete();
+ final ToDoItem toDoItem = wrap(all.get(0));
+
+ assertThat(toDoItem.getDescription(), is("Buy milk"));
+
+ // when
+ toDoItem.setDescription("Buy milk and butter");
+
+ // then
+ assertThat(toDoItem.getDescription(), is("Buy milk and butter"));
+ }
+
+
+ @Test
+ public void t03_complete() throws Exception {
+ // given
+ final List<ToDoItem> all = wrap(toDoItems).notYetComplete();
+ final ToDoItem toDoItem = wrap(all.get(0));
+
+ assertThat(toDoItem.getDescription(), is("Buy milk and butter"));
+ assertThat(toDoItem.isComplete(), is(false));
+
+ // when
+ toDoItem.completed();
+
+ // then
+ assertThat(toDoItem.isComplete(), is(true));
+
+ final List<ToDoItem> all2 = wrap(toDoItems).notYetComplete();
+ assertThat(all2.size(), is(4));
+ }
+
+
+ @Test
+ public void t04_cannotCompleteAndObjectAlreadyCompleted() throws Exception {
+ // given
+ final List<ToDoItem> all = wrap(toDoItems).notYetComplete(); // 4 left
+ final ToDoItem toDoItem = wrap(all.get(0));
+
+ toDoItem.completed();
+
+ // when, then should fail
+ try {
+ toDoItem.completed();
+ fail("completed should have been disabled");
+ } catch(DisabledException ex) {
+ assertThat(ex.getMessage(), is("Already completed"));
+ }
+ }
+
+}
\ No newline at end of file