VESCollector Test optimization
[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.
6  * Copyright (C) 2023 AT&T Intellectual Property. All rights reserved.
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  */
21 package org.onap.dcae.common.model;
22
23 import org.assertj.core.api.Assertions;
24 import org.json.JSONObject;
25 import org.junit.Test;
26 import org.onap.dcae.common.JsonDataLoader;
27
28 import java.io.IOException;
29 import java.net.URISyntaxException;
30
31 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
32
33 public class VesEventTest {
34
35     private static final String FAULT_DOMAIN = "fault";
36     private static final String FAULT_STREAM_ID = "fault";
37     private static final String STND_DEFINED_DOMAIN = "stndDefined";
38   private static final String STND_DEFINED_STREAM_ID = "3GPP-FaultSupervision";
39
40     @Test
41     public void shouldReturnsOriginalDomainForNonStdEvent() throws IOException, URISyntaxException {
42         // given
43         final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves7_valid_event.json");
44
45         // when/then
46         Assertions.assertThat(vesEvent.getDomain()).isEqualTo(FAULT_DOMAIN);
47         Assertions.assertThat(vesEvent.getStreamId()).isEqualTo(FAULT_STREAM_ID);
48     }
49
50     @Test
51     public void shouldReturnsDomainStoredInStndDefinedNamespaceParameterForNonStdEvent() throws IOException, URISyntaxException {
52         // given
53         final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves_stdnDefined_valid.json");
54
55         // when/then
56         Assertions.assertThat(vesEvent.getDomain()).isEqualTo(STND_DEFINED_DOMAIN);
57         Assertions.assertThat(vesEvent.getStreamId()).isEqualTo(STND_DEFINED_STREAM_ID);
58     }
59
60
61     @Test
62     public void shouldReportThatStndDefinedNamespaceParameterIsNotDefinedInEvent() throws IOException, URISyntaxException {
63         // given
64         final VesEvent vesEvent = createVesEvent(
65                 "/eventsAfterTransformation/ves_stdnDefined_missing_namespace_invalid.json"
66         );
67
68         // when/then
69         // when
70         assertThatExceptionOfType(StndDefinedNamespaceParameterNotDefinedException.class)
71                 .isThrownBy(() -> {
72                     vesEvent.getStreamId();
73                 });
74     }
75
76     @Test
77     public void shouldReportThatStndDefinedNamespaceParameterHasEmptyValue() throws IOException, URISyntaxException {
78         // given
79         final VesEvent vesEvent = createVesEvent(
80                 "/eventsAfterTransformation/ves_stdnDefined_empty_namespace_invalid.json"
81         );
82
83         // when/then
84         assertThatExceptionOfType(StndDefinedNamespaceParameterHasEmptyValueException.class)
85                 .isThrownBy(() -> {
86                     vesEvent.getStreamId();
87                 });
88     }
89
90     private VesEvent createVesEvent(String path) throws IOException, URISyntaxException {
91         String event = JsonDataLoader.loadContent(path);
92         return new VesEvent(new JSONObject(event));
93     }
94 }