From e86ac5c697f8415552e52edf8f8ef834feb53079 Mon Sep 17 00:00:00 2001 From: JoeOLeary Date: Wed, 21 Aug 2019 11:48:37 +0000 Subject: Reduce technical debt * Improve code coverage * Remove sonar smells Issue-ID: DCAEGEN2-1731 Change-Id: Iefc7c18dc9daf1d60a498db4c4c5660d8acca779 Signed-off-by: JoeOLeary --- .../org/onap/dcaegen2/services/pmmapper/App.java | 144 +- .../services/pmmapper/config/ConfigHandler.java | 7 +- .../pmmapper/config/DynamicConfiguration.java | 20 +- .../pmmapper/datarouter/DeliveryHandler.java | 20 +- .../pmmapper/exceptions/CBSServerError.java | 2 +- .../pmmapper/exceptions/MapperConfigException.java | 2 +- .../pmmapper/exceptions/RequestFailure.java | 27 + .../exceptions/ServerResponseException.java | 2 +- .../pmmapper/exceptions/TooManyTriesException.java | 29 - .../pmmapper/filtering/MeasFilterHandler.java | 15 +- .../pmmapper/healthcheck/HealthCheckHandler.java | 20 +- .../pmmapper/messagerouter/VESPublisher.java | 4 +- .../services/pmmapper/model/MeasCollecFile.java | 1615 +------------------- .../services/pmmapper/model/ServerHandler.java | 34 + .../services/pmmapper/utils/MeasSplitter.java | 6 +- .../services/pmmapper/utils/RequestSender.java | 96 +- .../pmmapper/messagerouter/VESPublisherTest.java | 6 +- .../onap/dcaegen2/services/pmmapper/AppTest.java | 101 +- .../pmmapper/config/ConfigHandlerTests.java | 6 +- .../pmmapper/filtering/MeasFilterHandlerTest.java | 6 +- .../services/pmmapper/mapping/MapperTest.java | 10 +- .../services/pmmapper/utils/MeasSplitterTest.java | 20 +- .../pmmapper/utils/RequestSenderTests.java | 1 - src/test/java/utils/EventUtils.java | 1 - .../filter_test/meas_type_and_r_filtered.xml | 1 - .../meas_type_and_r_manyInfo_filtered.xml | 2 - 26 files changed, 409 insertions(+), 1788 deletions(-) create mode 100644 src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/RequestFailure.java delete mode 100644 src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/TooManyTriesException.java create mode 100644 src/main/java/org/onap/dcaegen2/services/pmmapper/model/ServerHandler.java (limited to 'src') diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java index 11a91f8..fdb4ee4 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java @@ -21,13 +21,14 @@ package org.onap.dcaegen2.services.pmmapper; import ch.qos.logback.classic.util.ContextInitializer; -import io.undertow.Handlers; import io.undertow.Undertow; +import io.undertow.server.RoutingHandler; import io.undertow.util.StatusCodes; +import java.util.Arrays; +import lombok.Data; import lombok.NonNull; import org.onap.dcaegen2.services.pmmapper.config.ConfigHandler; -import org.onap.dcaegen2.services.pmmapper.config.Configurable; import org.onap.dcaegen2.services.pmmapper.config.DynamicConfiguration; import org.onap.dcaegen2.services.pmmapper.datarouter.DeliveryHandler; import org.onap.dcaegen2.services.pmmapper.exceptions.CBSServerError; @@ -41,6 +42,7 @@ import org.onap.dcaegen2.services.pmmapper.messagerouter.VESPublisher; import org.onap.dcaegen2.services.pmmapper.model.Event; import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; import org.onap.dcaegen2.services.pmmapper.healthcheck.HealthCheckHandler; +import org.onap.dcaegen2.services.pmmapper.model.ServerHandler; import org.onap.dcaegen2.services.pmmapper.ssl.SSLContextFactory; import org.onap.dcaegen2.services.pmmapper.utils.DataRouterUtils; import org.onap.dcaegen2.services.pmmapper.utils.MeasConverter; @@ -60,65 +62,121 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +@Data public class App { - static { System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, "/opt/app/pm-mapper/etc/logback.xml"); } private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(App.class)); + private static final int HTTP_PORT = 8081; + private static final int HTTPS_PORT = 8443; private static Path mappingTemplate = Paths.get("/opt/app/pm-mapper/etc/mapping.ftl"); private static Path xmlSchema = Paths.get("/opt/app/pm-mapper/etc/measCollec_plusString.xsd"); - private static FluxSink fluxSink; - - public static void main(String[] args) throws EnvironmentConfigException, CBSServerError, MapperConfigException, IOException { - Flux flux = Flux.create(eventFluxSink -> fluxSink = eventFluxSink); - HealthCheckHandler healthCheckHandler = new HealthCheckHandler(); - MapperConfig mapperConfig = new ConfigHandler().getMapperConfig(); - MetadataFilter metadataFilter = new MetadataFilter(mapperConfig); - MeasConverter measConverter = new MeasConverter(); - MeasFilterHandler filterHandler = new MeasFilterHandler(measConverter); - Mapper mapper = new Mapper(mappingTemplate, measConverter); - MeasSplitter splitter = new MeasSplitter(measConverter); - XMLValidator validator = new XMLValidator(xmlSchema); - VESPublisher vesPublisher = new VESPublisher(mapperConfig); - - flux.onBackpressureDrop(App::handleBackPressure) + + private MapperConfig mapperConfig; + private MetadataFilter metadataFilter; + private MeasConverter measConverter; + private MeasFilterHandler filterHandler; + private Mapper mapper; + private MeasSplitter splitter; + private XMLValidator validator; + private VESPublisher vesPublisher; + private DeliveryHandler deliveryHandler; + private DynamicConfiguration dynamicConfiguration; + private HealthCheckHandler healthCheckHandler; + private int httpPort; + private int httpsPort; + + private Undertow applicationServer; + private List serverHandlers; + private Flux flux; + private FluxSink fluxSink; + + /** + * Creates an instance of the application. + * @param mappingTemplate path to template used to convert xml to VES. + * @param xmlSchema path to schema used to verify incoming XML will work with template. + * @param httpPort http port to start http server on. + * @param httpsPort https port to start https server on. + * @param configHandler instance of the ConfigurationHandler used to acquire config. + */ + public App(Path mappingTemplate, Path xmlSchema, int httpPort, int httpsPort, ConfigHandler configHandler) { + try { + this.mapperConfig = configHandler.getMapperConfig(); + } catch (EnvironmentConfigException | CBSServerError | MapperConfigException e) { + logger.unwrap().error("Failed to acquire initial configuration, Application cannot start", e); + throw new IllegalStateException("Config acquisition failed"); + } + this.httpPort = httpPort; + this.httpsPort = httpsPort; + this.metadataFilter = new MetadataFilter(mapperConfig); + this.measConverter = new MeasConverter(); + this.filterHandler = new MeasFilterHandler(measConverter); + this.mapper = new Mapper(mappingTemplate, this.measConverter); + this.splitter = new MeasSplitter(measConverter); + this.validator = new XMLValidator(xmlSchema); + this.vesPublisher = new VESPublisher(mapperConfig); + this.flux = Flux.create(eventFluxSink -> this.fluxSink = eventFluxSink); + + this.flux.onBackpressureDrop(App::handleBackPressure) .doOnNext(App::receiveRequest) .limitRate(1) .parallel() .runOn(Schedulers.newParallel(""), 1) .doOnNext(event -> MDC.setContextMap(event.getMdc())) - .filter(metadataFilter::filter) - .filter(event -> App.filterByFileType(filterHandler, event, mapperConfig)) - .filter(event -> App.validate(validator, event, mapperConfig)) - .concatMap(event -> App.split(splitter,event, mapperConfig)) - .filter(events -> App.filter(filterHandler, events, mapperConfig)) - .concatMap(events -> App.map(mapper, events, mapperConfig)) - .concatMap(vesPublisher::publish) - .subscribe(event -> App.sendEventProcessed(mapperConfig, event)); - - DeliveryHandler deliveryHandler = new DeliveryHandler(fluxSink::next); - ArrayList configurables = new ArrayList<>(); - configurables.add(mapperConfig); - DynamicConfiguration dynamicConfiguration = new DynamicConfiguration(configurables, mapperConfig); + .filter(this.metadataFilter::filter) + .filter(event -> App.filterByFileType(this.filterHandler, event, this.mapperConfig)) + .filter(event -> App.validate(this.validator, event, this.mapperConfig)) + .concatMap(event -> App.split(this.splitter,event, this.mapperConfig)) + .filter(events -> App.filter(this.filterHandler, events, this.mapperConfig)) + .concatMap(events -> App.map(this.mapper, events, this.mapperConfig)) + .concatMap(this.vesPublisher::publish) + .subscribe(event -> App.sendEventProcessed(this.mapperConfig, event)); - Undertow.Builder builder = Undertow.builder(); + this.healthCheckHandler = new HealthCheckHandler(); + this.deliveryHandler = new DeliveryHandler(fluxSink::next); + this.dynamicConfiguration = new DynamicConfiguration(Arrays.asList(mapperConfig), mapperConfig); + this.serverHandlers = Arrays.asList(healthCheckHandler, deliveryHandler, dynamicConfiguration); + try { + this.applicationServer = server(this.mapperConfig, this.serverHandlers); + } catch (IOException e) { + logger.unwrap().error("Failed to create server instance.", e); + throw new IllegalStateException("Server instantiation failed"); + } + } - SSLContextFactory sslContextFactory = new SSLContextFactory(mapperConfig); - SSLContext sslContext = sslContextFactory.createSSLContext(mapperConfig); - SSLContext.setDefault(sslContext); + /** + * Starts the application server. + */ + public void start() { + this.applicationServer.start(); + } + + /** + * Stops the application server. + */ + public void stop() { + this.applicationServer.stop(); + } - if(mapperConfig.getEnableHttp()) { - builder.addHttpListener(8081, "0.0.0.0"); + private Undertow server(MapperConfig config, List serverHandlers) throws IOException { + SSLContextFactory sslContextFactory = new SSLContextFactory(config); + SSLContext sslContext = sslContextFactory.createSSLContext(config); + SSLContext.setDefault(sslContext); + Undertow.Builder builder = Undertow.builder(); + if (config.getEnableHttp()) { + builder.addHttpListener(this.httpPort, "0.0.0.0"); } + RoutingHandler routes = new RoutingHandler(); + serverHandlers.forEach(handler -> routes.add(handler.getMethod(), handler.getTemplate(), handler.getHandler())); + return builder.addHttpsListener(this.httpsPort, "0.0.0.0", sslContext) + .setHandler(routes) + .build(); + } - builder.addHttpsListener(8443, "0.0.0.0", sslContext) - .setHandler(Handlers.routing() - .add("put", "/delivery/{filename}", deliveryHandler) - .add("get", "/healthcheck", healthCheckHandler) - .add("get", "/reconfigure", dynamicConfiguration)) - .build().start(); + public static void main(String[] args) { + new App(mappingTemplate, xmlSchema, HTTP_PORT, HTTPS_PORT, new ConfigHandler()).start(); } public static boolean filterByFileType(MeasFilterHandler filterHandler,Event event, MapperConfig config) { 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 fef1d19..273c953 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 @@ -63,11 +63,8 @@ public class ConfigHandler { * Retrieves PM-Mapper Configuration from DCAE's ConfigBinding Service. * * @throws EnvironmentConfigException - * @throws CBSServerError - * @throws MapperConfigException */ - public MapperConfig getMapperConfig() throws EnvironmentConfigException, - CBSServerError, MapperConfigException { + public MapperConfig getMapperConfig() throws EnvironmentConfigException { String mapperConfigJson = ""; String cbsSocketAddress = this.environmentConfig.getCBSHostName() + ":" + this.environmentConfig.getCBSPort(); String requestURL = "http://" + cbsSocketAddress + "/service_component/" + this.environmentConfig.getServiceName(); @@ -84,7 +81,7 @@ public class ConfigHandler { return convertMapperConfigToObject(mapperConfigJson); } - private MapperConfig convertMapperConfigToObject(String mapperConfigJson) throws MapperConfigException { + private MapperConfig convertMapperConfigToObject(String mapperConfigJson) { MapperConfig mapperConfig; try { JsonObject config = new Gson().fromJson(mapperConfigJson, JsonObject.class); 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 7e2c894..4516183 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 @@ -27,13 +27,16 @@ import java.util.List; import lombok.Data; import org.onap.dcaegen2.services.pmmapper.exceptions.ReconfigurationException; import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; +import org.onap.dcaegen2.services.pmmapper.model.ServerHandler; import org.onap.dcaegen2.services.pmmapper.utils.HttpServerExchangeAdapter; import org.onap.logging.ref.slf4j.ONAPLogAdapter; import org.slf4j.LoggerFactory; @Data -public class DynamicConfiguration implements HttpHandler { +public class DynamicConfiguration implements HttpHandler, ServerHandler { private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(DynamicConfiguration.class)); + private static final String METHOD = "get"; + private static final String ENDPOINT_TEMPLATE = "/reconfigure"; private List configurables; private MapperConfig originalConfig; private ConfigHandler configHandler; @@ -87,4 +90,19 @@ public class DynamicConfiguration implements HttpHandler { logger.exiting(); } } + + @Override + public String getMethod() { + return METHOD; + } + + @Override + public String getTemplate() { + return ENDPOINT_TEMPLATE; + } + + @Override + public HttpHandler getHandler() { + return this; + } } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandler.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandler.java index 4d6af29..ba218cb 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandler.java @@ -34,6 +34,7 @@ import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; import io.undertow.util.StatusCodes; +import org.onap.dcaegen2.services.pmmapper.model.ServerHandler; import org.onap.dcaegen2.services.pmmapper.utils.HttpServerExchangeAdapter; import org.onap.dcaegen2.services.pmmapper.utils.RequiredFieldDeserializer; import org.onap.logging.ref.slf4j.ONAPLogAdapter; @@ -47,7 +48,7 @@ import java.util.Optional; * Provides an undertow HttpHandler to be used as an endpoint for data router to send events to. */ @Data -public class DeliveryHandler implements HttpHandler { +public class DeliveryHandler implements HttpHandler, ServerHandler { public static final String METADATA_HEADER = "X-DMAAP-DR-META"; public static final String PUB_ID_HEADER = "X-DMAAP-DR-PUBLISH-ID"; @@ -56,6 +57,8 @@ public class DeliveryHandler implements HttpHandler { private static final String BAD_METADATA_MESSAGE = "Malformed Metadata."; private static final String NO_METADATA_MESSAGE = "Missing Metadata."; + private static final String METHOD = "put"; + private static final String ENDPOINT_TEMPLATE = "/delivery/{filename}"; private Gson metadataBuilder; @@ -116,4 +119,19 @@ public class DeliveryHandler implements HttpHandler { logger.exiting(); } } + + @Override + public String getMethod() { + return METHOD; + } + + @Override + public String getTemplate() { + return ENDPOINT_TEMPLATE; + } + + @Override + public HttpHandler getHandler() { + return this; + } } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/CBSServerError.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/CBSServerError.java index 787d21f..58262ba 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/CBSServerError.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/CBSServerError.java @@ -19,7 +19,7 @@ */ package org.onap.dcaegen2.services.pmmapper.exceptions; -public class CBSServerError extends Exception { +public class CBSServerError extends RuntimeException { public CBSServerError(String message, Throwable cause) { super(message, cause); } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/MapperConfigException.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/MapperConfigException.java index e78da98..4669871 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/MapperConfigException.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/MapperConfigException.java @@ -19,7 +19,7 @@ */ package org.onap.dcaegen2.services.pmmapper.exceptions; -public class MapperConfigException extends Exception { +public class MapperConfigException extends RuntimeException { public MapperConfigException(String message, Throwable cause) { super(message, cause); } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/RequestFailure.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/RequestFailure.java new file mode 100644 index 0000000..776634b --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/RequestFailure.java @@ -0,0 +1,27 @@ +/*- + * ============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.exceptions; + +public class RequestFailure extends RuntimeException { + public RequestFailure(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/ServerResponseException.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/ServerResponseException.java index b52e2d4..a392bb5 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/ServerResponseException.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/ServerResponseException.java @@ -20,7 +20,7 @@ package org.onap.dcaegen2.services.pmmapper.exceptions; -public class ServerResponseException extends Exception { +public class ServerResponseException extends RuntimeException { public ServerResponseException(String message, Throwable cause) { super(message, cause); } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/TooManyTriesException.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/TooManyTriesException.java deleted file mode 100644 index 922239b..0000000 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/TooManyTriesException.java +++ /dev/null @@ -1,29 +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.exceptions; - -/** - * Exception indicates that a task has been attempted too many times. - */ -public class TooManyTriesException extends Exception { - public TooManyTriesException(String errorMessage){ - super(errorMessage); - } -} 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 0438530..562f46c 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 @@ -57,12 +57,12 @@ public class MeasFilterHandler { Optional filter = Optional.ofNullable(event.getFilter()); MeasCollecFile measCollecFile = event.getMeasCollecFile(); - if(hasNoFilters(filter)) { + if (hasNoFilters(filter)) { logger.unwrap().info("Skipping filtering by measTypes as filter config does not contain measTypes."); return true; } - if(measCollecFile.getMeasData().isEmpty()) { + if (measCollecFile.getMeasData().isEmpty()) { logger.unwrap().info("Measurement file will not be processed further as MeasData is empty."); return false; } @@ -72,13 +72,12 @@ public class MeasFilterHandler { List measInfos = measData.getMeasInfo(); List filteredMeasInfos = new ArrayList<>(); - for (int i = 0; i < measInfos.size(); i++) { - MeasInfo currentMeasInfo = measInfos.get(i); + for (MeasInfo currentMeasInfo : measInfos) { List measTypesNode = currentMeasInfo.getMeasTypes(); - if(!measTypesNode.isEmpty()) { - setMeasInfosFromMeasTypes(currentMeasInfo,filteredMeasInfos, filter.get()); - }else { - setMeasInfoFromMeasType(currentMeasInfo,filteredMeasInfos, filter.get()); + if (measTypesNode != null && !measTypesNode.isEmpty()) { + setMeasInfosFromMeasTypes(currentMeasInfo, filteredMeasInfos, filter.get()); + } else { + setMeasInfoFromMeasType(currentMeasInfo, filteredMeasInfos, filter.get()); } } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/healthcheck/HealthCheckHandler.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/healthcheck/HealthCheckHandler.java index 70a9596..ddf55c7 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/healthcheck/HealthCheckHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/healthcheck/HealthCheckHandler.java @@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.pmmapper.healthcheck; +import org.onap.dcaegen2.services.pmmapper.model.ServerHandler; import org.onap.dcaegen2.services.pmmapper.utils.HttpServerExchangeAdapter; import org.onap.logging.ref.slf4j.ONAPLogAdapter; import org.slf4j.LoggerFactory; @@ -30,8 +31,11 @@ import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; import io.undertow.util.StatusCodes; -public class HealthCheckHandler implements HttpHandler { +public class HealthCheckHandler implements HttpHandler, ServerHandler { private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(HealthCheckHandler.class)); + private static final String METHOD = "get"; + private static final String ENDPOINT_TEMPLATE = "/healthcheck"; + @Override public void handleRequest(HttpServerExchange exchange) { try { @@ -45,4 +49,18 @@ public class HealthCheckHandler implements HttpHandler { } } + @Override + public String getMethod() { + return METHOD; + } + + @Override + public String getTemplate() { + return ENDPOINT_TEMPLATE; + } + + @Override + public HttpHandler getHandler() { + return this; + } } 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 744696a..6aaf1d6 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 @@ -53,8 +53,8 @@ public class VESPublisher { try { events.forEach(e -> this.publish(e.getVes())); logger.unwrap().info("Successfully published VES events to messagerouter."); - } catch(MRPublisherException e) { - logger.unwrap().error("Failed to publish VES event(s) to messagerouter. {}", e.getMessage()); + } catch (MRPublisherException e) { + logger.unwrap().error("Failed to publish VES event(s) to messagerouter.", e); return Flux.empty(); } return Flux.just(event); diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MeasCollecFile.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MeasCollecFile.java index 6e9e254..cc6ca0f 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MeasCollecFile.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MeasCollecFile.java @@ -17,10 +17,10 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ + package org.onap.dcaegen2.services.pmmapper.model; import java.math.BigInteger; -import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -36,183 +36,8 @@ import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.datatype.Duration; import javax.xml.datatype.XMLGregorianCalendar; +import lombok.Data; -/** - *

- * Generated Java class using XJC to represent 3GPP PM Measurement file - * - *

- * The following schema fragment specifies the expected content contained within - * this class. - * - *

- * <complexType>
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="fileHeader">
- *           <complexType>
- *             <complexContent>
- *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                 <sequence>
- *                   <element name="fileSender">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <attribute name="localDn" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                           <attribute name="elementType" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                   <element name="measCollec">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <attribute name="beginTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                 </sequence>
- *                 <attribute name="fileFormatVersion" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                 <attribute name="vendorName" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                 <attribute name="dnPrefix" type="{http://www.w3.org/2001/XMLSchema}string" />
- *               </restriction>
- *             </complexContent>
- *           </complexType>
- *         </element>
- *         <element name="measData" maxOccurs="unbounded" minOccurs="0">
- *           <complexType>
- *             <complexContent>
- *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                 <sequence>
- *                   <element name="managedElement">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <attribute name="localDn" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                           <attribute name="userLabel" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                           <attribute name="swVersion" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                   <element name="measInfo" maxOccurs="unbounded" minOccurs="0">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <sequence>
- *                             <element name="job" minOccurs="0">
- *                               <complexType>
- *                                 <complexContent>
- *                                   <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                                     <attribute name="jobId" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                                   </restriction>
- *                                 </complexContent>
- *                               </complexType>
- *                             </element>
- *                             <element name="granPeriod">
- *                               <complexType>
- *                                 <complexContent>
- *                                   <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                                     <attribute name="duration" use="required" type="{http://www.w3.org/2001/XMLSchema}duration" />
- *                                     <attribute name="endTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
- *                                   </restriction>
- *                                 </complexContent>
- *                               </complexType>
- *                             </element>
- *                             <element name="repPeriod" minOccurs="0">
- *                               <complexType>
- *                                 <complexContent>
- *                                   <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                                     <attribute name="duration" use="required" type="{http://www.w3.org/2001/XMLSchema}duration" />
- *                                   </restriction>
- *                                 </complexContent>
- *                               </complexType>
- *                             </element>
- *                             <choice>
- *                               <element name="measTypes">
- *                                 <simpleType>
- *                                   <list itemType="{http://www.w3.org/2001/XMLSchema}Name" />
- *                                 </simpleType>
- *                               </element>
- *                               <element name="measType" maxOccurs="unbounded" minOccurs="0">
- *                                 <complexType>
- *                                   <simpleContent>
- *                                     <extension base="<http://www.w3.org/2001/XMLSchema>Name">
- *                                       <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
- *                                     </extension>
- *                                   </simpleContent>
- *                                 </complexType>
- *                               </element>
- *                             </choice>
- *                             <element name="measValue" maxOccurs="unbounded" minOccurs="0">
- *                               <complexType>
- *                                 <complexContent>
- *                                   <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                                     <sequence>
- *                                       <choice>
- *                                         <element name="measResults">
- *                                           <simpleType>
- *                                             <list itemType="{http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec}measResultType" />
- *                                           </simpleType>
- *                                         </element>
- *                                         <element name="r" maxOccurs="unbounded" minOccurs="0">
- *                                           <complexType>
- *                                             <simpleContent>
- *                                               <extension base="<http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec>measResultType">
- *                                                 <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
- *                                               </extension>
- *                                             </simpleContent>
- *                                           </complexType>
- *                                         </element>
- *                                       </choice>
- *                                       <element name="suspect" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
- *                                     </sequence>
- *                                     <attribute name="measObjLdn" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                                   </restriction>
- *                                 </complexContent>
- *                               </complexType>
- *                             </element>
- *                           </sequence>
- *                           <attribute name="measInfoId" type="{http://www.w3.org/2001/XMLSchema}string" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                 </sequence>
- *               </restriction>
- *             </complexContent>
- *           </complexType>
- *         </element>
- *         <element name="fileFooter">
- *           <complexType>
- *             <complexContent>
- *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                 <sequence>
- *                   <element name="measCollec">
- *                     <complexType>
- *                       <complexContent>
- *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                           <attribute name="endTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
- *                         </restriction>
- *                       </complexContent>
- *                     </complexType>
- *                   </element>
- *                 </sequence>
- *               </restriction>
- *             </complexContent>
- *           </complexType>
- *         </element>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "fileHeader", @@ -220,6 +45,7 @@ import javax.xml.datatype.XMLGregorianCalendar; "fileFooter" }) @XmlRootElement(name = "measCollecFile") +@Data public class MeasCollecFile { @XmlElement(required = true) @@ -227,247 +53,34 @@ public class MeasCollecFile { protected List measData; @XmlElement(required = true) protected MeasCollecFile.FileFooter fileFooter; - - /** - * Gets the value of the fileHeader property. - * - * @return - * possible object is - * {@link MeasCollecFile.FileHeader } - * - */ - public MeasCollecFile.FileHeader getFileHeader() { - return fileHeader; - } - - /** - * Sets the value of the fileHeader property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.FileHeader } - * - */ - public void setFileHeader(MeasCollecFile.FileHeader value) { - this.fileHeader = value; - } - - /** - * Gets the value of the measData property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the measData property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getMeasData().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link MeasCollecFile.MeasData } - * - * - */ - public List getMeasData() { - if (measData == null) { - measData = new ArrayList(); - } - return this.measData; - } - - /** - * Gets the value of the fileFooter property. - * - * @return - * possible object is - * {@link MeasCollecFile.FileFooter } - * - */ - public MeasCollecFile.FileFooter getFileFooter() { - return fileFooter; - } - - /** - * Sets the value of the fileFooter property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.FileFooter } - * - */ - public void setFileFooter(MeasCollecFile.FileFooter value) { - this.fileFooter = value; - } - - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-     * <complexType>
-     *   <complexContent>
-     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       <sequence>
-     *         <element name="measCollec">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <attribute name="endTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *       </sequence>
-     *     </restriction>
-     *   </complexContent>
-     * </complexType>
-     * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "measCollec" }) + @Data public static class FileFooter { @XmlElement(required = true) protected MeasCollecFile.FileFooter.MeasCollec measCollec; - /** - * Gets the value of the measCollec property. - * - * @return - * possible object is - * {@link MeasCollecFile.FileFooter.MeasCollec } - * - */ - public MeasCollecFile.FileFooter.MeasCollec getMeasCollec() { - return measCollec; - } - - /** - * Sets the value of the measCollec property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.FileFooter.MeasCollec } - * - */ - public void setMeasCollec(MeasCollecFile.FileFooter.MeasCollec value) { - this.measCollec = value; - } - - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <attribute name="endTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
-         * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") public static class MeasCollec { - @XmlAttribute(name = "endTime", required = true) @XmlSchemaType(name = "dateTime") protected XMLGregorianCalendar endTime; - - /** - * Gets the value of the endTime property. - * - * @return - * possible object is - * {@link XMLGregorianCalendar } - * - */ - public XMLGregorianCalendar getEndTime() { - return endTime; - } - - /** - * Sets the value of the endTime property. - * - * @param value - * allowed object is - * {@link XMLGregorianCalendar } - * - */ - public void setEndTime(XMLGregorianCalendar value) { - this.endTime = value; - } - } } - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-     * <complexType>
-     *   <complexContent>
-     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       <sequence>
-     *         <element name="fileSender">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <attribute name="localDn" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                 <attribute name="elementType" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *         <element name="measCollec">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <attribute name="beginTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *       </sequence>
-     *       <attribute name="fileFormatVersion" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *       <attribute name="vendorName" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *       <attribute name="dnPrefix" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *     </restriction>
-     *   </complexContent>
-     * </complexType>
-     * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "fileSender", "measCollec" }) + @Data public static class FileHeader { - @XmlElement(required = true) protected MeasCollecFile.FileHeader.FileSender fileSender; @XmlElement(required = true) @@ -479,632 +92,52 @@ public class MeasCollecFile { @XmlAttribute(name = "dnPrefix") protected String dnPrefix; - /** - * Gets the value of the fileSender property. - * - * @return - * possible object is - * {@link MeasCollecFile.FileHeader.FileSender } - * - */ - public MeasCollecFile.FileHeader.FileSender getFileSender() { - return fileSender; - } - - /** - * Sets the value of the fileSender property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.FileHeader.FileSender } - * - */ - public void setFileSender(MeasCollecFile.FileHeader.FileSender value) { - this.fileSender = value; - } - - /** - * Gets the value of the measCollec property. - * - * @return - * possible object is - * {@link MeasCollecFile.FileHeader.MeasCollec } - * - */ - public MeasCollecFile.FileHeader.MeasCollec getMeasCollec() { - return measCollec; - } - - /** - * Sets the value of the measCollec property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.FileHeader.MeasCollec } - * - */ - public void setMeasCollec(MeasCollecFile.FileHeader.MeasCollec value) { - this.measCollec = value; - } - - /** - * Gets the value of the fileFormatVersion property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getFileFormatVersion() { - return fileFormatVersion; - } - - /** - * Sets the value of the fileFormatVersion property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setFileFormatVersion(String value) { - this.fileFormatVersion = value; - } - - /** - * Gets the value of the vendorName property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getVendorName() { - return vendorName; - } - - /** - * Sets the value of the vendorName property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setVendorName(String value) { - this.vendorName = value; - } - - /** - * Gets the value of the dnPrefix property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getDnPrefix() { - return dnPrefix; - } - - /** - * Sets the value of the dnPrefix property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setDnPrefix(String value) { - this.dnPrefix = value; - } - - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <attribute name="localDn" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *       <attribute name="elementType" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
-         * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") + @Data public static class FileSender { - @XmlAttribute(name = "localDn") protected String localDn; @XmlAttribute(name = "elementType") protected String elementType; - - /** - * Gets the value of the localDn property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getLocalDn() { - return localDn; - } - - /** - * Sets the value of the localDn property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setLocalDn(String value) { - this.localDn = value; - } - - /** - * Gets the value of the elementType property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getElementType() { - return elementType; - } - - /** - * Sets the value of the elementType property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setElementType(String value) { - this.elementType = value; - } - } - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <attribute name="beginTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
-         * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") + @Data public static class MeasCollec { - @XmlAttribute(name = "beginTime", required = true) @XmlSchemaType(name = "dateTime") protected XMLGregorianCalendar beginTime; - - /** - * Gets the value of the beginTime property. - * - * @return - * possible object is - * {@link XMLGregorianCalendar } - * - */ - public XMLGregorianCalendar getBeginTime() { - return beginTime; - } - - /** - * Sets the value of the beginTime property. - * - * @param value - * allowed object is - * {@link XMLGregorianCalendar } - * - */ - public void setBeginTime(XMLGregorianCalendar value) { - this.beginTime = value; - } - } } - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-     * <complexType>
-     *   <complexContent>
-     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *       <sequence>
-     *         <element name="managedElement">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <attribute name="localDn" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                 <attribute name="userLabel" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                 <attribute name="swVersion" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *         <element name="measInfo" maxOccurs="unbounded" minOccurs="0">
-     *           <complexType>
-     *             <complexContent>
-     *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                 <sequence>
-     *                   <element name="job" minOccurs="0">
-     *                     <complexType>
-     *                       <complexContent>
-     *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                           <attribute name="jobId" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                         </restriction>
-     *                       </complexContent>
-     *                     </complexType>
-     *                   </element>
-     *                   <element name="granPeriod">
-     *                     <complexType>
-     *                       <complexContent>
-     *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                           <attribute name="duration" use="required" type="{http://www.w3.org/2001/XMLSchema}duration" />
-     *                           <attribute name="endTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
-     *                         </restriction>
-     *                       </complexContent>
-     *                     </complexType>
-     *                   </element>
-     *                   <element name="repPeriod" minOccurs="0">
-     *                     <complexType>
-     *                       <complexContent>
-     *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                           <attribute name="duration" use="required" type="{http://www.w3.org/2001/XMLSchema}duration" />
-     *                         </restriction>
-     *                       </complexContent>
-     *                     </complexType>
-     *                   </element>
-     *                   <choice>
-     *                     <element name="measTypes">
-     *                       <simpleType>
-     *                         <list itemType="{http://www.w3.org/2001/XMLSchema}Name" />
-     *                       </simpleType>
-     *                     </element>
-     *                     <element name="measType" maxOccurs="unbounded" minOccurs="0">
-     *                       <complexType>
-     *                         <simpleContent>
-     *                           <extension base="<http://www.w3.org/2001/XMLSchema>Name">
-     *                             <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
-     *                           </extension>
-     *                         </simpleContent>
-     *                       </complexType>
-     *                     </element>
-     *                   </choice>
-     *                   <element name="measValue" maxOccurs="unbounded" minOccurs="0">
-     *                     <complexType>
-     *                       <complexContent>
-     *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-     *                           <sequence>
-     *                             <choice>
-     *                               <element name="measResults">
-     *                                 <simpleType>
-     *                                   <list itemType="{http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec}measResultType" />
-     *                                 </simpleType>
-     *                               </element>
-     *                               <element name="r" maxOccurs="unbounded" minOccurs="0">
-     *                                 <complexType>
-     *                                   <simpleContent>
-     *                                     <extension base="<http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec>measResultType">
-     *                                       <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
-     *                                     </extension>
-     *                                   </simpleContent>
-     *                                 </complexType>
-     *                               </element>
-     *                             </choice>
-     *                             <element name="suspect" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
-     *                           </sequence>
-     *                           <attribute name="measObjLdn" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *                         </restriction>
-     *                       </complexContent>
-     *                     </complexType>
-     *                   </element>
-     *                 </sequence>
-     *                 <attribute name="measInfoId" type="{http://www.w3.org/2001/XMLSchema}string" />
-     *               </restriction>
-     *             </complexContent>
-     *           </complexType>
-     *         </element>
-     *       </sequence>
-     *     </restriction>
-     *   </complexContent>
-     * </complexType>
-     * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "managedElement", "measInfo" }) + @Data public static class MeasData { - @XmlElement(required = true) protected MeasCollecFile.MeasData.ManagedElement managedElement; protected List measInfo; - /** - * Gets the value of the managedElement property. - * - * @return - * possible object is - * {@link MeasCollecFile.MeasData.ManagedElement } - * - */ - public MeasCollecFile.MeasData.ManagedElement getManagedElement() { - return managedElement; - } - - /** - * Sets the value of the managedElement property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.MeasData.ManagedElement } - * - */ - public void setManagedElement(MeasCollecFile.MeasData.ManagedElement value) { - this.managedElement = value; - } - - /** - * Gets the value of the measInfo property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the measInfo property. - * - *

- * For example, to add a new item, do as follows: - *

-         *    getMeasInfo().add(newItem);
-         * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link MeasCollecFile.MeasData.MeasInfo } - * - * - */ - public List getMeasInfo() { - if (measInfo == null) { - measInfo = new ArrayList(); - } - return this.measInfo; - } - - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <attribute name="localDn" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *       <attribute name="userLabel" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *       <attribute name="swVersion" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
-         * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") + @Data public static class ManagedElement { - @XmlAttribute(name = "localDn") protected String localDn; @XmlAttribute(name = "userLabel") protected String userLabel; @XmlAttribute(name = "swVersion") protected String swVersion; - - /** - * Gets the value of the localDn property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getLocalDn() { - return localDn; - } - - /** - * Sets the value of the localDn property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setLocalDn(String value) { - this.localDn = value; - } - - /** - * Gets the value of the userLabel property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getUserLabel() { - return userLabel; - } - - /** - * Sets the value of the userLabel property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setUserLabel(String value) { - this.userLabel = value; - } - - /** - * Gets the value of the swVersion property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getSwVersion() { - return swVersion; - } - - /** - * Sets the value of the swVersion property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setSwVersion(String value) { - this.swVersion = value; - } - } - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-         * <complexType>
-         *   <complexContent>
-         *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *       <sequence>
-         *         <element name="job" minOccurs="0">
-         *           <complexType>
-         *             <complexContent>
-         *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *                 <attribute name="jobId" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *               </restriction>
-         *             </complexContent>
-         *           </complexType>
-         *         </element>
-         *         <element name="granPeriod">
-         *           <complexType>
-         *             <complexContent>
-         *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *                 <attribute name="duration" use="required" type="{http://www.w3.org/2001/XMLSchema}duration" />
-         *                 <attribute name="endTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
-         *               </restriction>
-         *             </complexContent>
-         *           </complexType>
-         *         </element>
-         *         <element name="repPeriod" minOccurs="0">
-         *           <complexType>
-         *             <complexContent>
-         *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *                 <attribute name="duration" use="required" type="{http://www.w3.org/2001/XMLSchema}duration" />
-         *               </restriction>
-         *             </complexContent>
-         *           </complexType>
-         *         </element>
-         *         <choice>
-         *           <element name="measTypes">
-         *             <simpleType>
-         *               <list itemType="{http://www.w3.org/2001/XMLSchema}Name" />
-         *             </simpleType>
-         *           </element>
-         *           <element name="measType" maxOccurs="unbounded" minOccurs="0">
-         *             <complexType>
-         *               <simpleContent>
-         *                 <extension base="<http://www.w3.org/2001/XMLSchema>Name">
-         *                   <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
-         *                 </extension>
-         *               </simpleContent>
-         *             </complexType>
-         *           </element>
-         *         </choice>
-         *         <element name="measValue" maxOccurs="unbounded" minOccurs="0">
-         *           <complexType>
-         *             <complexContent>
-         *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-         *                 <sequence>
-         *                   <choice>
-         *                     <element name="measResults">
-         *                       <simpleType>
-         *                         <list itemType="{http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec}measResultType" />
-         *                       </simpleType>
-         *                     </element>
-         *                     <element name="r" maxOccurs="unbounded" minOccurs="0">
-         *                       <complexType>
-         *                         <simpleContent>
-         *                           <extension base="<http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec>measResultType">
-         *                             <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
-         *                           </extension>
-         *                         </simpleContent>
-         *                       </complexType>
-         *                     </element>
-         *                   </choice>
-         *                   <element name="suspect" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
-         *                 </sequence>
-         *                 <attribute name="measObjLdn" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *               </restriction>
-         *             </complexContent>
-         *           </complexType>
-         *         </element>
-         *       </sequence>
-         *       <attribute name="measInfoId" type="{http://www.w3.org/2001/XMLSchema}string" />
-         *     </restriction>
-         *   </complexContent>
-         * </complexType>
-         * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "job", @@ -1114,6 +147,7 @@ public class MeasCollecFile { "measType", "measValue" }) + @Data public static class MeasInfo { protected MeasCollecFile.MeasData.MeasInfo.Job job; @@ -1127,343 +161,32 @@ public class MeasCollecFile { @XmlAttribute(name = "measInfoId") protected String measInfoId; - /** - * Gets the value of the job property. - * - * @return - * possible object is - * {@link MeasCollecFile.MeasData.MeasInfo.Job } - * - */ - public MeasCollecFile.MeasData.MeasInfo.Job getJob() { - return job; - } - - /** - * Sets the value of the job property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.MeasData.MeasInfo.Job } - * - */ - public void setJob(MeasCollecFile.MeasData.MeasInfo.Job value) { - this.job = value; - } - - /** - * Gets the value of the granPeriod property. - * - * @return - * possible object is - * {@link MeasCollecFile.MeasData.MeasInfo.GranPeriod } - * - */ - public MeasCollecFile.MeasData.MeasInfo.GranPeriod getGranPeriod() { - return granPeriod; - } - - /** - * Sets the value of the granPeriod property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.MeasData.MeasInfo.GranPeriod } - * - */ - public void setGranPeriod(MeasCollecFile.MeasData.MeasInfo.GranPeriod value) { - this.granPeriod = value; - } - - /** - * Gets the value of the repPeriod property. - * - * @return - * possible object is - * {@link MeasCollecFile.MeasData.MeasInfo.RepPeriod } - * - */ - public MeasCollecFile.MeasData.MeasInfo.RepPeriod getRepPeriod() { - return repPeriod; - } - - /** - * Sets the value of the repPeriod property. - * - * @param value - * allowed object is - * {@link MeasCollecFile.MeasData.MeasInfo.RepPeriod } - * - */ - public void setRepPeriod(MeasCollecFile.MeasData.MeasInfo.RepPeriod value) { - this.repPeriod = value; - } - - /** - * Gets the value of the measTypes property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the measTypes property. - * - *

- * For example, to add a new item, do as follows: - *

-             *    getMeasTypes().add(newItem);
-             * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link String } - * - * - */ - public List getMeasTypes() { - if (measTypes == null) { - measTypes = new ArrayList(); - } - return this.measTypes; - } - - /** - * Gets the value of the measType property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the measType property. - * - *

- * For example, to add a new item, do as follows: - *

-             *    getMeasType().add(newItem);
-             * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link MeasCollecFile.MeasData.MeasInfo.MeasType } - * - * - */ - public List getMeasType() { - if (measType == null) { - measType = new ArrayList(); - } - return this.measType; - } - - /** - * Gets the value of the measValue property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the measValue property. - * - *

- * For example, to add a new item, do as follows: - *

-             *    getMeasValue().add(newItem);
-             * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link MeasCollecFile.MeasData.MeasInfo.MeasValue } - * - * - */ - public List getMeasValue() { - if (measValue == null) { - measValue = new ArrayList(); - } - return this.measValue; - } - - /** - * Gets the value of the measInfoId property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getMeasInfoId() { - return measInfoId; - } - - /** - * Sets the value of the measInfoId property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setMeasInfoId(String value) { - this.measInfoId = value; - } - - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-             * <complexType>
-             *   <complexContent>
-             *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-             *       <attribute name="duration" use="required" type="{http://www.w3.org/2001/XMLSchema}duration" />
-             *       <attribute name="endTime" use="required" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
-             *     </restriction>
-             *   </complexContent>
-             * </complexType>
-             * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") + @Data public static class GranPeriod { - @XmlAttribute(name = "duration", required = true) protected Duration duration; @XmlAttribute(name = "endTime", required = true) @XmlSchemaType(name = "dateTime") protected XMLGregorianCalendar endTime; - - /** - * Gets the value of the duration property. - * - * @return - * possible object is - * {@link Duration } - * - */ - public Duration getDuration() { - return duration; - } - - /** - * Sets the value of the duration property. - * - * @param value - * allowed object is - * {@link Duration } - * - */ - public void setDuration(Duration value) { - this.duration = value; - } - - /** - * Gets the value of the endTime property. - * - * @return - * possible object is - * {@link XMLGregorianCalendar } - * - */ - public XMLGregorianCalendar getEndTime() { - return endTime; - } - - /** - * Sets the value of the endTime property. - * - * @param value - * allowed object is - * {@link XMLGregorianCalendar } - * - */ - public void setEndTime(XMLGregorianCalendar value) { - this.endTime = value; - } - } - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-             * <complexType>
-             *   <complexContent>
-             *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-             *       <attribute name="jobId" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-             *     </restriction>
-             *   </complexContent>
-             * </complexType>
-             * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") + @Data public static class Job { - @XmlAttribute(name = "jobId", required = true) protected String jobId; - - /** - * Gets the value of the jobId property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getJobId() { - return jobId; - } - - /** - * Sets the value of the jobId property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setJobId(String value) { - this.jobId = value; - } - } - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-             * <complexType>
-             *   <simpleContent>
-             *     <extension base="<http://www.w3.org/2001/XMLSchema>Name">
-             *       <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
-             *     </extension>
-             *   </simpleContent>
-             * </complexType>
-             * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "value" }) + @Data public static class MeasType { - @XmlValue @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlSchemaType(name = "Name") @@ -1471,102 +194,16 @@ public class MeasCollecFile { @XmlAttribute(name = "p", required = true) @XmlSchemaType(name = "positiveInteger") protected BigInteger p; - - /** - * Gets the value of the value property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getValue() { - return value; - } - - /** - * Sets the value of the value property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setValue(String value) { - this.value = value; - } - - /** - * Gets the value of the p property. - * - * @return - * possible object is - * {@link BigInteger } - * - */ - public BigInteger getP() { - return p; - } - - /** - * Sets the value of the p property. - * - * @param value - * allowed object is - * {@link BigInteger } - * - */ - public void setP(BigInteger value) { - this.p = value; - } - } - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-             * <complexType>
-             *   <complexContent>
-             *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-             *       <sequence>
-             *         <choice>
-             *           <element name="measResults">
-             *             <simpleType>
-             *               <list itemType="{http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec}measResultType" />
-             *             </simpleType>
-             *           </element>
-             *           <element name="r" maxOccurs="unbounded" minOccurs="0">
-             *             <complexType>
-             *               <simpleContent>
-             *                 <extension base="<http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec>measResultType">
-             *                   <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
-             *                 </extension>
-             *               </simpleContent>
-             *             </complexType>
-             *           </element>
-             *         </choice>
-             *         <element name="suspect" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
-             *       </sequence>
-             *       <attribute name="measObjLdn" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
-             *     </restriction>
-             *   </complexContent>
-             * </complexType>
-             * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "measResults", "r", "suspect" }) + @Data public static class MeasValue { - @XmlList protected List measResults; protected List r; @@ -1574,256 +211,36 @@ public class MeasCollecFile { @XmlAttribute(name = "measObjLdn", required = true) protected String measObjLdn; - /** - * Gets the value of the measResults property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the measResults property. - * - *

- * For example, to add a new item, do as follows: - *

-                 *    getMeasResults().add(newItem);
-                 * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link String } - * - * - */ - public List getMeasResults() { - if (measResults == null) { - measResults = new ArrayList(); - } - return this.measResults; - } - - /** - * Gets the value of the r property. - * - *

- * This accessor method returns a reference to the live list, - * not a snapshot. Therefore any modification you make to the - * returned list will be present inside the JAXB object. - * This is why there is not a set method for the r property. - * - *

- * For example, to add a new item, do as follows: - *

-                 *    getR().add(newItem);
-                 * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link MeasCollecFile.MeasData.MeasInfo.MeasValue.R } - * - * - */ - public List getR() { - if (r == null) { - r = new ArrayList(); - } - return this.r; - } - - /** - * Gets the value of the suspect property. - * - * @return - * possible object is - * {@link Boolean } - * - */ - public Boolean isSuspect() { - return suspect; - } - - /** - * Sets the value of the suspect property. - * - * @param value - * allowed object is - * {@link Boolean } - * - */ - public void setSuspect(Boolean value) { - this.suspect = value; - } - - /** - * Gets the value of the measObjLdn property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getMeasObjLdn() { - return measObjLdn; - } - - /** - * Sets the value of the measObjLdn property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setMeasObjLdn(String value) { - this.measObjLdn = value; - } - - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-                 * <complexType>
-                 *   <simpleContent>
-                 *     <extension base="<http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec>measResultType">
-                 *       <attribute name="p" use="required" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
-                 *     </extension>
-                 *   </simpleContent>
-                 * </complexType>
-                 * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "value" }) + @Data public static class R { - @XmlValue protected String value; @XmlAttribute(name = "p", required = true) @XmlSchemaType(name = "positiveInteger") protected BigInteger p; - - /** - * Gets the value of the value property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getValue() { - return value; - } - - /** - * Sets the value of the value property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setValue(String value) { - this.value = value; - } - - /** - * Gets the value of the p property. - * - * @return - * possible object is - * {@link BigInteger } - * - */ - public BigInteger getP() { - return p; - } - - /** - * Sets the value of the p property. - * - * @param value - * allowed object is - * {@link BigInteger } - * - */ - public void setP(BigInteger value) { - this.p = value; - } - } - - public void replaceR(List filteredRs) { this.r = filteredRs; } - public void replaceMeasResults(List filteredMeasResults) { this.measResults = filteredMeasResults; } - } - - - /** - *

Java class for anonymous complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

-             * <complexType>
-             *   <complexContent>
-             *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
-             *       <attribute name="duration" use="required" type="{http://www.w3.org/2001/XMLSchema}duration" />
-             *     </restriction>
-             *   </complexContent>
-             * </complexType>
-             * 
- * - * - */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") + @Data public static class RepPeriod { @XmlAttribute(name = "duration", required = true) protected Duration duration; - - /** - * Gets the value of the duration property. - * - * @return - * possible object is - * {@link Duration } - * - */ - public Duration getDuration() { - return duration; - } - - /** - * Sets the value of the duration property. - * - * @param value - * allowed object is - * {@link Duration } - * - */ - public void setDuration(Duration value) { - this.duration = value; - } } - public void replaceMeasTypes(List newMeasTypes) { this.measTypes = newMeasTypes; } diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/ServerHandler.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/ServerHandler.java new file mode 100644 index 0000000..9212375 --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/ServerHandler.java @@ -0,0 +1,34 @@ +/* + * - + * * ============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 io.undertow.server.HttpHandler; + +public interface ServerHandler { + + String getMethod(); + + String getTemplate(); + + HttpHandler getHandler(); +} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitter.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitter.java index 1821803..92d9e17 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitter.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitter.java @@ -42,7 +42,7 @@ public class MeasSplitter { public MeasSplitter(MeasConverter converter) { this.converter = converter; } - + /** * Splits the MeasCollecFile to multiple MeasCollecFile based on the number of MeasData **/ @@ -50,10 +50,10 @@ public class MeasSplitter { logger.unwrap().debug("Splitting 3GPP xml MeasData to individual MeasCollecFile"); MeasCollecFile currentMeasurement = converter.convert(event.getBody()); event.setMeasCollecFile(currentMeasurement); - if(currentMeasurement.getMeasData().isEmpty()) { + if (currentMeasurement.getMeasData() == null || currentMeasurement.getMeasData().isEmpty()) { throw new NoSuchElementException("MeasData is empty."); } - return currentMeasurement.getMeasData().stream().map( measData -> { + return currentMeasurement.getMeasData().stream().map(measData -> { Event newEvent = generateNewEvent(event); MeasCollecFile newMeasCollec = generateNewMeasCollec(newEvent,measData); newEvent.setMeasCollecFile(newMeasCollec); diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java index 411196c..9938eed 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java @@ -27,10 +27,12 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.security.NoSuchAlgorithmException; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; +import org.onap.dcaegen2.services.pmmapper.exceptions.RequestFailure; import org.onap.dcaegen2.services.pmmapper.exceptions.ServerResponseException; import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; import org.onap.logging.ref.slf4j.ONAPLogAdapter; @@ -56,7 +58,7 @@ public class RequestSender { * is set to {@code GET} by default. * @see RequestSender#send(String,String,String) */ - public String send(final String urlString) throws Exception { + public String send(final String urlString) throws InterruptedException { return send("GET", urlString); } @@ -65,7 +67,7 @@ public class RequestSender { * is set to empty String by default. * @see RequestSender#send(String,String,String) */ - public String send(String method, final String urlString) throws Exception { + public String send(String method, final String urlString) throws InterruptedException { return send(method,urlString,""); } @@ -74,7 +76,7 @@ public class RequestSender { * is set to empty String by default. * @see RequestSender#send(String,String,String,String) */ - public String send(String method, final String urlString, final String body) throws Exception { + public String send(String method, final String urlString, final String body) throws InterruptedException { return send(method,urlString,body,""); } @@ -85,56 +87,47 @@ public class RequestSender { * @param body of the request as json * @param encodedCredentials base64-encoded username password credentials * @return http response body - * @throws Exception + * @throws InterruptedException */ - public String send(String method, final String urlString, final String body, final String encodedCredentials) throws Exception { - String invocationID = Optional.ofNullable((String)MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)) - .orElse(logger.invoke(ONAPLogConstants.InvocationMode.SYNCHRONOUS).toString()); + public String send(String method, final String urlString, final String body, final String encodedCredentials) + throws InterruptedException { + String invocationID = Optional.ofNullable((String)MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)) + .orElse(logger.invoke(ONAPLogConstants.InvocationMode.SYNCHRONOUS).toString()); String requestID = Optional.ofNullable((String)MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)) - .orElse( UUID.randomUUID().toString()); + .orElse(UUID.randomUUID().toString()); String result = ""; + boolean status = false; + int attempts = 1; + try { + while (!status && attempts <= MAX_RETRIES) { + final URL url = new URL(urlString); + final HttpURLConnection connection = getHttpURLConnection(method, url, invocationID, requestID); + + if ("https".equalsIgnoreCase(url.getProtocol())) { + HttpsURLConnection.setDefaultSSLSocketFactory(SSLContext.getDefault().getSocketFactory()); + } - for (int i = 1; i <= MAX_RETRIES; i++) { - final URL url = new URL(urlString); - final HttpURLConnection connection = getHttpURLConnection(method, url, invocationID, requestID); - - - if("https".equalsIgnoreCase(url.getProtocol())) { - HttpsURLConnection.setDefaultSSLSocketFactory(SSLContext.getDefault().getSocketFactory()); - } - - if(!encodedCredentials.isEmpty()) { - connection.setRequestProperty("Authorization", "Basic " + encodedCredentials); - } - - if(!body.isEmpty()) { - setMessageBody(connection, body); - } - - logger.unwrap().info("Sending {} request to {}.", method, urlString); - - try (InputStream is = connection.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { - result = reader.lines() - .collect(Collectors.joining("\n")); - int responseCode = connection.getResponseCode(); - if (!(isWithinErrorRange(responseCode))) { - logger.unwrap().info("Response code: {}, Server Response Received:\n{}",responseCode, result); - break; + if (!encodedCredentials.isEmpty()) { + connection.setRequestProperty("Authorization", "Basic " + encodedCredentials); } - } catch (Exception e) { - if (retryLimitReached(i)) { - logger.unwrap().error("Execution error: {}", connection.getResponseMessage(), e); - throw new ServerResponseException(SERVER_ERROR_MESSAGE + ": " + connection.getResponseMessage(), e); + + if (!body.isEmpty()) { + setMessageBody(connection, body); } + result = getResult(attempts, connection); + status = !isWithinErrorRange(connection.getResponseCode()); + attempts++; + Thread.sleep(RETRY_INTERVAL); } - - Thread.sleep(RETRY_INTERVAL); + } catch (IOException | NoSuchAlgorithmException ex) { + logger.unwrap().warn("Request failure", ex); + throw new RequestFailure(ex); } return result; } - private HttpURLConnection getHttpURLConnection(String method, URL url, String invocationID, String requestID) throws IOException { + private HttpURLConnection getHttpURLConnection(String method, URL url, String invocationID, String requestID) + throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setReadTimeout(DEFAULT_READ_TIMEOUT); connection.setRequestProperty(ONAPLogConstants.Headers.REQUEST_ID, requestID); @@ -161,4 +154,23 @@ public class RequestSender { private boolean isWithinErrorRange(final int responseCode) { return responseCode >= ERROR_START_RANGE; } + + private String getResult(int attemptNumber, HttpURLConnection connection) throws IOException { + logger.unwrap().info("Sending {} request to {}.", connection.getRequestMethod(), connection.getURL()); + String result = ""; + try (InputStream is = connection.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { + result = reader.lines().collect(Collectors.joining("\n")); + int responseCode = connection.getResponseCode(); + if (!(isWithinErrorRange(responseCode))) { + logger.unwrap().info("Response code: {}, Server Response Received:\n{}", responseCode, result); + } + } catch (Exception e) { + if (retryLimitReached(attemptNumber)) { + logger.unwrap().error("Execution error: {}", connection.getResponseMessage(), e); + throw new ServerResponseException(SERVER_ERROR_MESSAGE + ": " + connection.getResponseMessage(), e); + } + } + return result; + } } \ 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 ef508f3..1772452 100644 --- a/src/test/java/org/onap/dcaegen2/pmmapper/messagerouter/VESPublisherTest.java +++ b/src/test/java/org/onap/dcaegen2/pmmapper/messagerouter/VESPublisherTest.java @@ -18,11 +18,12 @@ * ============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 org.onap.dcaegen2.services.pmmapper.exceptions.RequestFailure; import reactor.test.StepVerifier; import java.util.Arrays; import java.util.List; @@ -31,7 +32,6 @@ 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; @@ -79,7 +79,7 @@ public class VESPublisherTest { 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); + when(sender.send("POST",topicURL,ves,"base64encoded")).thenThrow(RequestFailure.class); Flux flux = sut.publish(events); 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 11215b3..46994b3 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java @@ -20,12 +20,17 @@ package org.onap.dcaegen2.services.pmmapper; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.*; +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 static org.mockserver.integration.ClientAndServer.startClientAndServer; import static org.mockserver.model.HttpResponse.response; +import static utils.ConfigUtils.getMapperConfigFromFile; import java.io.IOException; import java.nio.file.Files; @@ -37,6 +42,12 @@ import java.util.List; import com.google.gson.Gson; import io.undertow.server.HttpServerExchange; import io.undertow.util.StatusCodes; +import org.junit.jupiter.api.BeforeEach; +import org.onap.dcaegen2.services.pmmapper.config.ConfigHandler; +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.XMLValidator; import reactor.core.publisher.Flux; @@ -66,23 +77,76 @@ class AppTest { static MockServerClient client; private static EventMetadata eventMetadata; + private static MapperConfig mapperConfig; + private static ConfigHandler configHandler; private static final Path dataDirectory = Paths.get("src/test/resources/mapper_test/mapping_data/"); private static final Path metadata = Paths.get("src/test/resources/valid_metadata.json"); + private static final Path template = Paths.get("src/main/resources/mapping.ftl"); private static final Path schema = Paths.get("src/main/resources/measCollec_plusString.xsd"); + private static final String config = "valid_mapper_config.json"; + + private App objUnderTest; @BeforeAll - public static void setup() { + static void setup() { mockServer = startClientAndServer(35454); client = new MockServerClient("127.0.0.1", 35454); + mapperConfig = getMapperConfigFromFile(config); } @AfterAll - public static void teardown() { + static void teardown() { mockServer.stop(); } + @BeforeEach + void beforeEach() { + configHandler = mock(ConfigHandler.class); + } + + @Test + void testDisabledHTTPServer() throws Exception { + + MapperConfig mockConfig = Mockito.spy(mapperConfig); + when(mockConfig.getEnableHttp()).thenReturn(false); + when(configHandler.getMapperConfig()).thenReturn(mockConfig); + objUnderTest = new App(template, schema, 0, 0, configHandler); + objUnderTest.start(); + assertEquals(1, objUnderTest.getApplicationServer().getListenerInfo().size()); + assertEquals("https", objUnderTest.getApplicationServer().getListenerInfo().get(0).getProtcol()); + objUnderTest.stop(); + } + + @Test + void testEnabledHTTPServer() throws Exception { + MapperConfig mockConfig = Mockito.spy(mapperConfig); + when(mockConfig.getEnableHttp()).thenReturn(true); + when(configHandler.getMapperConfig()).thenReturn(mockConfig); + objUnderTest = new App(template, schema, 0, 0, configHandler); + objUnderTest.start(); + assertEquals(2, objUnderTest.getApplicationServer().getListenerInfo().size()); + assertEquals("http", objUnderTest.getApplicationServer().getListenerInfo().get(0).getProtcol()); + objUnderTest.stop(); + } + + @Test + void testConfigFailure() throws EnvironmentConfigException, CBSServerError, MapperConfigException { + when(configHandler.getMapperConfig()).thenThrow(MapperConfigException.class); + assertThrows(IllegalStateException.class, () -> new App(template, schema, 0, 0, configHandler)); + + } + + @Test + void testServerCreationFailure() throws EnvironmentConfigException, CBSServerError, MapperConfigException { + MapperConfig mockConfig = Mockito.spy(mapperConfig); + when(mockConfig.getKeyStorePath()).thenReturn("not_a_file"); + when(configHandler.getMapperConfig()).thenReturn(mockConfig); + assertThrows(IllegalStateException.class, () -> new App(template, schema, 0, 0, configHandler)); + + } + @Test void testHandleBackPressureNullValue() { assertThrows(NullPointerException.class, () -> App.handleBackPressure(null)); @@ -110,7 +174,7 @@ class AppTest { } @Test - public void testFilterByFileType_success() { + void testFilterByFileType_success() { Event mockEvent = Mockito.mock(Event.class); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); @@ -123,7 +187,7 @@ class AppTest { } @Test - public void testFilterByFileType_NonXML() { + void testFilterByFileType_NonXML() { Event mockEvent = Mockito.mock(Event.class); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); @@ -136,7 +200,7 @@ class AppTest { } @Test - public void testFilterByFileType_throwException() { + void testFilterByFileType_throwException() { Event mockEvent = Mockito.mock(Event.class); MeasFilterHandler mockFilter = Mockito.mock(MeasFilterHandler.class); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); @@ -148,7 +212,7 @@ class AppTest { } @Test - public void testValidateXML_success() throws IOException { + void testValidateXML_success() throws IOException { XMLValidator mockValidator = new XMLValidator(schema); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); @@ -164,7 +228,7 @@ class AppTest { } @Test - public void testValidateXML_failure() throws IOException { + void testValidateXML_failure() throws IOException { XMLValidator mockValidator = new XMLValidator(schema); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); @@ -180,7 +244,7 @@ class AppTest { } @Test - public void testValidateXML_throwException() { + void testValidateXML_throwException() { Event mockEvent = Mockito.mock(Event.class); XMLValidator mockValidator = Mockito.mock(XMLValidator.class); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); @@ -192,7 +256,7 @@ class AppTest { } @Test - public void testFilter_success() { + void testFilter_success() { Event mockEvent = Mockito.mock(Event.class); List mockEvents = Arrays.asList(mockEvent); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); @@ -201,7 +265,7 @@ class AppTest { } @Test - public void testFilter_throwException() { + void testFilter_throwException() { HttpRequest req = HttpRequest.request(); client.when(req).respond( response().withStatusCode(200)); @@ -222,36 +286,33 @@ class AppTest { } @Test - public void testSplit_empty_success() { + void testSplit_empty_success() { Event mockEvent = Mockito.mock(Event.class); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); MeasConverter mockMeasConverter = Mockito.mock(MeasConverter.class); Flux> splitResult = App.split(new MeasSplitter(mockMeasConverter), mockEvent, mockConfig); - splitResult.equals(Flux.>empty()); + assertEquals(splitResult, Flux.>empty()); } @Test - public void testSplit_success() { + void testSplit_success() { Event mockEvent = Mockito.mock(Event.class); List mockEvents = Arrays.asList(mockEvent,mockEvent); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); MeasSplitter mockSplitter = Mockito.mock(MeasSplitter.class); Mockito.when(mockSplitter.split(mockEvent)).thenReturn(mockEvents); - Flux> splitResult = App.split(mockSplitter, mockEvent, mockConfig); - - splitResult.equals(Flux.just(mockEvents)); + assertEquals(splitResult.toString(), Flux.just(mockEvents).toString()); } @Test - public void testMapping_empty_success() { + void testMapping_empty_success() { Event mockEvent = Mockito.mock(Event.class); MeasConverter mockMeasConverter = Mockito.mock(MeasConverter.class); List mockEvents = Arrays.asList(mockEvent); MapperConfig mockConfig = Mockito.mock(MapperConfig.class); Path mappingTemplate = Paths.get("src/main/resources/mapping.ftl"); Flux> mappingResult = App.map(new Mapper(mappingTemplate,mockMeasConverter), mockEvents, mockConfig); - mappingResult.equals(Flux.>empty()); + assertEquals(mappingResult, Flux.>empty()); } - } 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 index 92d2c93..2cbfffa 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandlerTests.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/ConfigHandlerTests.java @@ -45,6 +45,7 @@ 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.exceptions.RequestFailure; import org.onap.dcaegen2.services.pmmapper.utils.EnvironmentConfig; import org.onap.dcaegen2.services.pmmapper.model.MapperConfig; import org.onap.dcaegen2.services.pmmapper.utils.RequestSender; @@ -99,6 +100,9 @@ class ConfigHandlerTests { MapperConfig actualConfig = getMapperConfig(); JsonObject expectedConfigJson = gson.fromJson(validMapperConfig, JsonObject.class); MapperConfig expectedConfig = gson.fromJson(expectedConfigJson, MapperConfig.class); + assertEquals(expectedConfig.getPublisherTopicUrl(), actualConfig.getPublisherTopicUrl()); + assertEquals(expectedConfig.getPublisherUserName(), actualConfig.getPublisherUserName()); + assertEquals(expectedConfig.getPublisherPassword(), actualConfig.getPublisherPassword()); assertEquals(expectedConfig, actualConfig); assertTrue(logAppender.list.get(1).getMessage().contains("Received pm-mapper configuration from ConfigBinding Service")); logAppender.stop(); @@ -106,7 +110,7 @@ class ConfigHandlerTests { @Test void configbinding_server_error() throws Exception { - when(sender.send(anyString())).thenThrow(CBSServerError.class); + when(sender.send(anyString())).thenThrow(RequestFailure.class); assertThrows(CBSServerError.class, this::getMapperConfig); } diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java index 031a3c8..34b71f4 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java @@ -213,9 +213,7 @@ class MeasFilterHandlerTest { when(exchange.getRequestPath()) .thenReturn(invalidFiletypes.toString()); - invalidFiletypes.forEach(c -> { - assertFalse(objUnderTest.filterByFileType(event)); - }); + invalidFiletypes.forEach(c -> assertFalse(objUnderTest.filterByFileType(event))); } @@ -227,7 +225,7 @@ class MeasFilterHandlerTest { private Event generateEvent(String inputPath, Filter filter) { String inputXml = EventUtils.fileContentsToString(Paths.get(inputPath + ".xml")); - Event event = new Event(exchange, inputXml, metaData, new HashMap(), ""); + Event event = new Event(exchange, inputXml, metaData, new HashMap<>(), ""); event.setMeasCollecFile(converter.convert(inputXml)); event.setFilter(filter); return event; diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java index 7a8602e..f623d57 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java @@ -20,7 +20,7 @@ package org.onap.dcaegen2.services.pmmapper.mapping; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -37,7 +37,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.List; import org.everit.json.schema.Schema; @@ -49,15 +48,12 @@ 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.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.onap.dcaegen2.services.pmmapper.exceptions.MappingException; -import org.onap.dcaegen2.services.pmmapper.exceptions.XMLParseException; import org.onap.dcaegen2.services.pmmapper.model.Event; import org.onap.dcaegen2.services.pmmapper.model.EventMetadata; import org.onap.dcaegen2.services.pmmapper.model.MeasCollecFile; import org.onap.dcaegen2.services.pmmapper.utils.MeasConverter; -import org.onap.logging.ref.slf4j.ONAPLogAdapter; import org.powermock.reflect.Whitebox; import utils.EventUtils; @@ -141,9 +137,9 @@ class MapperTest { void testMapEvents() throws IOException { List events = getValidEvents(); List expectedEvents = objUnderTest.mapEvents(events); - expectedEvents.forEach(event->{ + expectedEvents.forEach(event -> { when(converter.convert(any(MeasCollecFile.class))).thenReturn(event.getBody()); - assertTrue(event.getVes() != null); + assertNotNull(event.getVes()); }); } diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java index 54c5091..5028464 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java @@ -43,7 +43,7 @@ import io.undertow.server.HttpServerExchange; import utils.EventUtils; @ExtendWith(MockitoExtension.class) -public class MeasSplitterTest { +class MeasSplitterTest { private static final String baseDir = "src/test/resources/split_test/"; private MeasSplitter objUnderTest; private MeasConverter converter; @@ -57,33 +57,31 @@ public class MeasSplitterTest { MapperConfig config; @BeforeEach - public void setup() { + void setup() { converter = new MeasConverter(); objUnderTest = new MeasSplitter(converter); } - public void setupBaseEvent() { + void setupBaseEvent() { Mockito.when(event.getHttpServerExchange()).thenReturn(exchange); Mockito.when(event.getMetadata()).thenReturn(meta); - Mockito.when(event.getMdc()).thenReturn(new HashMap()); + Mockito.when(event.getMdc()).thenReturn(new HashMap<>()); Mockito.when(event.getMetadata()).thenReturn(meta); Mockito.when(event.getPublishIdentity()).thenReturn(""); } @Test - public void no_measData() { + void no_measData() { String inputPath = baseDir + "no_measdata"; String inputXml = EventUtils.fileContentsToString(Paths.get(inputPath + ".xml")); Mockito.when(event.getBody()).thenReturn(inputXml); - Assertions.assertThrows(NoSuchElementException.class, ()->{ - objUnderTest.split(event); - }); + Assertions.assertThrows(NoSuchElementException.class, () -> objUnderTest.split(event)); } @Test - public void typeA_returns_only_one_event() throws JAXBException { + void typeA_returns_only_one_event() throws JAXBException { String inputPath = baseDir + "meas_results_typeA"; String inputXml = EventUtils.fileContentsToString(Paths.get(inputPath + ".xml")); MeasCollecFile measToBeSplit = converter.convert(inputXml); @@ -97,7 +95,7 @@ public class MeasSplitterTest { } @Test - public void typeC_returns_multiple_events() throws JAXBException { + void typeC_returns_multiple_events() throws JAXBException { String inputPath = baseDir + "meas_results_typeC"; String inputXml = EventUtils.fileContentsToString(Paths.get(inputPath + ".xml")); setupBaseEvent(); @@ -111,7 +109,7 @@ public class MeasSplitterTest { for (int i = 0; i < splitEvents.size(); i++) { String measInfoId = splitEvents.get(i).getMeasCollecFile() .getMeasData().get(0).getMeasInfo().get(0).getMeasInfoId(); - Assertions.assertTrue(measInfoId.equals("measInfoId"+(i+1))); + Assertions.assertEquals(measInfoId, "measInfoId" + (i + 1)); } } } 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 index 34a2277..c9f2998 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java @@ -70,7 +70,6 @@ public class RequestSenderTests { 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)) diff --git a/src/test/java/utils/EventUtils.java b/src/test/java/utils/EventUtils.java index f14e080..0051629 100644 --- a/src/test/java/utils/EventUtils.java +++ b/src/test/java/utils/EventUtils.java @@ -32,7 +32,6 @@ import java.nio.file.Path; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.onap.dcaegen2.services.pmmapper.model.Event; import org.onap.dcaegen2.services.pmmapper.model.EventMetadata; diff --git a/src/test/resources/filter_test/meas_type_and_r_filtered.xml b/src/test/resources/filter_test/meas_type_and_r_filtered.xml index 1b5a362..f2146f7 100644 --- a/src/test/resources/filter_test/meas_type_and_r_filtered.xml +++ b/src/test/resources/filter_test/meas_type_and_r_filtered.xml @@ -9,7 +9,6 @@ - a b diff --git a/src/test/resources/filter_test/meas_type_and_r_manyInfo_filtered.xml b/src/test/resources/filter_test/meas_type_and_r_manyInfo_filtered.xml index db50fca..b517a7d 100644 --- a/src/test/resources/filter_test/meas_type_and_r_manyInfo_filtered.xml +++ b/src/test/resources/filter_test/meas_type_and_r_manyInfo_filtered.xml @@ -9,7 +9,6 @@ - a b @@ -22,7 +21,6 @@ - a b -- cgit 1.2.3-korg