2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.helpserver.test;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.Enumeration;
28 import java.util.List;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.onap.ccsdk.features.sdnr.wt.helpserver.data.ExtactBundleResource;
32 import org.osgi.framework.Bundle;
34 public class TestExtract extends Mockito {
36 private boolean called = false;
37 private String testFile;
42 Bundle myBundle = mock(Bundle.class);
44 final ClassLoader loader = this.getClass().getClassLoader();
46 when(myBundle.getEntryPaths(anyString())).thenAnswer(invocation -> {
48 Object[] args = invocation.getArguments();
49 System.out.println("Get files from: " + args[0]);
50 Enumeration<URL> e = loader.getResources((String) args[0]);
51 List<String> res = new ArrayList<>();
52 while (e.hasMoreElements()) {
53 String resourceFileName = e.nextElement().toString();
54 System.out.println("is file: " + resourceFileName);
55 res.add(resourceFileName);
58 return Collections.enumeration(res);
63 when(myBundle.getEntry(anyString())).thenAnswer(invocation -> {
64 Object[] args = invocation.getArguments();
65 System.out.println("GetEntrye input: " + args[0]);
66 return new URL(testFile = (String) args[0]);
69 String TMPDATAFOLDER = "tmpData";
71 ExtactBundleResource.copyBundleResoucesRecursively(myBundle, TMPDATAFOLDER, "help/meta.json");
73 assertTrue("Test file not found: " + testFile, new File(TMPDATAFOLDER + testFile).exists());
75 ExtactBundleResource.deleteRecursively(new File(TMPDATAFOLDER + "file:"));
77 assertFalse("Test not deleted: " + testFile, new File(TMPDATAFOLDER + "file:").exists());
79 } catch (Exception e) {
81 fail("Exception" + e);