diff options
Diffstat (limited to 'src')
9 files changed, 95 insertions, 77 deletions
diff --git a/src/main/java/org/onap/dcae/ApplicationSettings.java b/src/main/java/org/onap/dcae/ApplicationSettings.java index 7d5c7db2..9462a380 100644 --- a/src/main/java/org/onap/dcae/ApplicationSettings.java +++ b/src/main/java/org/onap/dcae/ApplicationSettings.java @@ -196,6 +196,10 @@ public class ApplicationSettings { return eventTransformations; } + public String getApiVersionDescriptionFilepath() { + return properties.getString("collector.description.api.version.location", "etc/api_version_description.json"); + } + private void loadPropertiesFromFile() { try { properties.load(configurationFileLocation); diff --git a/src/main/java/org/onap/dcae/common/HeaderUtils.java b/src/main/java/org/onap/dcae/common/HeaderUtils.java index c046fb4c..81277d07 100644 --- a/src/main/java/org/onap/dcae/common/HeaderUtils.java +++ b/src/main/java/org/onap/dcae/common/HeaderUtils.java @@ -3,7 +3,7 @@ * PROJECT * ================================================================================ * Copyright (C) 2019 VMware, Inc. All rights reserved. - * Copyright (C) 2019 Nokia. All rights reserved.s + * Copyright (C) 2019-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. @@ -23,39 +23,33 @@ package org.onap.dcae.common; import java.util.Collections; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Component; /** - * @author nil + * A class with methods used in HTTP header management. */ @Component public class HeaderUtils { - public String getApiVerFilePath(String fileName) { - return Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResource(fileName)) - .getPath(); - } + public String getRestApiIdentify(String uri) { + return isBatchRequest(uri) ? "eventListener_eventBatch" : "eventListener"; + } - public String getRestApiIdentify(String uri) { - return isBatchRequest(uri) ? "eventListener_eventBatch" : "eventListener"; - } + public Map<String, String> extractHeaders(HttpServletRequest request) { + return Collections.list(request.getHeaderNames()).stream() + .collect(Collectors.toMap(h -> h, request::getHeader)); + } - public Map<String, String> extractHeaders(HttpServletRequest request) { - return Collections.list(request.getHeaderNames()).stream() - .collect(Collectors.toMap(h -> h, request::getHeader)); - } + public HttpHeaders fillHeaders(Map<String, String> headers) { + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.setAll(headers); + return httpHeaders; + } - public HttpHeaders fillHeaders(Map<String, String> headers) { - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setAll(headers); - return httpHeaders; - } - - private boolean isBatchRequest(String request) { - return request.contains("eventBatch"); - } + private boolean isBatchRequest(String request) { + return request.contains("eventBatch"); + } } diff --git a/src/main/java/org/onap/dcae/restapi/VesRestController.java b/src/main/java/org/onap/dcae/restapi/VesRestController.java index de0392e6..0a5930f6 100644 --- a/src/main/java/org/onap/dcae/restapi/VesRestController.java +++ b/src/main/java/org/onap/dcae/restapi/VesRestController.java @@ -137,7 +137,7 @@ public class VesRestController { private CustomHeaderUtils createHeaderUtils(String version, HttpServletRequest request) { return new CustomHeaderUtils(version.toLowerCase().replace("v", ""), headerUtils.extractHeaders(request), - headerUtils.getApiVerFilePath("api_version_config.json"), + settings.getApiVersionDescriptionFilepath(), headerUtils.getRestApiIdentify(request.getRequestURI())); } diff --git a/src/main/resources/api_version_config.json b/src/main/resources/api_version_config.json deleted file mode 100644 index 23f585f9..00000000 --- a/src/main/resources/api_version_config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "apiVersion": - { - "eventListener": ["4.7.2","5.4.1","7.0.1"], - "eventListener_eventBatch": ["4.7.2","5.4.1","7.0.1"] - } -} diff --git a/src/test/java/org/onap/dcae/common/JsonDataLoader.java b/src/test/java/org/onap/dcae/common/JsonDataLoader.java index 2ea59aa0..8c2fdd6d 100644 --- a/src/test/java/org/onap/dcae/common/JsonDataLoader.java +++ b/src/test/java/org/onap/dcae/common/JsonDataLoader.java @@ -20,7 +20,9 @@ package org.onap.dcae.common; import java.io.IOException; +import java.net.URL; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; /** @@ -35,15 +37,15 @@ public final class JsonDataLoader { } /** - * This method is validating given event using schema adn throws exception if event is not valid + * This method is validating given event using schema and throws exception when event is invalid * * @param path to file that will be loaded * @return contend of the file located under path, given in parameters, as string * @throws IOException when file under given path was not found */ public static String loadContent(String path) throws IOException { - return new String( - Files.readAllBytes(Paths.get(JsonDataLoader.class.getResource(path).getPath())) - ); + URL resource = JsonDataLoader.class.getResource(path); + Path resourcePath = Paths.get(resource.getPath()); + return new String(Files.readAllBytes(resourcePath)); } } diff --git a/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java b/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java index 0a03c1a4..ce7e09d3 100644 --- a/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java +++ b/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java @@ -315,9 +315,7 @@ public class VesRestControllerTest { private void configureHeadersForEventListener() { when(headerUtils.getRestApiIdentify(anyString())).thenReturn("eventListener"); - when(headerUtils.getApiVerFilePath(anyString())).thenReturn( - this.getClass().getResource("/api_version_config.json").getPath() - ); + when(applicationSettings.getApiVersionDescriptionFilepath()).thenReturn("etc/api_version_description.json"); } private void verifyThatTransformedEventWasSend(DMaaPEventPublisher eventPublisher, String eventBeforeTransformation) { diff --git a/src/test/resources/ves_stdnDefined_empty_namespace_invalid.json b/src/test/resources/ves_stdnDefined_empty_namespace_invalid.json index a63bca17..0466d004 100644 --- a/src/test/resources/ves_stdnDefined_empty_namespace_invalid.json +++ b/src/test/resources/ves_stdnDefined_empty_namespace_invalid.json @@ -15,31 +15,40 @@ "vesEventListenerVersion": "7.2" }, "stndDefinedFields": { - "schemaReference": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml#definitions/schemas/notifyNewAlarm-NotifType", + "schemaReference": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml#components/schemas/NotifyNewAlarm", "data": { - "uri": "xyz", - "notificationId": "xyz", + "href": 1, + "uri": "1", + "notificationId": 1, "notificationType": "notifyNewAlarm", "eventTime": "xyz", "systemDN": "xyz", - "probableCause": "xyz", - "perceivedSeverity": "Major", + "probableCause": 1, + "perceivedSeverity": "INDETERMINATE", "rootCauseIndicator": false, "specificProblem": "xyz", "correlatedNotifications": [], "backedUpStatus": true, "backUpObject": "xyz", - "trendIndication": "No change", - "thresholdInfo": {}, - "stateChangeDefinition": [], - "monitoredAttributes": [], + "trendIndication": "MORE_SEVERE", + "thresholdInfo": { + "observedMeasurement": "new", + "observedValue": 123 + }, + "stateChangeDefinition": { + }, + "monitoredAttributes": { + "newAtt": "new" + }, "proposedRepairActions": "xyz", "additionalText": "xyz", - "additionalInformation": [], - "alarmId": "xyz", - "alarmType": "Environmental Alarm" + "additionalInformation": { + "addInfo": "new" + }, + "alarmId": "1", + "alarmType": "COMMUNICATIONS_ALARM" }, "stndDefinedFieldsVersion": "1.0" } } -} +}
\ No newline at end of file diff --git a/src/test/resources/ves_stdnDefined_missing_namespace_invalid.json b/src/test/resources/ves_stdnDefined_missing_namespace_invalid.json index 7a35286d..a636e76e 100644 --- a/src/test/resources/ves_stdnDefined_missing_namespace_invalid.json +++ b/src/test/resources/ves_stdnDefined_missing_namespace_invalid.json @@ -14,31 +14,40 @@ "vesEventListenerVersion": "7.2" }, "stndDefinedFields": { - "schemaReference": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml#definitions/schemas/notifyNewAlarm-NotifType", + "schemaReference": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml#components/schemas/NotifyNewAlarm", "data": { - "uri": "xyz", - "notificationId": "xyz", + "href": 1, + "uri": "1", + "notificationId": 1, "notificationType": "notifyNewAlarm", "eventTime": "xyz", "systemDN": "xyz", - "probableCause": "xyz", - "perceivedSeverity": "Major", + "probableCause": 1, + "perceivedSeverity": "INDETERMINATE", "rootCauseIndicator": false, "specificProblem": "xyz", "correlatedNotifications": [], "backedUpStatus": true, "backUpObject": "xyz", - "trendIndication": "No change", - "thresholdInfo": {}, - "stateChangeDefinition": [], - "monitoredAttributes": [], + "trendIndication": "MORE_SEVERE", + "thresholdInfo": { + "observedMeasurement": "new", + "observedValue": 123 + }, + "stateChangeDefinition": { + }, + "monitoredAttributes": { + "newAtt": "new" + }, "proposedRepairActions": "xyz", "additionalText": "xyz", - "additionalInformation": [], - "alarmId": "xyz", - "alarmType": "Environmental Alarm" + "additionalInformation": { + "addInfo": "new" + }, + "alarmId": "1", + "alarmType": "COMMUNICATIONS_ALARM" }, "stndDefinedFieldsVersion": "1.0" } } -} +}
\ No newline at end of file diff --git a/src/test/resources/ves_stdnDefined_valid_unknown_topic.json b/src/test/resources/ves_stdnDefined_valid_unknown_topic.json index 46195f7c..4c248879 100644 --- a/src/test/resources/ves_stdnDefined_valid_unknown_topic.json +++ b/src/test/resources/ves_stdnDefined_valid_unknown_topic.json @@ -15,31 +15,40 @@ "vesEventListenerVersion": "7.2" }, "stndDefinedFields": { - "schemaReference": "https://www.3gpp.org/Rel-16/TS28532_generic_fault_supervision.json#definitions/schemas/notifyNewAlarm-NotifType", + "schemaReference": "https://forge.3gpp.org/rep/sa5/data-models/blob/REL-16/OpenAPI/faultMnS.yaml#components/schemas/NotifyNewAlarm", "data": { - "uri": "xyz", - "notificationId": "xyz", + "href": 1, + "uri": "1", + "notificationId": 1, "notificationType": "notifyNewAlarm", "eventTime": "xyz", "systemDN": "xyz", - "probableCause": "xyz", - "perceivedSeverity": "Major", + "probableCause": 1, + "perceivedSeverity": "INDETERMINATE", "rootCauseIndicator": false, "specificProblem": "xyz", "correlatedNotifications": [], "backedUpStatus": true, "backUpObject": "xyz", - "trendIndication": "No change", - "thresholdInfo": {}, - "stateChangeDefinition": [], - "monitoredAttributes": [], + "trendIndication": "MORE_SEVERE", + "thresholdInfo": { + "observedMeasurement": "new", + "observedValue": 123 + }, + "stateChangeDefinition": { + }, + "monitoredAttributes": { + "newAtt": "new" + }, "proposedRepairActions": "xyz", "additionalText": "xyz", - "additionalInformation": [], - "alarmId": "xyz", - "alarmType": "Environmental Alarm" + "additionalInformation": { + "addInfo": "new" + }, + "alarmId": "1", + "alarmType": "COMMUNICATIONS_ALARM" }, "stndDefinedFieldsVersion": "1.0" } } -} +}
\ No newline at end of file |