Merge "Fix more sonar issues in models: yaml to dao"
[policy/models.git] / models-interactions / model-impl / aai / src / test / java / org / onap / policy / aai / AaiNqVServerTest.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.assertNotNull;
26
27 import java.io.File;
28 import java.nio.file.Files;
29 import java.util.List;
30 import org.junit.Test;
31 import org.onap.policy.aai.util.Serialization;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class AaiNqVServerTest {
36     private static final Logger logger = LoggerFactory.getLogger(AaiNqVServerTest.class);
37
38     @Test
39     public void test() throws Exception {
40         // deserialize json and verify fields are populated properly
41         String json = new String(Files
42                         .readAllBytes(new File("src/test/resources/org/onap/policy/aai/AaiNqVServer.json").toPath()));
43
44         AaiNqVServer resp = Serialization.gsonPretty.fromJson(json, AaiNqVServer.class);
45
46         assertEquals(false, resp.getInMaint());
47         assertEquals(true, resp.getIsClosedLoopDisabled());
48         assertEquals("ACTIVE", resp.getProvStatus());
49         assertEquals("1533850964910", resp.getResourceVersion());
50         assertEquals("1c94da3f-16f1-4fc7-9ed1-e018dfa62774", resp.getVserverId());
51         assertEquals("vlb-ms-0809-1", resp.getVserverName());
52         assertEquals("vlb-ms-0809-7", resp.getVserverName2());
53         assertEquals("http://localhost:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774",
54                         resp.getVserverSelflink());
55
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);
59
60         List<Relationship> lst = relationshipList.getRelationships();
61         assertNotNull(lst);
62
63         assertEquals(3, lst.size());
64         assertEquals("generic-vnf", lst.get(0).getRelatedTo());
65         assertEquals("image", lst.get(1).getRelatedTo());
66
67         logger.info(Serialization.gsonPretty.toJson(resp));
68
69         // verify that setXxx methods work
70         relationshipList = new RelationshipList();
71
72         resp.setInMaint(true);
73         resp.setIsClosedLoopDisabled(false);
74         resp.setProvStatus("inactive");
75         resp.setRelationshipList(relationshipList);
76         resp.setResourceVersion("vers");
77         resp.setVserverId("vid");
78         resp.setVserverName("vname");
79         resp.setVserverName2("vname2");
80         resp.setVserverSelflink("link");
81
82         assertEquals(true, resp.getInMaint());
83         assertEquals(false, resp.getIsClosedLoopDisabled());
84         assertEquals("inactive", resp.getProvStatus());
85         assertEquals("vers", resp.getResourceVersion());
86         assertEquals("vid", resp.getVserverId());
87         assertEquals("vname", resp.getVserverName());
88         assertEquals("vname2", resp.getVserverName2());
89         assertEquals("link", resp.getVserverSelflink());
90         assertEquals(relationshipList, resp.getRelationshipList());
91     }
92
93 }