aboutsummaryrefslogtreecommitdiffstats
path: root/appc-client/client-simulator/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'appc-client/client-simulator/src/test')
-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
-rw-r--r--appc-client/client-simulator/src/test/resources/data/client-simulator.properties27
-rw-r--r--appc-client/client-simulator/src/test/resources/data/exceptions.txt1
-rw-r--r--appc-client/client-simulator/src/test/resources/data/input.json19
-rw-r--r--appc-client/client-simulator/src/test/resources/data/output/error.json1
-rw-r--r--appc-client/client-simulator/src/test/resources/data/output/error.txt1
8 files changed, 250 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)));
+ }
+
+}
diff --git a/appc-client/client-simulator/src/test/resources/data/client-simulator.properties b/appc-client/client-simulator/src/test/resources/data/client-simulator.properties
new file mode 100644
index 000000000..4125e2fb6
--- /dev/null
+++ b/appc-client/client-simulator/src/test/resources/data/client-simulator.properties
@@ -0,0 +1,27 @@
+#
+# Default Properties - Configured for client simulator
+#
+#--------------------------------------------------------------------------------------------
+ctx.model.package=com.att.appc.client.lcm.model
+
+client.pool.size=10
+client.rpc.exceptions.map.file=/root/exceptions.txt
+#client.response.timeout=TIMEOUT
+
+#------------------
+# UEB configuration
+#------------------
+topic.read=async_amrita2
+topic.read.timeout=30000
+#topic.read.limit=1000
+topic.write=appc_read_oecomp2
+client.name=name1
+client.name.id=0
+
+#true - force shutdown
+client.force.shutdown=false
+client.graceful.shutdown.timeout=60000
+
+#poolMembers=uebsb92sfdc.it.att.com:3904
+poolMembers=10.147.101.7:3904
+
diff --git a/appc-client/client-simulator/src/test/resources/data/exceptions.txt b/appc-client/client-simulator/src/test/resources/data/exceptions.txt
new file mode 100644
index 000000000..54d433017
--- /dev/null
+++ b/appc-client/client-simulator/src/test/resources/data/exceptions.txt
@@ -0,0 +1 @@
+ConfigScaleOut:config-scaleout
diff --git a/appc-client/client-simulator/src/test/resources/data/input.json b/appc-client/client-simulator/src/test/resources/data/input.json
new file mode 100644
index 000000000..940c8424a
--- /dev/null
+++ b/appc-client/client-simulator/src/test/resources/data/input.json
@@ -0,0 +1,19 @@
+{"input": {
+ "common-header": {
+ "timestamp": "2017-07-21T9:30:40.958Z",
+ "api-ver": "2.00",
+ "originator-id": "ORTG_1",
+ "request-id": "ST_122",
+ "sub-request-id": "12",
+ "flags": {
+ "force": "TRUE",
+ "ttl": 12000
+ }
+ },
+ "action" : "Start",
+ "action-identifiers": {
+ "vnf-id": "mj123!!"
+ },
+ "payload": " {\"vnf-host-ip-address\": \"10.147.124.163\" }"
+
+}}
diff --git a/appc-client/client-simulator/src/test/resources/data/output/error.json b/appc-client/client-simulator/src/test/resources/data/output/error.json
new file mode 100644
index 000000000..75d35709e
--- /dev/null
+++ b/appc-client/client-simulator/src/test/resources/data/output/error.json
@@ -0,0 +1 @@
+{"status": {"code": "200"}}
diff --git a/appc-client/client-simulator/src/test/resources/data/output/error.txt b/appc-client/client-simulator/src/test/resources/data/output/error.txt
new file mode 100644
index 000000000..8c2c9de2f
--- /dev/null
+++ b/appc-client/client-simulator/src/test/resources/data/output/error.txt
@@ -0,0 +1 @@
+{status:"200"} \ No newline at end of file