Add test cases for 65% branch coverage
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / NodeConfigTest.java
index 5e35737..7971924 100644 (file)
@@ -22,6 +22,9 @@
  ******************************************************************************/
 package org.onap.dmaap.datarouter.node;
 
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.junit.Assert;
@@ -31,10 +34,6 @@ import org.junit.runner.RunWith;
 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-
 @RunWith(PowerMockRunner.class)
 @SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.ProvData",
         "org.onap.dmaap.datarouter.node.NodeUtils"})
@@ -43,11 +42,107 @@ public class NodeConfigTest {
     private static NodeConfig nodeConfig;
 
     @BeforeClass
-    public static void setUp() throws IOException{
+    public static void setUp() throws IOException {
         ProvData provData = setUpProvData();
         nodeConfig = new NodeConfig(provData, "Name", "spool/dir", 80, "Key");
     }
 
+    private static ProvData setUpProvData() throws IOException {
+        JSONObject provData = new JSONObject();
+        createValidFeed(provData);
+        createValidSubscription(provData);
+        createValidParameters(provData);
+        createValidIngressValues(provData);
+        createValidEgressValues(provData);
+        createValidRoutingValues(provData);
+        Reader reader = new StringReader(provData.toString());
+        return new ProvData(reader);
+    }
+
+    private static void createValidFeed(JSONObject provData) {
+        JSONArray feeds = new JSONArray();
+        JSONObject feed = new JSONObject();
+        JSONObject auth = new JSONObject();
+        JSONArray endpointIds = new JSONArray();
+        JSONArray endpointAddrs = new JSONArray();
+        JSONObject endpointId = new JSONObject();
+        feed.put("feedid", "1");
+        feed.put("name", "Feed1");
+        feed.put("version", "m1.0");
+        feed.put("suspend", false);
+        feed.put("deleted", false);
+        endpointId.put("id", "user1");
+        endpointId.put("password", "password1");
+        endpointIds.put(endpointId);
+        auth.put("endpoint_ids", endpointIds);
+        endpointAddrs.put("172.0.0.1");
+        auth.put("endpoint_addrs", endpointAddrs);
+        feed.put("authorization", auth);
+        feed.put("aaf_instance", "legacy");
+        feeds.put(feed);
+        provData.put("feeds", feeds);
+    }
+
+    private static void createValidSubscription(JSONObject provData) {
+        JSONArray subscriptions = new JSONArray();
+        JSONObject subscription = new JSONObject();
+        JSONObject delivery = new JSONObject();
+        subscription.put("subid", "1");
+        subscription.put("feedid", "1");
+        subscription.put("suspend", false);
+        subscription.put("metadataOnly", false);
+        delivery.put("url", "https://172.0.0.2");
+        delivery.put("user", "user1");
+        delivery.put("password", "password1");
+        delivery.put("use100", true);
+        subscription.put("delivery", delivery);
+        subscription.put("privilegedSubscriber", false);
+        subscription.put("follow_redirect", false);
+        subscription.put("decompress", false);
+        subscriptions.put(subscription);
+        provData.put("subscriptions", subscriptions);
+    }
+
+    private static void createValidParameters(JSONObject provData) {
+        JSONObject parameters = new JSONObject();
+        JSONArray nodes = new JSONArray();
+        parameters.put("PROV_NAME", "prov.datarouternew.com");
+        parameters.put("DELIVERY_INIT_RETRY_INTERVAL", "10");
+        parameters.put("DELIVERY_MAX_AGE", "86400");
+        parameters.put("PROV_DOMAIN", "");
+        nodes.put("172.0.0.4");
+        parameters.put("NODES", nodes);
+        provData.put("parameters", parameters);
+    }
+
+    private static void createValidIngressValues(JSONObject provData) {
+        JSONArray ingresses = new JSONArray();
+        JSONObject ingress = new JSONObject();
+        ingress.put("feedid", "1");
+        ingress.put("subnet", "");
+        ingress.put("user", "");
+        ingress.put("node", "172.0.0.4");
+        ingresses.put(ingress);
+        provData.put("ingress", ingresses);
+    }
+
+    private static void createValidEgressValues(JSONObject provData) {
+        JSONObject egress = new JSONObject();
+        egress.put("subid", "1");
+        egress.put("nodeid", "172.0.0.4");
+        provData.put("egress", egress);
+    }
+
+    private static void createValidRoutingValues(JSONObject provData) {
+        JSONArray routings = new JSONArray();
+        JSONObject routing = new JSONObject();
+        routing.put("from", "prov.datarouternew.com");
+        routing.put("to", "172.0.0.4");
+        routing.put("via", "172.100.0.1");
+        routings.put(routing);
+        provData.put("routing", routings);
+    }
+
     @Test
     public void Given_Feed_Does_Not_Exist_Then_Is_Publish_Permitted_Returns_Not_Null() {
         String permitted = nodeConfig.isPublishPermitted("2", "user", "0.0.0.0");
@@ -73,7 +168,7 @@ public class NodeConfigTest {
     }
 
     @Test
-    public void Given_SubId_Then_Get_Feed_Id_Returns_Correct_Id(){
+    public void Given_SubId_Then_Get_Feed_Id_Returns_Correct_Id() {
         String feedId = nodeConfig.getFeedId("1");
         Assert.assertEquals("1", feedId);
     }
@@ -164,100 +259,4 @@ public class NodeConfigTest {
         String auth = nodeConfig.getMyAuth();
         Assert.assertEquals("Basic TmFtZTp6Z04wMFkyS3gybFppbXltNy94ZDhuMkdEYjA9", auth);
     }
-
-    private static ProvData setUpProvData() throws IOException {
-        JSONObject provData = new JSONObject();
-        createValidFeed(provData);
-        createValidSubscription(provData);
-        createValidParameters(provData);
-        createValidIngressValues(provData);
-        createValidEgressValues(provData);
-        createValidRoutingValues(provData);
-        Reader reader = new StringReader(provData.toString());
-        return new ProvData(reader);
-    }
-
-    private static void createValidFeed(JSONObject provData) {
-        JSONArray feeds = new JSONArray();
-        JSONObject feed = new JSONObject();
-        JSONObject auth = new JSONObject();
-        JSONArray endpointIds = new JSONArray();
-        JSONArray endpointAddrs = new JSONArray();
-        JSONObject endpointId = new JSONObject();
-        feed.put("feedid", "1");
-        feed.put("name", "Feed1");
-        feed.put("version", "m1.0");
-        feed.put("suspend", false);
-        feed.put("deleted", false);
-        endpointId.put("id", "user1");
-        endpointId.put("password", "password1");
-        endpointIds.put(endpointId);
-        auth.put("endpoint_ids", endpointIds);
-        endpointAddrs.put("172.0.0.1");
-        auth.put("endpoint_addrs", endpointAddrs);
-        feed.put("authorization", auth);
-        feed.put("aaf_instance", "legacy");
-        feeds.put(feed);
-        provData.put("feeds", feeds);
-    }
-
-    private static void createValidSubscription(JSONObject provData) {
-        JSONArray subscriptions = new JSONArray();
-        JSONObject subscription = new JSONObject();
-        JSONObject delivery = new JSONObject();
-        subscription.put("subid", "1");
-        subscription.put("feedid", "1");
-        subscription.put("suspend", false);
-        subscription.put("metadataOnly", false);
-        delivery.put("url", "https://172.0.0.2");
-        delivery.put("user", "user1");
-        delivery.put("password", "password1");
-        delivery.put("use100", true);
-        subscription.put("delivery", delivery);
-        subscription.put("privilegedSubscriber", false);
-        subscription.put("follow_redirect", false);
-        subscription.put("decompress", false);
-        subscriptions.put(subscription);
-        provData.put("subscriptions", subscriptions);
-    }
-
-    private static void createValidParameters(JSONObject provData) {
-        JSONObject parameters = new JSONObject();
-        JSONArray nodes = new JSONArray();
-        parameters.put("PROV_NAME", "prov.datarouternew.com");
-        parameters.put("DELIVERY_INIT_RETRY_INTERVAL", "10");
-        parameters.put("DELIVERY_MAX_AGE", "86400");
-        parameters.put("PROV_DOMAIN", "");
-        nodes.put("172.0.0.4");
-        parameters.put("NODES", nodes);
-        provData.put("parameters", parameters);
-    }
-
-    private static void createValidIngressValues(JSONObject provData) {
-        JSONArray ingresses = new JSONArray();
-        JSONObject ingress = new JSONObject();
-        ingress.put("feedid", "1");
-        ingress.put("subnet", "");
-        ingress.put("user", "");
-        ingress.put("node", "172.0.0.4");
-        ingresses.put(ingress);
-        provData.put("ingress", ingresses);
-    }
-
-    private static void createValidEgressValues(JSONObject provData) {
-        JSONObject egress = new JSONObject();
-        egress.put("subid", "1");
-        egress.put("nodeid", "172.0.0.4");
-        provData.put("egress", egress);
-    }
-
-    private static void createValidRoutingValues(JSONObject provData) {
-        JSONArray routings = new JSONArray();
-        JSONObject routing = new JSONObject();
-        routing.put("from", "prov.datarouternew.com");
-        routing.put("to", "172.0.0.4");
-        routing.put("via", "172.100.0.1");
-        routings.put(routing);
-        provData.put("routing", routings);
-    }
 }