Removing blueprints-processor
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / test / TestDeviceManagerWithDatabase.java
index 435e8e1..d9561e4 100644 (file)
@@ -17,6 +17,7 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.test;
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -25,53 +26,57 @@ import java.io.StringWriter;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.util.Scanner;
-import java.util.concurrent.TimeUnit;
-import org.json.JSONException;
-import org.json.JSONObject;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.common.ResourcesFromDeviceManager;
+import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
+import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
+import org.onap.ccsdk.features.sdnr.wt.database.config.EsConfig;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseWebAPIClient;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.Resources;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerService.Action;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.NetconfNodeService.Action;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.ClusterSingletonServiceProviderMock;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.DataBrokerNetconfMock;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.DataProviderMock;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.MountPointMock;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.MountPointServiceMock;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.NotificationPublishServiceMock;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.RpcProviderRegistryMock;
-import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.DBCleanServiceHelper;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.ReadOnlyTransactionMountpoint1211Mock;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.ReadOnlyTransactionMountpoint1211pMock;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.ReadOnlyTransactionMountpoint12Mock;
-import org.opendaylight.controller.md.sal.binding.api.MountPointService;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
+import org.opendaylight.mdsal.binding.api.MountPointService;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 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;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@SuppressWarnings("deprecation")
 public class TestDeviceManagerWithDatabase {
 
-    private static int DATABASETIMEOUTSECONDS = 30;
-
     private static Path KARAF_ETC = Paths.get("etc");
     private static DeviceManagerImpl deviceManager;
     private static MountPointMock mountPoint;
     private static DataBrokerNetconfMock dataBrokerNetconf;
+    private static IEntityDataProvider dataProvider = new IEntityDataProvider() {
 
-    private static final Logger LOG = LoggerFactory.getLogger(TestDeviceManagerWithDatabase.class);
+        @Override
+        public void setReadyStatus(boolean status) {
 
+        }
 
+        @Override
+        public DataProvider getDataProvider() {
+            return  new DataProviderMock();
+        }
+    };
+    private static final Logger LOG = LoggerFactory.getLogger(TestDeviceManagerWithDatabase.class);
 
     @BeforeClass
     public static void before() throws InterruptedException, IOException {
@@ -83,7 +88,12 @@ public class TestDeviceManagerWithDatabase {
 
         System.out.println("Create empty:" + etc.toString());
         Files.createDirectories(etc);
+        //write db config for testing
+        ConfigurationFileRepresentation configfile = new ConfigurationFileRepresentation(etc.resolve("devicemanager.properties").toFile());
+        EsConfig dbConfig = new EsConfig(configfile);
+           dbConfig.setHosts(new HostInfo[] {new HostInfo("localhost",Integer.valueOf(System.getProperty("databaseport")!=null?System.getProperty("databaseport"):"49200")) });
 
+        configfile.save();
         // Create mocks
         ReadOnlyTransactionMountpoint12Mock readOnlyTransaction = new ReadOnlyTransactionMountpoint12Mock();
         dataBrokerNetconf = new DataBrokerNetconfMock();
@@ -91,9 +101,9 @@ public class TestDeviceManagerWithDatabase {
         mountPoint = new MountPointMock();
         mountPoint.setReadOnlyTransaction(readOnlyTransaction);
         ClusterSingletonServiceProvider clusterSingletonService = new ClusterSingletonServiceProviderMock();
-               MountPointService mountPointService = new MountPointServiceMock(mountPoint);
+        MountPointService mountPointService = new MountPointServiceMock(mountPoint);
         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
-        RpcProviderRegistry rpcProviderRegistry = new RpcProviderRegistryMock();
+        RpcProviderService rpcProviderRegistry = new RpcProviderRegistryMock();
 
         // start using blueprint interface
         String msg = "";
@@ -105,6 +115,7 @@ public class TestDeviceManagerWithDatabase {
             deviceManager.setNotificationPublishService(notificationPublishService);
             deviceManager.setRpcProviderRegistry(rpcProviderRegistry);
             deviceManager.setClusterSingletonService(clusterSingletonService);
+            deviceManager.setEntityDataProvider(dataProvider);
             deviceManager.init();
         } catch (Exception e) {
             StringWriter sw = new StringWriter();
@@ -134,18 +145,6 @@ public class TestDeviceManagerWithDatabase {
 
     }
 
-    @Test
-    public void test0() throws InterruptedException {
-        HtDatabaseWebAPIClient client = new HtDatabaseWebAPIClient();
-        try {
-            String response = client.sendRequest("/mwtn/mediator-server/_search", "GET",
-                    new JSONObject("{\"match\":{\"id\":id}}"));
-            System.out.println(response);
-        } catch (JSONException | IOException e) {
-            e.printStackTrace();
-        }
-    }
-
     @Test
     public void test2() {
         System.out.println("Test2: slave mountpoint");
@@ -190,7 +189,7 @@ public class TestDeviceManagerWithDatabase {
             e.printStackTrace();
             fail("Exception received.");
         }
-
+        System.out.println("Devicemanager started ----");
         readOnlyTransaction.sendProblemNotification();
         try {
             Thread.sleep(500);
@@ -274,7 +273,7 @@ public class TestDeviceManagerWithDatabase {
 
         System.out.println("Test6: Write zip data file file");
         File testFile = new File("etc/elasticsearch_update.zip");
-        Resources.extractFileTo("elasticsearch_update.zip", testFile);
+        ResourcesFromDeviceManager.extractFileTo("elasticsearch_update.zip", testFile);
         int wait = 130;
         while (testFile.exists() && wait-- > 0) {
             System.out.println("Waiting " + wait);
@@ -290,6 +289,7 @@ public class TestDeviceManagerWithDatabase {
 
     }
 
+    /*
     @Test
     public void test7() throws Exception {
         final int NUM = 5;
@@ -310,7 +310,7 @@ public class TestDeviceManagerWithDatabase {
         System.out.println("Status of elements is: "+service.countOldEntries());
 
         // create old data and check if the will be cleaned completely
-        int elements = helper.writeDataToLogs(NUM, ARCHIVE_DAYS+5, 0 /*Hours*/);
+        int elements = helper.writeDataToLogs(NUM, ARCHIVE_DAYS+5, 0 ); //Hours
         System.out.println("Written elements are: "+elements);
 
         waitForDeletion(service, 2 * ARCHIVE_INTERVAL_SEC, elements, "Entries are not cleared completely as expected");
@@ -327,9 +327,10 @@ public class TestDeviceManagerWithDatabase {
 
         service.close();
     }
-
+*/
     // ********************* Private
 
+    @SuppressWarnings("unused")
     private void waitForDeletion(ArchiveCleanService service, long timeout, long numberAtBeginning, String faultMessage) {
         int numberEntries = 0;
         while (timeout-- > 0) {
@@ -347,7 +348,7 @@ public class TestDeviceManagerWithDatabase {
 
 
     private static void waitfordatabase() throws InterruptedException {
-
+/*
         System.out.println("Test1: Wait for database");
         int timeout = DATABASETIMEOUTSECONDS;
         while (!deviceManager.isDatabaseInitializationFinished() && timeout-- > 0) {
@@ -355,6 +356,7 @@ public class TestDeviceManagerWithDatabase {
             Thread.sleep(1000); // On second
         }
         System.out.println("Ddatabase initialized");
+*/
     }
 
     private static void sleep(int millis) {
@@ -366,13 +368,6 @@ public class TestDeviceManagerWithDatabase {
         }
     }
 
-    private static void waitEnter() {
-        Scanner sc = new Scanner(System.in);
-        System.out.println("Enter");
-        sc.next();
-        sc.close();
-    }
-
     private static void delete(Path etc) throws IOException {
         if (Files.exists(etc)) {
             System.out.println("Found and remove:" + etc.toString());
@@ -391,6 +386,7 @@ public class TestDeviceManagerWithDatabase {
         }
     }
 
+    @SuppressWarnings("unused")
     private String getContent(long archiveLimitSeconds, long esArchiveCheckIntervalSeconds) {
         return "[dcae]\n" + "dcaeUserCredentials=admin:admin\n" + "dcaeUrl=http://localhost:45/abc\n"
                 + "dcaeHeartbeatPeriodSeconds=120\n" + "dcaeTestCollector=no\n" + "\n" + "[aots]\n"