efcd86582c15054f27a98948e32d5d29fa225741
[ccsdk/features.git] /
1 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
2 /*******************************************************************************
3  * ============LICENSE_START========================================================================
4  * ONAP : ccsdk feature sdnr wt
5  * =================================================================================================
6  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
7  * =================================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software distributed under the License
14  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15  * or implied. See the License for the specific language governing permissions and limitations under
16  * the License.
17  * ============LICENSE_END==========================================================================
18  ******************************************************************************/
19
20 import static org.junit.Assert.fail;
21
22 import java.io.File;
23 import java.io.FileNotFoundException;
24 import java.io.IOException;
25 import java.io.PrintWriter;
26 import java.io.StringWriter;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStateProviderImpl;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 public class TestMountpointStateProviderImpl {
39
40         private static Path KARAF_ETC = Paths.get("etc");
41         private static MountpointStateProviderImpl mountpointStateProvider;
42
43         private static final Logger LOG = LoggerFactory.getLogger(TestMountpointStateProviderImpl.class);
44
45
46
47         @BeforeClass
48         public static void before() throws InterruptedException, IOException {
49
50                 System.out.println("Logger: " + LOG.getClass().getName() + " " + LOG.getName());
51                 // Call System property to get the classpath value
52                 Path etc = KARAF_ETC;
53                 delete(etc);
54
55                 System.out.println("Create empty:" + etc.toString());
56                 Files.createDirectories(etc);
57
58                 // Create mocks
59
60                 // start using blueprint interface
61                 try {
62                         mountpointStateProvider = new MountpointStateProviderImpl();
63
64                         //mountpointStateProvider.init(); // Can't be tested as this invokes a thread. Mockito doesn't help either
65                 } catch (Exception e) {
66                         StringWriter sw = new StringWriter();
67                         e.printStackTrace(new PrintWriter(sw));
68                         fail("Not initialized" +sw.toString());
69                 }
70                 System.out.println("Initialization status: " + mountpointStateProvider.isInitializationOk());
71                 System.out.println("Initialization done");
72         }
73
74         @AfterClass
75         public static void after() throws InterruptedException, IOException {
76
77                 System.out.println("Start shutdown");
78                 // close using blueprint interface
79                 try {
80                         mountpointStateProvider.close();
81                 } catch (Exception e) {
82                         System.out.println(e);
83                 }
84                 delete(KARAF_ETC);
85
86         }
87
88          @Test
89         public void test1() {
90                 System.out.println("Test1: slave mountpoint");
91                 System.out.println("Initialization status: " + mountpointStateProvider.isInitializationOk());
92                 System.out.println("Test2: Done");
93         }
94
95         // ********************* Private
96
97         private static void delete(Path etc) throws IOException {
98                 if (Files.exists(etc)) {
99                         System.out.println("Found and remove:" + etc.toString());
100                         delete(etc.toFile());
101                 }
102         }
103
104         private static void delete(File f) throws IOException {
105                 if (f.isDirectory()) {
106                         for (File c : f.listFiles()) {
107                                 delete(c);
108                         }
109                 }
110                 if (!f.delete()) {
111                         throw new FileNotFoundException("Failed to delete file: " + f);
112                 }
113         }
114 /*      @Test
115         public void testInit() {
116
117         }
118
119         @Test
120         public void testOnConfigChanged() {
121                 //fail("Not yet implemented");
122         }*/
123
124 }