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;
32 import static org.junit.Assert.assertNotNull;
34 public class TestInstarResponseHandlerImpl {
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 assertNotNull(resKey);
52 public void testProcessResponseForIpv6() {
53 ResponseKey resKey = new ResponseKey();
54 resKey.setUniqueKeyValue("x");
55 SvcLogicContext svc = new SvcLogicContext();
56 svc.setAttribute("vnf-name", "fqdn");
57 resKey.setFieldKeyName("ipaddress-v6");
58 String instarKey = "key";
59 String instarRes ="{\"vnfConfigurationParameterDetails\":"
60 + "[{\"fqdn\":\"fqdnx\",\"v6IPAddress\":\"value2\"}]}";
61 InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc);
62 impl.processResponse(instarRes, instarKey);
63 assertNotNull(resKey);
67 public void testProcessResponseInstarKeyValues() {
68 ResponseKey resKey = new ResponseKey();
69 resKey.setUniqueKeyValue("x");
70 String json ="{\"vnfConfigurationParameterDetails\":"
71 + "[{\"fqdn\":\"fqdnx\",\"v4IPAddress\":\"value2\"}]}";
72 SvcLogicContext svc = new SvcLogicContext();
73 svc.setAttribute("vnf-name", "fqdn");
74 svc.setAttribute("INSTAR-KEY-VALUES", json);
75 resKey.setFieldKeyName("ipaddress-v6");
76 String instarKey = "key";
77 String instarRes ="{\"vnfConfigurationParameterDetails\":"
78 + "[{\"fqdn\":\"fqdnx\",\"v6IPAddress\":\"value2\"}]}";
79 InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,svc);
80 impl.processResponse(instarRes, instarKey);
85 public void testV4SubNet() {
86 ResponseKey resKey = new ResponseKey();
87 resKey.setUniqueKeyValue("x");
88 resKey.setFieldKeyName(InstarClientConstant.INSTAR_V4_SUBNET);
89 String json ="{\"v4IpAddress\":\"ipAddressV4\"}]}";
90 SvcLogicContext ctx = new SvcLogicContext();
91 ctx.setAttribute("vnf-name", "fqdn");
92 ctx.setAttribute("INSTAR-KEY-VALUES", json);
93 String instarKey = "V4SubnetParameter";
94 String instarRes ="{\"vnfConfigurationParameterDetails\":"
95 + "[{\"fqdn\":\"fqdnx\",\"v4Subnet\":\"subnetv4\"}]}";
96 InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,ctx);
97 impl.processResponse(instarRes, instarKey);
98 String values = ctx.getAttribute("INSTAR-KEY-VALUES");
99 assertTrue(values.contains("subnetv4"));
103 public void testV6SubNet() {
104 ResponseKey resKey = new ResponseKey();
105 resKey.setUniqueKeyValue("x");
106 resKey.setFieldKeyName(InstarClientConstant.INSTAR_V6_SUBNET);
107 String json ="{\"v6IpAddress\":\"ipAddressV6\"}]}";
108 SvcLogicContext ctx = new SvcLogicContext();
109 ctx.setAttribute("vnf-name", "fqdn");
110 ctx.setAttribute("INSTAR-KEY-VALUES", json);
111 String instarKey = "V6SubnetParameter";
112 String instarRes ="{\"vnfConfigurationParameterDetails\":"
113 + "[{\"fqdn\":\"fqdnx\",\"v6Subnet\":\"subnetv6\"}]}";
114 InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,ctx);
115 impl.processResponse(instarRes, instarKey);
116 String values = ctx.getAttribute("INSTAR-KEY-VALUES");
117 assertTrue(values.contains("subnetv6"));
121 public void testV6DefaultGateway() {
122 ResponseKey resKey = new ResponseKey();
123 resKey.setUniqueKeyValue("x");
124 resKey.setFieldKeyName(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY);
125 String json ="{\"v6IpAddress\":\"ipAddressV6\"}]}";
126 SvcLogicContext ctx = new SvcLogicContext();
127 ctx.setAttribute("vnf-name", "fqdn");
128 ctx.setAttribute("INSTAR-KEY-VALUES", json);
129 String instarKey = "V6DefaultGatewayParameter";
130 String instarRes ="{\"vnfConfigurationParameterDetails\":"
131 + "[{\"fqdn\":\"fqdnx\",\"v6DefaultGateway\":\"defaultGatewayV6\"}]}";
132 InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,ctx);
133 impl.processResponse(instarRes, instarKey);
134 String values = ctx.getAttribute("INSTAR-KEY-VALUES");
135 assertTrue(values.contains("defaultGatewayV6"));
139 public void testV4DefaultGateway() {
140 ResponseKey resKey = new ResponseKey();
141 resKey.setUniqueKeyValue("x");
142 resKey.setFieldKeyName(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY);
143 String json ="{\"v4IpAddress\":\"ipAddressV4\"}]}";
144 SvcLogicContext ctx = new SvcLogicContext();
145 ctx.setAttribute("vnf-name", "fqdn");
146 ctx.setAttribute("INSTAR-KEY-VALUES", json);
147 String instarKey = "V4DefaultGatewayParameter";
148 String instarRes ="{\"vnfConfigurationParameterDetails\":"
149 + "[{\"fqdn\":\"fqdnx\",\"v4DefaultGateway\":\"defaultGatewayV4\"}]}";
150 InstarResponseHandlerImpl impl = new InstarResponseHandlerImpl(resKey,ctx);
151 impl.processResponse(instarRes, instarKey);
152 String values = ctx.getAttribute("INSTAR-KEY-VALUES");
153 assertTrue(values.contains("defaultGatewayV4"));