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");
 
     @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");
 
     @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");
     @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());
     @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);
     }
     @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);
     @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);
     @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);
     @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";
     @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";
     @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";
     @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";
 
     @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");
         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"));
+    }
 }