2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.instar.node;
26 import static org.junit.Assert.assertTrue;
29 import java.nio.charset.Charset;
30 import java.util.HashMap;
32 import javax.net.ssl.HostnameVerifier;
33 import javax.net.ssl.SSLContext;
34 import javax.ws.rs.HttpMethod;
36 import org.apache.commons.io.IOUtils;
37 import org.apache.commons.lang3.StringUtils;
38 import org.json.JSONObject;
39 import org.junit.Assert;
40 import org.junit.Test;
41 import org.onap.appc.aai.utils.AaiClientConstant;
42 import org.onap.appc.instar.dme2client.SecureRestClientTrustManager;
43 import org.onap.appc.instar.utils.InstarClientConstant;
44 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
46 import com.sun.jersey.api.client.Client;
47 import com.sun.jersey.api.client.ClientResponse;
48 import com.sun.jersey.api.client.WebResource;
49 import com.sun.jersey.api.client.config.DefaultClientConfig;
50 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
53 public class TestInstarClientNode {
57 @Test(expected=Exception.class)
58 public void testInstarClientNode() throws Exception {
59 SvcLogicContext ctx = new SvcLogicContext();
60 String key_conetent = IOUtils.toString(TestInstarClientNode.class.getClassLoader().getResourceAsStream("templates/sampleKeyContents"), Charset.defaultCharset());
61 Map<String, String> inParams = new HashMap<String, String>();
62 inParams.put(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST");
63 inParams.put(InstarClientConstant.INSTAR_KEYS, "LOCAL_ACCESS_IP_ADDR");
64 inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
65 ctx.setAttribute("INSTAR.LOCAL_ACCESS_IP_ADDR", key_conetent);
66 ctx.setAttribute(InstarClientConstant.INPUT_PARAM_RESPONSE_PRIFIX, "TEST");
67 ctx.setAttribute(InstarClientConstant.VNF_NAME, "basx0003v");
68 InstarClientNode icn = new InstarClientNode();
69 icn.getInstarInfo(inParams, ctx);
70 String address = (new JSONObject(ctx.getAttribute("TEST." + InstarClientConstant.INSTAR_KEY_VALUES))).getString("LOCAL_ACCESS_IP_ADDR");
72 @Test(expected=Exception.class)
73 public void testInstarData() throws Exception {
74 InstarClientNode inNode = new InstarClientNode();
75 SvcLogicContext ctx = new SvcLogicContext ();
76 Map<String, String> inParams = new HashMap<String, String>();
78 inParams.put(InstarClientConstant.VNF_NAME, "basx0003v");
79 inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
80 inNode.getInstarData(inParams, ctx);
84 public void TestGetAaiInfo() throws Exception {
85 InstarClientNode aaiNode=new InstarClientNode();
86 Map<String, String> inParams=new HashMap<String, String> ();
87 SvcLogicContext ctx=new SvcLogicContext();
88 String keyVals=new String("[\"LOCAL_CORE_ALT_IP_ADDR\",\"REMOTE_ACCESS_IP_ADDR\",\"PARAMETER3\",\"PARAMETER4\"]");
89 inParams.put("aaiKeys",keyVals);
90 inParams.put("responsePrefix","test");
91 String yamlParameterString=IOUtils.toString(TestInstarClientNode.class.getClassLoader().getResourceAsStream("./YamlParameter.txt"), Charset.defaultCharset());
92 ctx.setAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + "LOCAL_CORE_ALT_IP_ADDR",yamlParameterString);
93 String yamlParameterString2=IOUtils.toString(TestInstarClientNode.class.getClassLoader().getResourceAsStream("./YamlParameter2.txt"), Charset.defaultCharset());
94 ctx.setAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + "REMOTE_ACCESS_IP_ADDR",yamlParameterString2);
95 String yamlParameterString3=IOUtils.toString(TestInstarClientNode.class.getClassLoader().getResourceAsStream("./YamlParameter3.txt"), Charset.defaultCharset());
96 ctx.setAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + "PARAMETER3",yamlParameterString3);
97 String yamlParameterString4=IOUtils.toString(TestInstarClientNode.class.getClassLoader().getResourceAsStream("./YamlParameter4.txt"), Charset.defaultCharset());
98 ctx.setAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + "PARAMETER4",yamlParameterString4);
99 stubAaiVnfInfoData(ctx);
100 aaiNode.getAaiInfo(inParams, ctx);
101 String [] valToCompare={"\"LOCAL_CORE_ALT_IP_ADDR\":\"testVnf\"",
102 "\"REMOTE_ACCESS_IP_ADDR\":\"testVnfc2,testVnfc3\"",
103 "\"PARAM3\":\"testVnfcIpv4Address1\"",
104 "\"PARAM4\":\"server1,server2,server3\""};
105 String value=ctx.getAttribute("test."+AaiClientConstant.AAI_KEY_VALUES);
107 for (int i=0;i<valToCompare.length;i++) {
108 if (!StringUtils.contains(value,valToCompare[i] )) {
109 //System.out.println(value+"....... "+valToCompare[i].toString());
120 public void stubAaiVnfInfoData(SvcLogicContext context) {
122 context.setAttribute("tmp.vnfInfo.vm-count","3");
123 context.setAttribute("tmp.vnfInfo.vnf.vnf-name","testVnf");
124 context.setAttribute("tmp.vnfInfo.vnf.vnf-oam-ipv4-address","test-ipv4-address");
125 context.setAttribute("tmp.vnfInfo.vm[0].vserver-name","server1");
126 context.setAttribute("tmp.vnfInfo.vm[0].vserver-id","serverId1");
127 context.setAttribute("tmp.vnfInfo.vm[0].vnfc-count","1");
128 context.setAttribute("tmp.vnfInfo.vm[0].vnfc-name","testVnfc1");
129 context.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code","msc");
130 context.setAttribute("tmp.vnfInfo.vm[0].vnfc-ipaddress-v4-oam-vip","testVnfcIpv4Address1");
132 context.setAttribute("tmp.vnfInfo.vm[1].vserver-name","server2");
133 context.setAttribute("tmp.vnfInfo.vm[1].vserver-id","serverId2");
134 context.setAttribute("tmp.vnfInfo.vm[1].vnfc-count","1");
135 context.setAttribute("tmp.vnfInfo.vm[1].vnfc-name","testVnfc2");
136 context.setAttribute("tmp.vnfInfo.vm[1].vnfc-function-code","testFnCode");
137 context.setAttribute("tmp.vnfInfo.vm[1].vnfc-ipaddress-v4-oam-vip","testVnfcIpv4Address2");
139 context.setAttribute("tmp.vnfInfo.vm[2].vserver-name","server3");
140 context.setAttribute("tmp.vnfInfo.vm[2].vserver-id","serverId3");
141 context.setAttribute("tmp.vnfInfo.vm[2].vnfc-count","1");
142 context.setAttribute("tmp.vnfInfo.vm[2].vnfc-name","testVnfc3");
143 context.setAttribute("tmp.vnfInfo.vm[2].vnfc-function-code","testFnCode");
144 context.setAttribute("tmp.vnfInfo.vm[2].vnfc-ipaddress-v4-oam-vip","testVnfcIpv4Address3");