summaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'policy-endpoints/src/test')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java101
-rw-r--r--policy-endpoints/src/test/resources/webapps/alt-root/index.html28
-rw-r--r--policy-endpoints/src/test/resources/webapps/root/index.html28
3 files changed, 157 insertions, 0 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
index 0aec411b..e202b11b 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,12 +21,15 @@
package org.onap.policy.common.endpoints.http.server.test;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.google.gson.Gson;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
@@ -476,6 +480,103 @@ public class HttpServerTest {
assertTrue(HttpServletServerFactoryInstance.getServerFactory().inventory().isEmpty());
}
+ @Test
+ public void testSingleStaticResourceServer() throws Exception {
+ logger.info("-- testSingleStaticResourceServer() --");
+
+ HttpServletServer staticServer = HttpServletServerFactoryInstance.getServerFactory()
+ .buildStaticResourceServer("Static Resources Server", false, LOCALHOST, port, "/", true);
+ Throwable thrown = catchThrowable(() -> staticServer.addServletResource("/*", null));
+ assertThat(thrown).isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("No resourceBase provided");
+
+ staticServer.addServletResource(null,
+ HttpServerTest.class.getClassLoader().getResource("webapps/root").toExternalForm());
+
+ thrown = catchThrowable(() -> staticServer.addServletClass("/*", RestEchoService.class.getName()));
+ assertThat(thrown).isInstanceOf(UnsupportedOperationException.class)
+ .hasMessageContaining("is not supported on this type of jetty server");
+
+ thrown = catchThrowable(() -> staticServer.addServletPackage("/api/*", this.getClass().getPackage().getName()));
+ assertThat(thrown).isInstanceOf(UnsupportedOperationException.class)
+ .hasMessageContaining("is not supported on this type of jetty server");
+
+ thrown = catchThrowable(() -> staticServer.setSerializationProvider(MyGsonProvider.class.getName()));
+ assertThat(thrown).isInstanceOf(UnsupportedOperationException.class)
+ .hasMessageContaining("is not supported on this type of jetty server");
+
+ staticServer.waitedStart(5000);
+
+ assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive());
+ assertEquals(1, HttpServletServerFactoryInstance.getServerFactory().inventory().size());
+
+ String response = http(portUrl);
+ assertThat(response).contains("Test Jetty Static Resources Root");
+
+ HttpServletServerFactoryInstance.getServerFactory().destroy(port);
+ assertEquals(0, HttpServletServerFactoryInstance.getServerFactory().inventory().size());
+ }
+
+ @Test
+ public void testMultiStaticResourceServer() throws Exception {
+ logger.info("-- testMultiStaticResourceServer() --");
+
+ HttpServletServer staticResourceServer = HttpServletServerFactoryInstance.getServerFactory()
+ .buildStaticResourceServer("Static Resources Server", false, LOCALHOST, port, "/", true);
+ staticResourceServer.addServletResource("/root/*",
+ HttpServerTest.class.getClassLoader().getResource("webapps/root").toExternalForm());
+ staticResourceServer.addServletResource("/alt-root/*",
+ HttpServerTest.class.getClassLoader().getResource("webapps/alt-root").toExternalForm());
+ staticResourceServer.waitedStart(5000);
+
+ assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive());
+ assertEquals(1, HttpServletServerFactoryInstance.getServerFactory().inventory().size());
+
+ String response = http(portUrl + "/root/");
+ assertThat(response).contains("Test Jetty Static Resources Root");
+
+ response = http(portUrl + "/alt-root/");
+ assertThat(response).contains("Test Jetty Static Resources Alt-Root");
+
+ HttpServletServerFactoryInstance.getServerFactory().destroy(port);
+ assertEquals(0, HttpServletServerFactoryInstance.getServerFactory().inventory().size());
+ }
+
+ @Test
+ public void testMultiTypesServer() throws Exception {
+ logger.info("-- testMultiTypesServer() --");
+
+ HttpServletServer staticResourceServer = HttpServletServerFactoryInstance.getServerFactory()
+ .buildStaticResourceServer("Static Resources Server", false, LOCALHOST, port, "/", true);
+ staticResourceServer.addServletResource("/root/*",
+ HttpServerTest.class.getClassLoader().getResource("webapps/root").toExternalForm());
+ staticResourceServer.waitedStart(5000);
+
+ int port2 = port + 1;
+ HttpServletServer jerseyServer =
+ HttpServletServerFactoryInstance.getServerFactory().build("echo", LOCALHOST, port2, "/", false, true);
+ jerseyServer.addServletPackage("/api/*", this.getClass().getPackage().getName());
+
+ Throwable thrown = catchThrowable(() -> jerseyServer.addServletResource("/root/*",
+ HttpServerTest.class.getClassLoader().getResource("webapps/root").toExternalForm()));
+ assertThat(thrown).isInstanceOf(UnsupportedOperationException.class)
+ .hasMessageContaining("is not supported on this type of jetty server");
+
+ jerseyServer.waitedStart(5000);
+
+ assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive());
+ assertEquals(2, HttpServletServerFactoryInstance.getServerFactory().inventory().size());
+
+ String response = http(portUrl + "/root/");
+ assertThat(response).contains("Test Jetty Static Resources Root");
+
+ response = http(LOCALHOST_PREFIX + port2 + "/api" + JUNIT_ECHO_HELLO);
+ assertEquals(HELLO, response);
+
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ assertEquals(0, HttpServletServerFactoryInstance.getServerFactory().inventory().size());
+ }
+
/**
* performs an http request.
*
diff --git a/policy-endpoints/src/test/resources/webapps/alt-root/index.html b/policy-endpoints/src/test/resources/webapps/alt-root/index.html
new file mode 100644
index 00000000..0948cebd
--- /dev/null
+++ b/policy-endpoints/src/test/resources/webapps/alt-root/index.html
@@ -0,0 +1,28 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2020 Nordix Foundation.
+ ================================================================================
+ Licensed 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<html>
+ <head>
+ <title>Hello World</title>
+ </head>
+ <body>
+ <h4>Test Jetty Static Resources Alt-Root</h4>
+ </body>
+</html> \ No newline at end of file
diff --git a/policy-endpoints/src/test/resources/webapps/root/index.html b/policy-endpoints/src/test/resources/webapps/root/index.html
new file mode 100644
index 00000000..a7cc120b
--- /dev/null
+++ b/policy-endpoints/src/test/resources/webapps/root/index.html
@@ -0,0 +1,28 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2020 Nordix Foundation.
+ ================================================================================
+ Licensed 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<html>
+ <head>
+ <title>Hello World</title>
+ </head>
+ <body>
+ <h4>Test Jetty Static Resources Root</h4>
+ </body>
+</html> \ No newline at end of file