1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk feature sdnr wt
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 ******************************************************************************/
21 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
26 import java.io.FileNotFoundException;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerService.Action;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.DataBrokerNetconfMock;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.MountPointMock;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.MountPointServiceMock;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.NotificationPublishServiceMock;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.RpcProviderRegistryMock;
41 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
42 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
43 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
44 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
46 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
48 public class Test1dm {
50 private static int DATABASETIMEOUTSECONDS = 30;
52 private static Path KARAF_ETC = Paths.get("etc");
53 private static DeviceManagerImpl deviceManager;
54 private static MountPointMock mountPoint;
58 public static void before() throws InterruptedException, IOException {
60 // Call System property to get the classpath value
63 System.out.println("Create empty:"+etc.toString());
64 Files.createDirectories(etc);
67 DataBroker dataBroker = new DataBrokerNetconfMock();
68 MountPointService mountPointService = new MountPointServiceMock(mountPoint = new MountPointMock());
69 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
70 RpcProviderRegistry rpcProviderRegistry = new RpcProviderRegistryMock();
72 //start using blueprint interface
73 deviceManager = new DeviceManagerImpl();
75 deviceManager.setDataBroker(dataBroker);
76 deviceManager.setMountPointService(mountPointService);
77 deviceManager.setNotificationPublishService(notificationPublishService);
78 deviceManager.setRpcProviderRegistry(rpcProviderRegistry);
82 } catch (Exception e) {
85 System.out.println("Initialization status: "+deviceManager.isDevicemanagerInitializationOk());
86 assertTrue("Devicemanager not initialized", deviceManager.isDevicemanagerInitializationOk());
87 System.out.println("Initialization done");
91 public static void after() throws InterruptedException, IOException {
93 System.out.println("Start shutdown");
94 //close using blueprint interface
96 deviceManager.close();
97 } catch (Exception e) {
98 System.out.println(e);
105 public void test1() throws InterruptedException {
107 System.out.println("Test1: Wait for database");
108 int timeout = DATABASETIMEOUTSECONDS;
109 while ( !deviceManager.isDatabaseInitializationFinished() && timeout-- > 0) {
110 System.out.println("Test1: "+timeout);
111 Thread.sleep(1000); //On second
113 System.out.println("Test1: database initialized");
117 public void test2() {
118 System.out.println("Test2: slave mountpoint");
120 mountPoint.setDatabrokerAbsent(true);
121 NodeId nodeId = new NodeId("mountpointTest1");
122 NetconfNodeBuilder nNodeBuilder = new NetconfNodeBuilder();
124 System.out.println("Call devicemanager");
126 deviceManager.startListenerOnNodeForConnectedState(Action.ADD, nodeId, nNodeBuilder.build());
127 } catch (Exception e) {
129 fail("Exception received.");
131 System.out.println("Test2: Done");
136 public void test3() {
137 System.out.println("Test3: master mountpoint");
139 mountPoint.setDatabrokerAbsent(false);
140 NodeId nodeId = new NodeId("mountpointTest2");
141 NetconfNodeBuilder nNodeBuilder = new NetconfNodeBuilder();
143 System.out.println("Call devicemanager");
146 deviceManager.startListenerOnNodeForConnectedState(Action.ADD, nodeId, nNodeBuilder.build());
147 } catch (Exception e) {
149 fail("Exception received.");
151 System.out.println("Test3: Done");
155 //********************* Private
157 private static void delete(Path etc) throws IOException {
158 if (Files.exists(etc)) {
159 System.out.println("Found and remove:"+etc.toString());
160 delete(etc.toFile());
164 private static void delete(File f) throws IOException {
165 if (f.isDirectory()) {
166 for (File c : f.listFiles()) {
171 throw new FileNotFoundException("Failed to delete file: " + f);