bca2087e88289d242cdaa5df19e27dfe7bf729ca
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.instar.node;
26
27 import static org.junit.Assert.assertTrue;
28
29 import java.net.URI;
30 import java.nio.charset.Charset;
31 import java.util.HashMap;
32 import java.util.Map;
33 import javax.net.ssl.HostnameVerifier;
34 import javax.net.ssl.SSLContext;
35 import javax.ws.rs.HttpMethod;
36
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;
46
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;
52
53
54 public class TestInstarClientNode {
55
56     //ONAP Migration
57
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");
72     }
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>();
78
79          inParams.put(InstarClientConstant.VNF_NAME, "basx0003v");
80          inParams.put("operationName", InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME);
81          inNode.getInstarData(inParams, ctx);
82         }
83
84     @Test
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);
107         boolean pass=false;
108         for (int i=0;i<valToCompare.length;i++) {
109             if (!StringUtils.contains(value,valToCompare[i] )) {
110                 //System.out.println(value+"....... "+valToCompare[i].toString());
111                 pass=false;
112                 break;
113             }
114             else {
115                 pass=true;
116             }
117         }
118         assertTrue(pass);
119     }
120
121     public void stubAaiVnfInfoData(SvcLogicContext context) {
122
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");
132
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");
139
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");
146
147     }
148 }