3bd563bc44508440a78001282b02f8d07c15f111
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
4  *  ================================================================================
5  *  Copyright (C) 2022 CTC, Inc.
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
22 package org.onap.slice.analysis.ms.models.aai;
23
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.google.gson.JsonArray;
27 import org.apache.commons.lang3.StringUtils;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.powermock.core.classloader.annotations.PowerMockIgnore;
31 import org.powermock.modules.junit4.PowerMockRunner;
32 import org.powermock.modules.junit4.PowerMockRunnerDelegate;
33 import org.springframework.boot.test.context.SpringBootTest;
34 import org.springframework.test.context.junit4.SpringRunner;
35
36 import com.google.gson.JsonObject;
37
38 import static org.junit.jupiter.api.Assertions.assertEquals;
39 import static org.junit.jupiter.api.Assertions.assertTrue;
40
41 @RunWith(PowerMockRunner.class)
42 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
43 @PowerMockRunnerDelegate(SpringRunner.class)
44 @SpringBootTest(classes = RelationshipTest.class)
45 public class RelationshipTest {
46
47     @Test
48     public void RelationshipTest() throws JsonProcessingException {
49         JsonObject jsonObject = new JsonObject();
50         jsonObject.addProperty("related-to", "related-to");
51         jsonObject.addProperty("relationship-label", "relationship-label");
52         jsonObject.addProperty("related-link", "related-link");
53
54         JsonArray relationshipData = new JsonArray();
55         JsonObject relationshipDataObj = new JsonObject();
56         relationshipDataObj.addProperty("a","1");
57         relationshipData.add(relationshipDataObj);
58         JsonArray relatedToProperty = new JsonArray();
59         JsonObject relatedToPropertyObj = new JsonObject();
60         relatedToPropertyObj.addProperty("a","1");
61         relatedToProperty.add(relatedToPropertyObj);
62
63         jsonObject.add("relationship-data", relationshipData);
64         jsonObject.add("related-to-property", relatedToProperty);
65
66         Relationship relationship = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
67         assertEquals("related-to", relationship.getRelatedTo());
68         assertEquals("relationship-label", relationship.getRelationshipLabel());
69         assertEquals("related-link", relationship.getRelatedLink());
70         assertEquals(1, relationship.getRelationshipData().size());
71         assertEquals(1, relationship.getRelatedToProperty().size());
72     }
73
74     @Test
75     public void RelationshipEqualsTest() throws JsonProcessingException {
76         JsonObject jsonObject = new JsonObject();
77         jsonObject.addProperty("related-to", "related-to");
78         jsonObject.addProperty("relationship-label", "relationship-label");
79         jsonObject.addProperty("related-link", "related-link");
80
81         JsonArray relationshipData = new JsonArray();
82         JsonObject relationshipDataObj = new JsonObject();
83         relationshipDataObj.addProperty("a","1");
84         relationshipData.add(relationshipDataObj);
85         JsonArray relatedToProperty = new JsonArray();
86         JsonObject relatedToPropertyObj = new JsonObject();
87         relatedToPropertyObj.addProperty("a","1");
88         relatedToProperty.add(relatedToPropertyObj);
89
90         jsonObject.add("relationship-data", relationshipData);
91         jsonObject.add("related-to-property", relatedToProperty);
92
93         Relationship relationship = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
94         Relationship relationship1 = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
95
96         assertTrue(relationship1.equals(relationship));
97         assertTrue(StringUtils.isNotBlank(relationship1.toString()));
98
99     }
100 }