******************************************************************************/
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;
import org.junit.BeforeClass;
import org.junit.Test;
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"})
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");
@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);
}
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);
- 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);
- 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);
- }
}