From 2c8ddf3501cfc5106d20b51ef077cc6d07ab65dc Mon Sep 17 00:00:00 2001 From: JoeOLeary Date: Fri, 19 Jul 2019 10:02:12 +0000 Subject: Add DMaaP plugin support - Update blueprint with DMaaP plugin support. - Update configuration with new DMaaP plugin format. - Move Configuration tests to correct package. - Add latest-staging Docker image tag to pom. - Change file endings in some files to LF. - Remove publishing to non authenticated topic. - Fix some tests which were not executing correctly. - Fix some Sonar smells. Issue-ID: DCAEGEN2-1581 Change-Id: I37fbb662419179e3fe9fb8bdf710d6a6e8f0308a Signed-off-by: JoeOLeary --- dpo/blueprints/k8s-pm-mapper.yaml | 173 +++++++++--------- dpo/spec/dmaap.json | 8 +- dpo/spec/pmmapper-component-spec.json | 8 +- pom.xml | 14 +- .../services/pmmapper/config/ConfigHandler.java | 202 +++++++++++---------- .../services/pmmapper/config/Configurable.java | 1 + .../pmmapper/config/DynamicConfiguration.java | 8 +- .../pmmapper/datarouter/EventReceiver.java | 1 + .../pmmapper/filtering/MeasFilterHandler.java | 5 - .../pmmapper/filtering/MetadataFilter.java | 1 + .../pmmapper/messagerouter/VESPublisher.java | 5 +- .../services/pmmapper/model/EnvironmentConfig.java | 55 ------ .../services/pmmapper/model/MapperConfig.java | 124 ++++--------- .../services/pmmapper/model/PublisherConfig.java | 45 +++++ .../services/pmmapper/model/SubscriberConfig.java | 47 +++++ .../services/pmmapper/utils/DMaaPAdapter.java | 81 +++++++++ .../services/pmmapper/utils/EnvironmentConfig.java | 48 +++++ .../pmmapper/utils/RequiredFieldDeserializer.java | 2 +- .../pmmapper/config/ConfigHandlerTests.java | 165 ----------------- .../pmmapper/config/EnvironmentConfigTest.java | 71 -------- .../pmmapper/config/util/RequestSenderTests.java | 124 ------------- .../pmmapper/messagerouter/VESPublisherTest.java | 180 +++++++++--------- .../onap/dcaegen2/services/pmmapper/AppTest.java | 6 +- .../pmmapper/config/ConfigHandlerTests.java | 140 ++++++++++++++ .../pmmapper/config/DynamicConfigurationTest.java | 100 +++++----- .../pmmapper/datarouter/DeliveryHandlerTest.java | 36 ++-- .../pmmapper/filtering/MetadataFilterTest.java | 50 ++--- .../services/pmmapper/utils/DMaaPAdapterTest.java | 92 ++++++++++ .../pmmapper/utils/EnvironmentConfigTest.java | 85 +++++++++ .../pmmapper/utils/RequestSenderTests.java | 124 +++++++++++++ src/test/java/utils/ConfigUtils.java | 38 ++++ src/test/java/utils/EventUtils.java | 11 +- src/test/java/utils/FileUtils.java | 82 +++++++++ .../invalid_configs/empty_filter_object.json | 35 ++++ .../invalid_configs/invalid_filter_object.json | 41 +++++ .../invalid_configs/null_aaf_identity.json | 47 +++++ .../invalid_configs/null_aaf_password.json | 47 +++++ .../invalid_configs/null_client_role.json | 47 +++++ .../null_dmaap_dr_delete_endpoint.json | 47 +++++ .../invalid_configs/null_dr_location.json | 47 +++++ .../invalid_configs/null_dr_password.json | 47 +++++ .../invalid_configs/null_dr_subscriber_id.json | 47 +++++ .../invalid_configs/null_dr_username.json | 47 +++++ .../resources/invalid_configs/null_filter.json | 35 ++++ .../invalid_configs/null_filter_array.json | 37 ++++ .../invalid_configs/null_key_store_pass_path.json | 47 +++++ .../invalid_configs/null_key_store_path.json | 47 +++++ .../resources/invalid_configs/null_location.json | 47 +++++ .../resources/invalid_configs/null_topic_url.json | 47 +++++ .../null_trust_store_pass_path.json | 47 +++++ .../invalid_configs/null_trust_store_path.json | 47 +++++ .../resources/multiple_filter_mapper_config.json | 52 +++--- src/test/resources/no_filter_mapper_config.json | 35 +--- src/test/resources/valid_mapper_config.json | 80 ++++---- version.properties | 2 +- 55 files changed, 2089 insertions(+), 1018 deletions(-) delete mode 100644 src/main/java/org/onap/dcaegen2/services/pmmapper/model/EnvironmentConfig.java create mode 100644 src/main/java/org/onap/dcaegen2/services/pmmapper/model/PublisherConfig.java create mode 100644 src/main/java/org/onap/dcaegen2/services/pmmapper/model/SubscriberConfig.java create mode 100644 src/main/java/org/onap/dcaegen2/services/pmmapper/utils/DMaaPAdapter.java create mode 100644 src/main/java/org/onap/dcaegen2/services/pmmapper/utils/EnvironmentConfig.java delete mode 100644 src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java delete mode 100644 src/test/java/org/onap/dcaegen2/pmmapper/config/EnvironmentConfigTest.java delete mode 100644 src/test/java/org/onap/dcaegen2/pmmapper/config/util/RequestSenderTests.java create mode 100644 src/test/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandlerTests.java create mode 100644 src/test/java/org/onap/dcaegen2/services/pmmapper/utils/DMaaPAdapterTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/pmmapper/utils/EnvironmentConfigTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java create mode 100644 src/test/java/utils/ConfigUtils.java create mode 100644 src/test/java/utils/FileUtils.java create mode 100644 src/test/resources/invalid_configs/empty_filter_object.json create mode 100644 src/test/resources/invalid_configs/invalid_filter_object.json create mode 100644 src/test/resources/invalid_configs/null_aaf_identity.json create mode 100644 src/test/resources/invalid_configs/null_aaf_password.json create mode 100644 src/test/resources/invalid_configs/null_client_role.json create mode 100644 src/test/resources/invalid_configs/null_dmaap_dr_delete_endpoint.json create mode 100644 src/test/resources/invalid_configs/null_dr_location.json create mode 100644 src/test/resources/invalid_configs/null_dr_password.json create mode 100644 src/test/resources/invalid_configs/null_dr_subscriber_id.json create mode 100644 src/test/resources/invalid_configs/null_dr_username.json create mode 100644 src/test/resources/invalid_configs/null_filter.json create mode 100644 src/test/resources/invalid_configs/null_filter_array.json create mode 100644 src/test/resources/invalid_configs/null_key_store_pass_path.json create mode 100644 src/test/resources/invalid_configs/null_key_store_path.json create mode 100644 src/test/resources/invalid_configs/null_location.json create mode 100644 src/test/resources/invalid_configs/null_topic_url.json create mode 100644 src/test/resources/invalid_configs/null_trust_store_pass_path.json create mode 100644 src/test/resources/invalid_configs/null_trust_store_path.json diff --git a/dpo/blueprints/k8s-pm-mapper.yaml b/dpo/blueprints/k8s-pm-mapper.yaml index c129357..9da07c1 100644 --- a/dpo/blueprints/k8s-pm-mapper.yaml +++ b/dpo/blueprints/k8s-pm-mapper.yaml @@ -2,14 +2,14 @@ # ============LICENSE_START======================================================= # Copyright (C) 2019 Nordix Foundation. # ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); +# 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, +# 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. @@ -21,157 +21,160 @@ tosca_definitions_version: cloudify_dsl_1_3 imports: - - "http://www.getcloudify.org/spec/cloudify/3.4/types.yaml" - - "https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.13/k8splugin_types.yaml" + - 'http://www.getcloudify.org/spec/cloudify/3.4/types.yaml' + - 'https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R5/k8splugin/1.6.0/k8splugin_types.yaml' + - 'https://nexus.onap.org/service/local/repositories/raw/content/org.onap.ccsdk.platform.plugins/type_files/dmaap/dmaap.yaml' inputs: + filter: + type: string + description: PM Mapper filter on measInfo, measInfoId, measType, instanceId + default: '{ "filters":[]}' + enable_http: + type: boolean + description: Option to turn on HTTP connections + default: false tag_version: type: string description: Docker image to be used - default: "nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.pm-mapper:latest" + default: 'nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.pm-mapper:latest' replicas: type: integer description: Number of instances default: 1 - aaf_username: + feed_name: type: string - description: AAF user name - default: "username" - aaf_password: + default: 'bulk_pm_feed' + topic_name: type: string - description: AAF password - default: "password" + default: 'PERFORMANCE_MEASUREMENTS' client_role: type: string description: Client role to request secure access to topic - default: "org.onap.dmaap.mr.PM_MAPPER.pub" + default: 'org.onap.dcae.pmPublisher' client_id: type: string description: Client id for given AAF client - default: "dcae@dcae.onap.org" + default: 'dcae@dcae.onap.org' + client_password: + type: string + description: Password for AAF client provided as client_id dmaap_dr_username: type: string description: DMAAP Data Router user name - default: "username" + default: 'username' dmaap_dr_password: type: string description: DMAAP Data Router password - default: "password" + default: 'password' dcae_location: type: string description: DCAE location for the subscriber, used to set up routing - default: "san-francisco" - subscriber_id: - type: string - description: Subscriber id in Data Router - default: "1" + default: 'san-francisco' pm_mapper_service_protocol: type: string description: PM Mapper protocol - default: "https" + default: 'https' pm_mapper_service_port: type: string description: PM Mapper host port - default: "8443" + default: '8443' dmaap_dr_service_host: type: string description: DMAAP Data Router host address - default: "dmaap-dr-node" + default: 'dmaap-dr-node' dmaap_dr_service_port: type: string description: DMAAP Data Router host port - default: "8443" + default: '8443' dmaap_mr_service_protocol: type: string description: DMAAP Message Router protocol - default: "https" + default: 'https' dmaap_mr_service_host: type: string description: DMAAP Message Router host address - default: "message-router" + default: 'message-router' dmaap_mr_service_port: type: string description: DMAAP Message Router host port - default: "3905" - filter: - type: string - description: PM Mapper filter on measInfo, measInfoId, measType, instanceId - default: { "filters":[]} - enable_http: - type: boolean - description: Option to turn on HTTP connections - default: false + default: '3905' node_templates: + pm-feed: + type: ccsdk.nodes.Feed + properties: + feed_name: { get_input: feed_name } + + pm-topic: + type: ccsdk.nodes.Topic + properties: + topic_name: { get_input: topic_name } + pm-mapper: + type: dcae.nodes.ContainerizedServiceComponentUsingDmaap interfaces: cloudify.interfaces.lifecycle: - start: + create: inputs: ports: - '8443:0' - '8081:0' + + relationships: + - type: ccsdk.relationships.subscribe_to_files + target: pm-feed + - type: ccsdk.relationships.publish_events + target: pm-topic + properties: + service_component_type: 'dcae-pm-mapper' + service_component_name_override: 'dcae-pm-mapper' application_config: - enable_http: - { get_input: enable_http } - trust_store_path: "/opt/app/pm-mapper/etc/cert/trust.jks.b64" - trust_store_pass_path: "/opt/app/pm-mapper/etc/cert/trust.pass" - key_store_path: "/opt/app/pm-mapper/etc/cert/cert.jks.b64" - key_store_pass_path: "/opt/app/pm-mapper/etc/cert/jks.pass" - dmaap_dr_feed_name: "bulk_pm_feed" - dmaap_dr_delete_endpoint: - { concat: ["https://", { get_input: dmaap_dr_service_host }, - ":", { get_input: dmaap_dr_service_port},"/delete"]} - pm-mapper-filter: - get_input: filter + trust_store_path: '/opt/app/pm-mapper/etc/cert/trust.jks.b64' + trust_store_pass_path: '/opt/app/pm-mapper/etc/cert/trust.pass' + key_store_path: '/opt/app/pm-mapper/etc/cert/cert.jks.b64' + key_store_pass_path: '/opt/app/pm-mapper/etc/cert/jks.pass' + pm-mapper-filter: { get_input: filter } + enable_http: { get_input: enable_http } + dmaap_dr_delete_endpoint: { concat: ['https://',{ get_input: dmaap_dr_service_host },':',{ get_input: dmaap_dr_service_port },'/delete'] } + aaf_identity: { get_input: client_id } + aaf_password: { get_input: client_password } streams_subscribes: dmaap_subscriber: - type: - "data_router" - dmaap_info: - username: - get_input: dmaap_dr_username - password: - get_input: dmaap_dr_password - location: - get_input: dcae_location - subscriber_id: - get_input: subscriber_id - delivery_url: - { concat: [{ get_input: pm_mapper_service_protocol },"://dcae-pm-mapper:",{ get_input: pm_mapper_service_port },"/delivery"]} + type: data_router + dmaap_info: <> streams_publishes: dmaap_publisher: - aaf_username: - get_input: aaf_username - aaf_password: - get_input: aaf_password - type: - "message_router" - dmaap_info: - client_role: - get_input: client_role - client_id: - get_input: client_id - topic_url: - { concat: [{ get_input: dmaap_mr_service_protocol },"://",{ get_input: dmaap_mr_service_host }, - ":",{ get_input: dmaap_mr_service_port },"/events/org.onap.dmaap.mr.PM_MAPPER"]} - location: - get_input: dcae_location + type: message_router + dmaap_info: <> docker_config: healthcheck: endpoint: /healthcheck interval: 15s timeout: 1s type: https - image: - get_input: tag_version + streams_publishes: + - name: pm-topic + location: { get_input: dcae_location } + client_role: { get_input: client_role } + type: message-router + streams_subscribes: + - name: pm-feed + location: { get_input: dcae_location } + client_role: { get_input: client_role } + username: { get_input: dmaap_dr_username } + password: { get_input: dmaap_dr_password } + scheme: { get_input: pm_mapper_service_protocol } + route: delivery + delivery_url: '' + privileged: true + decompress: true + type: data_router + image: { get_input: tag_version } replicas: { get_input: replicas } - name: "dcae-pm-mapper" - dns_name: "dcae-pm-mapper" log_info: - log_directory: "/var/log/ONAP/dcaegen2/services/pm-mapper" + log_directory: '/var/log/ONAP/dcaegen2/services/pm-mapper' tls_info: - cert_directory: "/opt/app/pm-mapper/etc/cert/" - use_tls: true - type: dcae.nodes.ContainerizedPlatformComponent \ No newline at end of file + cert_directory: '/opt/app/pm-mapper/etc/cert/' + use_tls: true \ No newline at end of file diff --git a/dpo/spec/dmaap.json b/dpo/spec/dmaap.json index 1830723..2c998eb 100644 --- a/dpo/spec/dmaap.json +++ b/dpo/spec/dmaap.json @@ -1,16 +1,16 @@ { - "pm_mapper_publish_mr": { + "dmaap_publisher": { "aaf_username": "username", "aaf_password": "password", "type": "message_router", "dmaap_info": { - "client_role": "org.onap.dmaap.mr.PM_MAPPER.pub", + "client_role": "org.dcae.onap.pmPublisher", "client_id": "dcae@dcae.onap.org", "location": "san-francisco", - "topic_url": "https://message-router:3905//events/org.onap.dmaap.mr.PM_MAPPER" + "topic_url": "https://message-router:3905//events/org.onap.dmaap.mr.PERFORMANCE_MEASUREMENTS" } }, - "pm_mapper_subscribe_dr": { + "dmaap_subscriber": { "type": "data_router", "dmaap_info": { "username": "username", diff --git a/dpo/spec/pmmapper-component-spec.json b/dpo/spec/pmmapper-component-spec.json index d88c71c..6734841 100644 --- a/dpo/spec/pmmapper-component-spec.json +++ b/dpo/spec/pmmapper-component-spec.json @@ -9,8 +9,10 @@ "subscribes": [ { "type": "data_router", - "config_key": "pm_mapper_subscribe_dr", + "config_key": "dmaap_subscriber", "route": "/delivery", + "privileged": true, + "decompress": true, "format": "3GPP_XML", "version": "1.0.0" } @@ -18,7 +20,7 @@ "publishes": [ { "type": "message_router", - "config_key": "pm_mapper_publish_mr", + "config_key": "dmaap_publisher", "format": "VES_specification", "version": "7.30.1" } @@ -81,7 +83,7 @@ }, { "name": "enable_http", - "value": "true", + "value": "false", "description": "Option to turn on HTTP connections", "designer_editable": true, "sourced_at_deployment": false, diff --git a/pom.xml b/pom.xml index 41750d7..2b2b1e1 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.onap.dcaegen2.services pm-mapper - 1.1.1-SNAPSHOT + 1.1.2-SNAPSHOT org.onap.oparent @@ -232,6 +232,16 @@ ${project.version}-${timestamp} + + latest-snapshot + none + + tag + + + latest-snapshot + + push-latest none @@ -239,7 +249,7 @@ push - latest + latest-snapshot diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandler.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandler.java index e50ec6c..e98849e 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandler.java @@ -1,100 +1,102 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.dcaegen2.services.pmmapper.config; - -import org.onap.dcaegen2.services.pmmapper.exceptions.CBSConfigException; -import org.onap.dcaegen2.services.pmmapper.exceptions.CBSServerError; -import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException; -import org.onap.dcaegen2.services.pmmapper.exceptions.MapperConfigException; -import org.onap.dcaegen2.services.pmmapper.model.EnvironmentConfig; -import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; -import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; -import org.onap.dcaegen2.services.pmmapper.utils.RequiredFieldDeserializer; - -import org.onap.logging.ref.slf4j.ONAPLogAdapter; -import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.slf4j.LoggerFactory; -import com.google.gson.GsonBuilder; - -/** - * Handles the retrieval of the component spec-based PM-Mapper Configuration - * from DCAE. - */ - -public class ConfigHandler { - private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(ConfigHandler.class)); - private RequestSender sender; - - /** - * Creates a ConfigHandler. - */ - public ConfigHandler() { - this(new RequestSender()); - } - - /** - * @see ConfigHandler#ConfigHandler() - * @param sender A RequestSender - */ - public ConfigHandler(RequestSender sender) { - this.sender = sender; - } - - /** - * Retrieves PM-Mapper Configuration from DCAE's ConfigBinding Service. - * - * @throws EnvironmentConfigException - * @throws ConsulServerError - * @throws CBSConfigException - * @throws CBSServerError - * @throws MapperConfigException - */ - public MapperConfig getMapperConfig() throws EnvironmentConfigException, - CBSServerError, MapperConfigException { - String mapperConfigJson = ""; - String cbsSocketAddress = EnvironmentConfig.getCBSHostName() + ":" + EnvironmentConfig.getCBSPort(); - String requestURL = "http://" + cbsSocketAddress + "/service_component/" + EnvironmentConfig.getServiceName(); - try { - logger.unwrap().info(ONAPLogConstants.Markers.ENTRY, "Fetching pm-mapper configuration from Configbinding Service"); - mapperConfigJson = sender.send(requestURL); - } catch (Exception exception) { - throw new CBSServerError("Error connecting to Configbinding Service: ", exception); - } finally { - logger.unwrap().info(ONAPLogConstants.Markers.EXIT, "Received pm-mapper configuration from ConfigBinding Service:\n{}", mapperConfigJson); - } - - return convertMapperConfigToObject(mapperConfigJson); - } - - private MapperConfig convertMapperConfigToObject(String mapperConfigJson) throws MapperConfigException { - MapperConfig mapperConfig; - try { - mapperConfig = new GsonBuilder() - .registerTypeAdapter(MapperConfig.class, new RequiredFieldDeserializer()) - .create() - .fromJson(mapperConfigJson, MapperConfig.class); - } catch (Exception exception) { - throw new MapperConfigException("Error parsing mapper configuration:\n{}" + mapperConfigJson, exception); - } - - logger.unwrap().debug("Mapper configuration:\n{}", mapperConfig); - return mapperConfig; - } -} +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.dcaegen2.services.pmmapper.config; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.onap.dcaegen2.services.pmmapper.exceptions.CBSServerError; +import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException; +import org.onap.dcaegen2.services.pmmapper.exceptions.MapperConfigException; +import org.onap.dcaegen2.services.pmmapper.utils.EnvironmentConfig; +import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; +import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; +import org.onap.dcaegen2.services.pmmapper.utils.RequiredFieldDeserializer; + +import org.onap.logging.ref.slf4j.ONAPLogAdapter; +import org.slf4j.LoggerFactory; +import com.google.gson.GsonBuilder; + +/** + * Handles the retrieval of the component spec-based PM-Mapper Configuration + * from DCAE. + */ + +public class ConfigHandler { + private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(ConfigHandler.class)); + private RequestSender sender; + private EnvironmentConfig environmentConfig; + + /** + * Creates a ConfigHandler. + */ + public ConfigHandler() { + this(new RequestSender(), new EnvironmentConfig()); + } + + /** + * @see ConfigHandler#ConfigHandler() + * @param sender A RequestSender + */ + public ConfigHandler(RequestSender sender, EnvironmentConfig environmentConfig) { + this.sender = sender; + this.environmentConfig = environmentConfig; + } + + /** + * Retrieves PM-Mapper Configuration from DCAE's ConfigBinding Service. + * + * @throws EnvironmentConfigException + * @throws CBSServerError + * @throws MapperConfigException + */ + public MapperConfig getMapperConfig() throws EnvironmentConfigException, + CBSServerError, MapperConfigException { + String mapperConfigJson = ""; + String cbsSocketAddress = this.environmentConfig.getCBSHostName() + ":" + this.environmentConfig.getCBSPort(); + String requestURL = "http://" + cbsSocketAddress + "/service_component/" + this.environmentConfig.getServiceName(); + try { + logger.unwrap().info("Fetching pm-mapper configuration from Configbinding Service"); + mapperConfigJson = sender.send(requestURL); + } catch (Exception exception) { + throw new CBSServerError("Error connecting to Configbinding Service: ", exception); + } finally { + logger.unwrap().info("Received pm-mapper configuration from ConfigBinding Service:\n{}", mapperConfigJson); + } + + return convertMapperConfigToObject(mapperConfigJson); + } + + private MapperConfig convertMapperConfigToObject(String mapperConfigJson) throws MapperConfigException { + MapperConfig mapperConfig; + try { + JsonObject config = new Gson().fromJson(mapperConfigJson, JsonObject.class); + mapperConfig = new GsonBuilder() + .registerTypeAdapter(MapperConfig.class, new RequiredFieldDeserializer()) + .create() + .fromJson(config, MapperConfig.class); + } catch (Exception exception) { + String exceptionMessage = "Error parsing configuration, mapper config:\n" + mapperConfigJson; + throw new MapperConfigException(exceptionMessage, exception); + } + + logger.unwrap().debug("Mapper configuration:\n{}", mapperConfig); + return mapperConfig; + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/config/Configurable.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/config/Configurable.java index ac2fe57..9431cce 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/config/Configurable.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/config/Configurable.java @@ -25,6 +25,7 @@ package org.onap.dcaegen2.services.pmmapper.config; import org.onap.dcaegen2.services.pmmapper.exceptions.ReconfigurationException; import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; +@FunctionalInterface public interface Configurable { void reconfigure(MapperConfig mapperConfig) throws ReconfigurationException; diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfiguration.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfiguration.java index 37fa8b5..7e2c894 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfiguration.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfiguration.java @@ -23,6 +23,7 @@ package org.onap.dcaegen2.services.pmmapper.config; import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; import io.undertow.util.StatusCodes; +import java.util.List; import lombok.Data; import org.onap.dcaegen2.services.pmmapper.exceptions.ReconfigurationException; import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; @@ -30,10 +31,8 @@ import org.onap.dcaegen2.services.pmmapper.utils.HttpServerExchangeAdapter; import org.onap.logging.ref.slf4j.ONAPLogAdapter; import org.slf4j.LoggerFactory; -import java.util.List; - @Data -public class DynamicConfiguration implements HttpHandler{ +public class DynamicConfiguration implements HttpHandler { private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(DynamicConfiguration.class)); private List configurables; private MapperConfig originalConfig; @@ -44,7 +43,7 @@ public class DynamicConfiguration implements HttpHandler{ * @param configurables list of objects to reconfigure * @param originalConfig original config to compare against. */ - public DynamicConfiguration(List configurables, MapperConfig originalConfig){ + public DynamicConfiguration(List configurables, MapperConfig originalConfig) { this.configurables = configurables; this.originalConfig = originalConfig; this.configHandler = new ConfigHandler(); @@ -79,6 +78,7 @@ public class DynamicConfiguration implements HttpHandler{ } catch (ReconfigurationException e) { responseCode = StatusCodes.INTERNAL_SERVER_ERROR; responseMessage = StatusCodes.INTERNAL_SERVER_ERROR_STRING; + logger.unwrap().error("Failed to apply configuration update, reverting to original config", e); applyConfiguration(this.originalConfig); } } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/EventReceiver.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/EventReceiver.java index 77c8153..42dba87 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/EventReceiver.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/EventReceiver.java @@ -26,6 +26,7 @@ import org.onap.dcaegen2.services.pmmapper.model.Event; /** * Sink for Events received from the data router subscriber. */ +@FunctionalInterface public interface EventReceiver { void receive(Event event); } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java index 2dc4ae9..0438530 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java @@ -20,14 +20,9 @@ package org.onap.dcaegen2.services.pmmapper.filtering; -import java.math.BigInteger; import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.function.Function; import java.util.stream.Collectors; import org.apache.commons.io.FilenameUtils; diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MetadataFilter.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MetadataFilter.java index 1fb6019..d647c40 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MetadataFilter.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MetadataFilter.java @@ -99,6 +99,7 @@ public class MetadataFilter { return true; } + @FunctionalInterface interface Validator { boolean validate(A filter, B metadata); } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java index 46d40e4..744696a 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java @@ -64,11 +64,10 @@ public class VESPublisher { try { String topicUrl = config.getPublisherTopicUrl(); ves = ves.replaceAll("\n", ""); - String userCredentials = topicUrl.startsWith("https") ? Base64.getEncoder() + String userCredentials = Base64.getEncoder() .encodeToString((this.config.getPublisherUserName() + ":" + this.config.getPublisherPassword()) - .getBytes(StandardCharsets.UTF_8)) - : ""; + .getBytes(StandardCharsets.UTF_8)); sender.send("POST", topicUrl, ves, userCredentials); } catch (Exception e) { throw new MRPublisherException(e.getMessage(), e); diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/EnvironmentConfig.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/EnvironmentConfig.java deleted file mode 100644 index e2c1c6e..0000000 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/EnvironmentConfig.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.dcaegen2.services.pmmapper.model; - -import java.util.Optional; - -import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException; - -public class EnvironmentConfig { - - public static final int DEFAULT_CBS_PORT = 10000; - public static final String ENV_CBS_HOST_KEY = "CONFIG_BINDING_SERVICE_SERVICE_HOST"; - public static final String ENV_CBS_PORT_KEY = "CONFIG_BINDING_SERVICE_SERVICE_PORT"; - public static final String ENV_SERVICE_NAME_KEY = "HOSTNAME"; - - public static String getServiceName() throws EnvironmentConfigException { - return Optional.ofNullable(System.getenv(ENV_SERVICE_NAME_KEY)) - .orElseThrow(() -> new EnvironmentConfigException( - ENV_SERVICE_NAME_KEY+ " environment variable must be defined prior to pm-mapper initialization.")); - } - - public static String getCBSHostName() throws EnvironmentConfigException { - return Optional.ofNullable(System.getenv(ENV_CBS_HOST_KEY)) - .orElseThrow(() -> new EnvironmentConfigException( - ENV_CBS_HOST_KEY+ " environment variable must be defined prior to pm-mapper initialization.")); - } - - public static Integer getCBSPort() throws EnvironmentConfigException { - Integer port = DEFAULT_CBS_PORT; - try { - port = Optional.ofNullable(System.getenv(ENV_CBS_PORT_KEY)) - .map(Integer::valueOf).orElse(DEFAULT_CBS_PORT); - } catch (NumberFormatException e) { - throw new EnvironmentConfigException(ENV_CBS_PORT_KEY + " must be valid: " + port); - } - return port; - } -} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java index 0630d53..385a256 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java @@ -17,20 +17,24 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.pmmapper.model; -import org.onap.dcaegen2.services.pmmapper.config.Configurable; -import org.onap.dcaegen2.services.pmmapper.utils.GSONRequired; +import com.google.gson.annotations.JsonAdapter; import com.google.gson.annotations.SerializedName; -import lombok.Getter; -import lombok.AccessLevel; import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.ToString; +import org.onap.dcaegen2.services.pmmapper.config.Configurable; +import org.onap.dcaegen2.services.pmmapper.utils.DMaaPAdapter; +import org.onap.dcaegen2.services.pmmapper.utils.GSONRequired; @Getter @EqualsAndHashCode @NoArgsConstructor -public class MapperConfig implements Configurable{ +@ToString +public class MapperConfig implements Configurable { public static final String CLIENT_NAME = "pm-mapper"; @@ -54,16 +58,6 @@ public class MapperConfig implements Configurable{ @SerializedName("trust_store_pass_path") private String trustStorePassPath; - @GSONRequired - @Getter(AccessLevel.PRIVATE) - @SerializedName("streams_subscribes") - private StreamsSubscribes streamsSubscribes; - - @GSONRequired - @Getter(AccessLevel.PRIVATE) - @SerializedName("streams_publishes") - private StreamsPublishes streamsPublishes; - @GSONRequired @SerializedName("dmaap_dr_delete_endpoint") private String dmaapDRDeleteEndpoint; @@ -72,98 +66,48 @@ public class MapperConfig implements Configurable{ @SerializedName("pm-mapper-filter") private MeasFilterConfig filterConfig; - public String getSubscriberIdentity(){ - return this.getStreamsSubscribes().getDmaapSubscriber().getDmaapInfo().getSubscriberId(); - } - - public String getPublisherTopicUrl() { - return this.getStreamsPublishes().getDmaapPublisher().getDmaapInfo().getTopicUrl(); - } - - public boolean dmaapInfoEquals(MapperConfig mapperConfig){ - return this - .getStreamsSubscribes() - .getDmaapSubscriber() - .getDmaapInfo() - .equals(mapperConfig.getStreamsSubscribes().getDmaapSubscriber().getDmaapInfo()); - } - - @Getter - @EqualsAndHashCode - private class StreamsSubscribes { - @GSONRequired - @SerializedName("dmaap_subscriber") - DmaapSubscriber dmaapSubscriber; - } - - @Getter - @EqualsAndHashCode - class DmaapSubscriber { - @GSONRequired - @SerializedName("dmaap_info") - DmaapInfo dmaapInfo; - } + @GSONRequired + @SerializedName("aaf_identity") + private String aafUsername; - @Getter - @EqualsAndHashCode - private class StreamsPublishes { - @GSONRequired - @SerializedName("dmaap_publisher") - DmaapPublisher dmaapPublisher; - } + @GSONRequired + @SerializedName("aaf_password") + private String aafPassword; - @Getter - @EqualsAndHashCode - class DmaapPublisher { - @GSONRequired - @SerializedName("dmaap_info") - DmaapInfo dmaapInfo; + @GSONRequired + @SerializedName("streams_subscribes") + @JsonAdapter(DMaaPAdapter.class) + private SubscriberConfig subscriberConfig; - @SerializedName("aaf_username") - private String aafUsername; + @GSONRequired + @SerializedName("streams_publishes") + @JsonAdapter(DMaaPAdapter.class) + private PublisherConfig publisherConfig; - @SerializedName("aaf_password") - private String aafPassword; + public String getSubscriberIdentity() { + return this.getSubscriberConfig().getSubscriberId(); } - @Getter - @EqualsAndHashCode - class DmaapInfo { - private String location; - private String username; - private String password; - - @SerializedName("delivery_url") - private String deliveryUrl; - - @SerializedName("subscriber_id") - private String subscriberId; - - @SerializedName("client_role") - private String clientRole; - - @SerializedName("client_id") - private String clientId; - - @SerializedName("topic_url") - private String topicUrl; + public String getPublisherTopicUrl() { + return this.getPublisherConfig().getTopicUrl(); } public String getPublisherUserName() { - return this.getStreamsPublishes().getDmaapPublisher().getAafUsername(); + return this.getAafUsername(); } public String getPublisherPassword() { - return this.getStreamsPublishes().getDmaapPublisher().getAafPassword(); + return this.getAafPassword(); } - @Override public void reconfigure(MapperConfig mapperConfig) { - if(!this.equals(mapperConfig)) { + if (!this.equals(mapperConfig)) { this.filterConfig = mapperConfig.getFilterConfig(); - this.streamsSubscribes = mapperConfig.getStreamsSubscribes(); - this.streamsPublishes = mapperConfig.getStreamsPublishes(); + this.publisherConfig = mapperConfig.getPublisherConfig(); + this.subscriberConfig = mapperConfig.getSubscriberConfig(); this.dmaapDRDeleteEndpoint = mapperConfig.getDmaapDRDeleteEndpoint(); + this.aafUsername = mapperConfig.getAafUsername(); + this.aafPassword = mapperConfig.getAafPassword(); } } } \ No newline at end of file diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/PublisherConfig.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/PublisherConfig.java new file mode 100644 index 0000000..16ab941 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/PublisherConfig.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.pmmapper.model; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import org.onap.dcaegen2.services.pmmapper.utils.GSONRequired; + +@Data +public class PublisherConfig { + @GSONRequired + @SerializedName("topic_url") + private String topicUrl; + + @GSONRequired + @SerializedName("client_role") + private String clientRole; + + @GSONRequired + @SerializedName("client_id") + private String clientId; + + @GSONRequired + @SerializedName("location") + private String clusterLocation; + +} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/SubscriberConfig.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/SubscriberConfig.java new file mode 100644 index 0000000..65f680b --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/SubscriberConfig.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.pmmapper.model; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import org.onap.dcaegen2.services.pmmapper.utils.GSONRequired; + +@Data +public class SubscriberConfig { + @GSONRequired + @SerializedName("username") + private String username; + + @GSONRequired + @SerializedName("password") + private String password; + + @GSONRequired + @SerializedName("location") + private String drLocation; + + @SerializedName("delivery_url") + private String deliveryUrl; + + @GSONRequired + @SerializedName("subscriber_id") + private String subscriberId; +} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/DMaaPAdapter.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/DMaaPAdapter.java new file mode 100644 index 0000000..fa01740 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/DMaaPAdapter.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.pmmapper.utils; + +import com.google.gson.Gson; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Optional; +import org.onap.dcaegen2.services.pmmapper.model.PublisherConfig; +import org.onap.dcaegen2.services.pmmapper.model.SubscriberConfig; + +public class DMaaPAdapter extends TypeAdapter { + private static final String PUBLISHER = "dmaap_publisher"; + private static final String SUBSCRIBER = "dmaap_subscriber"; + private static final String DMAAP_INFO = "dmaap_info"; + + @Override + public void write(JsonWriter jsonWriter, Object dmaapObj) { + throw new UnsupportedOperationException(); + } + + @Override + public Object read(JsonReader jsonReader) throws IOException { + jsonReader.beginObject(); + String rootName = jsonReader.nextName(); + Class configClass = getConfigClass(rootName); + + Object generatedConfig = null; + jsonReader.beginObject(); + while (jsonReader.hasNext()) { + if (jsonReader.nextName().equals(DMAAP_INFO)) { + generatedConfig = new Gson().fromJson(jsonReader, configClass); + } else { + jsonReader.skipValue(); + } + } + if (generatedConfig == null) { + throw new JsonParseException("Failed to Identify DMaaP Object"); + } + + jsonReader.endObject(); + jsonReader.endObject(); + return generatedConfig; + } + private Class getConfigClass(String rootName) { + Class configClass; + switch (rootName) { + case PUBLISHER: + configClass = PublisherConfig.class; + break; + case SUBSCRIBER: + configClass = SubscriberConfig.class; + break; + default: + String reason = String.format("This adapter expects one of: [ %s, %s]", PUBLISHER, SUBSCRIBER); + throw new IllegalArgumentException(reason); + } + return configClass; + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/EnvironmentConfig.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/EnvironmentConfig.java new file mode 100644 index 0000000..8457989 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/EnvironmentConfig.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.dcaegen2.services.pmmapper.utils; + +import java.util.Optional; + +import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException; + +public class EnvironmentConfig { + public static final int DEFAULT_CBS_PORT = 10000; + public static final String ENV_CBS_HOST_KEY = "CONFIG_BINDING_SERVICE_SERVICE_HOST"; + public static final String ENV_CBS_PORT_KEY = "CONFIG_BINDING_SERVICE_SERVICE_PORT"; + public static final String ENV_SERVICE_NAME_KEY = "HOSTNAME"; + + public String getServiceName() throws EnvironmentConfigException { + return Optional.ofNullable(System.getenv(ENV_SERVICE_NAME_KEY)) + .orElseThrow(() -> new EnvironmentConfigException( + ENV_SERVICE_NAME_KEY+ " environment variable must be defined prior to pm-mapper initialization.")); + } + + public String getCBSHostName() throws EnvironmentConfigException { + return Optional.ofNullable(System.getenv(ENV_CBS_HOST_KEY)) + .orElseThrow(() -> new EnvironmentConfigException( + ENV_CBS_HOST_KEY+ " environment variable must be defined prior to pm-mapper initialization.")); + } + + public Integer getCBSPort() { + return Optional.ofNullable(System.getenv(ENV_CBS_PORT_KEY)) + .map(Integer::valueOf).orElse(DEFAULT_CBS_PORT); + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequiredFieldDeserializer.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequiredFieldDeserializer.java index 258b831..3520a19 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequiredFieldDeserializer.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequiredFieldDeserializer.java @@ -41,7 +41,7 @@ import java.util.stream.Stream; public class RequiredFieldDeserializer implements JsonDeserializer { @Override - public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { T obj = new Gson().fromJson(jsonElement, type); validateRequiredFields(obj.getClass().getDeclaredFields(), obj); return obj; diff --git a/src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java b/src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java deleted file mode 100644 index e2bb4f5..0000000 --- a/src/test/java/org/onap/dcaegen2/pmmapper/config/ConfigHandlerTests.java +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.dcaegen2.pmmapper.config; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.when; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.*; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.onap.dcaegen2.services.pmmapper.config.ConfigHandler; -import org.onap.dcaegen2.services.pmmapper.exceptions.CBSConfigException; -import org.onap.dcaegen2.services.pmmapper.exceptions.CBSServerError; -import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException; -import org.onap.dcaegen2.services.pmmapper.exceptions.MapperConfigException; -import org.onap.dcaegen2.services.pmmapper.model.EnvironmentConfig; -import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; -import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.read.ListAppender; -import utils.LoggingUtils; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(EnvironmentConfig.class) -public class ConfigHandlerTests { - private static String validMapperConfig; - private static String HOSTNAME = "pm-mapper-service-name"; - private static String CBS_HOST = "cbs_host"; - private static int CBS_PORT = 10000; - private Gson gson = new Gson(); - @Mock - private RequestSender sender; - - @BeforeClass() - public static void beforeClass() throws Exception { - validMapperConfig = getFileContents("valid_mapper_config.json"); - } - - - @Before - public void before() throws Exception { - PowerMockito.mockStatic(EnvironmentConfig.class); - PowerMockito.when(EnvironmentConfig.getCBSHostName()).thenReturn(CBS_HOST); - PowerMockito.when(EnvironmentConfig.getCBSPort()).thenReturn(CBS_PORT); - PowerMockito.when(EnvironmentConfig.getServiceName()).thenReturn(HOSTNAME); - } - - @Test - public void getMapperConfig_success() throws Exception { - ListAppender logAppender = LoggingUtils.getLogListAppender(ConfigHandler.class); - String validCbsUrl = "http://" + CBS_HOST + ":" + CBS_PORT +"/service_component/" + HOSTNAME; - when(sender.send(validCbsUrl)).thenReturn(validMapperConfig); - - MapperConfig actualConfig = getMapperConfig(); - MapperConfig expectedConfig = gson.fromJson(validMapperConfig, MapperConfig.class); - - assertEquals(expectedConfig, actualConfig); - assertEquals(logAppender.list.get(0).getMarker().getName(), "ENTRY"); - assertTrue(logAppender.list.get(1).getMessage().contains("Received pm-mapper configuration from ConfigBinding Service")); - assertEquals(logAppender.list.get(1).getMarker().getName(), "EXIT"); - logAppender.stop(); - } - - @Test - public void configbinding_server_error() throws Exception { - when(sender.send(anyString())).thenThrow(CBSServerError.class); - assertThrows(CBSServerError.class, this::getMapperConfig); - } - - @Test - public void configbinding_server_host_missing() throws Exception { - PowerMockito.when(EnvironmentConfig.getCBSHostName()).thenThrow(EnvironmentConfigException.class); - assertThrows(EnvironmentConfigException.class, this::getMapperConfig); - } - - @Test - public void mapper_parse_invalid_json() throws Exception { - when(sender.send(anyString())).thenReturn("mapper config with incorrect format"); - assertThrows(MapperConfigException.class, this::getMapperConfig); - } - - @Test - public void mapper_parse_valid_json_missing_attributes() throws Exception { - Map invalidConfigs = new HashMap<>(); - invalidConfigs.put("streams_subscribes", "{}"); - invalidConfigs.put("streams_publishes", "{}"); - invalidConfigs.put("streams_publishes", null); - invalidConfigs.remove("streams_publishes"); - invalidConfigs.put("pm-mapper-filter", null); - invalidConfigs.put("pm-mapper-filter", "{}"); - invalidConfigs.put("pm-mapper-filter", "{ \"filters\": null},"); - invalidConfigs.put("pm-mapper-filter", "{ \"filters\": [{\"pmDefVsn\": \"V9\"}] },"); - - invalidConfigs.forEach( (k,v) -> { - try { - when(sender.send(anyString())).thenReturn( getInvalidConfig(k,v)); - assertThrows(MapperConfigException.class, this::getMapperConfig); - } catch (Exception e) { - e.printStackTrace(); - } - }); - } - - private MapperConfig getMapperConfig() - throws UnknownHostException, EnvironmentConfigException, CBSConfigException, Exception { - return new ConfigHandler(sender).getMapperConfig(); - } - - private static String getFileContents(String fileName) throws IOException { - ClassLoader classLoader = ConfigHandlerTests.class.getClassLoader(); - String fileAsString = ""; - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(classLoader.getResourceAsStream(fileName)))) { - String line; - while ((line = reader.readLine()) != null) { - fileAsString += line; - } - } - return fileAsString; - } - - private String getInvalidConfig(String validKey, String invalidValue) { - JsonObject invalidConfigJson = new JsonParser().parse(validMapperConfig).getAsJsonObject(); - invalidConfigJson.addProperty(validKey, invalidValue); - return invalidConfigJson.toString(); - } - -} diff --git a/src/test/java/org/onap/dcaegen2/pmmapper/config/EnvironmentConfigTest.java b/src/test/java/org/onap/dcaegen2/pmmapper/config/EnvironmentConfigTest.java deleted file mode 100644 index 95a51f7..0000000 --- a/src/test/java/org/onap/dcaegen2/pmmapper/config/EnvironmentConfigTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.dcaegen2.pmmapper.config; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException; -import org.onap.dcaegen2.services.pmmapper.model.EnvironmentConfig; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(EnvironmentConfig.class) -public class EnvironmentConfigTest { - - @Before - public void before() throws Exception { - PowerMockito.mockStatic(System.class); - } - - @Test - public void environmentConfig_is_present_success() throws EnvironmentConfigException { - String CBS_HOST = "cbs_host"; - PowerMockito.when(System.getenv(EnvironmentConfig.ENV_CBS_HOST_KEY)).thenReturn(CBS_HOST); - assertEquals(CBS_HOST,EnvironmentConfig.getCBSHostName() ); - } - - @Test - public void environmentConfig_host_not_present() throws EnvironmentConfigException { - PowerMockito.when(System.getenv(EnvironmentConfig.ENV_CBS_HOST_KEY)).thenCallRealMethod(); - assertThrows(EnvironmentConfigException.class,EnvironmentConfig::getCBSHostName); - } - - @Test - public void environmentConfig_hostname_present() throws EnvironmentConfigException { - PowerMockito.when(System.getenv(EnvironmentConfig.ENV_SERVICE_NAME_KEY)).thenCallRealMethod(); - assertThrows(EnvironmentConfigException.class,EnvironmentConfig::getCBSHostName); - } - - @Test - public void environmentConfig_default_port_is_used() throws EnvironmentConfigException { - PowerMockito.when(System.getenv(EnvironmentConfig.ENV_CBS_PORT_KEY)).thenReturn(null); - assertEquals(Integer.valueOf(EnvironmentConfig.DEFAULT_CBS_PORT),EnvironmentConfig.getCBSPort()); - } - - @Test - public void environmentConfig_port_invalid() throws EnvironmentConfigException { - PowerMockito.when(System.getenv(EnvironmentConfig.ENV_CBS_PORT_KEY)).thenReturn("Invalid_port number"); - assertThrows(EnvironmentConfigException.class,EnvironmentConfig::getCBSHostName); - } -} diff --git a/src/test/java/org/onap/dcaegen2/pmmapper/config/util/RequestSenderTests.java b/src/test/java/org/onap/dcaegen2/pmmapper/config/util/RequestSenderTests.java deleted file mode 100644 index b349b80..0000000 --- a/src/test/java/org/onap/dcaegen2/pmmapper/config/util/RequestSenderTests.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.dcaegen2.pmmapper.config.util; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockserver.integration.ClientAndServer.startClientAndServer; -import static org.mockserver.model.HttpRequest.request; -import static org.mockserver.model.HttpResponse.response; - -import java.net.URL; -import java.net.UnknownHostException; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockserver.client.server.MockServerClient; -import org.mockserver.integration.ClientAndServer; -import org.mockserver.model.HttpRequest; -import org.mockserver.model.HttpStatusCode; -import org.mockserver.verify.VerificationTimes; -import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; -import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.read.ListAppender; -import utils.LoggingUtils; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(RequestSender.class) - -public class RequestSenderTests { - private static ClientAndServer mockServer; - private MockServerClient client = mockClient(); - - @BeforeClass - public static void setup() { - mockServer = startClientAndServer(1080); - } - - @AfterClass - public static void teardown() { - mockServer.stop(); - } - - @Test - public void send_success() throws Exception { - String url = "http://127.0.0.1:1080/once"; - String uuidRegex = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"; - ListAppender logAppender = LoggingUtils.getLogListAppender(RequestSender.class); - HttpRequest req = HttpRequest.request(); - - client.when(req - .withHeader(ONAPLogConstants.Headers.REQUEST_ID, uuidRegex) - .withHeader(ONAPLogConstants.Headers.INVOCATION_ID, uuidRegex)) - .respond(response() - .withStatusCode(HttpStatusCode.OK_200.code()) - .withBody("ResponseBody")); - String result = new RequestSender().send(url); - - client.verify(req, VerificationTimes.atLeast(1)); - assertEquals(result, "ResponseBody"); - assertTrue(logAppender.list.get(1).getMessage().contains("Sending")); - assertTrue(logAppender.list.get(2).getMessage().contains("Received")); - logAppender.stop(); - client.clear(req); - } - - @Test - public void host_unavailable_retry_mechanism() throws Exception { - PowerMockito.mockStatic(Thread.class); - - client.when(request()) - .respond(response().withStatusCode(HttpStatusCode.SERVICE_UNAVAILABLE_503.code())); - - assertThrows(Exception.class, () -> { - new RequestSender().send("http://127.0.0.1:1080/anypath"); - }); - - client.verify(request(), VerificationTimes.exactly(5)); - client.clear(request()); - } - - @Test - public void host_unknown() throws Exception { - PowerMockito.mockStatic(Thread.class); - String unknownHostUrl = "http://unknown-host:1080/host-is-unknown"; - PowerMockito.whenNew(URL.class).withArguments(unknownHostUrl) - .thenThrow(UnknownHostException.class); - - assertThrows(Exception.class, () -> { - new RequestSender().send(unknownHostUrl); - }); - - client.verify(request(), VerificationTimes.exactly(0)); - client.clear(request()); - } - - private MockServerClient mockClient() { - return new MockServerClient("127.0.0.1", 1080); - } - -} \ No newline at end of file diff --git a/src/test/java/org/onap/dcaegen2/pmmapper/messagerouter/VESPublisherTest.java b/src/test/java/org/onap/dcaegen2/pmmapper/messagerouter/VESPublisherTest.java index 2244d2d..ef508f3 100644 --- a/src/test/java/org/onap/dcaegen2/pmmapper/messagerouter/VESPublisherTest.java +++ b/src/test/java/org/onap/dcaegen2/pmmapper/messagerouter/VESPublisherTest.java @@ -1,90 +1,90 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.dcaegen2.pmmapper.messagerouter; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import reactor.test.StepVerifier; -import java.util.Arrays; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.dcaegen2.services.pmmapper.exceptions.MRPublisherException; -import org.onap.dcaegen2.services.pmmapper.messagerouter.VESPublisher; -import org.onap.dcaegen2.services.pmmapper.model.EnvironmentConfig; -import org.onap.dcaegen2.services.pmmapper.model.Event; -import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; -import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import reactor.core.publisher.Flux; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(EnvironmentConfig.class) -public class VESPublisherTest { - - private static String topicURL = "http://mr/topic"; - private static RequestSender sender; - private static MapperConfig config; - private VESPublisher sut; - private String ves = "{}"; - - @Before - public void before() throws Exception { - config = mock(MapperConfig.class); - sender = mock(RequestSender.class); - sut = new VESPublisher(config, sender); - when(config.getPublisherTopicUrl()).thenReturn(topicURL); - } - - @Test - public void publish_multiple_success() throws Exception { - Event event = mock(Event.class); - List events = Arrays.asList(event,event,event); - when(event.getVes()).thenReturn(ves); - - Flux flux = sut.publish(events); - - verify(sender, times(3)).send(Mockito.anyString(),Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - StepVerifier.create(flux) - .expectNextMatches(event::equals) - .expectComplete() - .verify(); - } - - @Test - public void publish_multiple_fail() throws Exception { - Event event = mock(Event.class); - List events = Arrays.asList(event,event,event); - when(event.getVes()).thenReturn(ves); - when(sender.send("POST",topicURL,ves,"base64encoded")).thenThrow(Exception.class); - - Flux flux = sut.publish(events); - - StepVerifier.create(flux) - .expectNext(events.get(0)) - .verifyComplete(); - } -} +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.dcaegen2.pmmapper.messagerouter; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import reactor.test.StepVerifier; +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.dcaegen2.services.pmmapper.exceptions.MRPublisherException; +import org.onap.dcaegen2.services.pmmapper.messagerouter.VESPublisher; +import org.onap.dcaegen2.services.pmmapper.utils.EnvironmentConfig; +import org.onap.dcaegen2.services.pmmapper.model.Event; +import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; +import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import reactor.core.publisher.Flux; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(EnvironmentConfig.class) +public class VESPublisherTest { + + private static String topicURL = "http://mr/topic"; + private static RequestSender sender; + private static MapperConfig config; + private VESPublisher sut; + private String ves = "{}"; + + @Before + public void before() throws Exception { + config = mock(MapperConfig.class); + sender = mock(RequestSender.class); + sut = new VESPublisher(config, sender); + when(config.getPublisherTopicUrl()).thenReturn(topicURL); + } + + @Test + public void publish_multiple_success() throws Exception { + Event event = mock(Event.class); + List events = Arrays.asList(event,event,event); + when(event.getVes()).thenReturn(ves); + + Flux flux = sut.publish(events); + + verify(sender, times(3)).send(Mockito.anyString(),Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); + StepVerifier.create(flux) + .expectNextMatches(event::equals) + .expectComplete() + .verify(); + } + + @Test + public void publish_multiple_fail() throws Exception { + Event event = mock(Event.class); + List events = Arrays.asList(event,event,event); + when(event.getVes()).thenReturn(ves); + when(sender.send("POST",topicURL,ves,"base64encoded")).thenThrow(Exception.class); + + Flux flux = sut.publish(events); + + StepVerifier.create(flux) + .expectNext(events.get(0)) + .verifyComplete(); + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java index 2db24b4..11215b3 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java @@ -74,8 +74,8 @@ class AppTest { @BeforeAll public static void setup() { - mockServer = startClientAndServer(1080); - client = new MockServerClient("127.0.0.1", 1080); + mockServer = startClientAndServer(35454); + client = new MockServerClient("127.0.0.1", 35454); } @AfterAll @@ -210,7 +210,7 @@ class AppTest { MeasFilterHandler mockFilter = Mockito.mock(MeasFilterHandler.class); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); - Mockito.when(mockConfig.getDmaapDRDeleteEndpoint()).thenReturn("http://127.0.0.1:1080"); + Mockito.when(mockConfig.getDmaapDRDeleteEndpoint()).thenReturn("http://127.0.0.1:35454"); Mockito.when(mockConfig.getSubscriberIdentity()).thenReturn("sid"); Mockito.when(mockEvent.getPublishIdentity()).thenReturn("pid"); Mockito.when(mockFilter.filterByMeasType(mockEvent)).thenThrow(RuntimeException.class); diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandlerTests.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandlerTests.java new file mode 100644 index 0000000..92d2c93 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandlerTests.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.pmmapper.config; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.UnknownHostException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.services.pmmapper.exceptions.CBSConfigException; +import org.onap.dcaegen2.services.pmmapper.exceptions.CBSServerError; +import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException; +import org.onap.dcaegen2.services.pmmapper.exceptions.MapperConfigException; +import org.onap.dcaegen2.services.pmmapper.utils.EnvironmentConfig; +import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; +import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; + + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; +import utils.FileUtils; +import utils.LoggingUtils; + +@ExtendWith(MockitoExtension.class) +class ConfigHandlerTests { + private static String validMapperConfig; + private static String HOSTNAME = "pm-mapper-service-name"; + private static String CBS_HOST = "cbs_host"; + private static int CBS_PORT = 10000; + private static Path invalidConfigsDirectory = Paths.get("src/test/resources/invalid_configs/"); + + private Gson gson = new Gson(); + + @Mock + private RequestSender sender; + + @Mock + private static EnvironmentConfig config; + + @BeforeAll + static void beforeAll() throws Exception { + validMapperConfig = FileUtils.getFileContents("valid_mapper_config.json"); + config = mock(EnvironmentConfig.class); + when(config.getServiceName()).thenReturn(HOSTNAME); + when(config.getCBSPort()).thenReturn(CBS_PORT); + } + + @BeforeEach + void setup() throws Exception { + when(config.getCBSHostName()).thenReturn(CBS_HOST); + } + + @Test + void getMapperConfig_success() throws Exception { + when(config.getCBSHostName()).thenReturn(CBS_HOST); + when(config.getServiceName()).thenReturn(HOSTNAME); + when(config.getCBSPort()).thenReturn(CBS_PORT); + + ListAppender logAppender = LoggingUtils.getLogListAppender(ConfigHandler.class); + String validCbsUrlMapperConfig = "http://" + CBS_HOST + ":" + CBS_PORT + "/service_component/" + HOSTNAME; + when(sender.send(validCbsUrlMapperConfig)).thenReturn(validMapperConfig); + MapperConfig actualConfig = getMapperConfig(); + JsonObject expectedConfigJson = gson.fromJson(validMapperConfig, JsonObject.class); + MapperConfig expectedConfig = gson.fromJson(expectedConfigJson, MapperConfig.class); + assertEquals(expectedConfig, actualConfig); + assertTrue(logAppender.list.get(1).getMessage().contains("Received pm-mapper configuration from ConfigBinding Service")); + logAppender.stop(); + } + + @Test + void configbinding_server_error() throws Exception { + when(sender.send(anyString())).thenThrow(CBSServerError.class); + assertThrows(CBSServerError.class, this::getMapperConfig); + } + + @Test + void configbinding_server_host_missing() throws Exception { + when(config.getCBSHostName()).thenThrow(EnvironmentConfigException.class); + assertThrows(EnvironmentConfigException.class, this::getMapperConfig); + } + + @Test + void mapper_parse_invalid_json_mapper_config() throws Exception { + when(sender.send(anyString())).thenReturn("mapper config with incorrect format"); + assertThrows(MapperConfigException.class, this::getMapperConfig); + } + + @ParameterizedTest + @MethodSource("getInvalidConfigs") + void parse_valid_json_bad_values_mapper_config(String mapperConfig) throws Exception { + when(sender.send(anyString())).thenReturn(mapperConfig); + assertThrows(MapperConfigException.class, this::getMapperConfig); + } + + private MapperConfig getMapperConfig() + throws UnknownHostException, EnvironmentConfigException, CBSConfigException, Exception { + return new ConfigHandler(sender, config).getMapperConfig(); + } + + private static List getInvalidConfigs() throws IOException { + return FileUtils.getFilesFromDirectory(invalidConfigsDirectory); + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfigurationTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfigurationTest.java index c900942..905d18a 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfigurationTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/DynamicConfigurationTest.java @@ -20,31 +20,27 @@ package org.onap.dcaegen2.services.pmmapper.config; - import com.google.gson.JsonObject; import com.google.gson.JsonParser; import io.undertow.server.HttpServerExchange; import io.undertow.util.StatusCodes; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; import org.onap.dcaegen2.services.pmmapper.exceptions.ReconfigurationException; -import org.onap.dcaegen2.services.pmmapper.model.EnvironmentConfig; +import org.onap.dcaegen2.services.pmmapper.utils.EnvironmentConfig; import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import utils.ConfigUtils; import java.util.ArrayList; +import utils.FileUtils; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -55,62 +51,55 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(PowerMockRunner.class) -@PrepareForTest({DynamicConfiguration.class, EnvironmentConfig.class}) -public class DynamicConfigurationTest { - private static Path VALID_CONFIG_PATH = Paths.get("src/test/resources/valid_mapper_config.json"); +@ExtendWith(MockitoExtension.class) +class DynamicConfigurationTest { + private static final String VALID_MAPPER_CONFIG_FILE = "valid_mapper_config.json"; private static ArrayList configurables; private DynamicConfiguration objUnderTest; - private static String config; + private static String mapperConfig; private MapperConfig originalMapperConfig; + private static ConfigHandler configHandler; + + @Mock + private static RequestSender sender; @Mock - private RequestSender sender; + private static EnvironmentConfig config; - @BeforeClass() - public static void setupBeforeClass() throws Exception { - config = new String(Files.readAllBytes(VALID_CONFIG_PATH)); + @BeforeAll + static void setupBeforeAll() throws Exception { + mapperConfig = FileUtils.getFileContents(VALID_MAPPER_CONFIG_FILE); } - @Before - public void setup() throws Exception { + @BeforeEach + void setup() throws Exception { + configHandler = new ConfigHandler(sender, config); + when(sender.send(any())).thenReturn(mapperConfig); + originalMapperConfig = ConfigUtils.getMapperConfigFromFile(VALID_MAPPER_CONFIG_FILE); configurables = new ArrayList<>(); - PowerMockito.mockStatic(EnvironmentConfig.class); - PowerMockito.when(EnvironmentConfig.getCBSHostName()).thenReturn(""); - PowerMockito.when(EnvironmentConfig.getCBSPort()).thenReturn(1); - PowerMockito.when(EnvironmentConfig.getServiceName()).thenReturn(""); - - when(sender.send(any())).thenReturn(config); - ConfigHandler configHandler = new ConfigHandler(sender); - originalMapperConfig = configHandler.getMapperConfig(); objUnderTest = new DynamicConfiguration(configurables, originalMapperConfig); } @Test - public void testNoChangeResponse() throws Exception { - ConfigHandler configHandler = new ConfigHandler(sender); + void testNoChangeResponse() throws Exception { originalMapperConfig = configHandler.getMapperConfig(); objUnderTest.setConfigHandler(configHandler); - HttpServerExchange httpServerExchange = mock(HttpServerExchange.class, RETURNS_DEEP_STUBS); objUnderTest.handleRequest(httpServerExchange); - assertEquals(originalMapperConfig, objUnderTest.getOriginalConfig()); verify(httpServerExchange, times(1)).setStatusCode(StatusCodes.OK); + assertEquals(originalMapperConfig, objUnderTest.getOriginalConfig()); } @Test - public void testApplyOriginalUponFailure() throws Exception { - ConfigHandler configHandler = new ConfigHandler(sender); + void testApplyOriginalUponFailure() throws Exception { Configurable configurable = mock(Configurable.class); configurables.add(configurable); - JsonObject modifiedConfig = new JsonParser().parse(config).getAsJsonObject(); + JsonObject modifiedConfig = new JsonParser().parse(mapperConfig).getAsJsonObject(); modifiedConfig.addProperty("dmaap_dr_delete_endpoint","http://modified-delete-endpoint/1"); when(sender.send(any())).thenReturn(modifiedConfig.toString()); MapperConfig modifiedMapperConfig = configHandler.getMapperConfig(); - objUnderTest.setConfigHandler(configHandler); - doAnswer(new Answer() { boolean failFirstReconfigure = true; @Override @@ -132,14 +121,14 @@ public class DynamicConfigurationTest { } @Test - public void testSuccessfulReconfiguration() throws Exception { - ConfigHandler configHandler = new ConfigHandler(sender); + void testSuccessfulReconfiguration() throws Exception { Configurable configurable = mock(Configurable.class); configurables.add(configurable); - JsonObject modifiedConfig = new JsonParser().parse(config).getAsJsonObject(); + JsonObject modifiedConfig = new JsonParser().parse(mapperConfig).getAsJsonObject(); modifiedConfig.addProperty("dmaap_dr_delete_endpoint","http://modified-delete-endpoint/1"); - when(sender.send(any())).thenReturn(modifiedConfig.toString()); + when(sender.send(any())) + .thenReturn(modifiedConfig.toString()); MapperConfig modifiedMapperConfig = configHandler.getMapperConfig(); objUnderTest.setConfigHandler(configHandler); @@ -152,18 +141,21 @@ public class DynamicConfigurationTest { } @Test - public void testMapperConfigReconfiguration() throws Exception { - ConfigHandler configHandler = new ConfigHandler(sender); - JsonObject modifiedConfigJson = new JsonParser().parse(config).getAsJsonObject(); + void testMapperConfigReconfiguration() throws Exception { + JsonObject modifiedConfigJson = new JsonParser().parse(mapperConfig).getAsJsonObject(); modifiedConfigJson.addProperty("dmaap_dr_delete_endpoint","http://modified-delete-endpoint/1"); - String newConfig = modifiedConfigJson.toString(); - - when(sender.send(any())).thenReturn(config,newConfig); - - MapperConfig originalConfig = configHandler.getMapperConfig(); + when(sender.send(any())) + .thenReturn(modifiedConfigJson.toString()); MapperConfig modifiedConfig = configHandler.getMapperConfig(); + originalMapperConfig.reconfigure(modifiedConfig); + assertEquals(originalMapperConfig, modifiedConfig); + } - originalConfig.reconfigure(modifiedConfig); - assertEquals(originalConfig, modifiedConfig); + @Test + void testMapperConfigReconfigurationNoChange() throws Exception { + when(sender.send(any())).thenReturn(mapperConfig); + MapperConfig inboundConfig = configHandler.getMapperConfig(); + originalMapperConfig.reconfigure(inboundConfig); + assertEquals(originalMapperConfig, inboundConfig); } } diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandlerTest.java index 94a2c7d..9b7bc4d 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandlerTest.java @@ -44,20 +44,17 @@ import io.undertow.util.StatusCodes; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; -import org.onap.dcaegen2.services.pmmapper.model.EnvironmentConfig; import org.onap.dcaegen2.services.pmmapper.model.Event; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import utils.LoggingUtils; -@RunWith(PowerMockRunner.class) -@PrepareForTest({DeliveryHandler.class, EnvironmentConfig.class}) -public class DeliveryHandlerTest { +@ExtendWith(MockitoExtension.class) +class DeliveryHandlerTest { private Path VALID_METADATA_PATH = Paths.get("src/test/resources/valid_metadata.json"); private Path INVALID_METADATA_PATH = Paths.get("src/test/resources/invalid_metadata.json"); @@ -67,13 +64,13 @@ public class DeliveryHandlerTest { private DeliveryHandler objUnderTest; - @Before - public void setUp() { + @BeforeEach + void setUp() { objUnderTest = new DeliveryHandler(eventReceiver); } @Test - public void testRequestInboundInvalidMetadata() throws Exception { + void testRequestInboundInvalidMetadata() throws Exception { HttpServerExchange httpServerExchange = mock(HttpServerExchange.class, RETURNS_DEEP_STUBS); JsonObject metadata = new JsonParser().parse(new String(Files .readAllBytes(INVALID_METADATA_PATH))).getAsJsonObject(); @@ -87,7 +84,7 @@ public class DeliveryHandlerTest { } @Test - public void testRequestInboundNoMetadata() throws Exception { + void testRequestInboundNoMetadata() throws Exception { HttpServerExchange httpServerExchange = mock(HttpServerExchange.class, RETURNS_DEEP_STUBS); Receiver receiver = mock(Receiver.class); HeaderMap headers = mock(HeaderMap.class); @@ -95,17 +92,6 @@ public class DeliveryHandlerTest { when(httpServerExchange.setStatusCode(anyInt())).thenReturn(httpServerExchange); when(httpServerExchange.getRequestHeaders()).thenReturn(headers); when(headers.get(any(String.class))).thenReturn(null); - - doAnswer((Answer) invocationOnMock -> { - Receiver.FullStringCallback callback = invocationOnMock.getArgument(0); - callback.handle(httpServerExchange, ""); - return null; - }).when(receiver).receiveFullString(any()); - doAnswer((Answer) invocationOnMock -> { - Runnable runnable = invocationOnMock.getArgument(0); - runnable.run(); - return null; - }).when(httpServerExchange).dispatch(any(Runnable.class)); objUnderTest.handleRequest(httpServerExchange); verify(httpServerExchange, times(1)).setStatusCode(StatusCodes.BAD_REQUEST); verify(httpServerExchange.getResponseSender(), times(1)).send("Missing Metadata."); @@ -113,7 +99,7 @@ public class DeliveryHandlerTest { } @Test - public void testRequestInboundSuccess() throws Exception { + void testRequestInboundSuccess() throws Exception { ListAppender logAppender = LoggingUtils.getLogListAppender(DeliveryHandler.class); HttpServerExchange httpServerExchange = mock(HttpServerExchange.class, RETURNS_DEEP_STUBS); Receiver receiver = mock(Receiver.class); diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MetadataFilterTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MetadataFilterTest.java index 47c187a..abe1b39 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MetadataFilterTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MetadataFilterTest.java @@ -20,7 +20,6 @@ package org.onap.dcaegen2.services.pmmapper.filtering; -import com.google.gson.Gson; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -29,10 +28,10 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.onap.dcaegen2.services.pmmapper.model.Event; import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; import org.powermock.core.classloader.annotations.PrepareForTest; +import utils.ConfigUtils; import utils.EventUtils; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; @@ -44,41 +43,26 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @PrepareForTest(MapperConfig.class) public class MetadataFilterTest { - private MetadataFilter metadataFilter; + private static final String VALID_MAPPER_CONFIG_FILE = "valid_mapper_config.json"; + private static final String NO_FILTER_CONFIG_FILE = "no_filter_mapper_config.json"; + private static final String MULTIPLE_FILTER_CONFIG_FILE = "multiple_filter_mapper_config.json"; + private static final Path DATA_DIRECTORY = Paths.get("src/test/resources/xml_validator_test/test_data/"); + private static final Path VALID_METADATA = Paths.get("src/test/resources/valid_metadata.json"); + private static final Path INCORRECT_METADATA = Paths.get("src/test/resources/incorrect_metadata.json"); + private MetadataFilter metadataFilter; private static MapperConfig validConfig; private static MapperConfig noFilterConfig; private static MapperConfig multipleFilterConfig; - private static String validConfigFileContents; - private static String noFilterConfigFileContents; - private static String multipleFilterConfigFileContents; - - private static final Path validMetadata = Paths.get("src/test/resources/valid_metadata.json"); - private static final Path incorrectMetadata = Paths.get("src/test/resources/incorrect_metadata.json"); - - private static final Path validConfigPath = Paths.get("src/test/resources/valid_mapper_config.json"); - private static final Path noFilterConfigPath = Paths.get("src/test/resources/no_filter_mapper_config.json"); - private static final Path multipleFilterConfigPath = Paths.get("src/test/resources/multiple_filter_mapper_config.json"); - - private static final Path dataDirectory = Paths.get("src/test/resources/xml_validator_test/test_data/"); - - @BeforeEach void setup() throws Exception { - validConfigFileContents = new String(Files.readAllBytes(validConfigPath)); - noFilterConfigFileContents = new String(Files.readAllBytes(noFilterConfigPath)); - multipleFilterConfigFileContents = new String(Files.readAllBytes(multipleFilterConfigPath)); - - validConfig = new Gson().fromJson(validConfigFileContents, MapperConfig.class); - noFilterConfig = new Gson().fromJson(noFilterConfigFileContents, MapperConfig.class); - multipleFilterConfig = new Gson().fromJson(multipleFilterConfigFileContents, MapperConfig.class); - - - metadataFilter = new MetadataFilter(this.validConfig); + validConfig = ConfigUtils.getMapperConfigFromFile(VALID_MAPPER_CONFIG_FILE); + noFilterConfig = ConfigUtils.getMapperConfigFromFile(NO_FILTER_CONFIG_FILE); + multipleFilterConfig = ConfigUtils.getMapperConfigFromFile(MULTIPLE_FILTER_CONFIG_FILE); + metadataFilter = new MetadataFilter(validConfig); } - @ParameterizedTest @MethodSource("getEventsWithValidMetadata") void testValidMetadataPass(Event testEvent) { @@ -105,15 +89,13 @@ public class MetadataFilterTest { assertFalse(metadataFilter.filter(testEvent)); } - - private static List getEventsWithValidMetadata() throws IOException { - Path validDataDirectory = Paths.get(dataDirectory.toString() + "/valid/"); - return EventUtils.eventsFromDirectory(validDataDirectory, validMetadata); + Path validDataDirectory = Paths.get(DATA_DIRECTORY.toString() + "/valid/"); + return EventUtils.eventsFromDirectory(validDataDirectory, VALID_METADATA); } private static List getEventsWithInvalidMetadata() throws IOException { - Path validDataDirectory = Paths.get(dataDirectory.toString() + "/valid/"); - return EventUtils.eventsFromDirectory(validDataDirectory, incorrectMetadata); + Path validDataDirectory = Paths.get(DATA_DIRECTORY.toString() + "/valid/"); + return EventUtils.eventsFromDirectory(validDataDirectory, INCORRECT_METADATA); } } \ No newline at end of file diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/DMaaPAdapterTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/DMaaPAdapterTest.java new file mode 100644 index 0000000..9b22b95 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/DMaaPAdapterTest.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.pmmapper.utils; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.google.gson.JsonParseException; +import com.google.gson.stream.JsonReader; +import java.io.IOException; +import java.io.StringReader; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.services.pmmapper.model.PublisherConfig; +import org.onap.dcaegen2.services.pmmapper.model.SubscriberConfig; + +@ExtendWith(MockitoExtension.class) +class DMaaPAdapterTest { + private DMaaPAdapter objUnderTest; + + @BeforeEach + void beforeEach() { + objUnderTest = new DMaaPAdapter(); + } + + @Test + void testSuccessfulPublisher() throws IOException { + String dmaapPublisher = "{\"dmaap_publisher\": {\"dmaap_info\": {" + + "\"topic_url\": \"https://message-router:3905/events/org.onap.dmaap.mr.VES_PM\"," + + "\"client_role\": \"org.onap.dcae.pmPublisher\"," + + "\"location\": \"san-francisco\"," + + "\"client_id\": \"1562763644939\"" + "}," + + "\"something\":\"completely different\"}}"; + JsonReader reader = new JsonReader(new StringReader(dmaapPublisher)); + assertTrue(objUnderTest.read(reader) instanceof PublisherConfig); + } + + @Test + void testSuccessfulSubscriber() throws IOException { + String dmaapSubscriber = "{\"dmaap_subscriber\": {\"dmaap_info\": {" + + "\"username\": \"username\"," + + "\"password\": \"password\"," + + "\"location\": \"san-francisco\"," + + "\"delivery_url\": \"http://dcae-pm-mapper:8443/delivery\"," + + "\"subscriber_id\": 1" + "}}}"; + JsonReader reader = new JsonReader(new StringReader(dmaapSubscriber)); + assertTrue(objUnderTest.read(reader) instanceof SubscriberConfig); + } + + @Test + void testFailedAdaption() { + JsonReader reader = new JsonReader(new StringReader("{\"dmaap_subscriber\": {\"dmaap_info\": \"nope\"}")); + assertThrows(JsonParseException.class, () -> objUnderTest.read(reader)); + } + + @Test + void testNoAdaptionAttempt() { + JsonReader reader = new JsonReader(new StringReader("{\"dmaap_subscriber\": {}")); + assertThrows(JsonParseException.class, () -> objUnderTest.read(reader)); + } + + @Test + void testInvalidAdaptionTarget() { + JsonReader reader = new JsonReader(new StringReader("{\"A scratch? \": \"Your arm's off!\" }")); + assertThrows(IllegalArgumentException.class, () -> objUnderTest.read(reader)); + } + + @Test + void testFailWriting() { + assertThrows(UnsupportedOperationException.class, () -> objUnderTest.write(null, null)); + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/EnvironmentConfigTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/EnvironmentConfigTest.java new file mode 100644 index 0000000..e3c32c8 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/EnvironmentConfigTest.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.pmmapper.utils; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(EnvironmentConfig.class) +public class EnvironmentConfigTest { + private EnvironmentConfig objUnderTest; + + @Before + public void before() throws Exception { + PowerMockito.mockStatic(System.class); + objUnderTest = new EnvironmentConfig(); + } + + @Test + public void environmentConfig_is_present_success() throws EnvironmentConfigException { + String CBS_HOST = "cbs_host"; + PowerMockito.when(System.getenv(EnvironmentConfig.ENV_CBS_HOST_KEY)).thenReturn(CBS_HOST); + assertEquals(CBS_HOST, objUnderTest.getCBSHostName()); + } + + @Test + public void environmentConfig_host_not_present() throws EnvironmentConfigException { + PowerMockito.when(System.getenv(EnvironmentConfig.ENV_CBS_HOST_KEY)).thenReturn(null); + assertThrows(EnvironmentConfigException.class, objUnderTest::getCBSHostName); + } + + @Test + public void environmentConfig_hostname_present() throws EnvironmentConfigException { + PowerMockito.when(System.getenv(EnvironmentConfig.ENV_SERVICE_NAME_KEY)).thenCallRealMethod(); + assertThrows(EnvironmentConfigException.class, objUnderTest::getCBSHostName); + } + + @Test + public void environmentConfig_default_port_is_used() throws EnvironmentConfigException { + PowerMockito.when(System.getenv(EnvironmentConfig.ENV_CBS_PORT_KEY)).thenReturn(null); + assertEquals(Integer.valueOf(EnvironmentConfig.DEFAULT_CBS_PORT), objUnderTest.getCBSPort()); + } + + @Test + public void environmentConfig_port_invalid() throws EnvironmentConfigException { + PowerMockito.when(System.getenv(EnvironmentConfig.ENV_CBS_PORT_KEY)).thenReturn("Invalid_port number"); + assertThrows(EnvironmentConfigException.class, objUnderTest::getCBSHostName); + } + + @Test + public void environmentConfig_service_name_missing() { + PowerMockito.when(System.getenv(EnvironmentConfig.ENV_SERVICE_NAME_KEY)).thenReturn(null); + assertThrows(EnvironmentConfigException.class, objUnderTest::getServiceName); + } + @Test + public void environmentConfig_service_name_success() throws EnvironmentConfigException { + String serviceName = "we the best service"; + PowerMockito.when(System.getenv(EnvironmentConfig.ENV_SERVICE_NAME_KEY)).thenReturn(serviceName); + assertEquals(serviceName, objUnderTest.getServiceName()); + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java new file mode 100644 index 0000000..34a2277 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.dcaegen2.services.pmmapper.utils; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockserver.integration.ClientAndServer.startClientAndServer; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; + +import java.net.URL; +import java.net.UnknownHostException; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockserver.client.server.MockServerClient; +import org.mockserver.integration.ClientAndServer; +import org.mockserver.model.HttpRequest; +import org.mockserver.model.HttpStatusCode; +import org.mockserver.verify.VerificationTimes; +import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; +import utils.LoggingUtils; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(RequestSender.class) + +public class RequestSenderTests { + private static ClientAndServer mockServer; + private MockServerClient client = mockClient(); + + @BeforeClass + public static void setup() { + mockServer = startClientAndServer(35454); + } + + @AfterClass + public static void teardown() { + mockServer.stop(); + } + + @Test + public void send_success() throws Exception { + String url = "http://127.0.0.1:35454/once"; + String uuidRegex = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"; + ListAppender logAppender = LoggingUtils.getLogListAppender(RequestSender.class); + HttpRequest req = HttpRequest.request(); + + client.when(req + .withHeader(ONAPLogConstants.Headers.REQUEST_ID, uuidRegex) + .withHeader(ONAPLogConstants.Headers.INVOCATION_ID, uuidRegex)) + .respond(response() + .withStatusCode(HttpStatusCode.OK_200.code()) + .withBody("ResponseBody")); + String result = new RequestSender().send(url); + + client.verify(req, VerificationTimes.atLeast(1)); + assertEquals(result, "ResponseBody"); + assertTrue(logAppender.list.get(1).getMessage().contains("Sending")); + assertTrue(logAppender.list.get(2).getMessage().contains("Received")); + logAppender.stop(); + client.clear(req); + } + + @Test + public void host_unavailable_retry_mechanism() throws Exception { + PowerMockito.mockStatic(Thread.class); + + client.when(request()) + .respond(response().withStatusCode(HttpStatusCode.SERVICE_UNAVAILABLE_503.code())); + + assertThrows(Exception.class, () -> { + new RequestSender().send("http://127.0.0.1:35454/anypath"); + }); + + client.verify(request(), VerificationTimes.exactly(5)); + client.clear(request()); + } + + @Test + public void host_unknown() throws Exception { + PowerMockito.mockStatic(Thread.class); + String unknownHostUrl = "http://unknown-host:35454/host-is-unknown"; + PowerMockito.whenNew(URL.class).withArguments(unknownHostUrl) + .thenThrow(UnknownHostException.class); + + assertThrows(Exception.class, () -> { + new RequestSender().send(unknownHostUrl); + }); + + client.verify(request(), VerificationTimes.exactly(0)); + client.clear(request()); + } + + private MockServerClient mockClient() { + return new MockServerClient("127.0.0.1", 35454); + } + +} \ No newline at end of file diff --git a/src/test/java/utils/ConfigUtils.java b/src/test/java/utils/ConfigUtils.java new file mode 100644 index 0000000..8cf6d87 --- /dev/null +++ b/src/test/java/utils/ConfigUtils.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package utils; + +import com.google.gson.Gson; +import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; + + +public class ConfigUtils { + + /** + * Returns A MapperConfig Object Created from a file. + * Fails test in the event of failure to read file. + * @param mapperConfigFile Filename for the mapper config + * @return A Mapper Config Object + */ + public static MapperConfig getMapperConfigFromFile(String mapperConfigFile) { + return new Gson().fromJson(FileUtils.getFileContents(mapperConfigFile), MapperConfig.class); + } +} diff --git a/src/test/java/utils/EventUtils.java b/src/test/java/utils/EventUtils.java index eae050d..f14e080 100644 --- a/src/test/java/utils/EventUtils.java +++ b/src/test/java/utils/EventUtils.java @@ -51,13 +51,10 @@ public class EventUtils { */ public static List eventsFromDirectory(Path eventBodyDirectory, Path metadataPath) throws IOException { EventMetadata eventMetadata = new Gson().fromJson(fileContentsToString(metadataPath), EventMetadata.class); - try (Stream eventFileStream = Files.walk(eventBodyDirectory)) { - return eventFileStream.filter(Files::isRegularFile) - .filter(Files::isReadable) - .map(EventUtils::fileContentsToString) - .map(body -> EventUtils.makeMockEvent(body, eventMetadata)) - .collect(Collectors.toList()); - } + List eventFiles = FileUtils.getFilesFromDirectory(eventBodyDirectory); + return eventFiles.stream() + .map(contents -> EventUtils.makeMockEvent(contents, eventMetadata)) + .collect(Collectors.toList()); } /** diff --git a/src/test/java/utils/FileUtils.java b/src/test/java/utils/FileUtils.java new file mode 100644 index 0000000..8b58618 --- /dev/null +++ b/src/test/java/utils/FileUtils.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package utils; + +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class FileUtils { + + /** + * Reads contents of files inside the eventBodyDirectory, combines contents with metadata to make an Event Object. + * Fails test in the event of failure to read a file. + * @param targetDirectory Path to directory with files. + * @return List of Strings containing the body as acquired from files inside targetDirectory. + * @throws IOException in the event it fails to read from the files. + */ + public static List getFilesFromDirectory(Path targetDirectory ) throws IOException { + try (Stream eventFileStream = Files.walk(targetDirectory)) { + return eventFileStream.filter(Files::isRegularFile) + .filter(Files::isReadable) + .map(FileUtils::getFileContents) + .collect(Collectors.toList()); + } + } + + /** + * reads contents of file into a string. + * fails a tests in the event failure occurs. + * @param path path to file. + * @return string containing files contents + */ + public static String getFileContents(Path path) { + try { + return new String(Files.readAllBytes(path)); + } catch (IOException exception) { + fail("IOException occurred while reading file."); + } + return null; + } + + /** + * Reads contents of resource. + * fails a test in the event failure occurs. + * @param fileName of file in resources to be read. + * @return contents of file + */ + public static String getFileContents(String fileName) { + try { + Path path = Paths.get(ClassLoader.getSystemResource(fileName).toURI()); + return getFileContents(path); + } catch (URISyntaxException exception) { + fail("Exception occurred, failed to acquire resource URI."); + } + return null; + } +} diff --git a/src/test/resources/invalid_configs/empty_filter_object.json b/src/test/resources/invalid_configs/empty_filter_object.json new file mode 100644 index 0000000..8c72b83 --- /dev/null +++ b/src/test/resources/invalid_configs/empty_filter_object.json @@ -0,0 +1,35 @@ +{ + "pm-mapper-filter": {}, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/invalid_filter_object.json b/src/test/resources/invalid_configs/invalid_filter_object.json new file mode 100644 index 0000000..1b7b0e3 --- /dev/null +++ b/src/test/resources/invalid_configs/invalid_filter_object.json @@ -0,0 +1,41 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9" + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_aaf_identity.json b/src/test/resources/invalid_configs/null_aaf_identity.json new file mode 100644 index 0000000..8f9c7ef --- /dev/null +++ b/src/test/resources/invalid_configs/null_aaf_identity.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": null, + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_aaf_password.json b/src/test/resources/invalid_configs/null_aaf_password.json new file mode 100644 index 0000000..d54d825 --- /dev/null +++ b/src/test/resources/invalid_configs/null_aaf_password.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": null, + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_client_role.json b/src/test/resources/invalid_configs/null_client_role.json new file mode 100644 index 0000000..40471de --- /dev/null +++ b/src/test/resources/invalid_configs/null_client_role.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": null, + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_dmaap_dr_delete_endpoint.json b/src/test/resources/invalid_configs/null_dmaap_dr_delete_endpoint.json new file mode 100644 index 0000000..d86de5e --- /dev/null +++ b/src/test/resources/invalid_configs/null_dmaap_dr_delete_endpoint.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": null, + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_dr_location.json b/src/test/resources/invalid_configs/null_dr_location.json new file mode 100644 index 0000000..79bd05d --- /dev/null +++ b/src/test/resources/invalid_configs/null_dr_location.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": null, + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_dr_password.json b/src/test/resources/invalid_configs/null_dr_password.json new file mode 100644 index 0000000..365b328 --- /dev/null +++ b/src/test/resources/invalid_configs/null_dr_password.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": null, + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_dr_subscriber_id.json b/src/test/resources/invalid_configs/null_dr_subscriber_id.json new file mode 100644 index 0000000..c6c2a45 --- /dev/null +++ b/src/test/resources/invalid_configs/null_dr_subscriber_id.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": null + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_dr_username.json b/src/test/resources/invalid_configs/null_dr_username.json new file mode 100644 index 0000000..511dd35 --- /dev/null +++ b/src/test/resources/invalid_configs/null_dr_username.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": null, + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_filter.json b/src/test/resources/invalid_configs/null_filter.json new file mode 100644 index 0000000..7eb6af0 --- /dev/null +++ b/src/test/resources/invalid_configs/null_filter.json @@ -0,0 +1,35 @@ +{ + "pm-mapper-filter": null, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_filter_array.json b/src/test/resources/invalid_configs/null_filter_array.json new file mode 100644 index 0000000..3d2df14 --- /dev/null +++ b/src/test/resources/invalid_configs/null_filter_array.json @@ -0,0 +1,37 @@ +{ + "pm-mapper-filter": { + "filters": null + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_key_store_pass_path.json b/src/test/resources/invalid_configs/null_key_store_pass_path.json new file mode 100644 index 0000000..2145e01 --- /dev/null +++ b/src/test/resources/invalid_configs/null_key_store_pass_path.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": null, + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_key_store_path.json b/src/test/resources/invalid_configs/null_key_store_path.json new file mode 100644 index 0000000..8f6f831 --- /dev/null +++ b/src/test/resources/invalid_configs/null_key_store_path.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": null, + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_location.json b/src/test/resources/invalid_configs/null_location.json new file mode 100644 index 0000000..b7d9266 --- /dev/null +++ b/src/test/resources/invalid_configs/null_location.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": null, + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_topic_url.json b/src/test/resources/invalid_configs/null_topic_url.json new file mode 100644 index 0000000..faea169 --- /dev/null +++ b/src/test/resources/invalid_configs/null_topic_url.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": null, + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_trust_store_pass_path.json b/src/test/resources/invalid_configs/null_trust_store_pass_path.json new file mode 100644 index 0000000..c98274e --- /dev/null +++ b/src/test/resources/invalid_configs/null_trust_store_pass_path.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": null, + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/invalid_configs/null_trust_store_path.json b/src/test/resources/invalid_configs/null_trust_store_path.json new file mode 100644 index 0000000..2673fb9 --- /dev/null +++ b/src/test/resources/invalid_configs/null_trust_store_path.json @@ -0,0 +1,47 @@ +{ + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": null, + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/multiple_filter_mapper_config.json b/src/test/resources/multiple_filter_mapper_config.json index 251beb2..72aa1f0 100644 --- a/src/test/resources/multiple_filter_mapper_config.json +++ b/src/test/resources/multiple_filter_mapper_config.json @@ -1,37 +1,33 @@ { - "pm-mapper-filter": {"filters":[{"pmDefVsn": "V8","nfType": "LTE","vendor": "Ericsson","measTypes": [ "A", "B" ]},{"pmDefVsn": "V9","nfType": "NrRadio","vendor": "Ericsson","measTypes": [ "A", "B" ]}]}, - "streams_subscribes": { - "dmaap_subscriber": { - "type": "data_router", - "aaf_username": null, - "aaf_password": null, - "dmaap_info": { - "location": "location", - "delivery_url": "delivery_url", - "username": "username", - "password": "password", - "subscriber_id": "subscriber_id" - } - } - }, - "streams_publishes": { - "dmaap_publisher": { - "type": "message_router", - "aaf_password": null, - "dmaap_info": { - "topic_url": "https://message-router.onap.svc.cluster.local:3904/events/some-topic", - "client_role": null, - "location": null, - "client_id": null + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V8", + "nfType": "LTE", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] }, - "aaf_username": null - } + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] }, - "dmaap_dr_delete_endpoint": "http://dmaap-dr-node.onap.svc.cluster.local:8443/delete", - "services_calls": {}, "key_store_path": "src/test/resources/testkeystore.jks.b64", "key_store_pass_path": "src/test/resources/password", "trust_store_path": "src/test/resources/testkeystore.jks.b64", "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", "enable_http": false } \ No newline at end of file diff --git a/src/test/resources/no_filter_mapper_config.json b/src/test/resources/no_filter_mapper_config.json index 87fc021..0f24f90 100644 --- a/src/test/resources/no_filter_mapper_config.json +++ b/src/test/resources/no_filter_mapper_config.json @@ -1,37 +1,14 @@ { - "pm-mapper-filter": {"filters":[]}, - "streams_subscribes": { - "dmaap_subscriber": { - "type": "data_router", - "aaf_username": null, - "aaf_password": null, - "dmaap_info": { - "location": "location", - "delivery_url": "delivery_url", - "username": "username", - "password": "password", - "subscriber_id": "subscriber_id" - } - } + "pm-mapper-filter": { + "filters": [] }, - "streams_publishes": { - "dmaap_publisher": { - "type": "message_router", - "aaf_password": null, - "dmaap_info": { - "topic_url": "https://message-router.onap.svc.cluster.local:3904/events/some-topic", - "client_role": null, - "location": null, - "client_id": null - }, - "aaf_username": null - } - }, - "dmaap_dr_delete_endpoint": "http://dmaap-dr-node.onap.svc.cluster.local:8443/delete", - "services_calls": {}, "key_store_path": "src/test/resources/testkeystore.jks.b64", "key_store_pass_path": "src/test/resources/password", "trust_store_path": "src/test/resources/testkeystore.jks.b64", "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", "enable_http": false } \ No newline at end of file diff --git a/src/test/resources/valid_mapper_config.json b/src/test/resources/valid_mapper_config.json index 3d9d707..39d4ee6 100644 --- a/src/test/resources/valid_mapper_config.json +++ b/src/test/resources/valid_mapper_config.json @@ -1,37 +1,47 @@ { - "pm-mapper-filter": {"filters":[{"pmDefVsn": "V9","nfType": "NrRadio","vendor": "Ericsson","measTypes": [ "A", "B" ]}]}, - "streams_subscribes": { - "dmaap_subscriber": { - "type": "data_router", - "aaf_username": null, - "aaf_password": null, - "dmaap_info": { - "location": "location", - "delivery_url": "delivery_url", - "username": "username", - "password": "password", - "subscriber_id": "subscriber_id" - } - } - }, - "streams_publishes": { - "dmaap_publisher": { - "type": "message_router", - "aaf_password": null, - "dmaap_info": { - "topic_url": "https://message-router.onap.svc.cluster.local:3904/events/some-topic", - "client_role": null, - "location": null, - "client_id": null - }, - "aaf_username": null - } - }, - "dmaap_dr_delete_endpoint": "http://dmaap-dr-node.onap.svc.cluster.local:8443/delete", - "services_calls": {}, - "key_store_path": "src/test/resources/testkeystore.jks.b64", - "key_store_pass_path": "src/test/resources/password", - "trust_store_path": "src/test/resources/testkeystore.jks.b64", - "trust_store_pass_path": "src/test/resources/password", - "enable_http": false + "pm-mapper-filter": { + "filters": [ + { + "pmDefVsn": "V9", + "nfType": "NrRadio", + "vendor": "Ericsson", + "measTypes": [ + "A", + "B" + ] + } + ] + }, + "key_store_path": "src/test/resources/testkeystore.jks.b64", + "key_store_pass_path": "src/test/resources/password", + "trust_store_path": "src/test/resources/testkeystore.jks.b64", + "trust_store_pass_path": "src/test/resources/password", + "dmaap_dr_delete_endpoint": "https://dmaap-dr-node:8443/delete", + "dmaap_dr_feed_name": "bulk_pm_feed", + "aaf_identity": "dcae@dcae.onap.org", + "aaf_password": "iheartrainbows44", + "enable_http": false, + "streams_publishes": { + "dmaap_publisher": { + "type": "message_router", + "dmaap_info": { + "topic_url": "https://message-router:3905/events/org.onap.dmaap.mr.VES_PM", + "client_role": "org.onap.dcae.pmPublisher", + "location": "san-francisco", + "client_id": "1562763644939" + } + } + }, + "streams_subscribes": { + "dmaap_subscriber": { + "type": "data_router", + "dmaap_info": { + "username": "username", + "password": "password", + "location": "san-francisco", + "delivery_url": "https://dcae-pm-mapper:8443/delivery", + "subscriber_id": 1 + } + } + } } \ No newline at end of file diff --git a/version.properties b/version.properties index b304d19..b2fcf61 100644 --- a/version.properties +++ b/version.properties @@ -1,6 +1,6 @@ major=1 minor=1 -patch=1 +patch=2 base_version=${major}.${minor}.${patch} release_version=${base_version} snapshot_version=${base_version}-SNAPSHOT \ No newline at end of file -- cgit 1.2.3-korg