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:54 UTC
[1/2] git commit: TAP5-2273 - TapestryIOCJUnit4ClassRunner. Tests
passing but needs documentation
Repository: tapestry-5
Updated Branches:
refs/heads/master 91e851364 -> 642bd724e
TAP5-2273 - TapestryIOCJUnit4ClassRunner. Tests passing but needs documentation
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/deab2b3f
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/deab2b3f
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/deab2b3f
Branch: refs/heads/master
Commit: deab2b3f177b500ac4dbf9d05603d61742f821d8
Parents: 91e8513
Author: uklance <uk...@gmail.com>
Authored: Tue Apr 1 22:26:13 2014 +0100
Committer: uklance <uk...@gmail.com>
Committed: Tue Apr 1 22:58:34 2014 +0100
----------------------------------------------------------------------
settings.gradle | 2 +-
tapestry-ioc-test/build.gradle | 10 ++
.../apache/tapestry5/ioc/test/ModuleDef.java | 14 +++
.../org/apache/tapestry5/ioc/test/Registry.java | 15 +++
.../ioc/test/RegistryShutdownType.java | 5 +
.../ioc/test/TapestryIOCJUnit4ClassRunner.java | 65 ++++++++++
.../tapestry5/ioc/test/TestRegistryManager.java | 120 +++++++++++++++++++
.../apache/tapestry5/ioc/test/MapModuleDef.java | 80 +++++++++++++
...estryIOCJUnit4ClassRunnerAfterClassTest.java | 39 ++++++
...stryIOCJUnit4ClassRunnerAfterMethodTest.java | 41 +++++++
...pestryIOCJUnit4ClassRunnerModuleDefTest.java | 49 ++++++++
11 files changed, 439 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index 82e801e..5f1ddf9 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -2,6 +2,6 @@ include "plastic", "tapestry5-annotations", "tapestry-test", "tapestry-func", "t
include "tapestry-hibernate-core", "tapestry-hibernate", "tapestry-jmx", "tapestry-upload", "tapestry-spring"
include "tapestry-beanvalidator", "tapestry-jpa", "tapestry-kaptcha"
include "tapestry-javadoc", "quickstart", "tapestry-clojure", "tapestry-mongodb"
-include "tapestry-test-data", 'tapestry-internal-test'
+include "tapestry-test-data", 'tapestry-internal-test', "tapestry-ioc-test"
include "tapestry-webresources", "tapestry-runner", "tapestry-test-constants"
// include "tapestry-cdi"
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/tapestry-ioc-test/build.gradle
----------------------------------------------------------------------
diff --git a/tapestry-ioc-test/build.gradle b/tapestry-ioc-test/build.gradle
new file mode 100644
index 0000000..eae7e9c
--- /dev/null
+++ b/tapestry-ioc-test/build.gradle
@@ -0,0 +1,10 @@
+description = "Utilities for integration testing a tapestry-ioc app"
+
+dependencies {
+ compile project(':tapestry-ioc')
+ compile 'junit:junit:4.8.1'
+}
+
+test {
+ useJUnit()
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..8734fd4
--- /dev/null
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/ModuleDef.java
@@ -0,0 +1,14 @@
+package org.apache.tapestry5.ioc.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@Inherited
+public @interface ModuleDef {
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..359f512
--- /dev/null
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/Registry.java
@@ -0,0 +1,15 @@
+package org.apache.tapestry5.ioc.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Inherited
+public @interface Registry {
+ Class<?>[] modules();
+ RegistryShutdownType shutdown() default RegistryShutdownType.AFTER_CLASS;
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..a138dcb
--- /dev/null
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/RegistryShutdownType.java
@@ -0,0 +1,5 @@
+package org.apache.tapestry5.ioc.test;
+
+public enum RegistryShutdownType {
+ AFTER_CLASS, AFTER_METHOD;
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..943ce2b
--- /dev/null
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunner.java
@@ -0,0 +1,65 @@
+package org.apache.tapestry5.ioc.test;
+
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+
+@SuppressWarnings("deprecation")
+public class TapestryIOCJUnit4ClassRunner extends BlockJUnit4ClassRunner {
+ private final TestRegistryManager registryManager;
+
+ public TapestryIOCJUnit4ClassRunner(Class<?> type) throws InitializationError {
+ super(type);
+ this.registryManager = new TestRegistryManager(type);
+ }
+
+ @Override
+ protected Object createTest() throws Exception {
+ return registryManager.createTest();
+ }
+
+ @Override
+ protected Statement withBeforeClasses(Statement statement) {
+ final Statement next = super.withBeforeClasses(statement);
+ return new Statement() {
+ public void evaluate() throws Throwable {
+ registryManager.beforeTestClass();
+ next.evaluate();
+ }
+ };
+ }
+
+ @Override
+ protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
+ final Statement next = super.withBefores(method, target, statement);
+ return new Statement() {
+ public void evaluate() throws Throwable {
+ registryManager.beforeTestMethod();
+ next.evaluate();
+ }
+ };
+ }
+
+ @Override
+ protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) {
+ final Statement first = super.withAfters(method, target, statement);
+ return new Statement() {
+ public void evaluate() throws Throwable {
+ first.evaluate();
+ registryManager.afterTestMethod();
+ }
+ };
+ }
+
+ @Override
+ protected Statement withAfterClasses(Statement statement) {
+ final Statement first = super.withAfterClasses(statement);
+ return new Statement() {
+ public void evaluate() throws Throwable {
+ first.evaluate();
+ registryManager.afterTestClass();
+ }
+ };
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..e0a04b7
--- /dev/null
+++ b/tapestry-ioc-test/src/main/java/org/apache/tapestry5/ioc/test/TestRegistryManager.java
@@ -0,0 +1,120 @@
+package org.apache.tapestry5.ioc.test;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tapestry5.ioc.RegistryBuilder;
+import org.junit.runners.model.InitializationError;
+
+public class TestRegistryManager {
+ private final Registry annotation;
+ private final Class<?> type;
+ private final List<Method> moduleDefFactories;
+
+ private org.apache.tapestry5.ioc.Registry registry;
+
+ public TestRegistryManager(Class<?> type) throws InitializationError {
+ super();
+
+ Registry annotation = type.getAnnotation(Registry.class);
+ if (annotation == null) {
+ throw new InitializationError(type.getName() + " does not specify a @Registry");
+ }
+
+ this.type = type;
+ this.annotation = annotation;
+ this.moduleDefFactories = findModuleDefFactories(type);
+ }
+
+ protected List<Method> findModuleDefFactories(Class<?> type) throws InitializationError {
+ List<Method> factoryMethods = new ArrayList<Method>();
+ for (Method method : type.getMethods()) {
+ if (method.getAnnotation(ModuleDef.class) != null) {
+ validateModuleDefMethod(method);
+ factoryMethods.add(method);
+ }
+ }
+ return factoryMethods.isEmpty() ? Collections.<Method> emptyList() : factoryMethods;
+ }
+
+ protected void validateModuleDefMethod(Method method) throws InitializationError {
+ int modifiers = method.getModifiers();
+ if (method.getParameterTypes().length != 0
+ || !Modifier.isStatic(modifiers)
+ || !Modifier.isPublic(modifiers)) {
+
+ throw new InitializationError(
+ String.format("@ModuleDef method %s must be public static and accept no arguments",
+ method.getName()));
+ }
+ if (method.getReturnType().isAssignableFrom(org.apache.tapestry5.ioc.def.ModuleDef.class)) {
+ throw new InitializationError(
+ String.format("@ModuleDef method %s return type %s is not valid",
+ method.getName(), method.getReturnType()));
+ }
+ }
+
+ public void beforeTestClass() {
+ }
+
+ public void beforeTestMethod() {
+ }
+
+ public Object createTest() throws Exception {
+ if (!isRegistryStarted()) {
+ try {
+ createRegistry();
+ } catch (Throwable e) {
+ throw new Exception(e);
+ }
+ }
+ return registry.autobuild(type);
+ }
+
+ public void afterTestMethod() {
+ if (annotation.shutdown() == RegistryShutdownType.AFTER_METHOD) {
+ shutdownRegistry();
+ }
+ }
+
+ public void afterTestClass() {
+ if (annotation.shutdown() == RegistryShutdownType.AFTER_CLASS) {
+ shutdownRegistry();
+ }
+ }
+
+ protected void createRegistry() throws Throwable {
+ RegistryBuilder builder = new RegistryBuilder();
+ if (annotation.modules() != null) {
+ builder.add(annotation.modules());
+ }
+ for (Method moduleDefFactory : moduleDefFactories) {
+ try {
+ org.apache.tapestry5.ioc.def.ModuleDef moduleDef =
+ (org.apache.tapestry5.ioc.def.ModuleDef) moduleDefFactory.invoke(null);
+
+ builder.add(moduleDef);
+ } catch (InvocationTargetException e) {
+ throw e.getTargetException();
+ }
+ }
+ registry = builder.build();
+ registry.performRegistryStartup();
+ }
+
+ protected boolean isRegistryStarted() {
+ return registry != null;
+ }
+
+ protected void shutdownRegistry() {
+ try {
+ registry.shutdown();
+ } finally {
+ registry = null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..7d3766c
--- /dev/null
+++ b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/MapModuleDef.java
@@ -0,0 +1,80 @@
+package org.apache.tapestry5.ioc.test;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tapestry5.ioc.ObjectCreator;
+import org.apache.tapestry5.ioc.ScopeConstants;
+import org.apache.tapestry5.ioc.ServiceBuilderResources;
+import org.apache.tapestry5.ioc.def.ContributionDef;
+import org.apache.tapestry5.ioc.def.DecoratorDef;
+import org.apache.tapestry5.ioc.def.ModuleDef;
+import org.apache.tapestry5.ioc.def.ServiceDef;
+
+public class MapModuleDef implements ModuleDef {
+ private final Map<String, Object> map;
+
+ public MapModuleDef(Map<String, Object> map) {
+ super();
+ this.map = map;
+ }
+ public Class getBuilderClass() {
+ return null;
+ }
+ public Set<ContributionDef> getContributionDefs() {
+ return Collections.emptySet();
+ }
+ public Set<DecoratorDef> getDecoratorDefs() {
+ return Collections.emptySet();
+ }
+ public String getLoggerName() {
+ return "MapModuleDef";
+ }
+ public Set<String> getServiceIds() {
+ return map.keySet();
+ }
+ public ServiceDef getServiceDef(String serviceId) {
+ return new MapServiceDef(map, serviceId);
+ }
+
+ public static class MapServiceDef implements ServiceDef {
+ private final Map<String, Object> map;
+ private final String serviceId;
+
+ public MapServiceDef(Map<String, Object> map, String serviceId) {
+ super();
+ this.map = map;
+ this.serviceId = serviceId;
+ }
+
+ public ObjectCreator createServiceCreator(ServiceBuilderResources resources) {
+ return new ObjectCreator() {
+ public Object createObject() {
+ return map.get(serviceId);
+ }
+ };
+ }
+
+ public String getServiceId() {
+ return serviceId;
+ }
+
+ public Set<Class> getMarkers() {
+ return Collections.emptySet();
+ }
+
+ public Class getServiceInterface() {
+ return map.get(serviceId).getClass();
+ }
+
+ public String getServiceScope() {
+ return ScopeConstants.DEFAULT;
+ }
+
+ public boolean isEagerLoad() {
+ return false;
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..349a32c
--- /dev/null
+++ b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterClassTest.java
@@ -0,0 +1,39 @@
+package org.apache.tapestry5.ioc.test;
+
+import static org.apache.tapestry5.ioc.test.RegistryShutdownType.AFTER_CLASS;
+
+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.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(TapestryIOCJUnit4ClassRunner.class)
+@Registry(modules=TestModule.class, shutdown=AFTER_CLASS)
+public class TapestryIOCJUnit4ClassRunnerAfterClassTest {
+ public static class TestModule {
+ public List<String> buildList() {
+ List<String> list = new ArrayList<String>();
+ list.add("foo");
+ return list;
+ }
+ }
+
+ @Inject
+ private List<String> list;
+
+ @Test
+ public void testInjectA() {
+ Assert.assertEquals(1, list.size());
+ list.add("bar");
+ Assert.assertEquals(2, list.size());
+ }
+
+ @Test
+ public void testInjectB() {
+ Assert.assertEquals(2, list.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..3c556b0
--- /dev/null
+++ b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerAfterMethodTest.java
@@ -0,0 +1,41 @@
+package org.apache.tapestry5.ioc.test;
+
+import static org.apache.tapestry5.ioc.test.RegistryShutdownType.AFTER_METHOD;
+
+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.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(TapestryIOCJUnit4ClassRunner.class)
+@Registry(modules=TestModule.class, shutdown=AFTER_METHOD)
+public class TapestryIOCJUnit4ClassRunnerAfterMethodTest {
+ public static class TestModule {
+ public List<String> buildList() {
+ List<String> list = new ArrayList<String>();
+ list.add("foo");
+ return list;
+ }
+ }
+
+ @Inject
+ private List<String> list;
+
+ @Test
+ public void testInjectA() {
+ Assert.assertEquals(1, list.size());
+ list.add("bar");
+ Assert.assertEquals(2, list.size());
+ }
+
+ @Test
+ public void testInjectB() {
+ Assert.assertEquals(1, list.size());
+ list.add("baz");
+ Assert.assertEquals(2, list.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/deab2b3f/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
new file mode 100644
index 0000000..f67a946
--- /dev/null
+++ b/tapestry-ioc-test/src/test/java/org/apache/tapestry5/ioc/test/TapestryIOCJUnit4ClassRunnerModuleDefTest.java
@@ -0,0 +1,49 @@
+package org.apache.tapestry5.ioc.test;
+
+import static org.apache.tapestry5.ioc.test.RegistryShutdownType.AFTER_METHOD;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.test.TapestryIOCJUnit4ClassRunnerModuleDefTest.ModuleDefTestModule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(TapestryIOCJUnit4ClassRunner.class)
+@Registry(modules=ModuleDefTestModule.class, shutdown=AFTER_METHOD)
+public class TapestryIOCJUnit4ClassRunnerModuleDefTest {
+ @ModuleDef
+ public static MapModuleDef createMapModuleDef() {
+ Map<String,Object> map = new HashMap<String, Object>();
+ map.put("foo", new Date(100));
+ map.put("bar", new Long(999));
+
+ return new MapModuleDef(map);
+ }
+
+ public static class ModuleDefTestModule {
+ public Integer buildBaz() {
+ return new Integer(666);
+ }
+ }
+
+ @Inject
+ private Date foo;
+
+ @Inject
+ private Long bar;
+
+ @Inject
+ private Integer baz;
+
+ @Test
+ public void testModuleDefInject() {
+ Assert.assertEquals(new Date(100), foo);
+ Assert.assertEquals(new Long(999), bar);
+ Assert.assertEquals(new Integer(666), baz);
+ }
+}
[2/2] git commit: TAP5-2273: TapestryIOCJUnit4ClassRunner
documentation added
Posted by uk...@apache.org.
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;
[2/2] git commit: TAP5-2273: TapestryIOCJUnit4ClassRunner
documentation added
Posted by uk...@apache.org.
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;