You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by uk...@apache.org on 2014/04/01 23:58:55 UTC
[2/2] git commit: TAP5-2273: TapestryIOCJUnit4ClassRunner
documentation added
TAP5-2273: TapestryIOCJUnit4ClassRunner documentation added
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/642bd724
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/642bd724
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/642bd724
Branch: refs/heads/master
Commit: 642bd724ebf420bfb688c49149299d53a4d69e9f
Parents: deab2b3
Author: uklance <uk...@gmail.com>
Authored: Tue Apr 1 22:55:57 2014 +0100
Committer: uklance <uk...@gmail.com>
Committed: Tue Apr 1 22:58:36 2014 +0100
----------------------------------------------------------------------
.../apache/tapestry5/ioc/test/ModuleDef.java | 19 ++++++++++
.../org/apache/tapestry5/ioc/test/Registry.java | 26 ++++++++++++++
.../ioc/test/RegistryShutdownType.java | 27 +++++++++++++-
.../ioc/test/TapestryIOCJUnit4ClassRunner.java | 37 ++++++++++++++++++++
.../tapestry5/ioc/test/TestRegistryManager.java | 17 +++++++++
.../apache/tapestry5/ioc/test/MapModuleDef.java | 14 ++++++++
...estryIOCJUnit4ClassRunnerAfterClassTest.java | 20 +++++++++--
...stryIOCJUnit4ClassRunnerAfterMethodTest.java | 20 +++++++++--
...pestryIOCJUnit4ClassRunnerModuleDefTest.java | 14 ++++++++
9 files changed, 187 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/ModuleDef.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/ModuleDef.java b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/ModuleDef.java
index 8734fd4..529bad6 100644
--- a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/ModuleDef.java
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/ModuleDef.java
@@ -1,3 +1,17 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
import java.lang.annotation.ElementType;
@@ -6,6 +20,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * Marker annotation for a method which creates a {@link org.apache.tapestry5.ioc.def.ModuleDef}.
+ * Used by the {@link TapestryIOCJUnit4ClassRunner}, methods with this annotation must be public, static, no-args methods
+ * which return {@link ModuleDef} (or a subclass)
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Inherited
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/Registry.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/Registry.java b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/Registry.java
index 359f512..e11c995 100644
--- a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/Registry.java
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/Registry.java
@@ -1,3 +1,17 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
import java.lang.annotation.ElementType;
@@ -6,10 +20,22 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * Used by the {@link TapestryIOCJUnit4ClassRunner} to configure a test {@link org.apache.tapestry5.ioc.Registry}
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface Registry {
+ /**
+ * Tapestry module classes
+ * @return module class array
+ */
Class<?>[] modules();
+
+ /**
+ * Determines the registry lifecycle
+ * @return RegistryShutdownType
+ */
RegistryShutdownType shutdown() default RegistryShutdownType.AFTER_CLASS;
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/RegistryShutdownType.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/RegistryShutdownType.java b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/RegistryShutdownType.java
index a138dcb..a457043 100644
--- a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/RegistryShutdownType.java
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/RegistryShutdownType.java
@@ -1,5 +1,30 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
+/**
+ * @see TapestryIOCJUnit4ClassRunner
+ */
public enum RegistryShutdownType {
- AFTER_CLASS, AFTER_METHOD;
+ /**
+ * Test registry will be shut down once per test class
+ */
+ AFTER_CLASS,
+
+ /**
+ * Test registry will be shut down after each test method
+ */
+ AFTER_METHOD;
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunner.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunner.java b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunner.java
index 943ce2b..315781a 100644
--- a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunner.java
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunner.java
@@ -1,10 +1,47 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.def.ModuleDef;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
+/**
+ * <p>
+ * A JUnit4ClassRunner to help with Tapestry IOC integration tests. The test runner requires a
+ * registry configuration to be defined in a {@link Registry} annotation. A {@link RegistryShutdownType} can
+ * be specified to configure the lifecycle of the test registry and it's services
+ * </p>
+ *
+ * <p>{@link ModuleDef}s can be added to the {@link org.apache.tapestry5.ioc.Registry} by annotating a factory method(s)
+ * with {@link org.apache.tapestry5.ioc.test.ModuleDef}. These {@link ModuleDef} factory methods must be
+ * <ul>
+ * <li>public</li>
+ * <li>static</li>
+ * <li>take zero arguments</li>
+ * <li>return a subclass of {@link ModuleDef}</li>
+ * </ul>
+ * </p>
+ *
+ * <p>
+ * Any services defined in the registry can be {@link Inject}ed into the test class to be used during testing.
+ * </p>
+ */
@SuppressWarnings("deprecation")
public class TapestryIOCJUnit4ClassRunner extends BlockJUnit4ClassRunner {
private final TestRegistryManager registryManager;
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TestRegistryManager.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TestRegistryManager.java b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TestRegistryManager.java
index e0a04b7..2f225ef 100644
--- a/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TestRegistryManager.java
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TestRegistryManager.java
@@ -1,3 +1,17 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
import java.lang.reflect.InvocationTargetException;
@@ -10,6 +24,9 @@ import java.util.List;
import org.apache.tapestry5.ioc.RegistryBuilder;
import org.junit.runners.model.InitializationError;
+/**
+ * Helper class used by the {@link TapestryIOCJUnit4ClassRunner} to manage the test registry
+ */
public class TestRegistryManager {
private final Registry annotation;
private final Class<?> type;
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/MapModuleDef.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/MapModuleDef.java b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/MapModuleDef.java
index 7d3766c..a66fccf 100644
--- a/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/MapModuleDef.java
+++ b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/MapModuleDef.java
@@ -1,3 +1,17 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterClassTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterClassTest.java b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterClassTest.java
index 349a32c..078d346 100644
--- a/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterClassTest.java
+++ b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterClassTest.java
@@ -1,3 +1,17 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
import static org.apache.tapestry5.ioc.test.RegistryShutdownType.AFTER_CLASS;
@@ -6,15 +20,15 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.test.TapestryIOCJUnit4ClassRunnerAfterClassTest.TestModule;
+import org.apache.tapestry5.ioc.test.TapestryIOCJUnit4ClassRunnerAfterClassTest.AfterClassTestModule;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(TapestryIOCJUnit4ClassRunner.class)
-@Registry(modules=TestModule.class, shutdown=AFTER_CLASS)
+@Registry(modules=AfterClassTestModule.class, shutdown=AFTER_CLASS)
public class TapestryIOCJUnit4ClassRunnerAfterClassTest {
- public static class TestModule {
+ public static class AfterClassTestModule {
public List<String> buildList() {
List<String> list = new ArrayList<String>();
list.add("foo");
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java
index 3c556b0..62b832e 100644
--- a/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java
+++ b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java
@@ -1,3 +1,17 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
import static org.apache.tapestry5.ioc.test.RegistryShutdownType.AFTER_METHOD;
@@ -6,15 +20,15 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.test.TapestryIOCJUnit4ClassRunnerAfterMethodTest.TestModule;
+import org.apache.tapestry5.ioc.test.TapestryIOCJUnit4ClassRunnerAfterMethodTest.AfterMethodTestModule;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(TapestryIOCJUnit4ClassRunner.class)
-@Registry(modules=TestModule.class, shutdown=AFTER_METHOD)
+@Registry(modules=AfterMethodTestModule.class, shutdown=AFTER_METHOD)
public class TapestryIOCJUnit4ClassRunnerAfterMethodTest {
- public static class TestModule {
+ public static class AfterMethodTestModule {
public List<String> buildList() {
List<String> list = new ArrayList<String>();
list.add("foo");
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/642bd724/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerModuleDefTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerModuleDefTest.java b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerModuleDefTest.java
index f67a946..7d4a909 100644
--- a/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerModuleDefTest.java
+++ b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerModuleDefTest.java
@@ -1,3 +1,17 @@
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.test;
import static org.apache.tapestry5.ioc.test.RegistryShutdownType.AFTER_METHOD;