Surefire 2.18 allocates and initializes the statics for ALL the test classes up front. Thus, the "Server" and similar ports get overwridden and tests fail. Update TestUtil to record the port on the various package names walkingup the class so we can start fixing tests.
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/f57d8ae4 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/f57d8ae4 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/f57d8ae4 Branch: refs/heads/master Commit: f57d8ae4cf0c664eae9d93b54236870139e6b090 Parents: 05b96b6 Author: Daniel Kulp <[email protected]> Authored: Wed May 20 13:37:06 2015 -0400 Committer: Daniel Kulp <[email protected]> Committed: Wed May 20 13:38:53 2015 -0400 ---------------------------------------------------------------------- .../apache/cxf/testutil/common/TestUtil.java | 38 ++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/f57d8ae4/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java ---------------------------------------------------------------------- diff --git a/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java b/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java index f21675e..04baa99 100644 --- a/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java +++ b/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java @@ -142,13 +142,42 @@ public final class TestUtil { public static String getNewPortNumber(String name) { return getNewPortNumber(name, name); } - public static String getNewPortNumber(String fullName, String simpleName) { + + private static void applyNames(String fullName, String simpleName, String p) { + ports.setProperty("testutil.ports." + fullName, p); + ports.setProperty("testutil.ports." + simpleName, p); + System.setProperty("testutil.ports." + fullName, p); + System.setProperty("testutil.ports." + simpleName, p); + if (fullName.endsWith("." + simpleName)) { + int idx = fullName.lastIndexOf('.', fullName.lastIndexOf('.')); + while (idx != -1) { + String name = fullName.substring(idx + 1); + ports.setProperty("testutil.ports." + name, p); + System.setProperty("testutil.ports." + name, p); + idx = fullName.lastIndexOf('.', idx - 1); + } + } + } + private static void removeNames(String fullName, String simpleName) { ports.remove("testutil.ports." + fullName); ports.remove("testutil.ports." + simpleName); System.clearProperty("testutil.ports." + fullName); System.clearProperty("testutil.ports." + simpleName); + if (fullName.endsWith("." + simpleName)) { + int idx = fullName.lastIndexOf('.', fullName.lastIndexOf('.')); + while (idx != -1) { + String name = fullName.substring(idx + 1); + ports.remove("testutil.ports." + name); + System.clearProperty("testutil.ports." + name); + idx = fullName.lastIndexOf('.', idx - 1); + } + } + } + + public static String getNewPortNumber(String fullName, String simpleName) { + removeNames(fullName, simpleName); return getPortNumber(fullName, simpleName); - } + } public static String getPortNumber(String fullName, String simpleName) { String p = ports.getProperty("testutil.ports." + fullName); if (p == null) { @@ -170,10 +199,7 @@ public final class TestUtil { // } } - ports.put("testutil.ports." + fullName, p); - ports.put("testutil.ports." + simpleName, p); - System.setProperty("testutil.ports." + fullName, p); - System.setProperty("testutil.ports." + simpleName, p); + applyNames(fullName, simpleName, p); return p; }
