5e7640f6ad39bf1280fc1c401d4afe35f623ff7b
[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 java.util.ArrayList;
39 import java.util.List;
40
41 import static org.junit.jupiter.api.Assertions.assertEquals;
42 import static org.junit.jupiter.api.Assertions.assertTrue;
43
44 @RunWith(PowerMockRunner.class)
45 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
46 @PowerMockRunnerDelegate(SpringRunner.class)
47 @SpringBootTest(classes = RelationshipListTest.class)
48 public class RelationshipListTest {
49
50     @Test
51     public void RelationshipListTest() throws JsonProcessingException {
52         JsonObject jsonObject = new JsonObject();
53         jsonObject.addProperty("related-to", "related-to");
54         jsonObject.addProperty("relationship-label", "relationship-label");
55         jsonObject.addProperty("related-link", "related-link");
56
57         JsonArray relationshipData = new JsonArray();
58         JsonObject relationshipDataObj = new JsonObject();
59         relationshipDataObj.addProperty("a","1");
60         relationshipData.add(relationshipDataObj);
61         JsonArray relatedToProperty = new JsonArray();
62         JsonObject relatedToPropertyObj = new JsonObject();
63         relatedToPropertyObj.addProperty("a","1");
64         relatedToProperty.add(relatedToPropertyObj);
65
66         jsonObject.add("relationship-data", relationshipData);
67         jsonObject.add("related-to-property", relatedToProperty);
68
69         Relationship relationship = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
70
71         List<Relationship> relationships = new ArrayList<>();
72         relationships.add(relationship);
73
74         RelationshipList relationshipList = new RelationshipList();
75         relationshipList.setRelationship(relationships);
76
77         assertEquals(1, relationshipList.getRelationship().size());
78     }
79
80     @Test
81     public void RelationshipListEqualsTest() throws JsonProcessingException {
82         JsonObject jsonObject = new JsonObject();
83         jsonObject.addProperty("related-to", "related-to");
84         jsonObject.addProperty("relationship-label", "relationship-label");
85         jsonObject.addProperty("related-link", "related-link");
86
87         JsonArray relationshipData = new JsonArray();
88         JsonObject relationshipDataObj = new JsonObject();
89         relationshipDataObj.addProperty("a","1");
90         relationshipData.add(relationshipDataObj);
91         JsonArray relatedToProperty = new JsonArray();
92         JsonObject relatedToPropertyObj = new JsonObject();
93         relatedToPropertyObj.addProperty("a","1");
94         relatedToProperty.add(relatedToPropertyObj);
95
96         jsonObject.add("relationship-data", relationshipData);
97         jsonObject.add("related-to-property", relatedToProperty);
98
99         Relationship relationship = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
100
101         List<Relationship> relationships = new ArrayList<>();
102         relationships.add(relationship);
103
104         RelationshipList relationshipList = new RelationshipList();
105         relationshipList.setRelationship(relationships);
106
107         RelationshipList relationshipList1 = new RelationshipList();
108         relationshipList1.setRelationship(relationships);
109
110         assertTrue(relationshipList1.equals(relationshipList));
111         assertTrue(StringUtils.isNotBlank(relationshipList.toString()));
112     }
113 }