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 static org.junit.jupiter.api.Assertions.assertEquals;
39 import static org.junit.jupiter.api.Assertions.assertTrue;
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 {
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");
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);
63 jsonObject.add("relationship-data", relationshipData);
64 jsonObject.add("related-to-property", relatedToProperty);
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());
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");
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);
90 jsonObject.add("relationship-data", relationshipData);
91 jsonObject.add("related-to-property", relatedToProperty);
93 Relationship relationship = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
94 Relationship relationship1 = new ObjectMapper().readValue(jsonObject.toString(), Relationship.class);
96 assertTrue(relationship1.equals(relationship));
97 assertTrue(StringUtils.isNotBlank(relationship1.toString()));