c66e0a9b058b17069b26798a023def76f6579fb2
[dcaegen2/collectors/ves.git] / src / test / java / org / onap / dcae / common / model / VesEventTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * VES Collector
4  * ================================================================================
5  * Copyright (C) 2020 Nokia. All rights reserved.s
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.dcae.common.model;
21
22 import org.assertj.core.api.Assertions;
23 import org.json.JSONObject;
24 import org.junit.Test;
25 import org.onap.dcae.common.JsonDataLoader;
26
27 import java.io.IOException;
28
29 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
30
31 public class VesEventTest {
32
33     private static final String FAULT_DOMAIN = "fault";
34     private static final String FAULT_STREAM_ID = "fault";
35     private static final String STND_DEFINED_DOMAIN = "stndDefined";
36   private static final String STND_DEFINED_STREAM_ID = "3GPP-FaultSupervision";
37
38     @Test
39     public void shouldReturnsOriginalDomainForNonStdEvent() throws IOException {
40         // given
41         final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves7_valid_event.json");
42
43         // when/then
44         Assertions.assertThat(vesEvent.getDomain()).isEqualTo(FAULT_DOMAIN);
45         Assertions.assertThat(vesEvent.getStreamId()).isEqualTo(FAULT_STREAM_ID);
46     }
47
48     @Test
49     public void shouldReturnsDomainStoredInStndDefinedNamespaceParameterForNonStdEvent() throws IOException {
50         // given
51         final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves_stdnDefined_valid.json");
52
53         // when/then
54         Assertions.assertThat(vesEvent.getDomain()).isEqualTo(STND_DEFINED_DOMAIN);
55         Assertions.assertThat(vesEvent.getStreamId()).isEqualTo(STND_DEFINED_STREAM_ID);
56     }
57
58
59     @Test
60     public void shouldReportThatStndDefinedNamespaceParameterIsNotDefinedInEvent() throws IOException {
61         // given
62         final VesEvent vesEvent = createVesEvent(
63                 "/eventsAfterTransformation/ves_stdnDefined_missing_namespace_invalid.json"
64         );
65
66         // when/then
67         // when
68         assertThatExceptionOfType(StndDefinedNamespaceParameterNotDefinedException.class)
69                 .isThrownBy(() -> {
70                     vesEvent.getStreamId();
71                 });
72     }
73
74     @Test
75     public void shouldReportThatStndDefinedNamespaceParameterHasEmptyValue() throws IOException {
76         // given
77         final VesEvent vesEvent = createVesEvent(
78                 "/eventsAfterTransformation/ves_stdnDefined_empty_namespace_invalid.json"
79         );
80
81         // when/then
82         assertThatExceptionOfType(StndDefinedNamespaceParameterHasEmptyValueException.class)
83                 .isThrownBy(() -> {
84                     vesEvent.getStreamId();
85                 });
86     }
87
88     private VesEvent createVesEvent(String path) throws IOException {
89         String event = JsonDataLoader.loadContent(path);
90         return new VesEvent(new JSONObject(event));
91     }
92 }