60676ccf4b86a189d71050f58d9650048223120c
[appc.git] /
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
24 package org.onap.appc.instar.node;
25
26 import static org.junit.Assert.assertTrue;
27
28 import java.net.URI;
29 import java.nio.charset.Charset;
30 import java.util.HashMap;
31 import java.util.Map;
32 import javax.net.ssl.HostnameVerifier;
33 import javax.net.ssl.SSLContext;
34 import javax.ws.rs.HttpMethod;
35
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;
45
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;
51
52
53 public class TestInstarClientNode {
54
55     //ONAP Migration
56
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");
71     }
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>();
77
78          inParams.put(InstarClientConstant.VNF_NAME, "basx0003v");
79          inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
80          inNode.getInstarData(inParams, ctx);
81         }
82
83     @Test
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);
106         boolean pass=false;
107         for (int i=0;i<valToCompare.length;i++) {
108             if (!StringUtils.contains(value,valToCompare[i] )) {
109                 //System.out.println(value+"....... "+valToCompare[i].toString());
110                 pass=false;
111                 break;
112             }
113             else {
114                 pass=true;
115             }
116         }
117         assertTrue(pass);
118     }
119
120     public void stubAaiVnfInfoData(SvcLogicContext context) {
121
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");
131
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");
138
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");
145
146     }
147 }