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 2013/05/09 17:08:23 UTC
svn commit: r1480675 - in /tomee/tomee/trunk:
arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/
container/openejb-core/src/main/...
Author: rmannibucau
Date: Thu May 9 15:08:22 2013
New Revision: 1480675
URL: http://svn.apache.org/r1480675
Log:
TOMEE-926 avoiding ambiguity when replacing server.xml ports
Added:
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/SetupTest.java
Modified:
tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java
Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java?rev=1480675&r1=1480674&r2=1480675&view=diff
==============================================================================
--- tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java (original)
+++ tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java Thu May 9 15:08:22 2013
@@ -67,14 +67,6 @@ public class Setup {
final File serverXml = Files.path(tomeeHome, "conf", "server.xml");
final QuickServerXmlParser ports = QuickServerXmlParser.parse(serverXml);
- /* DMB: TODO - Looks like there's a bug here. We should add some tests for our server.xml manipulation
- This will work fine with the default ports, but if someone should update their ports to say
- http="111", https="1111" and stop="11111", then someone updates just the http port to "444"
- .. the resulting ports will mistakenly be 444, 4441, and 44411 respectively.
-
- We really should add some tests for comparing server.xml files before and after, as well as
- have a few different server.xml files with non-standard settings.
- */
final Map<String, String> replacements = new HashMap<String, String>();
replacements.put(ports.http(), String.valueOf(configuration.getHttpPort()));
replacements.put(ports.stop(), String.valueOf(configuration.getStopPort()));
@@ -86,7 +78,7 @@ public class Setup {
replacements.put("unpackWARs=\"true\"", "unpackWARs=\"false\"");
}
- replace(replacements, serverXml);
+ replace(replacements, serverXml, true);
}
public static File findHome(File directory) {
@@ -172,9 +164,26 @@ public class Setup {
}
}
- public static void replace(final Map<String, String> replacements, final File file) throws IOException {
+ public static void replace(final Map<String, String> replacements, final File file, final boolean escape) throws IOException {
InputStream in = IO.read(file);
+
+ if (escape) {
+ final Map<String, String> escaped = new HashMap<String, String>();
+ for (final Map.Entry<String, String> entry : replacements.entrySet()) {
+ final String key = entry.getKey();
+ final String value = entry.getValue();
+ if (key.startsWith("\"") && key.endsWith("\"")) {
+ escaped.put(key, value);
+ } else {
+ escaped.put("\"" + key + "\"", "\"" + value + "\"");
+ }
+ }
+
+ replacements.clear();
+ replacements.putAll(escaped);
+ }
+
in = new ReplaceStringsInputStream(in, replacements);
final String data = IO.slurp(in);
@@ -186,6 +195,11 @@ public class Setup {
}
}
+ @Deprecated
+ public static void replace(final Map<String, String> replacements, final File file) throws IOException {
+ replace(replacements, file, false);
+ }
+
public static void removeUselessWebapps(final File tomeeHome) {
final File webapps = new File(tomeeHome, "webapps");
if (webapps.isDirectory()) {
Added: tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/SetupTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/SetupTest.java?rev=1480675&view=auto
==============================================================================
--- tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/SetupTest.java (added)
+++ tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/SetupTest.java Thu May 9 15:08:22 2013
@@ -0,0 +1,70 @@
+/*
+ * 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 org.apache.openejb.arquillian.common;
+
+import org.apache.openejb.testng.PropertiesBuilder;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class SetupTest {
+ @Test
+ public void simpleReplace() throws IOException {
+ replaceTest(8080, 8005, 8009, 1111, 2222, 3333);
+ }
+
+ private void replaceTest(int http1, int stop1, int ajp1, int http2, int stop2, int ajp2) throws IOException {
+ final File target = write("target/setup1.xml", serverXml(http1, stop1, ajp1));
+ Setup.replace(new PropertiesBuilder()
+ .p(Integer.toString(http1), Integer.toString(http2))
+ .p(Integer.toString(stop1), Integer.toString(stop2))
+ .p(Integer.toString(ajp1), Integer.toString(ajp2))
+ .asMap(), target, true);
+ assertEquals(serverXml(http2, stop2, ajp2), IO.slurp(target));
+ }
+
+ @Test
+ public void ambiguousReplace() throws IOException {
+ replaceTest(111, 1111, 11111, 3333, 4444, 5555);
+ }
+
+ private File write(final String file, final String s1) throws IOException {
+ final File target = new File(file);
+ final FileWriter writer = new FileWriter(target);
+ writer.write(s1);
+ writer.close();
+ return target;
+ }
+
+ private static String serverXml(final int http, final int stop, final int ajp) {
+ return "<?xml version='1.0' encoding='utf-8'?>\n" +
+ "<Server port=\"" + stop + "\" shutdown=\"SHUTDOWN\">\n" +
+ " <Listener className=\"org.apache.tomee.catalina.ServerListener\" />\n" +
+ " <Service name=\"Catalina\">\n" +
+ " <Connector port=\"" + http + "\" protocol=\"HTTP/1.1\" connectionTimeout=\"20000\"/>\n" +
+ " <Connector port=\"" + ajp + "\" protocol=\"AJP/1.3\" redirectPort=\"8443\" />\n" +
+ " <Engine name=\"Catalina\" defaultHost=\"localhost\">\n" +
+ " <Host name=\"localhost\" appBase=\"webapps\" unpackWARs=\"true\" autoDeploy=\"true\"/>\n" +
+ " </Engine>\n" +
+ " </Service>\n" +
+ "</Server>\n";
+ }
+}
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java?rev=1480675&r1=1480674&r2=1480675&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testng/PropertiesBuilder.java Thu May 9 15:08:22 2013
@@ -16,6 +16,8 @@
*/
package org.apache.openejb.testng;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
public class PropertiesBuilder {
@@ -33,4 +35,12 @@ public class PropertiesBuilder {
public Properties build() {
return properties;
}
+
+ public Map<String, String> asMap() {
+ final Map<String, String> map = new HashMap<String, String>();
+ for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
+ map.put(String.class.cast(entry.getKey()), String.class.cast(entry.getValue()));
+ }
+ return map;
+ }
}