2067ab439af704fe03fe989aa32aaf2bfa8d4da2
[aai/champ.git] / champ-lib / champ-core / src / test / java / org / onap / aai / champcore / event / envelope / ChampEventEnvelopeTest.java
1 /**
2  * ============LICENSE_START==========================================
3  * org.onap.aai
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
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.champcore.event.envelope;
23
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;
34
35 public class ChampEventEnvelopeTest {
36
37     @Test
38     public void testEventEnvelopeBodyNoKey() throws Exception {
39         String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-no-key.json");
40
41         ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").build()).build();
42
43         String envelope = new ChampEventEnvelope(body).toJson();
44
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)));
50     }
51
52     @Test
53     public void testEventEnvelopeBodyWithKey() throws Exception {
54         String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-with-key.json");
55
56         ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").key("1234").build()).build();
57
58         String envelope = new ChampEventEnvelope(body).toJson();
59
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)));
65     }
66
67
68     @Test
69     public void testRequestIdIsTransactionId() throws Exception {
70         ChampEvent body = ChampEvent.builder().entity(new ChampObject.Builder("pserver").build()).build();
71
72         ChampEventEnvelope envelope = new ChampEventEnvelope(body);
73
74         assertThat(envelope.getHeader().getRequestId(), is(envelope.getBody().getTransactionId()));
75     }
76 }