2 * ============LICENSE_START==========================================
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
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============================================
21 package org.onap.champ.event;
23 import static org.hamcrest.Matchers.is;
24 import static org.junit.Assert.assertThat;
25 import org.junit.Test;
26 import org.onap.aai.champcore.model.ChampObject;
27 import org.onap.champ.event.GraphEvent.GraphEventOperation;
28 import org.onap.champ.event.envelope.GraphEventEnvelope;
29 import org.onap.champ.util.TestUtil;
30 import org.skyscreamer.jsonassert.Customization;
31 import org.skyscreamer.jsonassert.JSONAssert;
32 import org.skyscreamer.jsonassert.JSONCompareMode;
33 import org.skyscreamer.jsonassert.comparator.CustomComparator;
35 public class GraphEventEnvelopeTest {
38 public void testEventEnvelopeFormat() throws Exception {
39 String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope.json");
41 GraphEvent body = GraphEvent.builder(GraphEventOperation.CREATE)
42 .vertex(GraphEventVertex.fromChampObject(new ChampObject.Builder("pserver").build(), "v13")).build();
44 String graphEventEnvelope = new GraphEventEnvelope(body).toJson();
46 JSONAssert.assertEquals(expectedEnvelope, graphEventEnvelope,
47 new CustomComparator(JSONCompareMode.STRICT, new Customization("header.request-id", (o1, o2) -> true),
48 new Customization("header.timestamp", (o1, o2) -> true),
49 new Customization("body.timestamp", (o1, o2) -> true),
50 new Customization("body.transaction-id", (o1, o2) -> true)));
54 public void testRequestIdIsTransactionId() throws Exception {
55 GraphEvent body = GraphEvent.builder(GraphEventOperation.CREATE)
56 .vertex(GraphEventVertex.fromChampObject(new ChampObject.Builder("pserver").build(), "v13")).build();
58 GraphEventEnvelope envelope = new GraphEventEnvelope(body);
60 assertThat(envelope.getHeader().getRequestId(), is(envelope.getBody().getTransactionId()));