2 * Copyright 2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.holmes.common.aai;
20 import static org.hamcrest.core.IsEqual.equalTo;
21 import static org.junit.Assert.assertThat;
23 import java.io.IOException;
24 import java.util.List;
25 import org.junit.Before;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.ExpectedException;
29 import org.onap.holmes.common.aai.entity.VmEntity;
30 import org.onap.holmes.common.aai.entity.VmResourceLink;
31 import org.onap.holmes.common.aai.entity.VnfEntity;
32 import org.powermock.core.classloader.annotations.PrepareForTest;
34 @PrepareForTest(AaiResponseUtil.class)
35 public class AaiResponseUtilTest {
38 public ExpectedException thrown = ExpectedException.none();
40 private AaiResponseUtil aaiResponseUtil;
44 aaiResponseUtil = new AaiResponseUtil();
48 public void testAaiResponseUtil_convert_resouce_link_success() throws IOException {
50 + "\"result-data\": ["
52 + "\"resource-link\": \"/aai/example-vserver-id-val-2\","
53 + "\"resource-type\": \"vserver\""
56 + "\"resource-link\": \"/111aai/example-vserver-id-val-2\","
57 + "\"resource-type\": \"111vserver\""
62 List<VmResourceLink> actual = aaiResponseUtil.convertJsonToVmResourceLink(json);
64 assertThat(actual.get(0).getResourceLink(), equalTo("/aai/example-vserver-id-val-2"));
65 assertThat(actual.get(0).getResourceType(), equalTo("vserver"));
66 assertThat(actual.get(1).getResourceLink(), equalTo("/111aai/example-vserver-id-val-2"));
67 assertThat(actual.get(1).getResourceType(), equalTo("111vserver"));
71 public void testAaiResponseUtil_convert_resource_link_input_empty_array() throws IOException {
73 + "\"result-data\": ["
76 List<VmResourceLink> actual = aaiResponseUtil.convertJsonToVmResourceLink(json);
77 assertThat(actual.isEmpty(), equalTo(true));
81 public void testAaiResponseUtil_convert_resource_link_input_empty() throws IOException {
83 List<VmResourceLink> actual = aaiResponseUtil.convertJsonToVmResourceLink(json);
84 assertThat(actual.isEmpty(), equalTo(true));
88 public void testAaiResponseUtil_convert_resource_link_input_error() throws IOException {
90 + "\"result-data\": ["
92 + "\"resource-link1\": \"/aai/example-vserver-id-val-2\","
93 + "\"resource-type\": \"vserver\""
96 + "\"resource-link\": \"/111aai/example-vserver-id-val-2\","
97 + "\"resource-type\": \"111vserver\""
101 List<VmResourceLink> actual = aaiResponseUtil.convertJsonToVmResourceLink(json);
102 assertThat(actual.size(), equalTo(1));
103 assertThat(actual.get(0).getResourceType(), equalTo("111vserver"));
107 public void testAaiResponseUtil_convert_resource_link_input_error1() throws IOException {
109 + "\"result-data1\": ["
112 List<VmResourceLink> actual = aaiResponseUtil.convertJsonToVmResourceLink(json);
113 assertThat(actual.isEmpty(), equalTo(true));
118 public void testAaiResponseUtil_convert_VmEntity_success() throws IOException {
120 + "\"in-maint\": true,"
121 + "\"is-closed-loop-disabled\": true,"
122 + "\"prov-status\": \"example-prov-status-val-2\","
123 + "\"resource-version\": \"1504912891060\","
124 + "\"vserver-id\": \"example-vserver-id-val-2\","
125 + "\"vserver-name\": \"example-vserver-name-val-2\","
126 + "\"vserver-name2\": \"example-vserver-name2-val-2\","
127 + "\"vserver-selflink\": \"example-vserver-selflink-val-2\""
129 VmEntity actual = aaiResponseUtil.convertJsonToVmEntity(json);
130 assertThat(actual.getInMaint(), equalTo(true));
131 assertThat(actual.getClosedLoopDisable(), equalTo(true));
132 assertThat(actual.getProvStatus(), equalTo("example-prov-status-val-2"));
133 assertThat(actual.getResourceVersion(), equalTo("1504912891060"));
134 assertThat(actual.getVserverId(), equalTo("example-vserver-id-val-2"));
135 assertThat(actual.getVserverName(), equalTo("example-vserver-name-val-2"));
136 assertThat(actual.getVserverName2(), equalTo("example-vserver-name2-val-2"));
137 assertThat(actual.getVserverSelflink(), equalTo("example-vserver-selflink-val-2"));
142 public void testAaiResponseUtil_convert_VmEntity_input_empty() throws IOException {
144 VmEntity actual = aaiResponseUtil.convertJsonToVmEntity(json);
145 assertThat(actual == null, equalTo(true));
149 public void testAaiResponseUtil_convert_VmEntity_input_error() throws IOException {
151 + "\"in-maint1\": true,"
152 + "\"is-closed-loop-disabled\": true,"
153 + "\"prov-status\": \"example-prov-status-val-2\","
154 + "\"resource-version\": \"1504912891060\","
155 + "\"vserver-id\": \"example-vserver-id-val-2\","
156 + "\"vserver-name\": \"example-vserver-name-val-2\","
157 + "\"vserver-name2\": \"example-vserver-name2-val-2\","
158 + "\"vserver-selflink\": \"example-vserver-selflink-val-2\""
160 VmEntity actual = aaiResponseUtil.convertJsonToVmEntity(json);
161 assertThat(actual.getInMaint() == null, equalTo(true));
162 assertThat(actual.getClosedLoopDisable(), equalTo(true));
163 assertThat(actual.getProvStatus(), equalTo("example-prov-status-val-2"));
164 assertThat(actual.getResourceVersion(), equalTo("1504912891060"));
165 assertThat(actual.getVserverId(), equalTo("example-vserver-id-val-2"));
166 assertThat(actual.getVserverName(), equalTo("example-vserver-name-val-2"));
167 assertThat(actual.getVserverName2(), equalTo("example-vserver-name2-val-2"));
168 assertThat(actual.getVserverSelflink(), equalTo("example-vserver-selflink-val-2"));
172 public void testAaiResponseUtil_convert_success() throws IOException {
174 + "\"in-maint\":false,"
175 + "\"relationship-list\":{"
176 + "\"relationship\":["
178 + "\"related-link\":\"/aai/v11/e8fe\","
179 + "\"related-to\":\"service-instance\","
180 + "\"related-to-property\":["
182 + "\"property-key\":\"service-i\","
183 + "\"property-value\":\"vCPEInfraSI13\""
186 + "\"relationship-data\":["
188 + "\"relationship-key\":\"custome\","
189 + "\"relationship-value\":\"Demonstration3\""
196 VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
198 assertThat(actual.getInMaint(), equalTo(false));
199 assertThat(actual.getRelationshipList().getRelationships().get(0).getRelatedLink(),
200 equalTo("/aai/v11/e8fe"));
201 assertThat(actual.getRelationshipList().getRelationships().get(0).getRelatedTo(),
202 equalTo("service-instance"));
203 assertThat(actual.getRelationshipList().getRelationships().get(0).getRelatedToPropertyList()
204 .get(0).getPropertyKey(), equalTo("service-i"));
205 assertThat(actual.getRelationshipList().getRelationships().get(0).getRelatedToPropertyList()
206 .get(0).getPropertyValue(), equalTo("vCPEInfraSI13"));
207 assertThat(actual.getRelationshipList().getRelationships().get(0).getRelationshipDataList().get(0)
208 .getRelationshipKey(), equalTo("custome"));
209 assertThat(actual.getRelationshipList().getRelationships().get(0).getRelationshipDataList().get(0)
210 .getRelationshipValue(), equalTo("Demonstration3"));
214 public void testAaiResponseUtil_convert_VnfEntity_input_empty() throws IOException {
216 VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
217 assertThat(actual == null, equalTo(true));
221 public void testAaiResponseUtil_convert_input_not_include_relationship_list() throws IOException {
223 + "\"in-maint\":false,"
224 + "\"vnf-type\":\"vCPEInfraService10/vCPEInfraService10 0\""
226 VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
227 assertThat(actual.getRelationshipList().getRelationships().isEmpty(), equalTo(true));
231 public void testAaiResponseUtil_convert_input_not_include_relationship() throws IOException {
233 + "\"in-maint\":false,"
234 + "\"is-closed-loop-disabled\":false,"
235 + "\"relationship-list\":{"
237 + "\"service-id\":\"e8cb8968-5411-478b-906a-f28747de72cd\""
239 VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
240 assertThat(actual.getRelationshipList().getRelationships().isEmpty(), equalTo(true));
244 public void testAaiResponseUtil_convert_input_relationship_empty() throws IOException {
246 + "\"in-maint\":false,"
247 + "\"relationship-list\":{"
248 + "\"relationship\":["
251 + "\"vnf-type\":\"vCPEInfraService10/vCPEInfraService10 0\""
253 VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
254 assertThat(actual.getRelationshipList().getRelationships().isEmpty(), equalTo(true));
258 public void testAaiResponseUtil_convert_input_not_include_related_to_property() throws IOException {
260 + "\"in-maint\":false,"
261 + "\"relationship-list\":{"
262 + "\"relationship\":["
264 + "\"related-link\":\"/aai/6\","
265 + "\"related-to\":\"service-instance\","
266 + "\"relationship-data\":["
268 + "\"relationship-key\":\"service-instance.service-instance-id\","
269 + "\"relationship-value\":\"e8feceb6-28ae-480a-bfbc-1985ce333526\""
275 + "\"vnf-type\":\"vCPEInfraSe0\""
277 VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
278 assertThat(actual.getRelationshipList().getRelationships().get(0).getRelatedToPropertyList()
279 .isEmpty(), equalTo(true));
283 public void testAaiResponseUtil_convert_input_related_to_property_empty() throws IOException {
285 + "\"in-maint\":false,"
286 + "\"relationship-list\":{"
287 + "\"relationship\":["
289 + "\"related-link\":\"/aai/3526\","
290 + "\"related-to\":\"service-instance\","
291 + "\"related-to-property\":["
293 + "\"relationship-data\":["
295 + "\"relationship-key\":\"servicnce-id\","
296 + "\"relationship-value\":\"e8feceb6-28a6\""
302 + "\"vnf-type\":\"vCPEce10\""
304 VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
305 assertThat(actual.getRelationshipList().getRelationships().get(0).getRelatedToPropertyList()
306 .isEmpty(), equalTo(true));