1 /*******************************************************************************
2 * ============LICENSE_START======================================================= ONAP : ccsdk
3 * feature sdnr wt ================================================================================
4 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
5 * ================================================================================ Licensed under
6 * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
7 * with the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License
12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing permissions and limitations under
14 * the License. ============LICENSE_END=========================================================
15 ******************************************************************************/
16 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.fail;
22 import java.io.FileNotFoundException;
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.io.StringWriter;
26 import java.nio.file.Files;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
30 import org.junit.After;
31 import org.junit.AfterClass;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MountpointRegistrarImpl;
36 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.ClusterSingletonServiceProviderMock;
37 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.DataBrokerNetconfMock;
38 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.MountPointServiceMock;
39 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.NotificationPublishServiceMock;
40 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.mock.odlapi.RpcProviderRegistryMock;
41 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
42 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
43 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
44 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 @SuppressWarnings("deprecation")
49 public class TestMountpointRegistrarImpl {
51 private static Path KARAF_ETC = Paths.get("etc");
52 private static MountpointRegistrarImpl mountpointRegistrar;
53 private static DataBrokerNetconfMock dataBrokerNetconf;
55 private static final Logger LOG = LoggerFactory.getLogger(TestMountpointRegistrarImpl.class);
60 public void before() throws InterruptedException, IOException {
62 System.out.println("Logger: " + LOG.getClass().getName() + " " + LOG.getName());
63 // Call System property to get the classpath value
67 System.out.println("Create empty:" + etc.toString());
68 Files.createDirectories(etc);
71 dataBrokerNetconf = new DataBrokerNetconfMock();
72 ClusterSingletonServiceProvider clusterSingletonService = new ClusterSingletonServiceProviderMock();
73 MountPointService mountPointService = new MountPointServiceMock(null);
74 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
75 RpcProviderRegistry rpcProviderRegistry = new RpcProviderRegistryMock();
77 // start using blueprint interface
79 mountpointRegistrar = new MountpointRegistrarImpl();
81 mountpointRegistrar.setDataBroker(dataBrokerNetconf);
82 mountpointRegistrar.setMountPointService(mountPointService);
83 mountpointRegistrar.setNotificationPublishService(notificationPublishService);
84 mountpointRegistrar.setRpcProviderRegistry(rpcProviderRegistry);
85 mountpointRegistrar.setClusterSingletonService(clusterSingletonService);
86 mountpointRegistrar.init();
87 } catch (Exception e) {
88 StringWriter sw = new StringWriter();
89 e.printStackTrace(new PrintWriter(sw));
90 fail("Not initialized" +sw.toString());
92 System.out.println("Initialization status: " + mountpointRegistrar.isInitializationOk());
93 System.out.println("Initialization done");
97 public void after() throws InterruptedException, IOException {
99 System.out.println("Start shutdown");
100 // close using blueprint interface
102 mountpointRegistrar.close();
103 } catch (Exception e) {
104 System.out.println(e);
111 public void test1() {
112 System.out.println("Test1: slave mountpoint");
113 assertNotNull(mountpointRegistrar);
114 System.out.println("Initialization status: " + mountpointRegistrar.isInitializationOk());
115 System.out.println("Test2: Done");
118 // ********************* Private
120 @SuppressWarnings("unused")
121 private static void sleep(int millis) {
123 Thread.sleep(millis);
124 } catch (InterruptedException e) {
125 LOG.warn(e.getMessage());
126 Thread.interrupted();
130 private static void delete(Path etc) throws IOException {
131 if (Files.exists(etc)) {
132 System.out.println("Found and remove:" + etc.toString());
133 delete(etc.toFile());
137 private static void delete(File f) throws IOException {
138 if (f.isDirectory()) {
139 for (File c : f.listFiles()) {
144 throw new FileNotFoundException("Failed to delete file: " + f);