From 4026d98bc9802e41146ff6ef727d349c7ac1e89e Mon Sep 17 00:00:00 2001 From: Jakub Zieba Date: Tue, 4 Sep 2018 07:23:41 +0200 Subject: Add protocols to hosts Add default protocols for Consul hosts Add controller for healt check Fix for merging properties from file and Consul Change-Id: Ifa8c7cdfa333d8ffee175b5eb4446f0c3a986f27 Issue-ID: DCAEGEN2-747 Signed-off-by: Jakub Zieba --- README.md | 4 +- src/main/java/org/onap/dcae/VesApplication.java | 3 +- .../onap/dcae/controller/ConfigFilesFacade.java | 30 +++++---- .../org/onap/dcae/controller/ConfigSource.java | 10 +-- .../onap/dcae/controller/EnvPropertiesReader.java | 27 ++++++-- .../java/org/onap/dcae/controller/EnvProps.java | 14 +++- .../onap/dcae/restapi/HealthCheckController.java | 36 +++++++++++ .../java/org/onap/dcae/restapi/SwaggerConfig.java | 14 +--- .../java/org/onap/dcae/restapi/WebMvcConfig.java | 56 ++++++++++++++++ .../org/onap/dcae/ApplicationSettingsTest.java | 69 ++++++++++---------- src/test/java/org/onap/dcae/TestingUtilities.java | 15 ++--- src/test/java/org/onap/dcae/WiremockBasedTest.java | 16 ++--- .../dcae/commonFunction/EventProcessorTest.java | 27 ++++++-- .../onap/dcae/controller/ConfigCBSSourceTest.java | 17 ++--- .../org/onap/dcae/vestest/TestConfigProcessor.java | 24 ++----- .../java/org/onap/dcae/vestest/TestVESLogger.java | 75 +++++++++++----------- 16 files changed, 275 insertions(+), 162 deletions(-) create mode 100644 src/main/java/org/onap/dcae/restapi/HealthCheckController.java create mode 100644 src/main/java/org/onap/dcae/restapi/WebMvcConfig.java diff --git a/README.md b/README.md index b7bbdb83..9e38dd6b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,9 @@ Variables set manually / coming from deployment system: - COLLECTOR_IP - DMAAPHOST - should contain an address to DMaaP, so that event publishing can work - CBSPOLLTIMER - it should be put in here if we want to automatically fetch configuration from CBS. -- CONSUL_HOST - used with conjunction with CBSPOLLTIMER, should be a host address (without port! e.g http://my-ip-or-host) where Consul service lies +- CONSUL_PROTOCOL - Consul protocol by default set to **http**, if it is need to change it then that can be set to different value +- CONSUL_HOST - used with conjunction with CBSPOLLTIMER, should be a host address (without port! e.g my-ip-or-host) where Consul service lies +- CBS_PROTOCOL - Config Binding Service protocol by default set to **http**, if it is need to change it then that can be set to different value - CONFIG_BINDING_SERVICE - used with conjunction with CBSPOLLTIMER, should be a name of CBS as it is registered in Consul - HOSTNAME - used with conjunction with CBSPOLLTIMER, should be a name of VESCollector application as it is registered in CBS catalog diff --git a/src/main/java/org/onap/dcae/VesApplication.java b/src/main/java/org/onap/dcae/VesApplication.java index d9d12e35..a7426be2 100644 --- a/src/main/java/org/onap/dcae/VesApplication.java +++ b/src/main/java/org/onap/dcae/VesApplication.java @@ -42,8 +42,7 @@ import org.springframework.context.annotation.Lazy; import java.nio.file.Paths; import java.util.concurrent.*; -@SpringBootApplication -@EnableAutoConfiguration(exclude = {GsonAutoConfiguration.class, SecurityAutoConfiguration.class}) +@SpringBootApplication(exclude = {GsonAutoConfiguration.class, SecurityAutoConfiguration.class}) public class VesApplication { private static final Logger metriclog = LoggerFactory.getLogger("com.att.ecomp.metrics"); diff --git a/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java b/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java index 42155eda..9338bf62 100644 --- a/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java +++ b/src/main/java/org/onap/dcae/controller/ConfigFilesFacade.java @@ -20,26 +20,25 @@ */ package org.onap.dcae.controller; -import static io.vavr.API.Try; -import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.enhanceError; -import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.f; -import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.logError; -import static org.onap.dcae.controller.Conversions.toList; - import io.vavr.CheckedRunnable; import io.vavr.Tuple2; import io.vavr.collection.Map; import io.vavr.control.Try; -import java.io.FileNotFoundException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.FileNotFoundException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import static io.vavr.API.Try; +import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.*; +import static org.onap.dcae.controller.Conversions.toList; + class ConfigFilesFacade { private static Logger log = LoggerFactory.getLogger(ConfigFilesFacade.class); @@ -100,6 +99,7 @@ class ConfigFilesFacade { private PropertiesConfiguration readProperties() throws ConfigurationException { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); + propertiesConfiguration.setDelimiterParsingDisabled(true); propertiesConfiguration.load(propertiesPath.toFile()); return propertiesConfiguration; } @@ -109,12 +109,20 @@ class ConfigFilesFacade { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(propertiesPath.toFile()); propertiesConfiguration.setEncoding(null); for (Tuple2 property : properties) { - propertiesConfiguration.addProperty(property._1, property._2); + updateProperty(propertiesConfiguration, property); } propertiesConfiguration.save(); }; } + private void updateProperty(PropertiesConfiguration propertiesConfiguration, Tuple2 property) { + if (propertiesConfiguration.containsKey(property._1)) { + propertiesConfiguration.setProperty(property._1, property._2); + } else { + propertiesConfiguration.addProperty(property._1, property._2); + } + } + private String indentConfiguration(String configuration) { return new JSONObject(configuration).toString(4); } diff --git a/src/main/java/org/onap/dcae/controller/ConfigSource.java b/src/main/java/org/onap/dcae/controller/ConfigSource.java index 7e6a9fc8..c20a22a2 100644 --- a/src/main/java/org/onap/dcae/controller/ConfigSource.java +++ b/src/main/java/org/onap/dcae/controller/ConfigSource.java @@ -43,7 +43,7 @@ final class ConfigSource { .peek(strBody -> log.info(f("Received following CBS configuration from Consul '%s'", strBody))) .flatMap(strBody -> toJsonArray(strBody)) .flatMap(json -> withdrawCatalog(json)) - .flatMap(json -> constructFullCBSUrl(json)) + .flatMap(json -> constructFullCBSUrl(envProps, json)) .flatMap(cbsUrl -> callCBSForAppConfig(envProps, cbsUrl)) .flatMap(strBody -> toJson(strBody)) .peek(jsonNode -> log.info(f("Received app configuration: '%s'", jsonNode))) @@ -51,12 +51,14 @@ final class ConfigSource { } private static Try callConsulForCBSConfiguration(EnvProps envProps) { - return executeGet(envProps.consulHost + ":" + envProps.consulPort + "/v1/catalog/service/" + envProps.cbsName) + return executeGet(envProps.consulProtocol + "://" + envProps.consulHost + ":" + + envProps.consulPort + "/v1/catalog/service/" + envProps.cbsName) .mapFailure(enhanceError("Unable to retrieve CBS configuration from Consul")); } - private static Try constructFullCBSUrl(JSONObject json) { - return Try(() -> json.get("ServiceAddress").toString() + ":" + json.get("ServicePort").toString()) + private static Try constructFullCBSUrl(EnvProps envProps, JSONObject json) { + return Try(() -> envProps.cbsProtocol + "://" + json.get("ServiceAddress").toString() + ":" + + json.get("ServicePort").toString()) .mapFailure(enhanceError("ServiceAddress / ServicePort missing from CBS conf: '%s'", json)); } diff --git a/src/main/java/org/onap/dcae/controller/EnvPropertiesReader.java b/src/main/java/org/onap/dcae/controller/EnvPropertiesReader.java index 23bcbda8..5f7a2fbd 100644 --- a/src/main/java/org/onap/dcae/controller/EnvPropertiesReader.java +++ b/src/main/java/org/onap/dcae/controller/EnvPropertiesReader.java @@ -20,15 +20,15 @@ */ package org.onap.dcae.controller; -import static io.vavr.API.List; -import static io.vavr.API.Try; -import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.f; - import io.vavr.collection.Map; import io.vavr.control.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static io.vavr.API.List; +import static io.vavr.API.Try; +import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.f; + final class EnvPropertiesReader { private final static Logger log = LoggerFactory.getLogger(EnvPropertiesReader.class); @@ -36,11 +36,13 @@ final class EnvPropertiesReader { static Option readEnvProps(Map environmentVariables) { log.info("Loading necessary environment variables for dynamic configuration update"); int consulPort = getConsulPort(environmentVariables); + String consulProtocol = getConsulProtocol(environmentVariables); + String cbsProtocol = getCbsProtocol(environmentVariables); Option consulHost = getConsulHost(environmentVariables); Option cbsServiceName = getCBSName(environmentVariables); Option vesCollectorAppName = getAppName(environmentVariables); return Option.sequence(List(consulHost, cbsServiceName, vesCollectorAppName)) - .map(e -> new EnvProps(e.get(0), consulPort, e.get(1), e.get(2))) + .map(e -> new EnvProps(consulProtocol, e.get(0), consulPort, cbsProtocol, e.get(1), e.get(2))) .onEmpty(() -> log.warn("Some required environment variables are missing")) .peek(props -> log.info(f("Discovered following environment variables: '%s'", props))); } @@ -74,4 +76,19 @@ final class EnvPropertiesReader { + "is missing from environment variables.")); } + private static String getConsulProtocol(Map environmentVariables) { + return getProtocolFrom("CONSUL_PROTOCOL", environmentVariables); + } + + private static String getCbsProtocol(Map environmentVariables) { + return getProtocolFrom("CBS_PROTOCOL", environmentVariables); + } + + private static String getProtocolFrom(String variableName, Map environmentVariables) { + return environmentVariables.get(variableName) + .onEmpty(() -> log.warn("Consul protocol (env var: '" + variableName + "') is missing " + + "from environment variables.")) + .getOrElse("http"); + } + } diff --git a/src/main/java/org/onap/dcae/controller/EnvProps.java b/src/main/java/org/onap/dcae/controller/EnvProps.java index 2ee41cc6..5f7d08d5 100644 --- a/src/main/java/org/onap/dcae/controller/EnvProps.java +++ b/src/main/java/org/onap/dcae/controller/EnvProps.java @@ -26,14 +26,18 @@ import java.util.Objects; */ final class EnvProps { + final String consulProtocol; final String consulHost; final int consulPort; final String cbsName; + final String cbsProtocol; final String appName; - EnvProps(String consulHost, int consulPort, String cbsName, String appName) { + EnvProps(String consulProtocol, String consulHost, int consulPort, String cbsProtocol, String cbsName, String appName) { + this.consulProtocol = consulProtocol; this.consulHost = consulHost; this.consulPort = consulPort; + this.cbsProtocol = cbsProtocol; this.cbsName = cbsName; this.appName = appName; } @@ -41,8 +45,10 @@ final class EnvProps { @Override public String toString() { return "EnvProps{" + - "consulHost='" + consulHost + '\'' + + "consulProtocol='" + consulProtocol + '\'' + + ", consulHost='" + consulHost + '\'' + ", consulPort=" + consulPort + + ", cbsProtocol='" + cbsProtocol + '\'' + ", cbsName='" + cbsName + '\'' + ", appName='" + appName + '\'' + '}'; @@ -58,13 +64,15 @@ final class EnvProps { } EnvProps envProps = (EnvProps) o; return consulPort == envProps.consulPort && + Objects.equals(consulProtocol, envProps.consulProtocol) && Objects.equals(consulHost, envProps.consulHost) && + Objects.equals(cbsProtocol, envProps.cbsProtocol) && Objects.equals(cbsName, envProps.cbsName) && Objects.equals(appName, envProps.appName); } @Override public int hashCode() { - return Objects.hash(consulHost, consulPort, cbsName, appName); + return Objects.hash(consulProtocol, consulHost, consulPort, cbsProtocol, cbsName, appName); } } \ No newline at end of file diff --git a/src/main/java/org/onap/dcae/restapi/HealthCheckController.java b/src/main/java/org/onap/dcae/restapi/HealthCheckController.java new file mode 100644 index 00000000..9c65619c --- /dev/null +++ b/src/main/java/org/onap/dcae/restapi/HealthCheckController.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * PROJECT + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018 Nokia. All rights reserved.s + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcae.restapi; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + + +@Controller +public class HealthCheckController { + + @GetMapping("/healthcheck") + public String healthCheck() { + return "hello"; + } + +} diff --git a/src/main/java/org/onap/dcae/restapi/SwaggerConfig.java b/src/main/java/org/onap/dcae/restapi/SwaggerConfig.java index d8554cbe..60740a80 100644 --- a/src/main/java/org/onap/dcae/restapi/SwaggerConfig.java +++ b/src/main/java/org/onap/dcae/restapi/SwaggerConfig.java @@ -22,8 +22,6 @@ package org.onap.dcae.restapi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.spi.DocumentationType; @@ -32,7 +30,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 -public class SwaggerConfig extends WebMvcConfigurationSupport { +public class SwaggerConfig{ @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) @@ -42,14 +40,4 @@ public class SwaggerConfig extends WebMvcConfigurationSupport { .build(); } - @Override - protected void addResourceHandlers(ResourceHandlerRegistry registry) { - registry - .addResourceHandler("swagger-ui.html") - .addResourceLocations("classpath:/META-INF/resources/"); - - registry - .addResourceHandler("/webjars/**") - .addResourceLocations("classpath:/META-INF/resources/webjars/"); - } } diff --git a/src/main/java/org/onap/dcae/restapi/WebMvcConfig.java b/src/main/java/org/onap/dcae/restapi/WebMvcConfig.java new file mode 100644 index 00000000..7059c4e5 --- /dev/null +++ b/src/main/java/org/onap/dcae/restapi/WebMvcConfig.java @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START======================================================= + * PROJECT + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018 Nokia. All rights reserved.s + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcae.restapi; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +@Configuration +public class WebMvcConfig extends WebMvcConfigurationSupport { + + @Override + protected void addResourceHandlers(ResourceHandlerRegistry registry) { + registry + .addResourceHandler("swagger-ui.html") + .addResourceLocations("classpath:/META-INF/resources/"); + + registry + .addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + + registry + .addResourceHandler("**") + .addResourceLocations("classpath:/templates/"); + } + + @Bean + public InternalResourceViewResolver jspViewResolver() { + InternalResourceViewResolver resolver = new InternalResourceViewResolver(); + resolver.setPrefix("/"); + resolver.setSuffix(".html"); + return resolver; + } + +} diff --git a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java index 26b0a68b..67b9cb64 100644 --- a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java +++ b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java @@ -23,11 +23,9 @@ package org.onap.dcae; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jsonschema.core.exceptions.ProcessingException; -import com.github.fge.jsonschema.core.report.ProcessingReport; import com.github.fge.jsonschema.main.JsonSchema; import io.vavr.collection.HashMap; import io.vavr.collection.Map; -import org.json.JSONObject; import org.junit.Test; import java.io.File; @@ -62,7 +60,7 @@ public class ApplicationSettingsTest { @Test public void shouldMakeApplicationSettingsOutOfCLIArgumentsAndAConfigurationFile() - throws IOException { + throws IOException { // given File tempConfFile = File.createTempFile("doesNotMatter", "doesNotMatter"); Files.write(tempConfFile.toPath(), Arrays.asList("section.subSection1=abc", "section.subSection2=zxc")); @@ -103,7 +101,7 @@ public class ApplicationSettingsTest { public void shouldReturnHTTPPort() throws IOException { // when int applicationPort = fromTemporaryConfiguration("collector.service.port=8090") - .httpPort(); + .httpPort(); // then assertEquals(8090, applicationPort); @@ -122,7 +120,7 @@ public class ApplicationSettingsTest { public void shouldReturnIfHTTPSIsEnabled() throws IOException { // when boolean httpsEnabled = fromTemporaryConfiguration("collector.service.secure.port=8443") - .httpsEnabled(); + .httpsEnabled(); // then assertTrue(httpsEnabled); @@ -149,7 +147,7 @@ public class ApplicationSettingsTest { public void shouldReturnHTTPSPort() throws IOException { // when int httpsPort = fromTemporaryConfiguration("collector.service.secure.port=8443") - .httpsPort(); + .httpsPort(); // then assertEquals(8443, httpsPort); @@ -159,7 +157,7 @@ public class ApplicationSettingsTest { public void shouldReturnConfigurationUpdateInterval() throws IOException { // when int updateFrequency = fromTemporaryConfiguration("collector.dynamic.config.update.frequency=10") - .configurationUpdateFrequency(); + .configurationUpdateFrequency(); // then assertEquals(10, updateFrequency); @@ -169,7 +167,7 @@ public class ApplicationSettingsTest { public void shouldReturnDefaultConfigurationUpdateInterval() throws IOException { // when int updateFrequency = fromTemporaryConfiguration() - .configurationUpdateFrequency(); + .configurationUpdateFrequency(); // then assertEquals(5, updateFrequency); @@ -178,7 +176,8 @@ public class ApplicationSettingsTest { @Test public void shouldReturnLocationOfThePasswordFile() throws IOException { // when - String passwordFileLocation = fromTemporaryConfiguration("collector.keystore.passwordfile=/somewhere/password").keystorePasswordFileLocation(); + String passwordFileLocation = fromTemporaryConfiguration("collector.keystore.passwordfile=/somewhere/password") + .keystorePasswordFileLocation(); // then assertEquals(sanitizePath("/somewhere/password"), passwordFileLocation); @@ -197,7 +196,7 @@ public class ApplicationSettingsTest { public void shouldReturnLocationOfTheKeystoreFile() throws IOException { // when String keystoreFileLocation = fromTemporaryConfiguration("collector.keystore.file.location=/somewhere/keystore") - .keystoreFileLocation(); + .keystoreFileLocation(); // then assertEquals(sanitizePath("/somewhere/keystore"), keystoreFileLocation); @@ -234,7 +233,8 @@ public class ApplicationSettingsTest { @Test public void shouldReturnDMAAPConfigFileLocation() throws IOException { // when - String dmaapConfigFileLocation = fromTemporaryConfiguration("collector.dmaapfile=/somewhere/dmaapFile").dMaaPConfigurationFileLocation(); + String dmaapConfigFileLocation = fromTemporaryConfiguration("collector.dmaapfile=/somewhere/dmaapFile") + .dMaaPConfigurationFileLocation(); // then assertEquals(sanitizePath("/somewhere/dmaapFile"), dmaapConfigFileLocation); @@ -253,7 +253,7 @@ public class ApplicationSettingsTest { public void shouldReturnMaximumAllowedQueuedEvents() throws IOException { // when int maximumAllowedQueuedEvents = fromTemporaryConfiguration("collector.inputQueue.maxPending=10000") - .maximumAllowedQueuedEvents(); + .maximumAllowedQueuedEvents(); // then assertEquals(10000, maximumAllowedQueuedEvents); @@ -272,7 +272,7 @@ public class ApplicationSettingsTest { public void shouldTellIfSchemaValidationIsEnabled() throws IOException { // when boolean jsonSchemaValidationEnabled = fromTemporaryConfiguration("collector.schema.checkflag=1") - .jsonSchemaValidationEnabled(); + .jsonSchemaValidationEnabled(); // then assertTrue(jsonSchemaValidationEnabled); @@ -291,16 +291,17 @@ public class ApplicationSettingsTest { public void shouldReturnJSONSchema() throws IOException, ProcessingException { // when String sampleJsonSchema = "{" + - " \"type\": \"object\"," + - " \"properties\": {" + - " \"state\": { \"type\": \"string\" }" + - " }" + - "}"; + " \"type\": \"object\"," + + " \"properties\": {" + + " \"state\": { \"type\": \"string\" }" + + " }" + + "}"; Path temporarySchemaFile = createTemporaryFile(sampleJsonSchema); // when - JsonSchema schema = fromTemporaryConfiguration(String.format("collector.schema.file={\"v1\": \"%s\"}", temporarySchemaFile)) - .jsonSchema("v1"); + JsonSchema schema = fromTemporaryConfiguration( + String.format("collector.schema.file={\"v1\": \"%s\"}", temporarySchemaFile)) + .jsonSchema("v1"); // then JsonNode incorrectTestObject = new ObjectMapper().readTree("{ \"state\": 1 }"); @@ -313,7 +314,7 @@ public class ApplicationSettingsTest { public void shouldReturnExceptionConfigFileLocation() throws IOException { // when String exceptionConfigFileLocation = fromTemporaryConfiguration("exceptionConfig=/somewhere/exceptionFile") - .exceptionConfigFileLocation(); + .exceptionConfigFileLocation(); // then assertEquals("/somewhere/exceptionFile", exceptionConfigFileLocation); @@ -333,13 +334,14 @@ public class ApplicationSettingsTest { public void shouldReturnDMAAPStreamId() throws IOException { // given Map expected = HashMap.of( - "s", new String[]{"something", "something2"}, - "s2", new String[]{"something3"} + "s", new String[]{"something", "something2"}, + "s2", new String[]{"something3"} ); // when - Map dmaapStreamID = fromTemporaryConfiguration("collector.dmaap.streamid=s=something,something2|s2=something3") - .dMaaPStreamsMapping(); + Map dmaapStreamID = fromTemporaryConfiguration( + "collector.dmaap.streamid=s=something,something2|s2=something3") + .dMaaPStreamsMapping(); // then assertArrayEquals(expected.get("s").get(), Objects.requireNonNull(dmaapStreamID).get("s").get()); @@ -360,7 +362,7 @@ public class ApplicationSettingsTest { public void shouldReturnIfAuthorizationIsEnabled() throws IOException { // when boolean authorizationEnabled = fromTemporaryConfiguration("header.authflag=1") - .authorizationEnabled(); + .authorizationEnabled(); // then assertTrue(authorizationEnabled); @@ -379,7 +381,7 @@ public class ApplicationSettingsTest { public void shouldReturnValidCredentials() throws IOException { // when Map allowedUsers = fromTemporaryConfiguration( - "header.authlist=pasza,c2ltcGxlcGFzc3dvcmQNCg==|someoneelse,c2ltcGxlcGFzc3dvcmQNCg==" + "header.authlist=pasza,c2ltcGxlcGFzc3dvcmQNCg==|someoneelse,c2ltcGxlcGFzc3dvcmQNCg==" ).validAuthorizationCredentials(); // then @@ -391,7 +393,7 @@ public class ApplicationSettingsTest { public void shouldbyDefaultThereShouldBeNoValidCredentials() throws IOException { // when Map userToBase64PasswordDelimitedByCommaSeparatedByPipes = fromTemporaryConfiguration(). - validAuthorizationCredentials(); + validAuthorizationCredentials(); // then assertTrue(userToBase64PasswordDelimitedByCommaSeparatedByPipes.isEmpty()); @@ -401,7 +403,7 @@ public class ApplicationSettingsTest { public void shouldReturnIfEventTransformingIsEnabled() throws IOException { // when boolean isEventTransformingEnabled = fromTemporaryConfiguration("event.transform.flag=0") - .eventTransformingEnabled(); + .eventTransformingEnabled(); // then assertFalse(isEventTransformingEnabled); @@ -419,8 +421,9 @@ public class ApplicationSettingsTest { @Test public void shouldReturnCambriaConfigurationFileLocation() throws IOException { // when - String cambriaConfigurationFileLocation = fromTemporaryConfiguration("collector.dmaapfile=/somewhere/dmaapConfig") - .dMaaPConfigurationFileLocation(); + String cambriaConfigurationFileLocation = fromTemporaryConfiguration( + "collector.dmaapfile=/somewhere/dmaapConfig") + .dMaaPConfigurationFileLocation(); // then assertEquals(sanitizePath("/somewhere/dmaapConfig"), cambriaConfigurationFileLocation); @@ -430,14 +433,14 @@ public class ApplicationSettingsTest { public void shouldReturnDefaultCambriaConfigurationFileLocation() throws IOException { // when String cambriaConfigurationFileLocation = fromTemporaryConfiguration() - .dMaaPConfigurationFileLocation(); + .dMaaPConfigurationFileLocation(); // then assertEquals(sanitizePath("etc/DmaapConfig.json"), cambriaConfigurationFileLocation); } private static ApplicationSettings fromTemporaryConfiguration(String... fileLines) - throws IOException { + throws IOException { File tempConfFile = File.createTempFile("doesNotMatter", "doesNotMatter"); Files.write(tempConfFile.toPath(), Arrays.asList(fileLines)); tempConfFile.deleteOnExit(); diff --git a/src/test/java/org/onap/dcae/TestingUtilities.java b/src/test/java/org/onap/dcae/TestingUtilities.java index 092983bf..21edfc88 100644 --- a/src/test/java/org/onap/dcae/TestingUtilities.java +++ b/src/test/java/org/onap/dcae/TestingUtilities.java @@ -19,19 +19,18 @@ */ package org.onap.dcae; -import static java.nio.file.Files.readAllBytes; -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import io.vavr.control.Try; +import org.assertj.core.api.AbstractThrowableAssert; +import org.assertj.core.api.Java6Assertions; +import org.json.JSONObject; + import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.assertj.core.api.AbstractThrowableAssert; -import org.assertj.core.api.Java6Assertions; -import org.json.JSONObject; + +import static java.nio.file.Files.readAllBytes; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Pawel Szalapski (pawel.szalapski@nokia.com) diff --git a/src/test/java/org/onap/dcae/WiremockBasedTest.java b/src/test/java/org/onap/dcae/WiremockBasedTest.java index ae851259..58626340 100644 --- a/src/test/java/org/onap/dcae/WiremockBasedTest.java +++ b/src/test/java/org/onap/dcae/WiremockBasedTest.java @@ -17,19 +17,17 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static io.vavr.API.Map; +package org.onap.dcae; import com.github.tomakehurst.wiremock.junit.WireMockRule; import io.vavr.collection.Map; import org.junit.Rule; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static io.vavr.API.Map; + /** * @author Pawel Szalapski (pawel.szalapski@nokia.com) */ @@ -51,7 +49,7 @@ public class WiremockBasedTest { protected Map wiremockBasedEnvProps() { return Map( - "CONSUL_HOST", "http://localhost", + "CONSUL_HOST", "localhost", "CONSUL_PORT", "" + wireMockRule.port(), "HOSTNAME", "VESCollector", "CONFIG_BINDING_SERVICE", "CBSName" @@ -61,7 +59,7 @@ public class WiremockBasedTest { protected String validLocalCBSConf() { return "" + "[{ " - + "\"ServiceAddress\": \"http://localhost\"," + + "\"ServiceAddress\": \"localhost\"," + "\"ServicePort\":" + wireMockRule.port() + "}]"; } diff --git a/src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java b/src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java index 97dccb5b..3e358466 100644 --- a/src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java +++ b/src/test/java/org/onap/dcae/commonFunction/EventProcessorTest.java @@ -40,15 +40,23 @@ import static org.onap.dcae.commonFunction.EventProcessor.EVENT_LIST_TYPE; public class EventProcessorTest { - private final String ev = "{\"event\": {\"commonEventHeader\": { \"reportingEntityName\": \"VM name will be provided by ECOMP\", \"startEpochMicrosec\": 1477012779802988,\"lastEpochMicrosec\": 1477012789802988,\"eventId\": \"83\",\"sourceName\": \"Dummy VM name - No Metadata available\",\"sequence\": 83,\"priority\": \"Normal\",\"functionalRole\": \"vFirewall\",\"domain\": \"measurementsForVfScaling\",\"reportingEntityId\": \"VM UUID will be provided by ECOMP\",\"sourceId\": \"Dummy VM UUID - No Metadata available\",\"version\": 1.1},\"measurementsForVfScalingFields\": {\"measurementInterval\": 10,\"measurementsForVfScalingVersion\": 1.1,\"vNicUsageArray\": [{\"multicastPacketsIn\": 0,\"bytesIn\": 3896,\"unicastPacketsIn\": 0, \"multicastPacketsOut\": 0,\"broadcastPacketsOut\": 0, \"packetsOut\": 28,\"bytesOut\": 12178,\"broadcastPacketsIn\": 0,\"packetsIn\": 58,\"unicastPacketsOut\": 0,\"vNicIdentifier\": \"eth0\"}]}}}"; + private final String ev = "{\"event\": {\"commonEventHeader\": { \"reportingEntityName\": " + + "\"VM name will be provided by ECOMP\", \"startEpochMicrosec\": 1477012779802988,\"lastEpochMicrosec\": " + + "1477012789802988,\"eventId\": \"83\",\"sourceName\": \"Dummy VM name - No Metadata available\"," + + "\"sequence\": 83,\"priority\": \"Normal\",\"functionalRole\": \"vFirewall\",\"domain\": " + + "\"measurementsForVfScaling\",\"reportingEntityId\": \"VM UUID will be provided by ECOMP\"," + + "\"sourceId\": \"Dummy VM UUID - No Metadata available\",\"version\": 1.1},\"measurementsForVfScalingFields\":" + + " {\"measurementInterval\": 10,\"measurementsForVfScalingVersion\": 1.1,\"vNicUsageArray\": " + + "[{\"multicastPacketsIn\": 0,\"bytesIn\": 3896,\"unicastPacketsIn\": 0, " + + "\"multicastPacketsOut\": 0,\"broadcastPacketsOut\": 0, " + + "\"packetsOut\": 28,\"bytesOut\": 12178,\"broadcastPacketsIn\": " + + "0,\"packetsIn\": 58,\"unicastPacketsOut\": 0,\"vNicIdentifier\": \"eth0\"}]}}}"; - private Map streamID; private ApplicationSettings properties; @Before public void setUp() { properties = new ApplicationSettings(new String[]{}, CLIUtils::processCmdLine); - streamID = properties.dMaaPStreamsMapping(); } @Test @@ -68,10 +76,15 @@ public class EventProcessorTest { public void shouldParseJsonEvents() throws ReflectiveOperationException { //given EventProcessor eventProcessor = new EventProcessor(mock(EventPublisher.class), properties); - String event_json = "[{ \"filter\": {\"event.commonEventHeader.domain\":\"heartbeat\",\"VESversion\":\"v4\"},\"processors\":[" + - "{\"functionName\": \"concatenateValue\",\"args\":{\"field\":\"event.commonEventHeader.eventName\",\"concatenate\": [\"$event.commonEventHeader.domain\",\"$event.commonEventHeader.eventType\",\"$event.faultFields.alarmCondition\"], \"delimiter\":\"_\"}}" + - ",{\"functionName\": \"addAttribute\",\"args\":{\"field\": \"event.heartbeatFields.heartbeatFieldsVersion\",\"value\": \"1.0\",\"fieldType\": \"number\"}}" + - ",{\"functionName\": \"map\",\"args\":{\"field\": \"event.commonEventHeader.nfNamingCode\",\"oldField\": \"event.commonEventHeader.functionalRole\"}}]}]"; + String event_json = + "[{ \"filter\": {\"event.commonEventHeader.domain\":\"heartbeat\",\"VESversion\":\"v4\"},\"processors\":[" + + "{\"functionName\": \"concatenateValue\",\"args\":{\"field\":\"event.commonEventHeader.eventName\"," + + "\"concatenate\": [\"$event.commonEventHeader.domain\",\"$event.commonEventHeader.eventType\"," + + "\"$event.faultFields.alarmCondition\"], \"delimiter\":\"_\"}}" + + ",{\"functionName\": \"addAttribute\",\"args\":{\"field\": " + + "\"event.heartbeatFields.heartbeatFieldsVersion\",\"value\": \"1.0\",\"fieldType\": \"number\"}}" + + ",{\"functionName\": \"map\",\"args\":{\"field\": \"event.commonEventHeader.nfNamingCode\"," + + "\"oldField\": \"event.commonEventHeader.functionalRole\"}}]}]"; List events = new Gson().fromJson(event_json, EVENT_LIST_TYPE); EventProcessor.ConfigProcessorAdapter configProcessorAdapter = mock(EventProcessor.ConfigProcessorAdapter.class); diff --git a/src/test/java/org/onap/dcae/controller/ConfigCBSSourceTest.java b/src/test/java/org/onap/dcae/controller/ConfigCBSSourceTest.java index 336788a9..bee2ccee 100644 --- a/src/test/java/org/onap/dcae/controller/ConfigCBSSourceTest.java +++ b/src/test/java/org/onap/dcae/controller/ConfigCBSSourceTest.java @@ -20,19 +20,16 @@ */ package org.onap.dcae.controller; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.assertj.core.api.Java6Assertions.assertThat; -import static org.onap.dcae.TestingUtilities.assertFailureHasInfo; -import static org.onap.dcae.controller.ConfigSource.getAppConfig; - import io.vavr.control.Try; import org.json.JSONObject; import org.junit.Test; import org.onap.dcae.WiremockBasedTest; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.onap.dcae.TestingUtilities.assertFailureHasInfo; +import static org.onap.dcae.controller.ConfigSource.getAppConfig; + public class ConfigCBSSourceTest extends WiremockBasedTest { @Test @@ -82,7 +79,7 @@ public class ConfigCBSSourceTest extends WiremockBasedTest { // given String notAListCatalog = "" + "{" - + "\"ServiceAddress\":\"http://localhost\"," + + "\"ServiceAddress\":\"localhost\"," + "\"ServicePort\":" + wireMockRule.port() + "}"; @@ -145,7 +142,7 @@ public class ConfigCBSSourceTest extends WiremockBasedTest { } private Try tryToGetConfig() { - return getAppConfig(new EnvProps("http://localhost", wireMockRule.port(), "CBSName", "VESCollector")); + return getAppConfig(new EnvProps("http", "localhost", wireMockRule.port(), "http", "CBSName", "VESCollector")); } } diff --git a/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java b/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java index 310e8be3..eaf59410 100644 --- a/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java +++ b/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java @@ -22,11 +22,11 @@ package org.onap.dcae.vestest; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import com.google.gson.JsonParser; +import com.google.gson.JsonObject; import java.io.FileReader; import java.io.IOException; import org.json.JSONObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonObject; import org.junit.Test; import org.onap.dcae.commonFunction.ConfigProcessors; @@ -87,7 +87,8 @@ public class TestConfigProcessor { System.out.println("event==" + jsonObject.toString()); System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation); final JSONObject jsonArgs = new JSONObject( - "{\"field\": \"event.faultFields.eventAdditionalInformation\",\"oldField\": \"event.faultFields.alarmAdditionalInformation\"}"); + "{\"field\": \"event.faultFields.eventAdditionalInformation\",\"oldField\": " + + "\"event.faultFields.alarmAdditionalInformation\"}"); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); cpEvent.map(jsonArgs); final String responseData = cpEvent.getEventObjectVal("event.faultFields.eventAdditionalInformation") @@ -101,11 +102,10 @@ public class TestConfigProcessor { public void testJSONObjectMapToArray() { final JSONObject jsonObject = getFileAsJsonObject(); - //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString(); System.out.println("event==" + jsonObject.toString()); - //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation); final JSONObject jsonArgs = new JSONObject( - "{\"field\": \"event.faultFields.vNicPerformanceArray[]\",\"oldField\": \"event.faultFields.errors\",\"attrMap\":{\"receiveDiscards\":\"receivedDiscardedPacketsAccumulated\"}}"); + "{\"field\": \"event.faultFields.vNicPerformanceArray[]\",\"oldField\": " + + "\"event.faultFields.errors\",\"attrMap\":{\"receiveDiscards\":\"receivedDiscardedPacketsAccumulated\"}}"); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); final String receiveDiscards = cpEvent.getEventObjectVal("event.faultFields.errors.receiveDiscards").toString(); System.out.println("receiveDiscards==" + receiveDiscards); @@ -122,9 +122,7 @@ public class TestConfigProcessor { public void testMapRenameObject() { final JSONObject jsonObject = getFileAsJsonObject(); - //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString(); System.out.println("event==" + jsonObject.toString()); - //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation); final JSONObject jsonArgs = new JSONObject( "{\"field\": \"event.faultFields.faultVFScalingFields\",\"oldField\": \"event.faultFields.errors\",\"mapType\":\"renameObject\"}"); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); @@ -142,9 +140,7 @@ public class TestConfigProcessor { public void testMapHashmapToNameValueArray() { final JSONObject jsonObject = getFileAsJsonObject(); - //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString(); System.out.println("event==" + jsonObject.toString()); - //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation); final JSONObject jsonArgs = new JSONObject( "{\"field\": \"event.faultFields.errors\",\"mapType\":\"hashmapToNameValueArray\"}"); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); @@ -163,9 +159,7 @@ public class TestConfigProcessor { public void testMapNameValueArrayToHashmap() { final JSONObject jsonObject = getFileAsJsonObject(); - //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString(); System.out.println("event==" + jsonObject.toString()); - //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation); final JSONObject jsonArgs = new JSONObject( "{\"field\": \"event.faultFields.alarmAdditionalInformation\",\"mapType\":\"nameValueArrayToHashmap\"}"); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); @@ -184,9 +178,7 @@ public class TestConfigProcessor { public void testAttrAdd() { final JSONObject jsonObject = getFileAsJsonObject(); - //final String functionRole = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("functionalRole").toString(); System.out.println("event==" + jsonObject.toString()); - //System.out.println("functionRole==" + functionRole); final JSONObject jsonArgs = new JSONObject( "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}"); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); @@ -201,9 +193,7 @@ public class TestConfigProcessor { public void testAttrUpdate() { final JSONObject jsonObject = getFileAsJsonObject(); - //final String functionRole = (jsonObject.getJSONObject("event")).getJSONObject("commonEventHeader").get("functionalRole").toString(); System.out.println("event==" + jsonObject.toString()); - //System.out.println("functionRole==" + functionRole); final JSONObject jsonArgs = new JSONObject( "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}"); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); @@ -280,7 +270,6 @@ public class TestConfigProcessor { final JSONObject jsonObject = getFileAsJsonObject(); System.out.println("event==" + jsonObject.toString()); System.out.println("Testing SetEventObjectVal"); - //final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.version\",\"value\": \"2.0\",\"fieldType\": \"number\"}" ); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); cpEvent.setEventObjectVal("event.faultFields.version", "2.0", "number"); final String responseData = cpEvent.getEventObjectVal("event.faultFields.version").toString(); @@ -310,7 +299,6 @@ public class TestConfigProcessor { final JSONObject jsonObject = getFileAsJsonObject(); System.out.println("event==" + jsonObject.toString()); System.out.println("Testing GetEventObjectVal"); - //final JSONObject jsonArgs = new JSONObject ( "{\"field\": \"event.faultFields.eventSeverity\"}" ); ConfigProcessors cpEvent = new ConfigProcessors(jsonObject); cpEvent.getEventObjectVal("event.faultFields.eventSeverity"); final String responseData = cpEvent.getEventObjectVal("event.faultFields.eventSeverity").toString(); diff --git a/src/test/java/org/onap/dcae/vestest/TestVESLogger.java b/src/test/java/org/onap/dcae/vestest/TestVESLogger.java index 484f7dc8..848f2b76 100644 --- a/src/test/java/org/onap/dcae/vestest/TestVESLogger.java +++ b/src/test/java/org/onap/dcae/vestest/TestVESLogger.java @@ -19,57 +19,56 @@ */ package org.onap.dcae.vestest; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.onap.dcae.commonFunction.VESLogger.REQUEST_ID; - import com.att.nsa.logging.LoggingContext; import com.att.nsa.logging.log4j.EcompFields; -import java.util.UUID; import org.junit.Test; import org.onap.dcae.commonFunction.VESLogger; +import java.util.UUID; + +import static org.junit.Assert.*; +import static org.onap.dcae.commonFunction.VESLogger.REQUEST_ID; + public class TestVESLogger { - @Test - public void shouldOnLoggingContextInitializationPutRandomUUIDAsRequestID() { - LoggingContext commonLoggingContext = VESLogger.getCommonLoggingContext(); - String requestId = commonLoggingContext.get(REQUEST_ID, "default"); + @Test + public void shouldOnLoggingContextInitializationPutRandomUuidAsRequestId() { + LoggingContext commonLoggingContext = VESLogger.getCommonLoggingContext(); + String requestId = commonLoggingContext.get(REQUEST_ID, "default"); - assertNotNull(requestId); - assertNotSame(requestId, "default"); + assertNotNull(requestId); + assertNotSame(requestId, "default"); - } + } - @Test - public void shouldOnLoggingContextInitializationPutGivenUUIDAsRequestIDAndSupplyEndTimestamp() { - final UUID uuid = UUID.randomUUID(); - LoggingContext loggingContextForThread = VESLogger.getLoggingContextForThread(uuid); - String requestId = loggingContextForThread.get(REQUEST_ID, "default"); - String endTimestamp = loggingContextForThread.get(EcompFields.kEndTimestamp, "default"); + @Test + public void shouldOnLoggingContextInitializationPutGivenUuuidAsRequestIdAndSupplyEndTimestamp() { + final UUID uuid = UUID.randomUUID(); + LoggingContext loggingContextForThread = VESLogger.getLoggingContextForThread(uuid); + String requestId = loggingContextForThread.get(REQUEST_ID, "default"); + String endTimestamp = loggingContextForThread.get(EcompFields.kEndTimestamp, "default"); - assertNotNull(requestId); - assertNotNull(endTimestamp); - assertNotSame(endTimestamp, "default"); - assertEquals(requestId, uuid.toString()); - } + assertNotNull(requestId); + assertNotNull(endTimestamp); + assertNotSame(endTimestamp, "default"); + assertEquals(requestId, uuid.toString()); + } - @Test - public void shouldOnLoggingContextInitializationPutGivenUUIDAsRequestIDAndSupplyEndTimestampAndCompleteStatusCode() { - final UUID uuid = UUID.randomUUID(); - LoggingContext loggingContextForThread = VESLogger.getLoggingContextForThread(uuid.toString()); - String requestId = loggingContextForThread.get(REQUEST_ID, "default"); - String statusCode = loggingContextForThread.get("statusCode", "default"); - String endTimestamp = loggingContextForThread.get(EcompFields.kEndTimestamp, "default"); + @Test + public void shouldOnLoggingContextInitializationPutGivenUuidAsRequestIdAndSupplyEndTimestampAndCompleteStatusCode() { + final UUID uuid = UUID.randomUUID(); + LoggingContext loggingContextForThread = VESLogger.getLoggingContextForThread(uuid.toString()); + String requestId = loggingContextForThread.get(REQUEST_ID, "default"); + String statusCode = loggingContextForThread.get("statusCode", "default"); + String endTimestamp = loggingContextForThread.get(EcompFields.kEndTimestamp, "default"); - assertNotNull(requestId); - assertNotNull(endTimestamp); - assertNotNull(statusCode); - assertNotSame(endTimestamp, "default"); - assertEquals(requestId, uuid.toString()); - assertEquals(statusCode, "COMPLETE"); - } + assertNotNull(requestId); + assertNotNull(endTimestamp); + assertNotNull(statusCode); + assertNotSame(endTimestamp, "default"); + assertEquals(requestId, uuid.toString()); + assertEquals(statusCode, "COMPLETE"); + } } -- cgit 1.2.3-korg