ansible adapter changes for multiple ansible servs
[appc.git] / appc-adapters / appc-ansible-adapter / appc-ansible-adapter-bundle / src / test / java / org / onap / appc / adapter / ansible / model / TestAnsibleAdapter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * ============LICENSE_END=========================================================
22  */
23 package org.onap.appc.adapter.ansible.model;
24
25 import static org.junit.Assert.assertNotNull;
26 import java.lang.reflect.*;
27 import org.junit.Test;
28 import org.json.JSONObject;
29
30 public class TestAnsibleAdapter {
31
32     private AnsibleMessageParser ansibleMessageParser;
33     private Method m;
34     private String name;
35     private Method m2;
36
37     @Test
38     public void callPrivateConstructorsMethodsForCodeCoverage() throws SecurityException, NoSuchMethodException,
39             IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
40
41         /* test constructors */
42         Class<?>[] classes = { AnsibleMessageParser.class, AnsibleServerEmulator.class, AnsibleResult.class };
43         for (Class<?> currentClass : classes) {
44             Constructor<?> constructor = currentClass.getDeclaredConstructor();
45             name = constructor.getName();
46             constructor.setAccessible(true);
47             assertNotNull("Constructor " + name + " returned null.", constructor.newInstance());
48         }
49
50         /* test methods */
51         ansibleMessageParser = new AnsibleMessageParser();
52         m = ansibleMessageParser.getClass().getDeclaredMethod("getFilePayload", String.class);
53         m.setAccessible(true);
54         assertNotNull(m.invoke(ansibleMessageParser, "{\"test\": test}"));
55         // test logging-suppression for an invalid host value (Fortify Log Forging fix)
56         String input = "{\"Results\":{\"192.168.1.10\":{\"Id\":\"101\",\"StatusCode\":200,\"StatusMessage\":\"SUCCESS\"},\"192%168%1%10\":{\"Id\":\"102\",\"StatusCode\":200,\"StatusMessage\":\"SUCCESS\"},\"server-dev.att.com\":{\"Id\":\"103\",\"StatusCode\":200,\"StatusMessage\":\"SUCCESS\"}},\"StatusCode\":200,\"StatusMessage\":\"FINISHED\"}";
57         JSONObject postResponse = new JSONObject(input);
58         m2 = ansibleMessageParser.getClass().getDeclaredMethod("parseGetResponseNested", AnsibleResult.class, JSONObject.class);
59         m2.setAccessible(true);
60         AnsibleResult ansibleResult = new AnsibleResult();
61
62         // assertNotNull(m2.invoke(ansibleMessageParser, ansibleResult, postResponse));
63         m2.invoke(ansibleMessageParser, ansibleResult, postResponse);
64     }
65 }