You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by rm...@apache.org on 2013/10/30 11:32:33 UTC

svn commit: r1537032 - in /incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template: JMXTest.java JTATest.java JVMTest.java SironaReportingTestBase.java ThreadsTest.java WebTest.java

Author: rmannibucau
Date: Wed Oct 30 10:32:32 2013
New Revision: 1537032

URL: http://svn.apache.org/r1537032
Log:
adding basic tests for all part of the gui (reporting)

Added:
    incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JMXTest.java
      - copied, changed from r1537021, incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/HomeTest.java
    incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JTATest.java
    incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JVMTest.java
    incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/ThreadsTest.java
    incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/WebTest.java
Modified:
    incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/SironaReportingTestBase.java

Copied: incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JMXTest.java (from r1537021, incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/HomeTest.java)
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JMXTest.java?p2=incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JMXTest.java&p1=incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/HomeTest.java&r1=1537021&r2=1537032&rev=1537032&view=diff
==============================================================================
--- incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/HomeTest.java (original)
+++ incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JMXTest.java Wed Oct 30 10:32:32 2013
@@ -16,25 +16,29 @@
  */
 package org.apache.sirona.reporting.template;
 
+import com.gargoylesoftware.htmlunit.TextPage;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertThat;
 import org.junit.Test;
 
 import java.io.IOException;
 
-public class HomeTest extends SironaReportingTestBase {
+import static com.gargoylesoftware.htmlunit.WebAssert.assertElementPresent;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+public class JMXTest extends SironaReportingTestBase {
     @Test
-    public void checkHomeShowsPlugins() throws IOException {
-        final HtmlPage page = page("");
-        final String plugins = page.getElementById("plugins").asText();
-        assertThat(plugins, containsString("Home"));
-        assertThat(plugins, containsString("Report"));
-        assertThat(plugins, containsString("JMX"));
-        assertThat(plugins, containsString("JVM"));
-        assertThat(plugins, containsString("JTA"));
-        assertThat(plugins, containsString("Threads"));
-        assertThat(plugins, containsString("Web"));
+    public void checkSomeMBeanIsAvailable() throws IOException {
+        final String classLoadingMBeanId = "amF2YS5sYW5nOnR5cGU9Q2xhc3NMb2FkaW5n";  // java.lang:ClassLoading
+
+        final HtmlPage page = page("jmx");
+        assertElementPresent(page, classLoadingMBeanId);
+
+        // we could click on the link but it would mandates to activate js in the WebClient (see parent)
+        // this is not as easy as setting the boolean because of dev environment (proxy, etc...)
+        final TextPage detail = page("jmx/" + classLoadingMBeanId);
+        final String detailAsStr = detail.getWebResponse().getContentAsString();
+        assertThat(detailAsStr, containsString("LoadedClassCount"));
+        assertThat(detailAsStr, containsString("sun.management.ClassLoadingImpl"));
     }
 }

Added: incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JTATest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JTATest.java?rev=1537032&view=auto
==============================================================================
--- incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JTATest.java (added)
+++ incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JTATest.java Wed Oct 30 10:32:32 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.sirona.reporting.template;
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static com.gargoylesoftware.htmlunit.WebAssert.assertElementPresent;
+import static org.junit.Assert.assertTrue;
+
+public class JTATest extends SironaReportingTestBase {
+    @Test
+    public void checkGraphArePresent() throws IOException {
+        final HtmlPage page = page("jta");
+        assertElementPresent(page, "Commits-graph");
+        assertElementPresent(page, "Rollbacks-graph");
+        assertElementPresent(page, "Actives-graph");
+    }
+
+    @Test
+    public void checkJsonEndpoint() throws IOException {
+        final String page = page("jta/Actives/0/" + System.currentTimeMillis()).getWebResponse().getContentAsString().replace(" ", "");
+        assertTrue(page.startsWith("{\"data\":["));
+        assertTrue(page.endsWith(",\"label\":\"Active\",\"color\":\"#317eac\"}"));
+    }
+}

Added: incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JVMTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JVMTest.java?rev=1537032&view=auto
==============================================================================
--- incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JVMTest.java (added)
+++ incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/JVMTest.java Wed Oct 30 10:32:32 2013
@@ -0,0 +1,41 @@
+/*
+ * 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.sirona.reporting.template;
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static com.gargoylesoftware.htmlunit.WebAssert.assertElementPresent;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+public class JVMTest extends SironaReportingTestBase {
+    @Test
+    public void checkGraphArePresent() throws IOException {
+        final HtmlPage page = page("jvm");
+        assertElementPresent(page, "cpu-graph");
+        assertElementPresent(page, "memory-graph");
+
+        final String detailAsStr = page.getWebResponse().getContentAsString();
+        assertThat(detailAsStr, containsString("CPU"));
+        assertThat(detailAsStr, containsString("Memory"));
+        assertThat(detailAsStr, containsString("OS Name"));
+        assertThat(detailAsStr, containsString(System.getProperty("os.name")));
+    }
+}

Modified: incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/SironaReportingTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/SironaReportingTestBase.java?rev=1537032&r1=1537031&r2=1537032&view=diff
==============================================================================
--- incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/SironaReportingTestBase.java (original)
+++ incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/SironaReportingTestBase.java Wed Oct 30 10:32:32 2013
@@ -16,18 +16,16 @@
  */
 package org.apache.sirona.reporting.template;
 
+import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
+import com.gargoylesoftware.htmlunit.Page;
 import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import org.apache.catalina.startup.Constants;
-import org.apache.sirona.reporting.web.plugin.Plugin;
-import org.apache.sirona.reporting.web.plugin.report.ReportPlugin;
 import org.apache.sirona.reporting.web.registration.MonitoringReportingInitializer;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.Archive;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.junit.runner.RunWith;
@@ -60,8 +58,8 @@ public abstract class SironaReportingTes
     @ArquillianResource
     protected URL base;
 
-    protected HtmlPage page(final String path) throws IOException {
-        return newClient().getPage(base.toExternalForm() + "/monitoring/" + path);
+    protected <P extends Page> P page(final String path) throws IOException {
+        return newClient().getPage(base.toExternalForm() + "monitoring/" + path);
     }
 
     protected static WebClient newClient() {
@@ -69,6 +67,7 @@ public abstract class SironaReportingTes
         webClient.getOptions().setJavaScriptEnabled(false);
         webClient.getOptions().setCssEnabled(false);
         webClient.getOptions().setAppletEnabled(false);
+        webClient.setAjaxController(new NicelyResynchronizingAjaxController());
         return webClient;
     }
 }

Added: incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/ThreadsTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/ThreadsTest.java?rev=1537032&view=auto
==============================================================================
--- incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/ThreadsTest.java (added)
+++ incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/ThreadsTest.java Wed Oct 30 10:32:32 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.sirona.reporting.template;
+
+import com.gargoylesoftware.htmlunit.TextPage;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static com.gargoylesoftware.htmlunit.WebAssert.assertElementPresent;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class ThreadsTest extends SironaReportingTestBase {
+    private static final String CONTAINER_BACKGROUND_THREAD = "Q29udGFpbmVyQmFja2dyb3VuZFByb2Nlc3NvcltTdGFuZGFyZEVuZ2luZVthcnF1aWxsaWFuLXRvbWNhdC1lbWJlZGRlZC03XV0="; // always exists
+
+    @Test
+    public void checkThreadsAreListed() throws IOException {
+        final HtmlPage page = page("threads");
+        assertElementPresent(page, CONTAINER_BACKGROUND_THREAD);
+    }
+
+    @Test
+    public void checkDetail() throws IOException {
+        final TextPage page = page("threads/" + CONTAINER_BACKGROUND_THREAD);
+        assertThat(page.getWebResponse().getContentAsString(), containsString("org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run"));
+    }
+}

Added: incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/WebTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/WebTest.java?rev=1537032&view=auto
==============================================================================
--- incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/WebTest.java (added)
+++ incubator/sirona/trunk/reporting/src/test/java/org/apache/sirona/reporting/template/WebTest.java Wed Oct 30 10:32:32 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.sirona.reporting.template;
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static com.gargoylesoftware.htmlunit.WebAssert.assertElementPresent;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class WebTest extends SironaReportingTestBase {
+    @Test
+    public void checkSessionsGraphIsPresent() throws IOException {
+        final HtmlPage page = page("web");
+        assertElementPresent(page, "sessions-graph");
+
+        final String detailAsStr = page.getWebResponse().getContentAsString();
+        assertThat(detailAsStr, containsString("Sessions"));
+    }
+
+    @Test
+    public void checkJsonEndpoint() throws IOException {
+        final String page = page("web/sessions/0/" + System.currentTimeMillis()).getWebResponse().getContentAsString().replace(" ", "");
+        assertEquals("", page); // we don't deploy in this tests sessions gauges so we have nothing
+    }
+}