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