Update mountpoint-state-provider
[ccsdk/features.git] / sdnr / wt / mountpoint-state-provider / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / mountpointstateprovider / test / TestMountpointNodeStateListenerImpl.java
index 2ee93b0..8d95a4c 100644 (file)
@@ -21,36 +21,70 @@ package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
 
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
-
+import com.google.common.io.Files;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
+import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.GeneralConfig;
 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointNodeStateListenerImpl;
-import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisher;
+import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisherMain;
 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfNodeMock;
-import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.odlapi.DataBrokerMountpointMock;
-import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfNodeStateServiceMock;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 
 public class TestMountpointNodeStateListenerImpl {
 
-    MountpointNodeStateListenerImpl nodeStateListener = new MountpointNodeStateListenerImpl();
+    // @formatter:off
+    private static final String TESTCONFIG_CONTENT =
+            "[general]\n"
+            + "dmaapEnabled=false\n"
+            + "TransportType=HTTPNOAUTH\n"
+            + "host=onap-dmap:3904\n"
+            + "topic=unauthenticated.SDNR_MOUNTPOINT_STATE_INFO\n"
+            + "contenttype=application/json\n"
+            + "timeout=20000\n"
+            + "limit=10000\n"
+            + "maxBatchSize=100\n"
+            + "maxAgeMs=250\n"
+            + "MessageSentThreadOccurance=50\n";
+    // @formatter:on
+    private final String fileName = "test2.properties";
+    private ConfigurationFileRepresentation globalCfg;
+
+    NetconfNodeStateServiceMock netconfNodeStateServiceMock = new NetconfNodeStateServiceMock();
+    MountpointNodeStateListenerImpl nodeStateListener =
+            new MountpointNodeStateListenerImpl(netconfNodeStateServiceMock);
+    MountpointStatePublisherMain mountpointStatePublisher;
     NetconfNodeMock netconfNodeMock = new NetconfNodeMock();
     NetconfNode netconfNode = netconfNodeMock.getNetconfNode();
     NodeId nNodeId = new NodeId("nSky");
-    DataBroker netconfNodeDataBroker = new DataBrokerMountpointMock();
+
+    @Before
+    public void initialize() throws IOException {
+        Files.asCharSink(new File(fileName), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
+        globalCfg = new ConfigurationFileRepresentation(fileName);
+        GeneralConfig cfg = new GeneralConfig(globalCfg);
+        mountpointStatePublisher = new MountpointStatePublisherMain(cfg);
+        nodeStateListener.start(mountpointStatePublisher);
+    }
 
     @Test
     public void testOnCreated() {
         assertNotNull(nNodeId);
         assertNotNull(netconfNode);
         nodeStateListener.onCreated(nNodeId, netconfNode);
-        assertNotEquals(MountpointStatePublisher.stateObjects.size(), 0);
+        assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
     }
 
     @Test
     public void testOnStateChange() {
         nodeStateListener.onStateChange(nNodeId, netconfNode);
-        assertNotEquals(MountpointStatePublisher.stateObjects.size(), 0);
+        assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
     }
 
     @Test
@@ -58,4 +92,14 @@ public class TestMountpointNodeStateListenerImpl {
         nodeStateListener.onRemoved(nNodeId);
     }
 
+    @After
+    public void after() {
+        File file = new File(fileName);
+        if (file.exists()) {
+            System.out.println("File exists, Deleting it");
+            file.delete();
+        }
+
+    }
+
 }