summaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test
diff options
context:
space:
mode:
authormmis <michael.morris@ericsson.com>2018-08-30 13:34:55 +0100
committermmis <michael.morris@ericsson.com>2018-08-30 13:39:26 +0100
commitef849e64bc904f729bace1fb2c43f8cf34de3dd5 (patch)
tree8879ae092ef1af626bce444fc486fa3076596a99 /policy-endpoints/src/test
parent5443573fe9f8a183f968aa63d08dc3543e73c305 (diff)
Add support for http PUT
Added support for http PUT for use by the policy forwarder in policy/distribution Issue-ID: POLICY-926 Change-Id: Ifa5c2e8be0582797936b95b772ad236f35c10f24 Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'policy-endpoints/src/test')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java98
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java17
2 files changed, 81 insertions, 34 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
index 1248744d..61525c33 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
@@ -21,13 +21,17 @@
package org.onap.policy.common.endpoints.http.server.test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.AfterClass;
@@ -51,7 +55,7 @@ public class HttpClientTest {
* Setup before class method.
*
* @throws InterruptedException can be interrupted
- * @throws IOException can have an IO exception
+ * @throws IOException can have an IO exception
*/
@BeforeClass
public static void setUp() throws InterruptedException, IOException {
@@ -76,21 +80,20 @@ public class HttpClientTest {
String keyStorePasswordSystemProperty =
System.getProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
if (keyStorePasswordSystemProperty != null) {
- savedValuesMap.put(
- JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME, keyStorePasswordSystemProperty);
+ savedValuesMap.put(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
+ keyStorePasswordSystemProperty);
}
String trustStoreSystemProperty = System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
if (trustStoreSystemProperty != null) {
- savedValuesMap
- .put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, trustStoreSystemProperty);
+ savedValuesMap.put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, trustStoreSystemProperty);
}
String trustStorePasswordSystemProperty =
System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
if (trustStorePasswordSystemProperty != null) {
- savedValuesMap
- .put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME, trustStorePasswordSystemProperty);
+ savedValuesMap.put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME,
+ trustStorePasswordSystemProperty);
}
System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, "src/test/resources/keystore-test");
@@ -158,14 +161,12 @@ public class HttpClientTest {
}
@Test
- public void testHttpNoAuthClient() throws Exception {
+ public void testHttpGetNoAuthClient() throws Exception {
logger.info("-- testHttpNoAuthClient() --");
final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpNoAuthClient")
- .useHttps(false)
- .allowSelfSignedCerts(false)
- .hostname("localhost")
- .port(6666).basePath("junit/echo").userName(null).password(null).managed(true).build());
+ .useHttps(false).allowSelfSignedCerts(false).hostname("localhost").port(6666).basePath("junit/echo")
+ .userName(null).password(null).managed(true).build());
final Response response = client.get("hello");
final String body = HttpClient.getBody(response, String.class);
@@ -174,18 +175,28 @@ public class HttpClientTest {
}
@Test
- public void testHttpAuthClient() throws Exception {
+ public void testHttpPutNoAuthClient() throws Exception {
+ logger.info("-- testHttpNoAuthClient() --");
+
+ final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpNoAuthClient")
+ .useHttps(false).allowSelfSignedCerts(false).hostname("localhost").port(6666).basePath("junit/echo")
+ .userName(null).password(null).managed(true).build());
+
+ Entity<MyEntity> entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON);
+ final Response response = client.put("hello", entity, Collections.emptyMap());
+ final String body = HttpClient.getBody(response, String.class);
+
+ assertTrue(response.getStatus() == 200);
+ assertTrue(body.equals("hello:{myParameter=myValue}"));
+ }
+
+ @Test
+ public void testHttpGetAuthClient() throws Exception {
logger.info("-- testHttpAuthClient() --");
final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpAuthClient")
- .useHttps(true)
- .allowSelfSignedCerts(true)
- .hostname("localhost")
- .port(6667)
- .basePath("junit/echo")
- .userName("x")
- .password("y")
- .managed(true).build());
+ .useHttps(true).allowSelfSignedCerts(true).hostname("localhost").port(6667).basePath("junit/echo")
+ .userName("x").password("y").managed(true).build());
final Response response = client.get("hello");
final String body = HttpClient.getBody(response, String.class);
@@ -195,20 +206,30 @@ public class HttpClientTest {
}
@Test
+ public void testHttpPutAuthClient() throws Exception {
+ logger.info("-- testHttpAuthClient() --");
+
+ final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpAuthClient")
+ .useHttps(true).allowSelfSignedCerts(true).hostname("localhost").port(6667).basePath("junit/echo")
+ .userName("x").password("y").managed(true).build());
+
+ Entity<MyEntity> entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON);
+ final Response response = client.put("hello", entity, Collections.emptyMap());
+ final String body = HttpClient.getBody(response, String.class);
+
+ assertTrue(response.getStatus() == 200);
+ assertTrue(body.equals("hello:{myParameter=myValue}"));
+ }
+
+ @Test
public void testHttpAuthClient401() throws Exception {
logger.info("-- testHttpAuthClient401() --");
final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpAuthClient401")
- .useHttps(true)
- .allowSelfSignedCerts(true)
- .hostname("localhost")
- .port(6667)
- .basePath("junit/echo")
- .userName(null)
- .password(null)
- .managed(true).build());
+ .useHttps(true).allowSelfSignedCerts(true).hostname("localhost").port(6667).basePath("junit/echo")
+ .userName(null).password(null).managed(true).build());
final Response response = client.get("hello");
- assertTrue(response.getStatus() == 401);
+ assertEquals(new Integer(response.getStatus()).toString(), response.getStatus(), 401);
}
@Test
@@ -298,5 +319,22 @@ public class HttpClientTest {
assertTrue(response2.getStatus() == 500);
}
+ class MyEntity {
+
+ private String myParameter;
+
+ public MyEntity(final String myParameter) {
+ this.myParameter = myParameter;
+ }
+
+ public void setMyParameter(final String myParameter) {
+ this.myParameter = myParameter;
+ }
+
+ public String getMyParameter() {
+ return myParameter;
+ }
+
+ }
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java
index fdb8770c..56ed8933 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java
@@ -22,12 +22,15 @@ package org.onap.policy.common.endpoints.http.server.test;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
+
import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+
@Api(value = "echo")
@Path("/junit/echo")
public class RestEchoService {
@@ -35,11 +38,17 @@ public class RestEchoService {
@GET
@Path("{word}")
@Produces(MediaType.TEXT_PLAIN)
- @ApiOperation(
- value = "echoes back whatever received"
- )
- public String echo(@PathParam("word") String word) {
+ @ApiOperation(value = "echoes back whatever received")
+ public String echo(@PathParam("word") String word) {
return word;
}
+ @PUT
+ @Path("{word}")
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(value = "echoes back whatever received")
+ public String echoPut(@PathParam("word") String word, Object entity) {
+ return word + ":" + entity.toString();
+ }
+
}