2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcae.common.model;
22 import org.assertj.core.api.Assertions;
23 import org.json.JSONObject;
24 import org.junit.Test;
25 import org.onap.dcae.common.JsonDataLoader;
27 import java.io.IOException;
29 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
31 public class VesEventTest {
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";
39 public void shouldReturnsOriginalDomainForNonStdEvent() throws IOException {
41 final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves7_valid_event.json");
44 Assertions.assertThat(vesEvent.getDomain()).isEqualTo(FAULT_DOMAIN);
45 Assertions.assertThat(vesEvent.getStreamId()).isEqualTo(FAULT_STREAM_ID);
49 public void shouldReturnsDomainStoredInStndDefinedNamespaceParameterForNonStdEvent() throws IOException {
51 final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves_stdnDefined_valid.json");
54 Assertions.assertThat(vesEvent.getDomain()).isEqualTo(STND_DEFINED_DOMAIN);
55 Assertions.assertThat(vesEvent.getStreamId()).isEqualTo(STND_DEFINED_STREAM_ID);
60 public void shouldReportThatStndDefinedNamespaceParameterIsNotDefinedInEvent() throws IOException {
62 final VesEvent vesEvent = createVesEvent(
63 "/eventsAfterTransformation/ves_stdnDefined_missing_namespace_invalid.json"
68 assertThatExceptionOfType(StndDefinedNamespaceParameterNotDefinedException.class)
70 vesEvent.getStreamId();
75 public void shouldReportThatStndDefinedNamespaceParameterHasEmptyValue() throws IOException {
77 final VesEvent vesEvent = createVesEvent(
78 "/eventsAfterTransformation/ves_stdnDefined_empty_namespace_invalid.json"
82 assertThatExceptionOfType(StndDefinedNamespaceParameterHasEmptyValueException.class)
84 vesEvent.getStreamId();
88 private VesEvent createVesEvent(String path) throws IOException {
89 String event = JsonDataLoader.loadContent(path);
90 return new VesEvent(new JSONObject(event));