diff --git a/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/StatsTests.java b/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/StatsTests.java index 8403d15734c2..f839b7e8c856 100644 --- a/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/StatsTests.java +++ b/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/StatsTests.java @@ -13,37 +13,23 @@ package org.eclipse.jetty.tests.distribution; -import java.io.ByteArrayInputStream; import java.net.URI; import java.nio.file.Path; -import java.util.Map; import java.util.concurrent.TimeUnit; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import org.eclipse.jetty.client.ContentResponse; -import org.eclipse.jetty.http.HttpHeader; -import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.tests.testers.JettyHomeTester; import org.eclipse.jetty.tests.testers.Tester; import org.eclipse.jetty.toolchain.test.FS; -import org.eclipse.jetty.util.ajax.JSON; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.w3c.dom.Document; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; public class StatsTests extends AbstractJettyHomeTest { - @Disabled //TODO stats.mod broken @ParameterizedTest @ValueSource(strings = {"ee9", "ee10", "ee11"}) public void testStatsServlet(String env) throws Exception @@ -56,19 +42,19 @@ public void testStatsServlet(String env) throws Exception String[] args1 = { "--create-startd", "--approve-all-licenses", - "--add-modules=resources,server,http,stats," + toEnvironment("webapp", env) + "," + toEnvironment("deploy", env) + "--add-modules=resources,server,http,statistics," + toEnvironment("webapp", env) + "," + toEnvironment("deploy", env) }; try (JettyHomeTester.Run run1 = distribution.start(args1)) { assertTrue(run1.awaitFor(START_TIMEOUT, TimeUnit.SECONDS)); + run1.getLogs().forEach(System.err::println); assertEquals(0, run1.getExitValue()); + // Make a context Path webappsDir = distribution.getJettyBase().resolve("webapps"); FS.ensureDirExists(webappsDir.resolve("demo")); - FS.ensureDirExists(webappsDir.resolve("demo/WEB-INF")); - distribution.installBaseResource("stats-webapp-" + env + "/index.html", "webapps/demo/index.html"); - distribution.installBaseResource("stats-webapp-" + env + "/WEB-INF/web.xml", "webapps/demo/WEB-INF/web.xml"); + // TODO add some actual content to it int port = Tester.freePort(); String[] args2 = { @@ -83,87 +69,10 @@ public void testStatsServlet(String env) throws Exception ContentResponse response; URI serverBaseURI = URI.create("http://localhost:" + port); - response = client.GET(serverBaseURI.resolve("/demo/index.html")); + response = client.GET(serverBaseURI.resolve("/demo/")); assertEquals(HttpStatus.OK_200, response.getStatus()); - assertThat(response.getContentAsString(), containsString("

Stats Demo

")); - // --------------- - // Test XML accept - response = client.newRequest(serverBaseURI.resolve("/demo/stats")) - .method(HttpMethod.GET) - .headers((headers) -> headers.add(HttpHeader.ACCEPT, "text/xml")) - .send(); - assertEquals(HttpStatus.OK_200, response.getStatus()); - - assertThat("Response.contentType", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("text/xml")); - - // Parse it, make sure it's well formed. - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - docBuilderFactory.setValidating(false); - DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); - try (ByteArrayInputStream input = new ByteArrayInputStream(response.getContent())) - { - Document doc = docBuilder.parse(input); - assertNotNull(doc); - assertEquals("statistics", doc.getDocumentElement().getNodeName()); - } - - // --------------- - // Test JSON accept - response = client.newRequest(serverBaseURI.resolve("/demo/stats")) - .method(HttpMethod.GET) - .headers((headers) -> headers.add(HttpHeader.ACCEPT, "application/json")) - .send(); - assertEquals(HttpStatus.OK_200, response.getStatus()); - - assertThat("Response.contentType", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("application/json")); - - Object doc = new JSON().parse(new JSON.StringSource(response.getContentAsString())); - assertNotNull(doc); - assertThat(doc, instanceOf(Map.class)); - Map docMap = (Map)doc; - assertEquals(4, docMap.size()); - assertNotNull(docMap.get("requests")); - assertNotNull(docMap.get("responses")); - assertNotNull(docMap.get("connections")); - assertNotNull(docMap.get("memory")); - - // --------------- - // Test TEXT accept - response = client.newRequest(serverBaseURI.resolve("/demo/stats")) - .method(HttpMethod.GET) - .headers((headers) -> headers.add(HttpHeader.ACCEPT, "text/plain")) - .send(); - assertEquals(HttpStatus.OK_200, response.getStatus()); - - assertThat("Response.contentType", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("text/plain")); - - String textContent = response.getContentAsString(); - assertThat(textContent, containsString("requests: ")); - assertThat(textContent, containsString("responses: ")); - assertThat(textContent, containsString("connections: ")); - assertThat(textContent, containsString("memory: ")); - - // --------------- - // Test HTML accept - response = client.newRequest(serverBaseURI.resolve("/demo/stats")) - .method(HttpMethod.GET) - .headers((headers) -> headers.add(HttpHeader.ACCEPT, "text/html")) - .send(); - assertEquals(HttpStatus.OK_200, response.getStatus()); - - assertThat("Response.contentType", response.getHeaders().get(HttpHeader.CONTENT_TYPE), containsString("text/html")); - - String htmlContent = response.getContentAsString(); - // Look for things that indicate it's a well formed HTML output - assertThat(htmlContent, containsString("")); - assertThat(htmlContent, containsString("")); - assertThat(htmlContent, containsString("requests: ")); - assertThat(htmlContent, containsString("responses: ")); - assertThat(htmlContent, containsString("connections: ")); - assertThat(htmlContent, containsString("memory: ")); - assertThat(htmlContent, containsString("")); - assertThat(htmlContent, containsString("")); + // TODO test the StatisticsHandler somehow } } } diff --git a/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee10/WEB-INF/web.xml b/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee10/WEB-INF/web.xml deleted file mode 100644 index ddeb05e499bf..000000000000 --- a/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee10/WEB-INF/web.xml +++ /dev/null @@ -1,17 +0,0 @@ - - stats-demo - - Stats - org.eclipse.jetty.ee10.servlet.StatisticsServlet - 1 - - - - Stats - /stats - - \ No newline at end of file diff --git a/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee10/index.html b/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee10/index.html deleted file mode 100644 index d203fae78fac..000000000000 --- a/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee10/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - stats-demo - - -

Stats Demo

- - \ No newline at end of file diff --git a/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee9/WEB-INF/web.xml b/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee9/WEB-INF/web.xml deleted file mode 100644 index fa91af5f4779..000000000000 --- a/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee9/WEB-INF/web.xml +++ /dev/null @@ -1,17 +0,0 @@ - - stats-demo - - Stats - org.eclipse.jetty.ee9.servlet.StatisticsServlet - 1 - - - - Stats - /stats - - \ No newline at end of file diff --git a/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee9/index.html b/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee9/index.html deleted file mode 100644 index d203fae78fac..000000000000 --- a/tests/test-distribution/test-distribution-common/src/test/resources/stats-webapp-ee9/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - stats-demo - - -

Stats Demo

- - \ No newline at end of file