aboutsummaryrefslogtreecommitdiffstats
path: root/appc-client/client-simulator/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'appc-client/client-simulator/src/test/java/org')
-rw-r--r--appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonRequestHandler.java53
-rw-r--r--appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonResponseHandler.java46
-rw-r--r--appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/main/TestClientRunner.java102
3 files changed, 201 insertions, 0 deletions
diff --git a/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonRequestHandler.java b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonRequestHandler.java
new file mode 100644
index 000000000..417b98d64
--- /dev/null
+++ b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonRequestHandler.java
@@ -0,0 +1,53 @@
+package org.openecomp.appc.simulator.client.impl;
+
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.openecomp.appc.client.lcm.api.LifeCycleManagerStateful;
+import org.openecomp.appc.client.lcm.exceptions.AppcClientException;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.*;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.*;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({LifeCycleManagerStateful.class})
+
+public class TestJsonRequestHandler {
+
+ JsonResponseHandler jsonResponseHandler=new JsonResponseHandler();
+ @Before
+ public void init(){
+ jsonResponseHandler= Mockito.mock(JsonResponseHandler.class);
+ }
+
+
+ @Test
+ public void testProceedFiles() throws AppcClientException,java.io.IOException{
+ String folder="src/test/resources/data";
+ List<File> sources = getJsonFiles(folder);
+ File source=sources.get(0);
+ File log = new File(folder + "/output.txt");
+ JsonRequestHandler requestHandler = new JsonRequestHandler();
+ Mockito.doNothing().when(jsonResponseHandler).onResponse(Matchers.anyBoolean());
+ requestHandler.proceedFile(source,log);
+
+ Assert.assertNotNull(log);
+
+ }
+
+ private static List<File> getJsonFiles(String folder) throws FileNotFoundException {
+ Path dir = Paths.get(folder);
+ FileFilter fileFilter = new WildcardFileFilter("*.json");
+ return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));
+ }
+
+
+} \ No newline at end of file
diff --git a/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonResponseHandler.java b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonResponseHandler.java
new file mode 100644
index 000000000..b477b8a61
--- /dev/null
+++ b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/impl/TestJsonResponseHandler.java
@@ -0,0 +1,46 @@
+package org.openecomp.appc.simulator.client.impl;
+
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.junit.Assert;
+import org.junit.Ignore;
+import java.io.*;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+
+public class TestJsonResponseHandler {
+ String folder="/data/output/error.json";
+ JsonResponseHandler responseHandler=new JsonResponseHandler();
+
+ @Ignore
+ public void testOnResponse() throws URISyntaxException, IOException{
+ responseHandler.onResponse(getNode());
+ List<File> files=getJsonFiles(folder);
+ Assert.assertNotNull(files);
+
+ }
+
+ private String readData(String inputFile) throws URISyntaxException, IOException {
+ File file = new File(this.getClass().getResource(inputFile).toURI());
+
+ byte[] bFile = new byte[(int) file.length()];
+ FileInputStream fileInputStream = new FileInputStream(file);
+ fileInputStream.read(bFile);
+ fileInputStream.close();
+ return new String(bFile);
+ }
+
+ private String getNode() throws java.io.IOException{
+ String jsonSring="{\"status\": {\"code\": \"200\"}}";
+ return jsonSring;
+}
+ public List<File> getJsonFiles(String folder) throws FileNotFoundException {
+ Path dir = Paths.get(folder);
+ FileFilter fileFilter = new WildcardFileFilter("*.error");
+ return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));
+ }
+}
diff --git a/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/main/TestClientRunner.java b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/main/TestClientRunner.java
new file mode 100644
index 000000000..d0de0cd49
--- /dev/null
+++ b/appc-client/client-simulator/src/test/java/org/openecomp/appc/simulator/client/main/TestClientRunner.java
@@ -0,0 +1,102 @@
+package org.openecomp.appc.simulator.client.main;
+
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.openecomp.appc.client.lcm.exceptions.AppcClientException;
+import org.openecomp.appc.simulator.client.impl.JsonRequestHandler;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.*;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({JsonRequestHandler.class,ClientRunner.class})
+
+public class TestClientRunner {
+
+ JsonRequestHandler jsonRequestHandler;
+ private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+
+ @Before
+ public void init() throws AppcClientException{
+ System.setOut(new PrintStream(outContent));
+ jsonRequestHandler= Mockito.mock(JsonRequestHandler.class);
+
+ }
+
+ @After
+ public void cleanUpStreams() {
+ System.setOut(null);
+ }
+
+ @Test
+ public void testMain() throws java.io.IOException,java.lang.Exception{
+ String []arguments=new String[]{"src/test/resources/data","JSON"};
+ PowerMockito.whenNew(JsonRequestHandler.class).withArguments(Mockito.anyObject()).thenReturn(jsonRequestHandler);
+ Mockito.doNothing().when(jsonRequestHandler).proceedFile(Matchers.anyObject(), Matchers.anyObject());
+
+ ClientRunner.main(arguments);
+ String expectedOutput=outContent.toString();
+ Assert.assertEquals(expectedOutput,outContent.toString());
+ }
+
+ @Test
+ public void testGetPrperties(){
+ String folder="src/test/resources/data";
+ Properties properties=new Properties();
+ properties=getProperties(folder);
+ Assert.assertNotNull(properties);
+ }
+
+ @Test
+ public void testGetJsonFIles() throws FileNotFoundException{
+ String folder="src/test/resources/data";
+ List<File> sources = getJsonFiles(folder);
+ Assert.assertNotNull(sources);
+ }
+
+ private static Properties getProperties(String folder) {
+ Properties prop = new Properties();
+
+ InputStream conf = null;
+ try {
+ conf = new FileInputStream(folder + "client-simulator.properties");
+ } catch (FileNotFoundException e) {
+
+ }
+ if (conf != null) {
+ try {
+ prop.load(conf);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } else {
+ try {
+ prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("client-simulator.properties"));
+ } catch (Exception e) {
+ throw new RuntimeException("### ERROR ### - Could not load properties to test");
+ }
+ }
+ return prop;
+ }
+
+ private static List<File> getJsonFiles(String folder) throws FileNotFoundException {
+ Path dir = Paths.get(folder);
+ FileFilter fileFilter = new WildcardFileFilter("*.json");
+ return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));
+ }
+
+}