2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.onap.ccsdk.adapter.ansible.model;
25 import java.lang.reflect.Constructor;
26 import java.lang.reflect.InvocationTargetException;
27 import java.lang.reflect.Method;
28 import org.json.JSONObject;
29 import org.junit.Test;
30 import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleMessageParser;
31 import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleResult;
32 import org.onap.ccsdk.sli.adaptors.ansible.model.AnsibleServerEmulator;
34 import static org.junit.Assert.assertNotNull;
36 public class TestAnsibleAdapter {
39 public void callPrivateConstructorsMethodsForCodeCoverage()
40 throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException,
41 InvocationTargetException {
43 /* test constructors */
44 Class<?>[] classesOne = {AnsibleMessageParser.class};
45 for (Class<?> clazz : classesOne) {
46 Constructor<?> constructor = clazz.getDeclaredConstructor();
47 constructor.setAccessible(true);
48 assertNotNull(constructor.newInstance());
50 Class<?>[] classesTwo = {AnsibleServerEmulator.class};
51 for (Class<?> clazz : classesTwo) {
52 Constructor<?> constructor = clazz.getDeclaredConstructor();
53 constructor.setAccessible(true);
54 assertNotNull(constructor.newInstance());
56 Class<?>[] classesThree = {AnsibleResult.class};
57 for (Class<?> clazz : classesThree) {
58 Constructor<?> constructor = clazz.getDeclaredConstructor();
59 constructor.setAccessible(true);
60 assertNotNull(constructor.newInstance());
64 AnsibleMessageParser ansibleMessageParser = new AnsibleMessageParser();
65 Class<?>[] parameterTypes = new Class[1];
66 parameterTypes[0] = java.lang.String.class;
68 Method m = ansibleMessageParser.getClass().getDeclaredMethod("getFilePayload", parameterTypes);
69 m.setAccessible(true);
70 assertNotNull(m.invoke(ansibleMessageParser, "{\"test\": test}"));
72 // test logging-suppression for an invalid host value (Fortify Log Forging fix)
75 + " \"192.168.1.10\": {"
77 + " \"StatusCode\": 200,"
78 + " \"StatusMessage\": \"SUCCESS\""
80 + " \"192%168%1%10\": {"
82 + " \"StatusCode\": 200,"
83 + " \"StatusMessage\": \"SUCCESS\""
85 + " \"server-dev.att.com\": {"
87 + " \"StatusCode\": 200,"
88 + " \"StatusMessage\": \"SUCCESS\""
91 + " \"StatusCode\": 200,"
92 + " \"StatusMessage\": \"FINISHED\""
94 Method m2 = ansibleMessageParser.getClass().getDeclaredMethod("parseGetResponseNested", AnsibleResult.class, JSONObject.class);
95 m2.setAccessible(true);
96 m2.invoke(ansibleMessageParser, new AnsibleResult(), new JSONObject(input));