summaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test/java/org
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-05-25 16:44:15 -0500
committerJorge Hernandez <jh1730@att.com>2017-05-25 16:44:15 -0500
commit881c32ec109f0fff6f5661940ad035c3dfc0c7d9 (patch)
tree79070ad7386cc9b62cf504ebf62ec8702792be4d /policy-endpoints/src/test/java/org
parentf354096969e91aa2b3dcdc52adcc2bde1b3b0b74 (diff)
[POLICY-16] generic introduction of swagger
On a per-server basis append /swagger.json or /swagger.yaml ie: HTTP GET :6969/swagger.json HTTP GET :9696/swagger.json Resulting specification can be used by swagger clients. Change-Id: I4b1a8b53d50b1528664150934b04e92447e4d4d7 Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'policy-endpoints/src/test/java/org')
-rw-r--r--policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java6
-rw-r--r--policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java44
-rw-r--r--policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java7
3 files changed, 47 insertions, 10 deletions
diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java
index 47774b1f..cd149f7a 100644
--- a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java
+++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java
@@ -38,7 +38,7 @@ public class HttpClientTest {
public void testHttpNoAuthClient() throws Exception {
System.out.println("-- testHttpNoAuthClient() --");
- HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", true);
+ HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true);
server.addServletPackage("/*", this.getClass().getPackage().getName());
server.waitedStart(5000);
@@ -59,7 +59,7 @@ public class HttpClientTest {
public void testHttpAuthClient() throws Exception {
System.out.println("-- testHttpAuthClient() --");
- HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", true);
+ HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true);
server.setBasicAuthentication("x", "y", null);
server.addServletPackage("/*", this.getClass().getPackage().getName());
server.waitedStart(5000);
@@ -81,7 +81,7 @@ public class HttpClientTest {
public void testHttpAuthClient401() throws Exception {
System.out.println("-- testHttpAuthClient401() --");
- HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", true);
+ HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true);
server.setBasicAuthentication("x", "y", null);
server.addServletPackage("/*", this.getClass().getPackage().getName());
server.waitedStart(5000);
diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java
index 94f29804..6a369814 100644
--- a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java
+++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java
@@ -31,7 +31,7 @@ import org.junit.Test;
import org.openecomp.policy.drools.http.server.HttpServletServer;
/**
- *
+ * HttpServletServer JUNIT tests
*/
public class HttpServerTest {
@@ -39,7 +39,7 @@ public class HttpServerTest {
public void testSingleServer() throws Exception {
System.out.println("-- testSingleServer() --");
- HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 5678, "/", true);
+ HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 5678, "/", false, true);
server.addServletPackage("/*", this.getClass().getPackage().getName());
server.waitedStart(5000);
@@ -50,6 +50,16 @@ public class HttpServerTest {
String response = response(url);
System.out.println("Received .. " + response);
assertTrue(response.equals(echo));
+
+ String responseSwagger = null;
+ try {
+ URL urlSwagger = new URL("http://localhost:5678/swagger.json" + echo);
+ responseSwagger = response(urlSwagger);
+ } catch(IOException ioe) {
+ // Expected
+ }
+
+ assertTrue(responseSwagger == null);
HttpServletServer.factory.destroy();
assertTrue(HttpServletServer.factory.inventory().size() == 0);
@@ -59,11 +69,11 @@ public class HttpServerTest {
public void testMultipleServers() throws Exception {
System.out.println("-- testMultipleServers() --");
- HttpServletServer server1 = HttpServletServer.factory.build("echo-1", "localhost", 5678, "/", true);
+ HttpServletServer server1 = HttpServletServer.factory.build("echo-1", "localhost", 5678, "/", true, true);
server1.addServletPackage("/*", this.getClass().getPackage().getName());
server1.waitedStart(5000);
- HttpServletServer server2 = HttpServletServer.factory.build("echo-2", "localhost", 5679, "/", true);
+ HttpServletServer server2 = HttpServletServer.factory.build("echo-2", "localhost", 5679, "/", false, true);
server2.addServletPackage("/*", this.getClass().getPackage().getName());
server2.waitedStart(5000);
@@ -77,11 +87,28 @@ public class HttpServerTest {
System.out.println("Received .. " + response1);
assertTrue(response1.equals(echo));
+ URL urlSwagger = new URL("http://localhost:5678/swagger.json");
+ String responseSwagger = response(urlSwagger);
+
+ System.out.println("Received .. " + responseSwagger);
+ assertTrue(responseSwagger != null);
+
URL url2 = new URL("http://localhost:5679/junit/echo/" + echo);
String response2 = response(url2);
System.out.println("Received .. " + response2);
assertTrue(response2.equals(echo));
+ String responseSwagger2 = null;
+ try {
+ URL urlSwagger2 = new URL("http://localhost:5679/swagger.json");
+ responseSwagger2 = response(urlSwagger2);
+ } catch(IOException ioe) {
+ // Expected
+ }
+
+ System.out.println("Received .. " + responseSwagger2);
+ assertTrue(responseSwagger2 == null);
+
HttpServletServer.factory.destroy();
assertTrue(HttpServletServer.factory.inventory().size() == 0);
}
@@ -92,7 +119,7 @@ public class HttpServerTest {
String randomName = UUID.randomUUID().toString();
- HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", true);
+ HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", false, true);
server.addServletPackage("/*", this.getClass().getPackage().getName());
server.waitedStart(5000);
@@ -118,7 +145,7 @@ public class HttpServerTest {
System.out.println("-- testServiceClass() --");
String randomName = UUID.randomUUID().toString();
- HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", true);
+ HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", false, true);
server.addServletClass("/*", RestEchoService.class.getCanonicalName());
server.waitedStart(5000);
@@ -140,7 +167,7 @@ public class HttpServerTest {
String randomName = UUID.randomUUID().toString();
- HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", true);
+ HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5678, "/", false, true);
server.addServletClass("/*", RestEchoService.class.getCanonicalName());
server.addServletClass("/*", RestEndpoints.class.getCanonicalName());
server.waitedStart(5000);
@@ -173,6 +200,9 @@ public class HttpServerTest {
while ((line = ioReader.readLine()) != null) {
response += line;
}
+
+ System.out.println("R is " + response);
+ ioReader.close();
return response;
}
diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java
index a0320a09..b714925f 100644
--- a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java
+++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/RestEchoService.java
@@ -6,12 +6,19 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+@Api(value="echo")
@Path("/junit/echo")
public class RestEchoService {
@GET
@Path("{word}")
@Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(
+ value="echoes back whatever received"
+ )
public String echo(@PathParam("word") String word) {
return word;
}