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