Increase code coverage
[aai/spike.git] / src / test / java / org / onap / aai / spike / event / incoming / GizmoGraphEventTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.spike.event.incoming;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import java.io.IOException;
26 import java.net.URISyntaxException;
27 import org.junit.Test;
28 import org.onap.aai.spike.event.envelope.EventEnvelopeParser;
29 import org.onap.aai.spike.event.outgoing.SpikeGraphEvent;
30 import org.onap.aai.spike.exception.SpikeException;
31 import org.onap.aai.spike.test.util.TestFileReader;
32
33 public class GizmoGraphEventTest {
34
35     @Test
36     public void TestToSpikeGraphEvent() throws SpikeException, IOException, URISyntaxException {
37         String champNotification =
38                 TestFileReader.getFileAsString("event/champ-update-notification-raw-with-relationship.json");
39
40         GizmoGraphEvent gizmoGraphEvent = new EventEnvelopeParser().parseEvent(champNotification);
41         SpikeGraphEvent spikeGraphEvent = gizmoGraphEvent.toSpikeGraphEvent();
42
43         assertEquals("b9c7d24a-64a5-4b89-a10a-a89ce58b1caa", spikeGraphEvent.getRelationship().getId());
44         assertEquals("537494bd-1e8a-4198-9712-8cefa0f80457", spikeGraphEvent.getRelationship().getSource().getId());
45         assertEquals("981c0494-c742-4d75-851c-8194bbbd8a96", spikeGraphEvent.getRelationship().getTarget().getId());
46     }
47
48     @Test
49     public void TestGetObjectKey() {
50         String objectKey;
51         GizmoGraphEvent gizmoGraphEvent;
52
53         gizmoGraphEvent = new GizmoGraphEvent();
54         GizmoVertex vertex = new GizmoVertex();
55         vertex.setId("addfff68");
56         gizmoGraphEvent.setVertex(vertex);
57         objectKey = gizmoGraphEvent.getObjectKey();
58         assertEquals("addfff68", objectKey);
59
60         gizmoGraphEvent = new GizmoGraphEvent();
61         GizmoEdge relationship = new GizmoEdge();
62         relationship.setId("909d");
63
64         gizmoGraphEvent.setRelationship(relationship);
65         objectKey = gizmoGraphEvent.getObjectKey();
66         assertEquals("909d", objectKey);
67
68         gizmoGraphEvent = new GizmoGraphEvent();
69         objectKey = gizmoGraphEvent.getObjectKey();
70         assertNull(objectKey);
71     }
72
73     @Test
74     public void TestGetObjectType() {
75         String objectType;
76         String type = "pserver";
77         GizmoGraphEvent gizmoGraphEvent;
78
79         gizmoGraphEvent = new GizmoGraphEvent();
80         GizmoVertex vertex = new GizmoVertex();
81         vertex.setType(type);
82         gizmoGraphEvent.setVertex(vertex);
83         objectType = gizmoGraphEvent.getObjectType();
84         assertEquals("Vertex->" + type, objectType);
85
86         gizmoGraphEvent = new GizmoGraphEvent();
87         GizmoEdge relationship = new GizmoEdge();
88         relationship.setType(type);
89
90         gizmoGraphEvent.setRelationship(relationship);
91         objectType = gizmoGraphEvent.getObjectType();
92         assertEquals("Relationship->" + type, objectType);
93
94         gizmoGraphEvent = new GizmoGraphEvent();
95         objectType = gizmoGraphEvent.getObjectType();
96         assertNull(objectType);
97     }
98 }