2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.champcore.event.envelope;
24 import static org.hamcrest.Matchers.is;
25 import static org.junit.Assert.assertThat;
26 import org.junit.Test;
27 import org.onap.aai.champcore.event.ChampEvent;
28 import org.onap.aai.champcore.model.ChampObject;
29 import org.onap.aai.champcore.model.ChampRelationship;
30 import org.onap.aai.champcore.util.TestUtil;
31 import org.skyscreamer.jsonassert.Customization;
32 import org.skyscreamer.jsonassert.JSONAssert;
33 import org.skyscreamer.jsonassert.JSONCompareMode;
34 import org.skyscreamer.jsonassert.comparator.CustomComparator;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import com.fasterxml.jackson.databind.node.ObjectNode;
38 public class ChampEventEnvelopeTest {
41 public void testVertexEventEnvelopeBodyNoKey() throws Exception {
42 String expectedEnvelope = TestUtil.getFileAsString("event/vertex-event-envelope-no-key.json");
44 ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").build()).build();
46 String envelope = new ChampEventEnvelope(body).toJson();
48 JSONAssert.assertEquals(expectedEnvelope, envelope,
49 new CustomComparator(JSONCompareMode.STRICT, new Customization("header.request-id", (o1, o2) -> true),
50 new Customization("header.timestamp", (o1, o2) -> true),
51 new Customization("body.timestamp", (o1, o2) -> true),
52 new Customization("body.transaction-id", (o1, o2) -> true)));
56 public void testVertexEventEnvelopeBodyWithKey() throws Exception {
57 String expectedEnvelope = TestUtil.getFileAsString("event/vertex-event-envelope-with-key.json");
59 ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").key("1234").build()).build();
61 String envelope = new ChampEventEnvelope(body).toJson();
63 JSONAssert.assertEquals(expectedEnvelope, envelope,
64 new CustomComparator(JSONCompareMode.STRICT, new Customization("header.request-id", (o1, o2) -> true),
65 new Customization("header.timestamp", (o1, o2) -> true),
66 new Customization("body.timestamp", (o1, o2) -> true),
67 new Customization("body.transaction-id", (o1, o2) -> true)));
72 public void testRequestIdIsTransactionId() throws Exception {
73 ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").build()).build();
75 ChampEventEnvelope envelope = new ChampEventEnvelope(body);
77 assertThat(envelope.getHeader().getRequestId(), is(envelope.getBody().getTransactionId()));
81 public void testEdgeEventEnvelope() throws Exception {
82 String expectedEnvelope = TestUtil.getFileAsString("event/edge-event-envelope.json");
84 ObjectMapper mapper = new ObjectMapper();
85 ObjectNode objectNode = mapper.createObjectNode();
86 objectNode.put("inVertexId", 5678);
87 objectNode.put("typeId", 1000);
88 objectNode.put("relationId", 2000);
89 objectNode.put("outVertexId", 1234);
91 ChampRelationship relationship =
92 new ChampRelationship.Builder(new ChampObject.Builder("vserver").key("1234").build(),
93 new ChampObject.Builder("pserver").key("5678").build(), "test").key(objectNode).build();
94 ChampEvent body = ChampEvent.builder().entity(relationship).build();
96 String envelope = new ChampEventEnvelope(body).toJson();
98 JSONAssert.assertEquals(expectedEnvelope, envelope,
99 new CustomComparator(JSONCompareMode.STRICT, new Customization("header.request-id", (o1, o2) -> true),
100 new Customization("header.timestamp", (o1, o2) -> true),
101 new Customization("body.timestamp", (o1, o2) -> true),
102 new Customization("body.transaction-id", (o1, o2) -> true)));