1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 *******************************************************************************/
22 package org.onap.slice.analysis.ms.models.aai;
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;
36 import com.google.gson.JsonObject;
38 import java.util.ArrayList;
39 import java.util.List;
41 import static org.junit.jupiter.api.Assertions.assertEquals;
42 import static org.junit.jupiter.api.Assertions.assertTrue;
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 {
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");
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);
66 jsonObject.add("relationship-data", relationshipData);
67 jsonObject.add("related-to-property", relatedToProperty);
69 Relationship relationship = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
71 List<Relationship> relationships = new ArrayList<>();
72 relationships.add(relationship);
74 RelationshipList relationshipList = new RelationshipList();
75 relationshipList.setRelationship(relationships);
77 assertEquals(1, relationshipList.getRelationship().size());
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");
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);
96 jsonObject.add("relationship-data", relationshipData);
97 jsonObject.add("related-to-property", relatedToProperty);
99 Relationship relationship = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
101 List<Relationship> relationships = new ArrayList<>();
102 relationships.add(relationship);
104 RelationshipList relationshipList = new RelationshipList();
105 relationshipList.setRelationship(relationships);
107 RelationshipList relationshipList1 = new RelationshipList();
108 relationshipList1.setRelationship(relationships);
110 assertTrue(relationshipList1.equals(relationshipList));
111 assertTrue(StringUtils.isNotBlank(relationshipList.toString()));