aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-ansible-adapter
diff options
context:
space:
mode:
authorSandeep J <sandeejh@in.ibm.com>2018-08-17 18:26:07 +0530
committerTakamune Cho <tc012c@att.com>2018-08-21 16:14:47 +0000
commit998de995faf5d554c0d07871b712c26374a5cda0 (patch)
treeaed5818b2170dd77f69eefabb669afd98af2234e /appc-adapters/appc-ansible-adapter
parent92566aed18ea21c367e879c9f514b6dd66d1ce23 (diff)
added test case to TestAnsibleMessageParser.java
to increase code coverage. Also, formatted the code. Issue-ID: APPC-1086 Change-Id: I3b7bf6c70f20b0e42326f2fe3b642742f3fcd524 Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
Diffstat (limited to 'appc-adapters/appc-ansible-adapter')
-rw-r--r--appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleMessageParser.java36
1 files changed, 22 insertions, 14 deletions
diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleMessageParser.java b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleMessageParser.java
index ad12b3004..9a4690e16 100644
--- a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleMessageParser.java
+++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/test/java/org/onap/appc/adapter/ansible/model/TestAnsibleMessageParser.java
@@ -27,15 +27,20 @@ import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;
+import org.junit.Before;
import org.junit.Test;
-import org.powermock.reflect.Whitebox;
public class TestAnsibleMessageParser {
+ private AnsibleMessageParser msgParser;
+
+ @Before
+ public void setup() {
+ msgParser = new AnsibleMessageParser();
+ }
@Test
public void testReqMessage() throws Exception {
// String result = "{"\AgentUrl : TestAgentUrl}";
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
Map<String, String> params = new HashMap<String, String>();
params.put("AgentUrl", "TestAgentUrl");
params.put("PlaybookName", "TestPlaybookName");
@@ -49,7 +54,6 @@ public class TestAnsibleMessageParser {
@Test
public void testReqUriResult() throws Exception {
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
Map<String, String> params = new HashMap<String, String>();
params.put("AgentUrl", "TestAgentUrl");
params.put("Id", "TestId");
@@ -63,7 +67,6 @@ public class TestAnsibleMessageParser {
@Test
public void testReqUriLog() throws Exception {
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
Map<String, String> params = new HashMap<String, String>();
params.put("AgentUrl", "TestAgent-Url");
params.put("Id", "TestId");
@@ -78,7 +81,6 @@ public class TestAnsibleMessageParser {
@Test
public void TestParsePostResponse() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"100\",\"StatusMessage\":\"TestMessage\"}";
ansibleResult = msgParser.parsePostResponse(input);
assertEquals("TestMessage", ansibleResult.getStatusMessage());
@@ -88,7 +90,6 @@ public class TestAnsibleMessageParser {
@Test(expected = Exception.class)
public void TestParsePostResponseException() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"600\",\"StatusMessage\":\"TestMessage\"}";
ansibleResult = msgParser.parsePostResponse(input);
}
@@ -96,7 +97,6 @@ public class TestAnsibleMessageParser {
@Test
public void TestParsePostResponseException2() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"600\"}";
String result = "Error parsing response";
ansibleResult = msgParser.parsePostResponse(input);
@@ -106,7 +106,6 @@ public class TestAnsibleMessageParser {
@Test(expected = Exception.class)
public void TestParseGetResponseException() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"100\",\"StatusMessage\":\"TestMessage\"}";
String result = "Invalid FinalResponse code";
ansibleResult = msgParser.parseGetResponse(input);
@@ -115,7 +114,6 @@ public class TestAnsibleMessageParser {
@Test
public void TestParseGetResponseExec() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\"}";
String result = "Results not found in GET for response";
ansibleResult = msgParser.parseGetResponse(input);
@@ -125,7 +123,6 @@ public class TestAnsibleMessageParser {
@Test
public void TestParseGetResponse() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\",\"Results\":{\"host\":{\"StatusCode\":\"200\",\"StatusMessage\":\"SUCCESS\"}},\"Output\":{\"results-output\":{\"OutputResult\":\"TestOutPutResult\"}}}";
ansibleResult = msgParser.parseGetResponse(input);
String result = "TestOutPutResult";
@@ -135,7 +132,6 @@ public class TestAnsibleMessageParser {
@Test
public void TestParseGetResponseEx() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\",\"Results\":{\"host\":\"TestHost\"}}";
ansibleResult = msgParser.parseGetResponse(input);
String result = "Error processing response message";
@@ -145,7 +141,6 @@ public class TestAnsibleMessageParser {
@Test
public void TestParseGetResponseJsonEx() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\",\"Results\":\"host\":\"TestHost\"}";
ansibleResult = msgParser.parseGetResponse(input);
String result = "Error parsing response";
@@ -155,7 +150,6 @@ public class TestAnsibleMessageParser {
@Test
public void TestParseGetResponseResultEx() throws Exception {
AnsibleResult ansibleResult;
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
String input = "{\"StatusCode\":\"200\",\"StatusMessage\":\"TestMessage\",\"Results\":{\"host\":{\"StatusCode\":\"100\",\"StatusMessage\":\"Failure\"}},\"Output\":{\"results-output\":{\"OutputResult\":\"TestOutPutResult\"}}}";
ansibleResult = msgParser.parseGetResponse(input);
String result = "TestOutPutResult";
@@ -164,7 +158,6 @@ public class TestAnsibleMessageParser {
@Test
public void testParseOptionalParam() throws Exception {
- AnsibleMessageParser msgParser = new AnsibleMessageParser();
Map<String, String> params = new HashMap<String, String>();
params.put("AgentUrl", "TestAgentUrl");
params.put("PlaybookName", "TestPlaybookName");
@@ -175,4 +168,19 @@ public class TestAnsibleMessageParser {
JSONObject jObject = msgParser.reqMessage(params);
assertEquals("1", jObject.get("Version"));
}
+
+ @Test
+ public void testParseOptionalParamForEnvParameters() throws Exception {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("AgentUrl", "TestAgentUrl");
+ params.put("PlaybookName", "TestPlaybookName");
+ params.put("User", "TestUser");
+ params.put("Password", "TestPassword");
+ params.put("EnvParameters", "{name:value}");
+ JSONObject result= msgParser.reqMessage(params);
+ assertEquals("TestAgentUrl",result.get("AgentUrl"));
+ assertEquals("TestPlaybookName",result.get("PlaybookName"));
+ assertEquals("TestUser",result.get("User"));
+ assertEquals("TestPassword",result.get("Password"));
+ }
}