From a58f199454d965305e68c8f7e2d41bf469ec9fc8 Mon Sep 17 00:00:00 2001 From: edyta Date: Wed, 1 Jul 2020 11:09:37 +0200 Subject: Update VES Collector schema and properties Issue-ID: DCAEGEN2-2254 Signed-off-by: Edyta Krukowska Change-Id: I6b89f4bc8ff0c2a9e51e94dc7d464608a7c153f2 --- src/test/java/org/onap/dcae/FileReader.java | 48 +++++++++++++++++++ .../org/onap/dcae/restapi/EventValidatorTest.java | 56 +++++++++++++++++++++- .../onap/dcae/restapi/VesRestControllerTest.java | 2 +- src/test/resources/testcollector.properties | 2 +- src/test/resources/ves7_invalid.json | 34 ------------- src/test/resources/ves7_invalid_30_1_1_event.json | 34 +++++++++++++ src/test/resources/ves7_valid.json | 34 ------------- src/test/resources/ves7_valid_30_1_1_event.json | 34 +++++++++++++ .../ves7_valid_eventWithStndDefinedFields.json | 49 +++++++++++++++++++ 9 files changed, 221 insertions(+), 72 deletions(-) create mode 100644 src/test/java/org/onap/dcae/FileReader.java delete mode 100644 src/test/resources/ves7_invalid.json create mode 100644 src/test/resources/ves7_invalid_30_1_1_event.json delete mode 100644 src/test/resources/ves7_valid.json create mode 100644 src/test/resources/ves7_valid_30_1_1_event.json create mode 100644 src/test/resources/ves7_valid_eventWithStndDefinedFields.json (limited to 'src') diff --git a/src/test/java/org/onap/dcae/FileReader.java b/src/test/java/org/onap/dcae/FileReader.java new file mode 100644 index 00000000..7e85474c --- /dev/null +++ b/src/test/java/org/onap/dcae/FileReader.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START======================================================= + * PROJECT + * ================================================================================ + * Copyright (C) 2020 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.onap.dcae; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + + +public class FileReader { + + private static final Logger log = LoggerFactory.getLogger(FileReader.class); + + private FileReader() { + } + + public static String readFileAsString(String fileName) { + String fileContent = ""; + try { + fileContent = new String(Files.readAllBytes(Paths.get(fileName))); + } catch (IOException e) { + log.error("Error while reading file.", e); + } + return fileContent; + } +} \ No newline at end of file diff --git a/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java b/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java index 53595100..0d38fdac 100644 --- a/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java +++ b/src/test/java/org/onap/dcae/restapi/EventValidatorTest.java @@ -26,7 +26,9 @@ import static org.mockito.Mockito.when; import com.networknt.schema.JsonSchema; import com.networknt.schema.JsonSchemaFactory; + import java.util.Optional; + import org.json.JSONObject; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -35,14 +37,18 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.onap.dcae.ApplicationSettings; +import org.onap.dcae.FileReader; import org.springframework.http.ResponseEntity; @ExtendWith(MockitoExtension.class) public class EventValidatorTest { private static final String DUMMY_SCHEMA_VERSION = "v5"; private static final String DUMMY_TYPE = "type"; - + private final String newSchemaV7 = FileReader.readFileAsString("etc/CommonEventFormat_30.2_ONAP.json"); + private JSONObject sentEvent; + private static final String V7_VERSION = "v7"; private static JSONObject jsonObject; + private static final String EVENT_TYPE = "event"; @Mock private static ApplicationSettings settings; @@ -50,8 +56,9 @@ public class EventValidatorTest { @InjectMocks private static EventValidator sut; + @BeforeAll - static void setupTests(){ + static void setupTests() { jsonObject = new JSONObject("{" + DUMMY_TYPE + ":dummy}"); } @@ -108,6 +115,51 @@ public class EventValidatorTest { assertEquals(Optional.empty(), result); } + @Test + public void shouldReturnNoErrorsWhenValidating30_1_1ValidEvent() { + //given + sentEvent = new JSONObject(FileReader.readFileAsString("src/test/resources/ves7_valid_30_1_1_event.json")); + + mockJsonSchema(newSchemaV7); + when(settings.eventSchemaValidationEnabled()).thenReturn(true); + + //when + Optional> result = sut.validate(sentEvent, EVENT_TYPE, V7_VERSION); + + //then + assertEquals(Optional.empty(), result); + } + + @Test + public void shouldReturnNoErrorsWhenValidatingValidEventWithStndDefinedFields() { + //given + sentEvent = new JSONObject(FileReader.readFileAsString("src/test/resources/ves7_valid_eventWithStndDefinedFields.json")); + + mockJsonSchema(newSchemaV7); + when(settings.eventSchemaValidationEnabled()).thenReturn(true); + + //when + Optional> result = sut.validate(sentEvent, EVENT_TYPE, V7_VERSION); + + //then + assertEquals(Optional.empty(), result); + } + + @Test + public void shouldReturnSchemaValidationFailedWhenValidating30_1_1InvalidEvent() { + //given + sentEvent = new JSONObject(FileReader.readFileAsString("src/test/resources/ves7_invalid_30_1_1_event.json")); + + mockJsonSchema(newSchemaV7); + when(settings.eventSchemaValidationEnabled()).thenReturn(true); + + //when + Optional> result = sut.validate(this.sentEvent, EVENT_TYPE, V7_VERSION); + + //then + assertEquals(generateResponseOptional(ApiException.SCHEMA_VALIDATION_FAILED), result); + } + private void mockJsonSchema(String jsonSchemaContent) { JsonSchemaFactory factory = JsonSchemaFactory.getInstance(); diff --git a/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java b/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java index 444e28e6..6b89a356 100644 --- a/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java +++ b/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java @@ -98,7 +98,7 @@ public class VesRestControllerTest { MockHttpServletRequest request = givenMockHttpServletRequest(); String validEvent = new String( - Files.readAllBytes(Paths.get(this.getClass().getResource("/ves7_valid.json").getPath())) + Files.readAllBytes(Paths.get(this.getClass().getResource("/ves7_valid_30_1_1_event.json").getPath())) ); //when diff --git a/src/test/resources/testcollector.properties b/src/test/resources/testcollector.properties index c3fcca62..3001001c 100644 --- a/src/test/resources/testcollector.properties +++ b/src/test/resources/testcollector.properties @@ -3,7 +3,7 @@ collector.service.secure.port=8443 collector.keystore.file.location=../etc/keystore collector.keystore.passwordfile=./etc/passwordfile collector.schema.checkflag=1 -collector.schema.file={\"v1\":\"./etc/CommonEventFormat_27.2.json\",\"v2\":\"./etc/CommonEventFormat_27.2.json\",\"v3\":\"./etc/CommonEventFormat_27.2.json\",\"v4\":\"./etc/CommonEventFormat_27.2.json\",\"v5\":\"./etc/CommonEventFormat_28.4.json\"} +collector.schema.file={\"v1\":\"./etc/CommonEventFormat_27.2.json\",\"v2\":\"./etc/CommonEventFormat_27.2.json\",\"v3\":\"./etc/CommonEventFormat_27.2.json\",\"v4\":\"./etc/CommonEventFormat_27.2.json\",\"v5\":\"./etc/CommonEventFormat_28.4.json\",\"v7\":\"./etc/CommonEventFormat_30.2_ONAP.json\"} collector.dmaap.streamid=fault=sec_fault|syslog=sec_syslog|heartbeat=sec_heartbeat|measurementsForVfScaling=sec_measurement|mobileFlow=sec_mobileflow|other=sec_other|stateChange=sec_statechange|thresholdCrossingAlert=sec_thresholdCrossingAlert|voiceQuality=ves_voicequality|sipSignaling=ves_sipsignaling collector.dmaapfile=./etc/DmaapConfig.json auth.method=noAuth diff --git a/src/test/resources/ves7_invalid.json b/src/test/resources/ves7_invalid.json deleted file mode 100644 index 74c0a92f..00000000 --- a/src/test/resources/ves7_invalid.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "event": { - "commonEventHeader": { - "version": "4.0.1", - "vesEventListenerVersion": "30.0.1", - "domain": "fault", - "eventName": "Fault_Vscf:Acs-Ericcson_PilotNumberPoolExhaustion", - "eventId": "fault0000245", - "sequence": 1, - "priority": "High", - "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", - "reportingEntityName": "ibcx0001vm002oam001", - "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", - "sourceName": "scfx0001vm002cap001", - "nfVendorName": "Ericsson", - "nfNamingCode": "scfx", - "nfcNamingCode": "ssc", - "startEpochMicrosec": 1413378172000000, - "lastEpochMicrosec": 1413378172000000, - "timeZoneOffset": "UTC-05:30" - }, - "faultFields": { - "faultFieldsVersion": "4.0", - "alarmCondition": "PilotNumberPoolExhaustion", - "eventSourceType": "other", - "specificProblem": "Calls cannot complete - pilot numbers are unavailable", - "eventSeverity": "CRITICAL", - "vfStatus": "Active", - "alarmAdditionalInformation": { - "PilotNumberPoolSize": "1000" - } - } - } -} diff --git a/src/test/resources/ves7_invalid_30_1_1_event.json b/src/test/resources/ves7_invalid_30_1_1_event.json new file mode 100644 index 00000000..74c0a92f --- /dev/null +++ b/src/test/resources/ves7_invalid_30_1_1_event.json @@ -0,0 +1,34 @@ +{ + "event": { + "commonEventHeader": { + "version": "4.0.1", + "vesEventListenerVersion": "30.0.1", + "domain": "fault", + "eventName": "Fault_Vscf:Acs-Ericcson_PilotNumberPoolExhaustion", + "eventId": "fault0000245", + "sequence": 1, + "priority": "High", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "nfVendorName": "Ericsson", + "nfNamingCode": "scfx", + "nfcNamingCode": "ssc", + "startEpochMicrosec": 1413378172000000, + "lastEpochMicrosec": 1413378172000000, + "timeZoneOffset": "UTC-05:30" + }, + "faultFields": { + "faultFieldsVersion": "4.0", + "alarmCondition": "PilotNumberPoolExhaustion", + "eventSourceType": "other", + "specificProblem": "Calls cannot complete - pilot numbers are unavailable", + "eventSeverity": "CRITICAL", + "vfStatus": "Active", + "alarmAdditionalInformation": { + "PilotNumberPoolSize": "1000" + } + } + } +} diff --git a/src/test/resources/ves7_valid.json b/src/test/resources/ves7_valid.json deleted file mode 100644 index 19116b15..00000000 --- a/src/test/resources/ves7_valid.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "event": { - "commonEventHeader": { - "version": "4.0.1", - "vesEventListenerVersion": "7.0.1", - "domain": "fault", - "eventName": "Fault_Vscf:Acs-Ericcson_PilotNumberPoolExhaustion", - "eventId": "fault0000245", - "sequence": 1, - "priority": "High", - "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", - "reportingEntityName": "ibcx0001vm002oam001", - "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", - "sourceName": "scfx0001vm002cap001", - "nfVendorName": "Ericsson", - "nfNamingCode": "scfx", - "nfcNamingCode": "ssc", - "startEpochMicrosec": 1413378172000000, - "lastEpochMicrosec": 1413378172000000, - "timeZoneOffset": "UTC-05:30" - }, - "faultFields": { - "faultFieldsVersion": "4.0", - "alarmCondition": "PilotNumberPoolExhaustion", - "eventSourceType": "other", - "specificProblem": "Calls cannot complete - pilot numbers are unavailable", - "eventSeverity": "CRITICAL", - "vfStatus": "Active", - "alarmAdditionalInformation": { - "PilotNumberPoolSize": "1000" - } - } - } -} diff --git a/src/test/resources/ves7_valid_30_1_1_event.json b/src/test/resources/ves7_valid_30_1_1_event.json new file mode 100644 index 00000000..19116b15 --- /dev/null +++ b/src/test/resources/ves7_valid_30_1_1_event.json @@ -0,0 +1,34 @@ +{ + "event": { + "commonEventHeader": { + "version": "4.0.1", + "vesEventListenerVersion": "7.0.1", + "domain": "fault", + "eventName": "Fault_Vscf:Acs-Ericcson_PilotNumberPoolExhaustion", + "eventId": "fault0000245", + "sequence": 1, + "priority": "High", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "nfVendorName": "Ericsson", + "nfNamingCode": "scfx", + "nfcNamingCode": "ssc", + "startEpochMicrosec": 1413378172000000, + "lastEpochMicrosec": 1413378172000000, + "timeZoneOffset": "UTC-05:30" + }, + "faultFields": { + "faultFieldsVersion": "4.0", + "alarmCondition": "PilotNumberPoolExhaustion", + "eventSourceType": "other", + "specificProblem": "Calls cannot complete - pilot numbers are unavailable", + "eventSeverity": "CRITICAL", + "vfStatus": "Active", + "alarmAdditionalInformation": { + "PilotNumberPoolSize": "1000" + } + } + } +} diff --git a/src/test/resources/ves7_valid_eventWithStndDefinedFields.json b/src/test/resources/ves7_valid_eventWithStndDefinedFields.json new file mode 100644 index 00000000..5d40b9d9 --- /dev/null +++ b/src/test/resources/ves7_valid_eventWithStndDefinedFields.json @@ -0,0 +1,49 @@ +{ + "event": { + "commonEventHeader": { + "domain": "stndDefined", + "eventId": "stndDefined-gNB_Nokia000001", + "eventName": "stndDefined-gNB-Nokia-PowerLost", + "stndDefinedNamespace": "3GPP-FaultSupervision", + "lastEpochMicrosec": 1234567890, + "priority": "Normal", + "reportingEntityName": "Nokia123456", + "sequence": 0, + "sourceName": "Nokia123456", + "startEpochMicrosec": 1234567890, + "version": "4.1", + "vesEventListenerVersion": "7.2" + }, + "stndDefinedFields": { + "schemaReference": "https://www.3gpp.org/Rel-16/TS28532_generic_fault_supervision.json#definitions/schemas/notifyNewAlarm-NotifType", + "data": { + "header": { + "uri": "xyz", + "notificationId": "xyz", + "notificationType": "notifyNewAlarm", + "eventTime": "xyz", + "systemDN": "xyz" + }, + "body": { + "probableCause": "xyz", + "perceivedSeverity": "Major", + "rootCauseIndicator": false, + "specificProblem": "xyz", + "correlatedNotifications": [], + "backedUpStatus": true, + "backUpObject": "xyz", + "trendIndication": "No change", + "thresholdInfo": {}, + "stateChangeDefinition": [], + "monitoredAttributes": [], + "proposedRepairActions": "xyz", + "additionalText": "xyz", + "additionalInformation": [], + "alarmId": "xyz", + "alarmType": "Environmental Alarm" + } + }, + "stndDefinedFieldsVersion": "1.0" + } + } +} \ No newline at end of file -- cgit 1.2.3-korg