2  * ============LICENSE_START=======================================================
 
   3  * ONAP : ccsdk features
 
   4  * ================================================================================
 
   5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
 
   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
 
  14  *     http://www.apache.org/licenses/LICENSE-2.0
 
  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=======================================================
 
  25 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
 
  27 import static org.junit.Assert.fail;
 
  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;
 
  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;
 
  45 public class TestMountpointStateProviderImpl {
 
  47     private static Path KARAF_ETC = Paths.get("etc");
 
  48     private static MountpointStateProviderImpl mountpointStateProvider;
 
  50     private static final Logger LOG = LoggerFactory.getLogger(TestMountpointStateProviderImpl.class);
 
  55     public static void before() throws InterruptedException, IOException {
 
  57         System.out.println("Logger: " + LOG.getClass().getName() + " " + LOG.getName());
 
  58         // Call System property to get the classpath value
 
  62         System.out.println("Create empty:" + etc.toString());
 
  63         Files.createDirectories(etc);
 
  67         // start using blueprint interface
 
  69             mountpointStateProvider = new MountpointStateProviderImpl();
 
  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());
 
  77         System.out.println("Initialization status: " + mountpointStateProvider.isInitializationOk());
 
  78         System.out.println("Initialization done");
 
  82     public static void after() throws InterruptedException, IOException {
 
  84         System.out.println("Start shutdown");
 
  85         // close using blueprint interface
 
  87             mountpointStateProvider.close();
 
  88         } catch (Exception e) {
 
  89             System.out.println(e);
 
  97         System.out.println("Test1: slave mountpoint");
 
  98         System.out.println("Initialization status: " + mountpointStateProvider.isInitializationOk());
 
  99         System.out.println("Test2: Done");
 
 102     // ********************* Private
 
 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());
 
 111     private static void delete(File f) throws IOException {
 
 112         if (f.isDirectory()) {
 
 113             for (File c : f.listFiles()) {
 
 118             throw new FileNotFoundException("Failed to delete file: " + f);
 
 122         public void testInit() {
 
 127         public void testOnConfigChanged() {
 
 128                 //fail("Not yet implemented");