summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/helpserver/provider/src/test
diff options
context:
space:
mode:
authorHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-02-28 18:15:10 +0100
committerHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-02-28 18:15:40 +0100
commitaf992dbf68c75093d56b12f99ca410ce06fd7ad5 (patch)
tree16a96f642f3f6841be8904d6c77fc86e74ed5565 /sdnr/wt/helpserver/provider/src/test
parent49b155ec687cdf58fb51fe8245a2f5f4582b68f0 (diff)
SDN-R helpserver show version info
SDN-R helpserver show version info Change-Id: Ifa9d5a8c914f942151594c583c31184eef6f3296 Issue-ID: SDNC-681 Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/helpserver/provider/src/test')
-rw-r--r--sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestExtract.java88
-rw-r--r--sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpInfObject.java69
-rw-r--r--sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpInfrastructure.java (renamed from sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpServer.java)28
-rw-r--r--sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestMyServlet.java161
-rw-r--r--sdnr/wt/helpserver/provider/src/test/resources/log4j.properties12
-rw-r--r--sdnr/wt/helpserver/provider/src/test/resources/simplelogger.properties37
6 files changed, 375 insertions, 20 deletions
diff --git a/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestExtract.java b/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestExtract.java
new file mode 100644
index 000000000..5f8558270
--- /dev/null
+++ b/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestExtract.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
+ * =================================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ * ============LICENSE_END==========================================================================
+ ******************************************************************************/
+package org.onap.ccsdk.features.sdnr.wt.helpserver.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.features.sdnr.wt.helpserver.data.ExtactBundleResource;
+import org.osgi.framework.Bundle;
+
+public class TestExtract extends Mockito {
+
+ private boolean called = false;
+ private String testFile;
+
+ @Test
+ public void test() {
+
+ Bundle myBundle = mock(Bundle.class);
+
+ final ClassLoader loader = this.getClass().getClassLoader();
+ try {
+ when(myBundle.getEntryPaths(anyString())).thenAnswer(invocation -> {
+ if (!called) {
+ Object[] args = invocation.getArguments();
+ System.out.println("Get files from: " + args[0]);
+ Enumeration<URL> e = loader.getResources((String) args[0]);
+ List<String> res = new ArrayList<>();
+ while (e.hasMoreElements()) {
+ String resourceFileName = e.nextElement().toString();
+ System.out.println("is file: " + resourceFileName);
+ res.add(resourceFileName);
+ }
+ called = true;
+ return Collections.enumeration(res);
+ } else {
+ return null;
+ }
+ });
+ when(myBundle.getEntry(anyString())).thenAnswer(invocation -> {
+ Object[] args = invocation.getArguments();
+ System.out.println("GetEntrye input: "+args[0]);
+ return new URL(testFile = (String) args[0]);
+ });
+
+ String TMPDATAFOLDER = "tmpData";
+
+ ExtactBundleResource.copyBundleResoucesRecursively(myBundle, TMPDATAFOLDER, "help/meta.json");
+
+ assertTrue("Test file not found: "+testFile, new File(TMPDATAFOLDER+testFile).exists());
+
+ ExtactBundleResource.deleteRecursively(new File(TMPDATAFOLDER+"file:"));
+
+ assertFalse("Test not deleted: "+testFile, new File(TMPDATAFOLDER+"file:").exists());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception" + e);
+ }
+
+
+
+ }
+
+}
diff --git a/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpInfObject.java b/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpInfObject.java
new file mode 100644
index 000000000..9d63da500
--- /dev/null
+++ b/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpInfObject.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
+ * =================================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ * ============LICENSE_END==========================================================================
+ ******************************************************************************/
+package org.onap.ccsdk.features.sdnr.wt.helpserver.test;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.helpserver.data.ExtactBundleResource;
+import org.onap.ccsdk.features.sdnr.wt.helpserver.data.HelpInfrastructureObject;
+
+public class TestHelpInfObject {
+
+ private static final String GETHELPDIRECTORYBASE = "data";
+ private static final String ROOT = "tmp";
+ private static final String CONTENT = "abc";
+
+ @Before
+ public void init() {
+ try {
+ ExtactBundleResource.deleteRecursively(new File(GETHELPDIRECTORYBASE));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ @After
+ public void deinit() {
+ this.init();
+ }
+ @Test
+ public void test() {
+ File root=new File(HelpInfrastructureObject.getHelpDirectoryBase()+"/"+ROOT);
+ TestMyServlet.createHelpFile("/"+ROOT+"/test/0.4.0/README.md", CONTENT);
+ TestMyServlet.createHelpFile("/"+ROOT+"/test2/0.4.0/README.md", CONTENT);
+ TestMyServlet.createHelpFile("/"+ROOT+"/test3/abc/0.4.0/README.md", CONTENT);
+ TestMyServlet.createHelpFile("/"+ROOT+"/test3/abc1/0.4.0/README.md", CONTENT);
+ TestMyServlet.createHelpFile("/"+ROOT+"/test5/0.4.0/README.md", CONTENT);
+
+ try {
+ new HelpInfrastructureObject(root.toPath());
+ } catch (URISyntaxException e) {
+ fail(e.getMessage());
+ }
+
+
+ }
+
+
+}
diff --git a/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpServer.java b/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpInfrastructure.java
index db6d783b9..dfe649a87 100644
--- a/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpServer.java
+++ b/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestHelpInfrastructure.java
@@ -1,4 +1,3 @@
-package org.onap.ccsdk.features.sdnr.wt.helpserver.test;
/*******************************************************************************
* ============LICENSE_START========================================================================
* ONAP : ccsdk feature sdnr wt
@@ -16,20 +15,33 @@ package org.onap.ccsdk.features.sdnr.wt.helpserver.test;
* the License.
* ============LICENSE_END==========================================================================
******************************************************************************/
-import static org.junit.Assert.assertNotNull;
+package org.onap.ccsdk.features.sdnr.wt.helpserver.test;
+
+import static org.junit.Assert.fail;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.helpserver.HelpServlet;
+import org.onap.ccsdk.features.sdnr.wt.helpserver.data.HelpInfrastructureObject;
-public class TestHelpServer {
+public class TestHelpInfrastructure {
@Test
- public void test() throws Exception {
+ public void test() {
- HelpServlet helpServelet = new HelpServlet();
+ final ClassLoader loader = this.getClass().getClassLoader();
+ URL url = loader.getResource("help/meta.json");
+ Path path;
+ try {
+ path = Paths.get(url.toURI());
+ HelpInfrastructureObject helpInfrastuctureObject = new HelpInfrastructureObject(path);
+ System.out.println("Help: "+helpInfrastuctureObject);
+ } catch (URISyntaxException e) {
+ fail(e.getMessage());
+ }
- assertNotNull("Helpservelet created", helpServelet);
- helpServelet.close();
}
}
diff --git a/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestMyServlet.java b/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestMyServlet.java
new file mode 100644
index 000000000..e51cc6843
--- /dev/null
+++ b/sdnr/wt/helpserver/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/helpserver/test/TestMyServlet.java
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
+ * =================================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ * ============LICENSE_END==========================================================================
+ ******************************************************************************/
+package org.onap.ccsdk.features.sdnr.wt.helpserver.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.nio.file.Files;
+import java.nio.file.OpenOption;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.features.sdnr.wt.helpserver.HelpServlet;
+import org.onap.ccsdk.features.sdnr.wt.helpserver.data.ExtactBundleResource;
+import org.onap.ccsdk.features.sdnr.wt.helpserver.data.HelpInfrastructureObject;
+import static java.nio.file.StandardOpenOption.CREATE_NEW;
+import static java.nio.file.StandardOpenOption.WRITE;
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
+
+public class TestMyServlet extends Mockito {
+
+ private static final String GETHELPDIRECTORYBASE = "data";
+ private static final String CONTENT = "abbccdfkamaosie aksdmais";
+
+ public static void createHelpFile(String filename,String content) {
+ File file=new File(HelpInfrastructureObject.getHelpDirectoryBase() + filename);
+ File folder = file.getParentFile();
+ if(!folder.exists()) {
+ folder.mkdirs();
+ }
+ try {
+ if(file.exists()) {
+ file.delete();
+ }
+ Files.write( file.toPath(),content.getBytes(),new OpenOption[] { WRITE, CREATE_NEW , CREATE, TRUNCATE_EXISTING});
+ } catch (IOException e1) {
+ fail(e1.getMessage());
+ }
+ }
+
+ @Before
+ public void init() {
+ try {
+ ExtactBundleResource.deleteRecursively(new File(GETHELPDIRECTORYBASE));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ @After
+ public void deinit() {
+ this.init();
+ }
+
+ @Test
+ public void testServlet() throws Exception {
+
+ System.out.println("Test get");
+
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+
+ when(request.getRequestURI()).thenReturn("help/");
+ when(request.getQueryString()).thenReturn("?meta");
+
+ StringWriter stringWriter = new StringWriter();
+ ServletOutputStream out=new ServletOutputStream() {
+
+ @Override
+ public void write(int arg0) throws IOException {
+ stringWriter.write(arg0);
+ }
+ };
+ when(response.getOutputStream()).thenReturn(out);
+
+ HelpServlet helpServlet=null;
+ try {
+ helpServlet = new HelpServlet();
+ System.out.println("Server created");
+ createHelpFile("/meta.json",CONTENT);
+
+ helpServlet.doOptions(request, response);
+ System.out.println("Get calling");
+ helpServlet.doGet(request, response);
+ System.out.println("Get called");
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ if (helpServlet != null) {
+ helpServlet.close();
+ }
+
+ String result = stringWriter.toString().trim();
+ System.out.println("Result: '" + result + "'");
+ assertEquals(CONTENT,result);
+ }
+
+ @Test
+ public void testServlet2() {
+ this.testGetRequest("test/0.4.0/test.txt");
+ this.testGetRequest("test.css");
+ this.testGetRequest("test.eps");
+ this.testGetRequest("test.pdf");
+ }
+
+ private void testGetRequest(String fn) {
+ HelpServlet helpServlet = new HelpServlet();
+ createHelpFile("/"+fn,CONTENT);
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+
+ when(request.getRequestURI()).thenReturn("help/"+fn);
+ StringWriter sw = new StringWriter();
+ ServletOutputStream out = new ServletOutputStream() {
+
+ @Override
+ public void write(int arg0) throws IOException {
+ sw.write(arg0);
+ }
+ };
+ try {
+ when(response.getOutputStream()).thenReturn(out);
+ helpServlet.doGet(request, response);
+ } catch (ServletException | IOException e) {
+ fail(e.getMessage());
+ }
+ try {
+ out.close();
+ } catch (Exception e) {
+ }
+ try {
+ helpServlet.close();
+ } catch (Exception e) {
+ }
+
+ assertEquals(CONTENT,sw.toString().trim());
+ }
+}
diff --git a/sdnr/wt/helpserver/provider/src/test/resources/log4j.properties b/sdnr/wt/helpserver/provider/src/test/resources/log4j.properties
deleted file mode 100644
index 142663bd2..000000000
--- a/sdnr/wt/helpserver/provider/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,12 +0,0 @@
-log4j.rootLogger=INFO, out
-
-log4j.logger.org.apache.camel.impl.converter=WARN
-log4j.logger.org.apache.camel.management=WARN
-log4j.logger.org.apache.camel.impl.DefaultPackageScanClassResolver=WARN
-log4j.logger.org.springframework=ERROR
-
-# CONSOLE appender not used by default
-log4j.appender.out=org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-
diff --git a/sdnr/wt/helpserver/provider/src/test/resources/simplelogger.properties b/sdnr/wt/helpserver/provider/src/test/resources/simplelogger.properties
new file mode 100644
index 000000000..6f38b507a
--- /dev/null
+++ b/sdnr/wt/helpserver/provider/src/test/resources/simplelogger.properties
@@ -0,0 +1,37 @@
+# SLF4J's SimpleLogger configuration file
+# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
+
+# Default logging detail level for all instances of SimpleLogger.
+# Must be one of ("trace", "debug", "info", "warn", or "error").
+# If not specified, defaults to "info".
+org.slf4j.simpleLogger.defaultLogLevel=trace
+
+# Logging detail level for a SimpleLogger instance named "xxx.yyy.zzz".
+# Must be one of ("trace", "debug", "info", "warn", or "error").
+# If not specified, the default logging detail level is used.
+# org.slf4j.simpleLogger.log.xxx.yyy=debug
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager=debug
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.Resources=info
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container=trace
+
+# Set to true if you want the current date and time to be included in output messages.
+# Default is false, and will output the number of milliseconds elapsed since startup.
+#org.slf4j.simpleLogger.showDateTime=false
+
+# The date and time format to be used in the output messages.
+# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
+# If the format is not specified or is invalid, the default format is used.
+# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
+#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
+
+# Set to true if you want to output the current thread name.
+# Defaults to true.
+#org.slf4j.simpleLogger.showThreadName=true
+
+# Set to true if you want the Logger instance name to be included in output messages.
+# Defaults to true.
+#org.slf4j.simpleLogger.showLogName=true
+
+# Set to true if you want the last component of the name to be included in output messages.
+# Defaults to false.
+#org.slf4j.simpleLogger.showShortLogName=false