Implement test cases for fabric discovery plugin
[ccsdk/sli/plugins.git] / fabric-discovery-plugin / provider / src / test / java / jtest / org / onap / ccsdk / sli / plugins / fabricdiscovery / TestFabricDiscoveryPlugin.java
1 package jtest.org.onap.ccsdk.sli.plugins.fabricdiscovery;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import org.junit.Assert;
6 import org.junit.Test;
7 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
8 import org.onap.ccsdk.sli.plugins.fabricdiscovery.FabricDiscoveryPlugin;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
12 /**
13  * Created by arun on 9/18/17.
14  */
15
16 public class TestFabricDiscoveryPlugin {
17     private static final Logger LOG = LoggerFactory.getLogger(TestFabricDiscoveryPlugin.class);
18     private static final String C_STREAM =
19         "ws://localhost:8185/data-change-event-subscription/network-topology:network-topology/datastore=CONFIGURATION/scope=BASE";
20     private static final String W_STREAM =
21         "get://localhost:8185/data-change-event-subscription/network-topology:network/datastore=CONFIGURATION/scope=BASE";
22     private final String FB_DISCOVERY_STATUS = "fb-response";
23
24     @Test
25     public void connectToNotificationServerSuccess() throws Exception {
26         SvcLogicContext ctx = new SvcLogicContext();
27         String stream = C_STREAM;
28
29         Map<String, String> p = new HashMap<String, String>();
30         p.put("stream", stream);
31         p.put("enable", "true");
32
33         FabricDiscoveryPlugin fdp = new FabricDiscoveryPlugin();
34         fdp.processDcNotificationStream(p, ctx);
35         Assert.assertEquals("Success", ctx.getAttribute(FB_DISCOVERY_STATUS));
36     }
37
38     @Test
39     public void connectToNotificationServerFailure() throws Exception {
40         SvcLogicContext ctx = new SvcLogicContext();
41         String stream = W_STREAM;
42
43         Map<String, String> p = new HashMap<>();
44         p.put("stream", stream);
45         p.put("enable", "true");
46
47         FabricDiscoveryPlugin fdp = new FabricDiscoveryPlugin();
48         try {
49             fdp.processDcNotificationStream(p, ctx);
50             LOG.info("Connection to Stream:{} succeeded.", stream);
51         } catch (Exception e) {
52             LOG.info("Received Exception while connecting to Fabric Discovery notification server: {}", e.getMessage());
53         } finally {
54             Assert.assertEquals("Failure", ctx.getAttribute(FB_DISCOVERY_STATUS));
55         }
56     }
57
58 }