e1b6123705ab7404e68ac2600bc9fc8e19acc6cc
[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.AfterClass;
31 import org.junit.BeforeClass;
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 AaiNqVServerTest {
38     private static final Logger logger = LoggerFactory.getLogger(AaiNqVServerTest.class);
39
40
41     @BeforeClass
42     public static void setUpBeforeClass() throws Exception {}
43
44     @AfterClass
45     public static void tearDownAfterClass() throws Exception {}
46
47     @Test
48     public void test() throws Exception {
49         // deserialize json and verify fields are populated properly
50         String json = new String(Files
51                         .readAllBytes(new File("src/test/resources/org/onap/policy/aai/AaiNqVServer.json").toPath()));
52
53         AaiNqVServer resp = Serialization.gsonPretty.fromJson(json, AaiNqVServer.class);
54
55         assertEquals(false, resp.getInMaint());
56         assertEquals(true, resp.getIsClosedLoopDisabled());
57         assertEquals("ACTIVE", resp.getProvStatus());
58         assertEquals("1533850964910", resp.getResourceVersion());
59         assertEquals("1c94da3f-16f1-4fc7-9ed1-e018dfa62774", resp.getVserverId());
60         assertEquals("vlb-ms-0809-1", resp.getVserverName());
61         assertEquals("vlb-ms-0809-7", resp.getVserverName2());
62         assertEquals("http://localhost:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774",
63                         resp.getVserverSelflink());
64
65         // don't need to verify this in depth, as it has its own tests that do that
66         RelationshipList relationshipList = resp.getRelationshipList();
67         assertNotNull(relationshipList);
68
69         List<Relationship> lst = relationshipList.getRelationships();
70         assertNotNull(lst);
71
72         assertEquals(3, lst.size());
73         assertEquals("generic-vnf", lst.get(0).getRelatedTo());
74         assertEquals("image", lst.get(1).getRelatedTo());
75
76         logger.info(Serialization.gsonPretty.toJson(resp));
77
78         // verify that setXxx methods work
79         relationshipList = new RelationshipList();
80
81         resp.setInMaint(true);
82         resp.setIsClosedLoopDisabled(false);
83         resp.setProvStatus("inactive");
84         resp.setRelationshipList(relationshipList);
85         resp.setResourceVersion("vers");
86         resp.setVserverId("vid");
87         resp.setVserverName("vname");
88         resp.setVserverName2("vname2");
89         resp.setVserverSelflink("link");
90
91         assertEquals(true, resp.getInMaint());
92         assertEquals(false, resp.getIsClosedLoopDisabled());
93         assertEquals("inactive", resp.getProvStatus());
94         assertEquals("vers", resp.getResourceVersion());
95         assertEquals("vid", resp.getVserverId());
96         assertEquals("vname", resp.getVserverName());
97         assertEquals("vname2", resp.getVserverName2());
98         assertEquals("link", resp.getVserverSelflink());
99         assertEquals(relationshipList, resp.getRelationshipList());
100     }
101
102 }