2 * ============LICENSE_START=======================================================
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
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.dcae.common.model;
23 import org.assertj.core.api.Assertions;
24 import org.json.JSONObject;
25 import org.junit.Test;
26 import org.onap.dcae.common.JsonDataLoader;
28 import java.io.IOException;
29 import java.net.URISyntaxException;
31 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
33 public class VesEventTest {
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";
41 public void shouldReturnsOriginalDomainForNonStdEvent() throws IOException, URISyntaxException {
43 final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves7_valid_event.json");
46 Assertions.assertThat(vesEvent.getDomain()).isEqualTo(FAULT_DOMAIN);
47 Assertions.assertThat(vesEvent.getStreamId()).isEqualTo(FAULT_STREAM_ID);
51 public void shouldReturnsDomainStoredInStndDefinedNamespaceParameterForNonStdEvent() throws IOException, URISyntaxException {
53 final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves_stdnDefined_valid.json");
56 Assertions.assertThat(vesEvent.getDomain()).isEqualTo(STND_DEFINED_DOMAIN);
57 Assertions.assertThat(vesEvent.getStreamId()).isEqualTo(STND_DEFINED_STREAM_ID);
62 public void shouldReportThatStndDefinedNamespaceParameterIsNotDefinedInEvent() throws IOException, URISyntaxException {
64 final VesEvent vesEvent = createVesEvent(
65 "/eventsAfterTransformation/ves_stdnDefined_missing_namespace_invalid.json"
70 assertThatExceptionOfType(StndDefinedNamespaceParameterNotDefinedException.class)
72 vesEvent.getStreamId();
77 public void shouldReportThatStndDefinedNamespaceParameterHasEmptyValue() throws IOException, URISyntaxException {
79 final VesEvent vesEvent = createVesEvent(
80 "/eventsAfterTransformation/ves_stdnDefined_empty_namespace_invalid.json"
84 assertThatExceptionOfType(StndDefinedNamespaceParameterHasEmptyValueException.class)
86 vesEvent.getStreamId();
90 private VesEvent createVesEvent(String path) throws IOException, URISyntaxException {
91 String event = JsonDataLoader.loadContent(path);
92 return new VesEvent(new JSONObject(event));