Network Inventory Client Updates
[appc.git] / appc-outbound / appc-network-inventory-client / provider / src / test / java / org / onap / appc / instar / interfaceImpl / TestInstarResponseHandlerImpl.java
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.interfaceImpl;
26
27 import static org.junit.Assert.assertTrue;
28
29 import org.junit.Test;
30 import org.onap.appc.instar.utils.InstarClientConstant;
31 import org.onap.sdnc.config.params.data.ResponseKey;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33
34 public class TestInstarResponseHandlerImpl {
35
36     @Test
37     public void testProcessResponseForIpv4() {
38         ResponseKey resKey = new ResponseKey();
39         resKey.setUniqueKeyValue("x");
40         SvcLogicContext svc = new SvcLogicContext();
41         svc.setAttribute("vnf-name", "fqdn");
42         resKey.setFieldKeyName("ipaddress-v4");
43         String instarKey = "key";
44         String instarRes ="{\"vnfConfigurationParameterDetails\":"
45                 + "[{\"fqdn\":\"fqdnx\",\"v4IPAddress\":\"value2\"}]}";
46         InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc);
47         impl.processResponse(instarRes, instarKey);
48     }
49
50     @Test
51     public void testProcessResponseForIpv6() {
52         ResponseKey resKey = new ResponseKey();
53         resKey.setUniqueKeyValue("x");
54         SvcLogicContext svc = new SvcLogicContext();
55         svc.setAttribute("vnf-name", "fqdn");
56         resKey.setFieldKeyName("ipaddress-v6");
57         String instarKey = "key";
58         String instarRes ="{\"vnfConfigurationParameterDetails\":"
59                 + "[{\"fqdn\":\"fqdnx\",\"v6IPAddress\":\"value2\"}]}";
60         InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc);
61         impl.processResponse(instarRes, instarKey);
62     }
63
64     @Test
65     public void testProcessResponseInstarKeyValues() {
66         ResponseKey resKey = new ResponseKey();
67         resKey.setUniqueKeyValue("x");
68         String json ="{\"vnfConfigurationParameterDetails\":"
69                 + "[{\"fqdn\":\"fqdnx\",\"v4IPAddress\":\"value2\"}]}";
70         SvcLogicContext svc = new SvcLogicContext();
71         svc.setAttribute("vnf-name", "fqdn");
72         svc.setAttribute("INSTAR-KEY-VALUES", json);
73         resKey.setFieldKeyName("ipaddress-v6");
74         String instarKey = "key";
75         String instarRes ="{\"vnfConfigurationParameterDetails\":"
76                 + "[{\"fqdn\":\"fqdnx\",\"v6IPAddress\":\"value2\"}]}";
77         InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc);
78         impl.processResponse(instarRes, instarKey);
79     }
80
81     @Test
82     public void testV4SubNet() {
83         ResponseKey resKey = new ResponseKey();
84         resKey.setUniqueKeyValue("x");
85         resKey.setFieldKeyName(InstarClientConstant.INSTAR_V4_SUBNET);
86         String json ="{\"v4IpAddress\":\"ipAddressV4\"}]}";
87         SvcLogicContext ctx = new SvcLogicContext();
88         ctx.setAttribute("vnf-name", "fqdn");
89         ctx.setAttribute("INSTAR-KEY-VALUES", json);
90         String instarKey = "V4SubnetParameter";
91         String instarRes ="{\"vnfConfigurationParameterDetails\":"
92                 + "[{\"fqdn\":\"fqdnx\",\"v4Subnet\":\"subnetv4\"}]}";
93         InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,ctx);
94         impl.processResponse(instarRes, instarKey);
95         String values = ctx.getAttribute("INSTAR-KEY-VALUES");
96         assertTrue(values.contains("subnetv4"));
97     }
98
99     @Test
100     public void testV6SubNet() {
101         ResponseKey resKey = new ResponseKey();
102         resKey.setUniqueKeyValue("x");
103         resKey.setFieldKeyName(InstarClientConstant.INSTAR_V6_SUBNET);
104         String json ="{\"v6IpAddress\":\"ipAddressV6\"}]}";
105         SvcLogicContext ctx = new SvcLogicContext();
106         ctx.setAttribute("vnf-name", "fqdn");
107         ctx.setAttribute("INSTAR-KEY-VALUES", json);
108         String instarKey = "V6SubnetParameter";
109         String instarRes ="{\"vnfConfigurationParameterDetails\":"
110                 + "[{\"fqdn\":\"fqdnx\",\"v6Subnet\":\"subnetv6\"}]}";
111         InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,ctx);
112         impl.processResponse(instarRes, instarKey);
113         String values = ctx.getAttribute("INSTAR-KEY-VALUES");
114         assertTrue(values.contains("subnetv6"));
115     }
116
117     @Test
118     public void testV6DefaultGateway() {
119         ResponseKey resKey = new ResponseKey();
120         resKey.setUniqueKeyValue("x");
121         resKey.setFieldKeyName(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY);
122         String json ="{\"v6IpAddress\":\"ipAddressV6\"}]}";
123         SvcLogicContext ctx = new SvcLogicContext();
124         ctx.setAttribute("vnf-name", "fqdn");
125         ctx.setAttribute("INSTAR-KEY-VALUES", json);
126         String instarKey = "V6DefaultGatewayParameter";
127         String instarRes ="{\"vnfConfigurationParameterDetails\":"
128                 + "[{\"fqdn\":\"fqdnx\",\"v6DefaultGateway\":\"defaultGatewayV6\"}]}";
129         InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,ctx);
130         impl.processResponse(instarRes, instarKey);
131         String values = ctx.getAttribute("INSTAR-KEY-VALUES");
132         assertTrue(values.contains("defaultGatewayV6"));
133     }
134
135     @Test
136     public void testV4DefaultGateway() {
137         ResponseKey resKey = new ResponseKey();
138         resKey.setUniqueKeyValue("x");
139         resKey.setFieldKeyName(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY);
140         String json ="{\"v4IpAddress\":\"ipAddressV4\"}]}";
141         SvcLogicContext ctx = new SvcLogicContext();
142         ctx.setAttribute("vnf-name", "fqdn");
143         ctx.setAttribute("INSTAR-KEY-VALUES", json);
144         String instarKey = "V4DefaultGatewayParameter";
145         String instarRes ="{\"vnfConfigurationParameterDetails\":"
146                 + "[{\"fqdn\":\"fqdnx\",\"v4DefaultGateway\":\"defaultGatewayV4\"}]}";
147         InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,ctx);
148         impl.processResponse(instarRes, instarKey);
149         String values = ctx.getAttribute("INSTAR-KEY-VALUES");
150         assertTrue(values.contains("defaultGatewayV4"));
151     }
152 }