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.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 ChampEventEnvelopeTest {
38 public void testEventEnvelopeBodyNoKey() throws Exception {
39 String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-no-key.json");
41 ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").build()).build();
43 String envelope = new ChampEventEnvelope(body).toJson();
45 JSONAssert.assertEquals(expectedEnvelope, envelope,
46 new CustomComparator(JSONCompareMode.STRICT, new Customization("header.request-id", (o1, o2) -> true),
47 new Customization("header.timestamp", (o1, o2) -> true),
48 new Customization("body.timestamp", (o1, o2) -> true),
49 new Customization("body.transaction-id", (o1, o2) -> true)));
53 public void testEventEnvelopeBodyWithKey() throws Exception {
54 String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-with-key.json");
56 ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").key("1234").build()).build();
58 String envelope = new ChampEventEnvelope(body).toJson();
60 JSONAssert.assertEquals(expectedEnvelope, envelope,
61 new CustomComparator(JSONCompareMode.STRICT, new Customization("header.request-id", (o1, o2) -> true),
62 new Customization("header.timestamp", (o1, o2) -> true),
63 new Customization("body.timestamp", (o1, o2) -> true),
64 new Customization("body.transaction-id", (o1, o2) -> true)));
69 public void testRequestIdIsTransactionId() throws Exception {
70 ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").build()).build();
72 ChampEventEnvelope envelope = new ChampEventEnvelope(body);
74 assertThat(envelope.getHeader().getRequestId(), is(envelope.getBody().getTransactionId()));