brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [01/12] git commit: port WebAppRunnerTest to java and improve shutdown
Date Fri, 18 Jul 2014 13:42:12 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 935236ec8 -> f0b8f296d


port WebAppRunnerTest to java and improve shutdown


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/2f4367e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/2f4367e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/2f4367e0

Branch: refs/heads/master
Commit: 2f4367e0d6b4cd2b5f3e0be61ce079586145d915
Parents: 965a3d1
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Jul 18 01:09:33 2014 -0400
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Jul 18 09:15:17 2014 -0400

----------------------------------------------------------------------
 .../brooklyn/launcher/WebAppRunnerTest.groovy   | 163 -------------------
 .../brooklyn/launcher/WebAppRunnerTest.java     | 160 ++++++++++++++++++
 2 files changed, 160 insertions(+), 163 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f4367e0/usage/launcher/src/test/java/brooklyn/launcher/WebAppRunnerTest.groovy
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/java/brooklyn/launcher/WebAppRunnerTest.groovy b/usage/launcher/src/test/java/brooklyn/launcher/WebAppRunnerTest.groovy
deleted file mode 100644
index af62480..0000000
--- a/usage/launcher/src/test/java/brooklyn/launcher/WebAppRunnerTest.groovy
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * 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 brooklyn.launcher
-
-import static java.util.concurrent.TimeUnit.*
-import static org.testng.Assert.*
-
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-import org.testng.annotations.AfterMethod
-import org.testng.annotations.Test
-
-import brooklyn.config.BrooklynProperties
-import brooklyn.entity.basic.Entities
-import brooklyn.management.internal.LocalManagementContext
-import brooklyn.test.HttpTestUtils
-import brooklyn.util.internal.TimeExtras
-import brooklyn.util.net.Networking
-import brooklyn.util.time.Duration
-
-import com.google.common.collect.Lists
-
-
-/**
- * These tests require the brooklyn.war to work. (Should be placed by maven build.)
- */
-public class WebAppRunnerTest {
-    static { TimeExtras.init() }
-
-    public static final Logger log = LoggerFactory.getLogger(WebAppRunnerTest.class);
-            
-    private static Duration TIMEOUT_MS;
-    static { TIMEOUT_MS = Duration.THIRTY_SECONDS; }
-    
-    List<LocalManagementContext> managementContexts = Lists.newCopyOnWriteArrayList();
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        for (LocalManagementContext managementContext : managementContexts) {
-            Entities.destroyAll(managementContext);
-        }
-        managementContexts.clear();
-    }
-    
-    LocalManagementContext newManagementContext(BrooklynProperties brooklynProperties) {
-        LocalManagementContext result = new LocalManagementContext(brooklynProperties);
-        managementContexts.add(result);
-        return result;
-    }
-    
-    BrooklynWebServer createWebServer(Map properties) {
-        Map bigProps = [:] + properties;
-        Map attributes = bigProps.attributes
-        if (attributes==null) {
-            attributes = [:]
-        } else {
-            attributes = [:] + attributes; //copy map, don't change what was supplied
-        }
-        bigProps.attributes = attributes;
-
-        BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newDefault();
-        brooklynProperties.putAll(bigProps);
-        brooklynProperties.put("brooklyn.webconsole.security.provider","brooklyn.rest.security.provider.AnyoneSecurityProvider")
-        brooklynProperties.put("brooklyn.webconsole.security.https.required","false");
-        return new BrooklynWebServer(bigProps, newManagementContext(brooklynProperties));
-    }
-    
-    @Test
-    public void testStartWar1() {
-        if (!Networking.isPortAvailable(8090))
-            fail("Another process is using port 8090 which is required for this test.");
-        BrooklynWebServer server = createWebServer(port:8090);
-        assertNotNull(server);
-        
-        try {
-            server.start();
-            assertBrooklynEventuallyAt("http://localhost:8090/");
-        } finally {
-            server.stop();
-        }
-    }
-
-    public static void assertBrooklynEventuallyAt(String url) {
-        HttpTestUtils.assertContentEventuallyContainsText(url, "Brooklyn Web Console");
-    }
-    
-    @Test
-    public void testStartSecondaryWar() {
-        if (!Networking.isPortAvailable(8090))
-            fail("Another process is using port 8090 which is required for this test.");
-        BrooklynWebServer server = createWebServer(port:8090, war:"brooklyn.war", wars:["hello":"hello-world.war"]);
-        assertNotNull(server);
-        
-        try {
-            server.start();
-
-            assertBrooklynEventuallyAt("http://localhost:8090/");
-            HttpTestUtils.assertContentEventuallyContainsText("http://localhost:8090/hello",
-                "This is the home page for a sample application");
-
-        } finally {
-            server.stop();
-        }
-    }
-
-    @Test
-    public void testStartSecondaryWarAfter() {
-        if (!Networking.isPortAvailable(8090))
-            fail("Another process is using port 8090 which is required for this test.");
-        BrooklynWebServer server = createWebServer(port:8090, war:"brooklyn.war");
-        assertNotNull(server);
-        
-        try {
-            server.start();
-            server.deploy("/hello", "hello-world.war");
-
-            assertBrooklynEventuallyAt("http://localhost:8090/");
-            HttpTestUtils.assertContentEventuallyContainsText("http://localhost:8090/hello",
-                "This is the home page for a sample application");
-
-        } finally {
-            server.stop();
-        }
-    }
-
-    @Test
-    public void testStartWithLauncher() {
-        BrooklynLauncher launcher = BrooklynLauncher.newInstance()
-                .brooklynProperties("brooklyn.webconsole.security.provider",'brooklyn.rest.security.provider.AnyoneSecurityProvider')
-                .webapp("/hello", "hello-world.war")
-                .start();
-        BrooklynServerDetails details = launcher.getServerDetails();
-        
-        try {
-            details.getWebServer().deploy("/hello2", "hello-world.war");
-
-            assertBrooklynEventuallyAt(details.getWebServerUrl());
-            HttpTestUtils.assertContentEventuallyContainsText(details.getWebServerUrl()+"hello",
"This is the home page for a sample application");
-            HttpTestUtils.assertContentEventuallyContainsText(details.getWebServerUrl()+"hello2",
"This is the home page for a sample application");
-            HttpTestUtils.assertHttpStatusCodeEventuallyEquals(details.getWebServerUrl()+"hello0",
404);
-
-        } finally {
-            details.getWebServer().stop();
-        }
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f4367e0/usage/launcher/src/test/java/brooklyn/launcher/WebAppRunnerTest.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/java/brooklyn/launcher/WebAppRunnerTest.java b/usage/launcher/src/test/java/brooklyn/launcher/WebAppRunnerTest.java
new file mode 100644
index 0000000..2fbd131
--- /dev/null
+++ b/usage/launcher/src/test/java/brooklyn/launcher/WebAppRunnerTest.java
@@ -0,0 +1,160 @@
+/*
+ * 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 brooklyn.launcher;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.fail;
+
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.config.BrooklynProperties;
+import brooklyn.entity.basic.Entities;
+import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.management.internal.ManagementContextInternal;
+import brooklyn.test.HttpTestUtils;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.net.Networking;
+
+import com.google.common.collect.Lists;
+
+
+/**
+ * These tests require the brooklyn.war to work. (Should be placed by maven build.)
+ */
+public class WebAppRunnerTest {
+
+    public static final Logger log = LoggerFactory.getLogger(WebAppRunnerTest.class);
+            
+    List<LocalManagementContext> managementContexts = Lists.newCopyOnWriteArrayList();
+    
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws Exception {
+        for (LocalManagementContext managementContext : managementContexts) {
+            Entities.destroyAll(managementContext);
+        }
+        managementContexts.clear();
+    }
+    
+    LocalManagementContext newManagementContext(BrooklynProperties brooklynProperties) {
+        LocalManagementContext result = new LocalManagementContext(brooklynProperties);
+        managementContexts.add(result);
+        return result;
+    }
+    
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    BrooklynWebServer createWebServer(Map properties) {
+        Map bigProps = MutableMap.copyOf(properties);
+        Map attributes = MutableMap.copyOf( (Map) bigProps.get("attributes") );
+        bigProps.put("attributes", attributes);
+
+        BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newDefault();
+        brooklynProperties.putAll(bigProps);
+        brooklynProperties.put("brooklyn.webconsole.security.provider","brooklyn.rest.security.provider.AnyoneSecurityProvider");
+        brooklynProperties.put("brooklyn.webconsole.security.https.required","false");
+        return new BrooklynWebServer(bigProps, newManagementContext(brooklynProperties));
+    }
+    
+    @Test
+    public void testStartWar1() throws Exception {
+        if (!Networking.isPortAvailable(8090))
+            fail("Another process is using port 8090 which is required for this test.");
+        BrooklynWebServer server = createWebServer(MutableMap.of("port", 8090));
+        assertNotNull(server);
+        
+        try {
+            server.start();
+            assertBrooklynEventuallyAt("http://localhost:8090/");
+        } finally {
+            server.stop();
+        }
+    }
+
+    public static void assertBrooklynEventuallyAt(String url) {
+        HttpTestUtils.assertContentEventuallyContainsText(url, "Brooklyn Web Console");
+    }
+    
+    @Test
+    public void testStartSecondaryWar() throws Exception {
+        if (!Networking.isPortAvailable(8090))
+            fail("Another process is using port 8090 which is required for this test.");
+        BrooklynWebServer server = createWebServer(
+            MutableMap.of("port", 8090, "war", "brooklyn.war", "wars", MutableMap.of("hello",
"hello-world.war")) );
+        assertNotNull(server);
+        
+        try {
+            server.start();
+
+            assertBrooklynEventuallyAt("http://localhost:8090/");
+            HttpTestUtils.assertContentEventuallyContainsText("http://localhost:8090/hello",
+                "This is the home page for a sample application");
+
+        } finally {
+            server.stop();
+        }
+    }
+
+    @Test
+    public void testStartSecondaryWarAfter() throws Exception {
+        if (!Networking.isPortAvailable(8090))
+            fail("Another process is using port 8090 which is required for this test.");
+        BrooklynWebServer server = createWebServer(MutableMap.of("port", 8090, "war", "brooklyn.war"));
+        assertNotNull(server);
+        
+        try {
+            server.start();
+            server.deploy("/hello", "hello-world.war");
+
+            assertBrooklynEventuallyAt("http://localhost:8090/");
+            HttpTestUtils.assertContentEventuallyContainsText("http://localhost:8090/hello",
+                "This is the home page for a sample application");
+
+        } finally {
+            server.stop();
+        }
+    }
+
+    @Test
+    public void testStartWithLauncher() throws Exception {
+        BrooklynLauncher launcher = BrooklynLauncher.newInstance()
+                .brooklynProperties("brooklyn.webconsole.security.provider","brooklyn.rest.security.provider.AnyoneSecurityProvider")
+                .webapp("/hello", "hello-world.war")
+                .start();
+        BrooklynServerDetails details = launcher.getServerDetails();
+        
+        try {
+            details.getWebServer().deploy("/hello2", "hello-world.war");
+
+            assertBrooklynEventuallyAt(details.getWebServerUrl());
+            HttpTestUtils.assertContentEventuallyContainsText(details.getWebServerUrl()+"hello",
"This is the home page for a sample application");
+            HttpTestUtils.assertContentEventuallyContainsText(details.getWebServerUrl()+"hello2",
"This is the home page for a sample application");
+            HttpTestUtils.assertHttpStatusCodeEventuallyEquals(details.getWebServerUrl()+"hello0",
404);
+
+        } finally {
+            details.getWebServer().stop();
+            ((ManagementContextInternal)details.getManagementContext()).terminate();
+        }
+    }
+    
+}


Mime
View raw message