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