X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-node%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FNodeConfigTest.java;h=79719243841e3b38af9f708b027edc3c99cce8ef;hb=5a55b790e8afa3131fd5f894e5d1b1e036dc4cd1;hp=7dddd67a371f3ade5e39c7cac4decf6e26ee26f0;hpb=5775de7b0fc84a29511dc4a1a480c3ab32da2ade;p=dmaap%2Fdatarouter.git diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java index 7dddd67a..79719243 100644 --- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java +++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java @@ -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,22 +34,115 @@ 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"}) +@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.ProvData", + "org.onap.dmaap.datarouter.node.NodeUtils"}) 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"); @@ -134,13 +230,15 @@ public class NodeConfigTest { @Test public void Given_Same_Ip_Then_Is_Another_Node_Returns_False() { - Boolean isAnotherNode = nodeConfig.isAnotherNode("Basic MTcyLjAuMC40OmtCTmhkWVFvbzhXNUphZ2g4T1N4Zmp6Mzl1ND0=", "172.0.0.1"); + Boolean isAnotherNode = + nodeConfig.isAnotherNode("Basic MTcyLjAuMC40OmtCTmhkWVFvbzhXNUphZ2g4T1N4Zmp6Mzl1ND0=", "172.0.0.1"); Assert.assertFalse(isAnotherNode); } @Test public void Given_Different_Ip_Then_Is_Another_Node_Returns_True() { - Boolean isAnotherNode = nodeConfig.isAnotherNode("Basic MTcyLjAuMC40OmtCTmhkWVFvbzhXNUphZ2g4T1N4Zmp6Mzl1ND0=", "172.0.0.4"); + Boolean isAnotherNode = + nodeConfig.isAnotherNode("Basic MTcyLjAuMC40OmtCTmhkWVFvbzhXNUphZ2g4T1N4Zmp6Mzl1ND0=", "172.0.0.4"); Assert.assertTrue(isAnotherNode); } @@ -161,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); - } }