2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.aai;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
27 import java.nio.file.Files;
28 import java.util.List;
29 import org.junit.Test;
30 import org.onap.policy.aai.util.Serialization;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class AaiGetVnfResponseTest {
35 private static final Logger logger = LoggerFactory.getLogger(AaiGetVnfResponseTest.class);
38 public void test() throws Exception {
39 // deserialize json and verify fields are populated properly
40 String json = new String(Files.readAllBytes(
41 new File("src/test/resources/org/onap/policy/aai/AaiGetVnfResponse.json").toPath()));
43 AaiGetVnfResponse resp = Serialization.gsonPretty.fromJson(json, AaiGetVnfResponse.class);
45 assertEquals("807a3f02-f878-436b-870c-f0e91e81570d", resp.getVnfId());
46 assertEquals("vLoadBalancerMS-Vnf-0809-2", resp.getVnfName());
47 assertEquals("vLoadBalancerMS/vLoadBalancerMS 0", resp.getVnfType());
48 assertEquals("1533850960381", resp.getResourceVersion());
49 assertEquals(false, resp.getInMaint());
50 assertEquals(true, resp.getIsClosedLoopDisabled());
51 assertEquals("53638a85-361a-437d-8830-4b0d5329225e", resp.getModelInvariantId());
52 assertEquals("PROV", resp.getProvStatus());
53 assertEquals("Active", resp.getOrchestrationStatus());
54 assertEquals("50e1b0be-e0c9-48e2-9f42-15279a783ee8", resp.getServiceId());
56 // don't need to verify this in depth, as it has its own tests that do that
57 RelationshipList relationshipList = resp.getRelationshipList();
58 assertNotNull(relationshipList);
60 List<Relationship> lst = relationshipList.getRelationships();
63 assertEquals(5, lst.size());
64 assertEquals("service-instance", lst.get(0).getRelatedTo());
65 assertEquals("line-of-business", lst.get(1).getRelatedTo());
67 logger.info(Serialization.gsonPretty.toJson(resp));
69 // verify that setXxx methods work
70 relationshipList = new RelationshipList();
72 resp.setInMaint(true);
73 resp.setIsClosedLoopDisabled(false);
74 resp.setModelInvariantId("modiv");
75 resp.setOrchestrationStatus("orch");
76 resp.setProvStatus("mystatus");
77 resp.setRelationshipList(relationshipList);
78 resp.setResourceVersion("vers");
79 resp.setServiceId("svc");
80 resp.setVnfId("vnfid");
81 resp.setVnfName("vnfname");
82 resp.setVnfType("vnftype");
84 assertEquals("vnfid", resp.getVnfId());
85 assertEquals("vnfname", resp.getVnfName());
86 assertEquals("vnftype", resp.getVnfType());
87 assertEquals("vers", resp.getResourceVersion());
88 assertEquals(true, resp.getInMaint());
89 assertEquals(false, resp.getIsClosedLoopDisabled());
90 assertEquals("modiv", resp.getModelInvariantId());
91 assertEquals("mystatus", resp.getProvStatus());
92 assertEquals("orch", resp.getOrchestrationStatus());
93 assertEquals("svc", resp.getServiceId());
94 assertEquals(relationshipList, resp.getRelationshipList());
98 json = new String(Files.readAllBytes(
99 new File("src/test/resources/org/onap/policy/aai/AaiGetResponseError.json").toPath()));
100 resp = Serialization.gsonPretty.fromJson(json, AaiGetVnfResponse.class);
102 // don't need to verify this in depth, as it has its own tests that do that
103 assertNotNull(resp.getRequestError());
104 assertNotNull(resp.getRequestError().getServiceExcept());
105 assertEquals("SVC3001", resp.getRequestError().getServiceExcept().getMessageId());