diff options
author | Ram Koya <rk541m@att.com> | 2018-08-31 18:46:37 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-31 18:46:37 +0000 |
commit | a1cc0279360b09663c1b59fd0b89a1c2e081dfbd (patch) | |
tree | 512c7daf4c4f6b31cbccf272792b201340078a69 /datarouter-prov/src/test/java | |
parent | 4fe3669fbd63c06ab4d87ed371a49ab2ac9b066a (diff) | |
parent | cca365206063aef585f2bf549e6c051baf67fcf7 (diff) |
Merge "Add Tests to LOGJSONObjectTest"
Diffstat (limited to 'datarouter-prov/src/test/java')
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)); } |