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