summaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/test
diff options
context:
space:
mode:
authorKyle Stewart <kyle.stewart@ericsson.com>2018-08-31 15:13:42 +0100
committerKyle Stewart <kyle.stewart@ericsson.com>2018-08-31 16:42:50 +0100
commitcca365206063aef585f2bf549e6c051baf67fcf7 (patch)
tree4f5be2fdf3c1fe81828130ea0e20994a91453b77 /datarouter-prov/src/test
parente647d5737c2735262a9cee302eb82e83d19a27c1 (diff)
Add Tests to LOGJSONObjectTest
Change-Id: I3443adf93cc36920a5b87093337909172e49c59c Signed-off-by: Kyle Stewart <kyle.stewart@ericsson.com> Issue-ID: DMAAP-101
Diffstat (limited to 'datarouter-prov/src/test')
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java3
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java43
2 files changed, 39 insertions, 7 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java
index 34421f52..f1082ba3 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java
@@ -273,6 +273,7 @@ public class RouteServletTest extends DrServletTestBase
@Test
public void Given_Request_Is_HTTP_PUT_And_Is_Not_Authorized() throws Exception {
+ FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true);
routeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
}
@@ -291,8 +292,8 @@ public class RouteServletTest extends DrServletTestBase
@Test
public void Given_Request_Is_HTTP_POST_And_Is_Not_Authorized() throws Exception {
- routeServlet.doPost(request, response);
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true);
+ routeServlet.doPost(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
index 7cfe68f9..4dd1b471 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
@@ -26,6 +26,7 @@ package org.onap.dmaap.datarouter.provisioning.utils;
import java.io.CharArrayWriter;
import java.io.Writer;
import org.json.JSONArray;
+import org.json.JSONTokener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -49,6 +50,39 @@ public class LOGJSONObjectTest {
}
@Test
+ public void Construct_JSONObject_From_A_Subset_Of_Values_From_Another_JSONObject()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key1", "value1");
+ map.put("key2", "value2");
+ map.put("key3", "value3");
+ LOGJSONObject ljo= new LOGJSONObject(map);
+ String[] sA = {"key1", "key3"};
+ LOGJSONObject logJObject = new LOGJSONObject(ljo, sA);
+ assertThat(logJObject.toString(), is("{\"key1\":\"value1\",\"key3\":\"value3\"}"));
+ }
+
+ @Test
+ public void Construct_JSONObject_From_A_JSONTokener()
+ throws Exception {
+ JSONTokener x = new JSONTokener("{\"key1\":\"value1\",\"key3\":\"value3\"}");
+ LOGJSONObject logJObject = new LOGJSONObject(x);
+ assertThat(logJObject.toString(), is("{\"key1\":\"value1\",\"key3\":\"value3\"}"));
+ }
+
+ @Test
+ public void Construct_JSONObject_From_A_Bean_Object_And_Populate_From_Its_Getters_And_Setters()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key1", "value1");
+ map.put("key2", "value2");
+ map.put("key3", "value3");
+ Object bean = map;
+ LOGJSONObject logJObject = new LOGJSONObject(bean);
+ assertThat(logJObject.toString(), is("{\"empty\":false}"));
+ }
+
+ @Test
public void Given_Method_Is_Accumulate_And_Value_Is_Valid_Put_Value_Into_New_JSONArray()
throws Exception {
Map<String, Object> map = new HashMap<>();
@@ -171,14 +205,11 @@ public class LOGJSONObjectTest {
public void Given_Method_Is_getNames_And_Value_Is_A_LOGJSONObject_Return_StringArray()
throws Exception {
LOGJSONObject logJObj = new LOGJSONObject();
- logJObj.put("name", "stub_name");
+ logJObj.put("name1", "elyk");
String[] sArray = new String[logJObj.length()];
- sArray[0] = "name";
- Map<String, Object> map = new HashMap<>();
- map.put("key", sArray);
- LOGJSONObject logJObject = new LOGJSONObject(map);
+ sArray[0] = "name1";
+ LOGJSONObject logJObject = new LOGJSONObject();
- String s = "key";
assertThat(logJObject.getNames(logJObj), is(sArray));
}