You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2014/12/08 11:41:17 UTC
tomee git commit: TOMEE-1472 TOMEE-1473 @RandomPort and @SimpleLog
Repository: tomee
Updated Branches:
refs/heads/tomee-1.7.x b1bc2c54e -> c1998e1b5
TOMEE-1472 TOMEE-1473 @RandomPort and @SimpleLog
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/c1998e1b
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/c1998e1b
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/c1998e1b
Branch: refs/heads/tomee-1.7.x
Commit: c1998e1b52b633174a2122478cf87596f6efd9f9
Parents: b1bc2c5
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Mon Dec 8 11:40:54 2014 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Mon Dec 8 11:40:54 2014 +0100
----------------------------------------------------------------------
.../openejb/testing/ApplicationComposers.java | 38 ++++++++++++++++++++
1 file changed, 38 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/c1998e1b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
index 6b2453a..5855754 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
@@ -68,6 +68,7 @@ import org.apache.openejb.loader.IO;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.spi.ContainerSystem;
import org.apache.openejb.util.Join;
+import org.apache.openejb.util.NetworkUtil;
import org.apache.openejb.util.ServiceManagerProxy;
import org.apache.openejb.util.URLs;
import org.apache.openejb.web.LightweightWebAppBuilder;
@@ -279,6 +280,15 @@ public final class ApplicationComposers {
}
}
+ for (final ClassFinder finder : testClassFinders.values()) {
+ for (final Field field : finder.findAnnotatedFields(RandomPort.class)) {
+ final Class<?> type = field.getType();
+ if (int.class != type && URL.class != type) {
+ throw new IllegalArgumentException("@RandomPort is only supported for int fields");
+ }
+ }
+ }
+
if (appModules > 1) {
final String gripe = "Test class should have no more than one @Module method that returns " + Application.class.getName();
errors.add(new Exception(gripe));
@@ -409,6 +419,34 @@ public final class ApplicationComposers {
}
SystemInstance.init(configuration);
+ for (final Map.Entry<Object, ClassFinder> finder : testClassFinders.entrySet()) {
+ for (final Field field : finder.getValue().findAnnotatedFields(RandomPort.class)) {
+ if (!field.isAccessible()) {
+ field.setAccessible(true);
+ }
+
+ final String key = field.getAnnotation(RandomPort.class).value() + ".port";
+ final String existing = SystemInstance.get().getProperty(key);
+ final int random;
+ if (existing == null) {
+ random = NetworkUtil.getNextAvailablePort();
+ SystemInstance.get().setProperty(key, Integer.toString(random));
+ } else {
+ random = Integer.parseInt(existing);
+ }
+ if (int.class == field.getType()) {
+ field.set(finder.getKey(), random);
+ } else if (URL.class == field.getType()) {
+ field.set(finder.getKey(), new URL("http://localhost:" + random + "/"));
+ }
+ }
+ }
+ for (final Map.Entry<Object, ClassFinder> finder : testClassFinders.entrySet()) {
+ if (!finder.getValue().findAnnotatedClasses(SimpleLog.class).isEmpty()) {
+ SystemInstance.get().setProperty("openejb.jul.forceReload", "true");
+ break;
+ }
+ }
final CdiExtensions cdiExtensions = testClass.getAnnotation(CdiExtensions.class);
if (cdiExtensions != null) {