aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/mountpoint-state-provider/provider/src/test
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2020-08-18 15:30:11 +0200
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2020-08-18 16:05:02 +0200
commit6e164bc0f1f6688714033e95731942a89f5f1868 (patch)
tree45e1192ca4edd763bab0587da8652a3cba4af2e9 /sdnr/wt/mountpoint-state-provider/provider/src/test
parente0ba85f7ef526aaa270f8a6cd5baad8e32eb920e (diff)
Develop a VES Provider
Common VES provider will be used by devicemanager bundles and other bundles for sending VES messages Issue-ID: SDNC-1188 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> Change-Id: Ied23b82a528aac23d7bebab272a2f414e67d0866 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/mountpoint-state-provider/provider/src/test')
-rw-r--r--sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/GeneralConfigTest.java80
-rw-r--r--sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeConnectListenerImpl.java79
-rw-r--r--sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java56
-rw-r--r--sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java112
-rw-r--r--sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java150
5 files changed, 107 insertions, 370 deletions
diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/GeneralConfigTest.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/GeneralConfigTest.java
deleted file mode 100644
index c921e7bcb..000000000
--- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/GeneralConfigTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * ============LICENSE_START========================================================================
- * ONAP : ccsdk feature sdnr wt
- * =================================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
- * =================================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- * ============LICENSE_END==========================================================================
- */
-
-package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
-
-import static org.junit.Assert.assertEquals;
-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.Test;
-import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
-import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.GeneralConfig;
-
-public class GeneralConfigTest {
-
- // @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 = "test.properties";
- private ConfigurationFileRepresentation globalCfg;
-
- @Test
- public void test() throws IOException {
-
- Files.asCharSink(new File(fileName), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
- globalCfg = new ConfigurationFileRepresentation(fileName);
- GeneralConfig cfg = new GeneralConfig(globalCfg);
- assertEquals("onap-dmap:3904", cfg.getHostPort());
- assertEquals(false, cfg.getEnabled());
- assertEquals("unauthenticated.SDNR_MOUNTPOINT_STATE_INFO", cfg.getTopic());
- assertEquals("application/json", cfg.getContenttype());
- assertEquals("20000", cfg.getTimeout());
- assertEquals("10000", cfg.getLimit());
- assertEquals("100", cfg.getMaxBatchSize());
- assertEquals("250", cfg.getMaxAgeMs());
- assertEquals("50", cfg.getMessageSentThreadOccurrence());
- assertEquals("HTTPNOAUTH", cfg.getTransportType());
- assertEquals("general", cfg.getSectionName());
-
-
- }
-
- @After
- public void cleanUp() {
- File file = new File(fileName);
- if (file.exists()) {
- System.out.println("File exists, Deleting it");
- file.delete();
- }
-
- }
-}
diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeConnectListenerImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeConnectListenerImpl.java
index 2466683fd..237e94989 100644
--- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeConnectListenerImpl.java
+++ b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeConnectListenerImpl.java
@@ -18,19 +18,19 @@
package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import com.google.common.io.Files;
-import java.io.File;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.util.Optional;
-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.devicemanager.service.DeviceManagerServiceProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointNodeConnectListenerImpl;
-import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisherMain;
+import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisher;
import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfAccessorMock;
import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfNodeMock;
import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfNodeStateServiceMock;
@@ -40,39 +40,32 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
public class TestMountpointNodeConnectListenerImpl {
- // @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 = "test1.properties";
- private ConfigurationFileRepresentation globalCfg;
-
-
- NetconfNodeStateServiceMock netconfNodeStateServiceMock = new NetconfNodeStateServiceMock();
- MountpointNodeConnectListenerImpl nodeConnectListener =
- new MountpointNodeConnectListenerImpl(netconfNodeStateServiceMock);
- MountpointStatePublisherMain mountpointStatePublisher;
- NetconfNodeMock netconfNodeMock = new NetconfNodeMock();
- NetconfNode netconfNode = netconfNodeMock.getNetconfNode();
- NodeId nNodeId = new NodeId("nSky");
- NetconfAccessor accessor = new NetconfAccessorMock(nNodeId, netconfNode);
+ DeviceManagerServiceProvider serviceProvider;
+ MountpointStatePublisher mountpointStatePublisher;
+ NetconfNodeStateServiceMock netconfNodeStateServiceMock;
+ MountpointNodeConnectListenerImpl nodeConnectListener;
+ NetconfNodeMock netconfNodeMock;
+ NetconfNode netconfNode;
+ NodeId nNodeId;
+ NetconfAccessor accessor;
+ VESCollectorService vesCollectorService;
@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);
+ serviceProvider = mock(DeviceManagerServiceProvider.class);
+ netconfNodeStateServiceMock = new NetconfNodeStateServiceMock();
+ netconfNodeMock = new NetconfNodeMock();
+ netconfNode = netconfNodeMock.getNetconfNode();
+ vesCollectorService = mock(VESCollectorService.class);
+ NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class);
+ nNodeId = new NodeId("nSky");
+ accessor = new NetconfAccessorMock(nNodeId, netconfNode);
+
+ mountpointStatePublisher = new MountpointStatePublisher(vesCollectorService);
+ when(netconfNetworkElementService.getServiceProvider()).thenReturn(serviceProvider);
+ when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
+
+ nodeConnectListener = new MountpointNodeConnectListenerImpl(netconfNodeStateServiceMock);
nodeConnectListener.start(mountpointStatePublisher);
}
@@ -90,18 +83,8 @@ public class TestMountpointNodeConnectListenerImpl {
@Test
public void testClose() throws Exception {
- //assertEquals(MountpointStatePublisher.stateObjects.size(), 0);
+ assertEquals(mountpointStatePublisher.getStateObjects().size(), 0);
nodeConnectListener.close();
}
- @After
- public void after() {
- File file = new File(fileName);
- if (file.exists()) {
- System.out.println("File exists, Deleting it");
- file.delete();
- }
-
- }
-
}
diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java
index 8d95a4c53..c6a9d11e5 100644
--- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java
+++ b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java
@@ -21,17 +21,15 @@ 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 static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
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.devicemanager.service.DeviceManagerServiceProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointNodeStateListenerImpl;
-import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisherMain;
+import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisher;
import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfNodeMock;
import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test.mock.NetconfNodeStateServiceMock;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
@@ -39,37 +37,23 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
public class TestMountpointNodeStateListenerImpl {
- // @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;
+ MountpointStatePublisher mountpointStatePublisher;
NetconfNodeMock netconfNodeMock = new NetconfNodeMock();
NetconfNode netconfNode = netconfNodeMock.getNetconfNode();
NodeId nNodeId = new NodeId("nSky");
+ VESCollectorService vesCollectorService;
@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);
+ public void initialize() {
+ DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class);
+ vesCollectorService = mock(VESCollectorService.class);
+ NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class);
+ when(netconfNetworkElementService.getServiceProvider()).thenReturn(serviceProvider);
+ when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
+ mountpointStatePublisher = new MountpointStatePublisher(vesCollectorService);
nodeStateListener.start(mountpointStatePublisher);
}
@@ -92,14 +76,4 @@ 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();
- }
-
- }
-
}
diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java
index 19d930866..1cebeb697 100644
--- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java
+++ b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java
@@ -24,108 +24,46 @@
package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.FileNotFoundException;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStateProviderImpl;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestMountpointStateProviderImpl {
-
- private static Path KARAF_ETC = Paths.get("etc");
- private static MountpointStateProviderImpl mountpointStateProvider;
-
private static final Logger LOG = LoggerFactory.getLogger(TestMountpointStateProviderImpl.class);
+ private MountpointStateProviderImpl mountpointStateProvider;
-
- @BeforeClass
- public static void before() throws InterruptedException, IOException {
-
- System.out.println("Logger: " + LOG.getClass().getName() + " " + LOG.getName());
- // Call System property to get the classpath value
- Path etc = KARAF_ETC;
- delete(etc);
-
- System.out.println("Create empty:" + etc.toString());
- Files.createDirectories(etc);
-
- // Create mocks
-
- // start using blueprint interface
- try {
- mountpointStateProvider = new MountpointStateProviderImpl();
-
- //mountpointStateProvider.init(); // Can't be tested as this invokes a thread. Mockito doesn't help either
- } catch (Exception e) {
- StringWriter sw = new StringWriter();
- e.printStackTrace(new PrintWriter(sw));
- fail("Not initialized" + sw.toString());
- }
- System.out.println("Initialization status: " + mountpointStateProvider.isInitializationOk());
- System.out.println("Initialization done");
+ @Test
+ public void before() throws InterruptedException, IOException {
+ NetconfNodeStateService netconfNodeStateService = mock(NetconfNodeStateService.class);
+ DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class);
+ VESCollectorService vesCollectorService = mock(VESCollectorService.class);
+ NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class);
+
+ when(netconfNetworkElementService.getServiceProvider()).thenReturn(serviceProvider);
+ when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
+
+ mountpointStateProvider = new MountpointStateProviderImpl();
+ mountpointStateProvider.setNetconfNetworkElementService(netconfNetworkElementService);
+ mountpointStateProvider.setNetconfNodeStateService(netconfNodeStateService);
+ mountpointStateProvider.init();
}
- @AfterClass
- public static void after() throws InterruptedException, IOException {
+ /* @After
+ public void after() throws InterruptedException, IOException {
- System.out.println("Start shutdown");
- // close using blueprint interface
try {
- mountpointStateProvider.close();
+ mountpointStateProvider.close();
} catch (Exception e) {
System.out.println(e);
}
- delete(KARAF_ETC);
-
- }
-
- @Test
- public void test1() {
- System.out.println("Test1: slave mountpoint");
- System.out.println("Initialization status: " + mountpointStateProvider.isInitializationOk());
- System.out.println("Test2: Done");
- }
-
- // ********************* Private
-
- private static void delete(Path etc) throws IOException {
- if (Files.exists(etc)) {
- System.out.println("Found and remove:" + etc.toString());
- delete(etc.toFile());
- }
- }
-
- private static void delete(File f) throws IOException {
- if (f.isDirectory()) {
- for (File c : f.listFiles()) {
- delete(c);
- }
- }
- if (!f.delete()) {
- throw new FileNotFoundException("Failed to delete file: " + f);
- }
- }
- /* @Test
- public void testInit() {
-
- }
-
- @Test
- public void testOnConfigChanged() {
- //fail("Not yet implemented");
- }*/
-
+ }*/
}
diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java
index 5fc1c5e15..468e0c1ee 100644
--- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java
+++ b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java
@@ -24,136 +24,58 @@
package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
-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.MountpointStatePublisherMain;
-import org.onap.dmaap.mr.client.MRBatchingPublisher;
-import org.onap.dmaap.mr.client.response.MRPublisherResponse;
-import org.slf4j.Logger;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
+import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisher;
public class TestMountpointStatePublisher {
- private static final String CONFIGURATIONTESTFILE = "test3.properties";
- public Thread publisher;
- MountpointStatePublisherMain mountpointStatePublisher;
- ConfigurationFileRepresentation configFileRepresentation;
- GeneralConfig cfg;
+ MountpointStatePublisher mountpointStatePublisher;
+ VESCollectorService vesCollectorService;
+ VESCollectorCfgService vesCfg;
+ String vesMsg = "{}";
+ JSONObject testJsonData;
@Before
public void testMountpointStatePublisherData() {
- String testJsonData =
- "{\"NodeId\":\"69322972e178_50001\",\"NetConfNodeState\":\"Connecting\",\"TimeStamp\":\"2019-11-12T12:45:08.604Z\"}";
- configFileRepresentation =
- new ConfigurationFileRepresentation(CONFIGURATIONTESTFILE);
- cfg = new GeneralConfig(configFileRepresentation);
- JSONObject jsonObj = new JSONObject(testJsonData);
- mountpointStatePublisher = new MountpointStatePublisherMain(cfg);
- mountpointStatePublisher.getStateObjects().add(jsonObj);
+ testJsonData = new JSONObject();
+ testJsonData.put("NodeId", "69322972e178_50001");
+ testJsonData.put("NetConfNodeState", "Connecting");
+ testJsonData.put("TimeStamp", java.time.Clock.systemUTC().instant());
+
+
+ DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class);
+ vesCollectorService = mock(VESCollectorService.class);
+ vesCfg = mock(VESCollectorCfgService.class);
+ NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class);
+ when(netconfNetworkElementService.getServiceProvider()).thenReturn(serviceProvider);
+ when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
+ when(vesCollectorService.getConfig()).thenReturn(vesCfg);
+ when(vesCfg.getReportingEntityName()).thenReturn("ONAP SDN-R");
+ when(vesCollectorService.publishVESMessage(vesMsg)).thenReturn(true);
+
+ mountpointStatePublisher = new MountpointStatePublisher(vesCollectorService);
+ mountpointStatePublisher.addToPublish(testJsonData);
+ //mountpointStatePublisher.getStateObjects().add(testJsonData);
}
@Test
public void testMountpointStatePublisherConfiguration() throws InterruptedException {
- ConfigurationFileRepresentation configFileRepresentation =
- new ConfigurationFileRepresentation(CONFIGURATIONTESTFILE);
- GeneralConfig cfg = new GeneralConfig(configFileRepresentation);
-
- MountpointStatePublisherMain pub = new MountpointStatePublisherMock(cfg);
- pub.createPublisher(null);
- pub.publishMessage(pub.createPublisher(null), "Test DMaaP Message");
-
- }
-
- public class MountpointStatePublisherMock extends MountpointStatePublisherMain {
-
- public MountpointStatePublisherMock(Configuration config) {
- super(config);
- }
-
- @Override
- public MRBatchingPublisher createPublisher(Properties publisherProperties) {
-
- return new MRBatchingPublisher() {
-
- @Override
- public int send(String msg) throws IOException {
- System.out.println("Message to send - " + msg);
- return 0;
- }
-
- @Override
- public int send(String partition, String msg) throws IOException {
- return 0;
- }
-
- @Override
- public int send(message msg) throws IOException {
- return 0;
- }
-
- @Override
- public int send(Collection<message> msgs) throws IOException {
- return 0;
- }
-
- @Override
- public void close() {
-
- }
-
- @Override
- public void logTo(Logger log) {
-
- }
-
- @Override
- public void setApiCredentials(String apiKey, String apiSecret) {
-
- }
-
- @Override
- public void clearApiCredentials() {
-
- }
-
- @Override
- public int getPendingMessageCount() {
- return 0;
- }
-
- @Override
- public List<message> close(long timeout, TimeUnit timeoutUnits)
- throws IOException, InterruptedException {
- return null;
- }
-
- @Override
- public MRPublisherResponse sendBatchWithResponse() {
- return null;
- }
-
- };
- }
+ Thread t = new Thread(mountpointStatePublisher);
+ t.start();
+ Thread.sleep(7000);
}
@After
- public void after() {
- File file = new File(CONFIGURATIONTESTFILE);
- if (file.exists()) {
- System.out.println("File exists, Deleting it");
- file.delete();
- }
-
+ public void close() {
+ mountpointStatePublisher.stop();
}
-
}