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