diff options
author | Singal, Kapil (ks220y) <ks220y@att.com> | 2020-09-22 12:16:46 -0400 |
---|---|---|
committer | Singal, Kapil (ks220y) <ks220y@att.com> | 2020-09-22 13:49:05 -0400 |
commit | 1072867dfac0df993cbd3e44bcc11a5cac7465fd (patch) | |
tree | 4a821659cf3b50cf946cbb535d528be8508e9fff /ms/blueprintsprocessor/application | |
parent | d97021cd756d63402545fdc2e14ac7611c3da118 (diff) |
Enabling Code Formatter
Code Formatter was turned off due to java 11 migation
Issue-ID: CCSDK-2852
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: I3d02ed3cc7a93d7551fe25356512cfe8db1517d8
Diffstat (limited to 'ms/blueprintsprocessor/application')
19 files changed, 170 insertions, 101 deletions
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt index e9557aed9..f5ccdee18 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt @@ -31,8 +31,10 @@ import javax.sql.DataSource @Configuration @Import(BluePrintDBLibConfiguration::class) @EnableJpaRepositories( - basePackages = ["org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor", - "org.onap.ccsdk.cds.error.catalog"], + basePackages = [ + "org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor", + "org.onap.ccsdk.cds.error.catalog" + ], entityManagerFactoryRef = "primaryEntityManager", transactionManagerRef = "primaryTransactionManager" ) diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt index 97b7d28b0..e576877e3 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt @@ -31,8 +31,10 @@ import org.springframework.context.annotation.ComponentScan @SpringBootApplication @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class, HazelcastAutoConfiguration::class]) @ComponentScan( - basePackages = ["org.onap.ccsdk.cds.error.catalog", - "org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"] + basePackages = [ + "org.onap.ccsdk.cds.error.catalog", + "org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints" + ] ) open class BlueprintProcessorApplication diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt index f241e3f42..598300f47 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt @@ -22,4 +22,4 @@ import org.springframework.web.bind.annotation.RestControllerAdvice @RestControllerAdvice("org.onap.ccsdk.cds") open class BlueprintProcessorExceptionHandler(private val errorCatalogService: ErrorCatalogService) : - ErrorCatalogExceptionHandler(errorCatalogService) + ErrorCatalogExceptionHandler(errorCatalogService) diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/actuator/indicator/BluePrintCustomIndicator.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/actuator/indicator/BluePrintCustomIndicator.kt index 8fcffbf06..c795ee5fb 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/actuator/indicator/BluePrintCustomIndicator.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/actuator/indicator/BluePrintCustomIndicator.kt @@ -32,7 +32,7 @@ import org.springframework.stereotype.Component */ @Component open class BluePrintCustomIndicator(private val bluePrintProcessorHealthCheck: BluePrintProcessorHealthCheck) : - AbstractHealthIndicator() { + AbstractHealthIndicator() { private var logger = LoggerFactory.getLogger(BluePrintCustomIndicator::class.java) diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt index f8e6bd486..5b3843a31 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt @@ -59,6 +59,7 @@ class MockInvocationLogger(private val marker: Marker) : InvocationListener { } companion object { + private const val INDENT = " " private val log = LoggerFactory.getLogger(MockInvocationLogger::class.java) } diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt index 6c5759155..b77caebcb 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt @@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.DeserializationContext import com.fasterxml.jackson.databind.deser.std.StdDeserializer internal class PathDeserializer : StdDeserializer<String>(String::class.java) { + override fun deserialize(jp: JsonParser, ctxt: DeserializationContext?): String { val path = jp.codec.readValue(jp, Any::class.java) return flatJoin(path) diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt index 0f98d7213..ca60bb3b3 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt @@ -23,6 +23,7 @@ import com.google.common.collect.Maps import org.mockito.ArgumentMatcher class RequiredMapEntriesMatcher<K, V>(private val requiredEntries: Map<K, V>) : ArgumentMatcher<Map<K, V>> { + override fun matches(argument: Map<K, V>?): Boolean { val missingEntries = Maps.difference(requiredEntries, argument).entriesOnlyOnLeft() return missingEntries.isEmpty() diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt index 17b79f588..d5bf3f4c6 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt @@ -47,9 +47,14 @@ data class RequestDefinition( ) @JsonInclude(JsonInclude.Include.NON_EMPTY) -data class ResponseDefinition(val status: Int = 200, val body: JsonNode? = null, val headers: Map<String, String> = mapOf("Content-Type" to "application/json")) { +data class ResponseDefinition( + val status: Int = 200, + val body: JsonNode? = null, + val headers: Map<String, String> = mapOf("Content-Type" to "application/json") +) { companion object { + val DEFAULT_RESPONSES = listOf(ResponseDefinition()) } } @@ -61,9 +66,11 @@ class ExpectationDefinition( responses: List<ResponseDefinition>? = null, val times: String = ">= 1" ) { + val responses: List<ResponseDefinition> = resolveOneOrMany(response, responses, ResponseDefinition.DEFAULT_RESPONSES) companion object { + fun <T> resolveOneOrMany(one: T?, many: List<T>?, defaultMany: List<T>): List<T> = when { many != null -> many one != null -> listOf(one) @@ -108,7 +115,8 @@ data class UatDefinition( } companion object { + fun load(mapper: ObjectMapper, spec: String): UatDefinition = - mapper.convertValue(Yaml().load(spec), UatDefinition::class.java) + mapper.convertValue(Yaml().load(spec), UatDefinition::class.java) } } diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt index d120e71d6..7d0c8751d 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt @@ -78,6 +78,7 @@ class UatExecutor( ) { companion object { + private const val NOOP_PASSWORD_PREFIX = "{noop}" private const val PROPERTY_IN_UAT = "IN_UAT" private val TIMES_SPEC_REGEX = "([<>]=?)?\\s*(\\d+)".toRegex() @@ -106,8 +107,8 @@ class UatExecutor( fun execute(uat: UatDefinition, cbaBytes: ByteArray): UatDefinition { val defaultHeaders = listOf(BasicHeader(HttpHeaders.AUTHORIZATION, clientAuthToken())) val httpClient = HttpClientBuilder.create() - .setDefaultHeaders(defaultHeaders) - .build() + .setDefaultHeaders(defaultHeaders) + .build() // Only if externalServices are defined val mockInterceptor = MockPreInterceptor() // Always defined and used, whatever the case @@ -117,13 +118,13 @@ class UatExecutor( markUatBegin() // Configure mocked external services and save their expectations for further validation val expectationsPerClient = uat.externalServices.associateBy( - { service -> - createRestClientMock(service.expectations).also { restClient -> - // side-effect: register restClient to override real instance - mockInterceptor.registerMock(service.selector, restClient) - } - }, - { service -> service.expectations } + { service -> + createRestClientMock(service.expectations).also { restClient -> + // side-effect: register restClient to override real instance + mockInterceptor.registerMock(service.selector, restClient) + } + }, + { service -> service.expectations } ) val newProcesses = httpClient.use { client -> @@ -134,14 +135,14 @@ class UatExecutor( log.info("Executing process '${process.name}'") val responseNormalizer = JsonNormalizer.getNormalizer(mapper, process.responseNormalizerSpec) val actualResponse = processBlueprint( - client, process.request, - process.expectedResponse, responseNormalizer + client, process.request, + process.expectedResponse, responseNormalizer ) ProcessDefinition( - process.name, - process.request, - actualResponse, - process.responseNormalizerSpec + process.name, + process.request, + actualResponse, + process.responseNormalizerSpec ) } } @@ -151,10 +152,10 @@ class UatExecutor( expectations.forEach { expectation -> val request = expectation.request verify(mockClient, evalVerificationMode(expectation.times)).exchangeResource( - eq(request.method), - eq(request.path), - argThat { assertJsonEquals(request.body, this) }, - argThat(RequiredMapEntriesMatcher(request.headers)) + eq(request.method), + eq(request.path), + argThat { assertJsonEquals(request.body, this) }, + argThat(RequiredMapEntriesMatcher(request.headers)) ) } // Don't mind the invocations to the overloaded exchangeResource(String, String, String) @@ -163,7 +164,7 @@ class UatExecutor( } val newExternalServices = spyInterceptor.getSpies() - .map(SpyService::asServiceDefinition) + .map(SpyService::asServiceDefinition) return UatDefinition(newProcesses, newExternalServices) } finally { @@ -181,43 +182,43 @@ class UatExecutor( } private fun createRestClientMock(restExpectations: List<ExpectationDefinition>): - BlueprintWebClientService { - val restClient = mock<BlueprintWebClientService>( + BlueprintWebClientService { + val restClient = mock<BlueprintWebClientService>( defaultAnswer = Answers.RETURNS_SMART_NULLS, // our custom verboseLogging handler invocationListeners = arrayOf(mockLoggingListener) - ) + ) - // Delegates to overloaded exchangeResource(String, String, String, Map<String, String>) - whenever(restClient.exchangeResource(any(), any(), any())) + // Delegates to overloaded exchangeResource(String, String, String, Map<String, String>) + whenever(restClient.exchangeResource(any(), any(), any())) .thenAnswer { invocation -> val method = invocation.arguments[0] as String val path = invocation.arguments[1] as String val request = invocation.arguments[2] as String restClient.exchangeResource(method, path, request, emptyMap()) } - for (expectation in restExpectations) { - var stubbing = whenever( + for (expectation in restExpectations) { + var stubbing = whenever( restClient.exchangeResource( - eq(expectation.request.method), - eq(expectation.request.path), - any(), - any() + eq(expectation.request.method), + eq(expectation.request.path), + any(), + any() ) - ) - for (response in expectation.responses) { - stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString())) + ) + for (response in expectation.responses) { + stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString())) + } } + return restClient } - return restClient - } @Throws(AssertionError::class) private fun uploadBlueprint(client: HttpClient, cbaBytes: ByteArray) { val multipartEntity = MultipartEntityBuilder.create() - .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) - .addBinaryBody("file", cbaBytes, ContentType.DEFAULT_BINARY, "cba.zip") - .build() + .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) + .addBinaryBody("file", cbaBytes, ContentType.DEFAULT_BINARY, "cba.zip") + .build() val request = HttpPost("$baseUrl/api/v1/blueprint-model/publish").apply { entity = multipartEntity } @@ -254,7 +255,8 @@ class UatExecutor( private fun evalVerificationMode(times: String): VerificationMode { val matchResult = TIMES_SPEC_REGEX.matchEntire(times) ?: throw InvalidUatDefinition( - "Time specification '$times' does not follow expected format $TIMES_SPEC_REGEX") + "Time specification '$times' does not follow expected format $TIMES_SPEC_REGEX" + ) val counter = matchResult.groups[2]!!.value.toInt() return when (matchResult.groups[1]?.value) { ">=" -> atLeast(counter) @@ -278,21 +280,25 @@ class UatExecutor( } private fun localServerPort(): Int = - (environment.getProperty("local.server.port") - ?: environment.getRequiredProperty("blueprint.httpPort")).toInt() + ( + environment.getProperty("local.server.port") + ?: environment.getRequiredProperty("blueprint.httpPort") + ).toInt() private fun clientAuthToken(): String { val username = environment.getRequiredProperty("security.user.name") val password = environment.getRequiredProperty("security.user.password") val plainPassword = when { password.startsWith(NOOP_PASSWORD_PREFIX) -> password.substring( - NOOP_PASSWORD_PREFIX.length) + NOOP_PASSWORD_PREFIX.length + ) else -> username } return "Basic " + Base64Utils.encodeToString("$username:$plainPassword".toByteArray()) } private class MockPreInterceptor : BluePrintRestLibPropertyService.PreInterceptor { + private val mocks = ConcurrentHashMap<String, BlueprintWebClientService>() override fun getInstance(jsonNode: JsonNode): BlueprintWebClientService? { @@ -300,7 +306,7 @@ class UatExecutor( } override fun getInstance(selector: String): BlueprintWebClientService? = - mocks[selector] + mocks[selector] fun registerMock(selector: String, client: BlueprintWebClientService) { mocks[selector] = client @@ -322,7 +328,7 @@ class UatExecutor( } fun getSpies(): List<SpyService> = - spies.values.toList() + spies.values.toList() } private class SpyService( @@ -330,14 +336,15 @@ class UatExecutor( val selector: String, private val realService: BlueprintWebClientService ) : - BlueprintWebClientService by realService { + BlueprintWebClientService by realService { private val expectations: MutableList<ExpectationDefinition> = mutableListOf() override fun exchangeResource(methodType: String, path: String, request: String): WebClientResponse<String> = - exchangeResource(methodType, path, request, - DEFAULT_HEADERS - ) + exchangeResource( + methodType, path, request, + DEFAULT_HEADERS + ) override fun exchangeResource( methodType: String, @@ -346,7 +353,7 @@ class UatExecutor( headers: Map<String, String> ): WebClientResponse<String> { val requestDefinition = - RequestDefinition(methodType, path, headers, toJson(request)) + RequestDefinition(methodType, path, headers, toJson(request)) val realAnswer = realService.exchangeResource(methodType, path, request, headers) val responseBody = when { // TODO: confirm if we need to normalize the response here @@ -354,12 +361,12 @@ class UatExecutor( else -> null } val responseDefinition = - ResponseDefinition(realAnswer.status, responseBody) + ResponseDefinition(realAnswer.status, responseBody) expectations.add( - ExpectationDefinition( - requestDefinition, - responseDefinition - ) + ExpectationDefinition( + requestDefinition, + responseDefinition + ) ) return realAnswer } @@ -369,7 +376,7 @@ class UatExecutor( } fun asServiceDefinition() = - ServiceDefinition(selector, expectations) + ServiceDefinition(selector, expectations) private fun toJson(str: String): JsonNode? { return when { @@ -379,9 +386,10 @@ class UatExecutor( } companion object { + private val DEFAULT_HEADERS = mapOf( - HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE ) } } diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt index f40b903de..f6dd88dd5 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt @@ -87,7 +87,8 @@ open class UatServices(private val uatExecutor: UatExecutor, private val mapper: val uat = UatDefinition.load(mapper, uatSpec) val cbaBytes = tempFile.readBytes() val updatedUat = uatExecutor.execute(uat, cbaBytes) - return@runBlocking updatedUat.dump(mapper, + return@runBlocking updatedUat.dump( + mapper, FIELDS_TO_EXCLUDE ) } catch (t: Throwable) { @@ -119,6 +120,7 @@ open class UatServices(private val uatExecutor: UatExecutor, private val mapper: } companion object { + // Fields that can be safely ignored from BPP response, and can be omitted on the UAT specification. private val FIELDS_TO_EXCLUDE = listOf("timestamp") } diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BaseUatTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BaseUatTest.kt index 7f38608c9..41e997b88 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BaseUatTest.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BaseUatTest.kt @@ -55,6 +55,7 @@ abstract class BaseUatTest { } companion object { + const val UAT_BLUEPRINTS_BASE_DIR = "../../../components/model-catalog/blueprint-model/uat-blueprints" } } diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BlueprintsAcceptanceTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BlueprintsAcceptanceTest.kt index ff7cd78c0..4a8da536f 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BlueprintsAcceptanceTest.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/BlueprintsAcceptanceTest.kt @@ -58,9 +58,11 @@ class BlueprintsAcceptanceTest( @Parameterized.Parameters(name = "{index} {0}") @JvmStatic fun scanUatEmpoweredBlueprints(): List<Array<Any>> { - return (File(UAT_BLUEPRINTS_BASE_DIR) - .listFiles { file -> file.isDirectory && File(file, UAT_SPECIFICATION_FILE).isFile } - ?: throw RuntimeException("Failed to scan $UAT_BLUEPRINTS_BASE_DIR")) + return ( + File(UAT_BLUEPRINTS_BASE_DIR) + .listFiles { file -> file.isDirectory && File(file, UAT_SPECIFICATION_FILE).isFile } + ?: throw RuntimeException("Failed to scan $UAT_BLUEPRINTS_BASE_DIR") + ) .map { file -> arrayOf( file.nameWithoutExtension, diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt index c9d55c18a..33e795728 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt @@ -22,7 +22,7 @@ import org.springframework.context.annotation.Configuration @Configuration @ComponentScan( - basePackages = ["org.onap.ccsdk.cds.error.catalog"] + basePackages = ["org.onap.ccsdk.cds.error.catalog"] ) @EnableAutoConfiguration open class ErrorCatalogTestConfiguration diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt index 4e7d4ce40..fe2d539e3 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt @@ -74,6 +74,7 @@ fun String.prefixIfNot(prefix: String) = class UatServicesTest : BaseUatTest() { companion object { + private const val BLUEPRINT_NAME = "pnf_config" private val BLUEPRINT_BASE_DIR = Paths.get(UAT_BLUEPRINTS_BASE_DIR, BLUEPRINT_NAME) private val UAT_PATH = BLUEPRINT_BASE_DIR.resolve(UAT_SPECIFICATION_FILE) @@ -223,11 +224,14 @@ class UatServicesTest : BaseUatTest() { for (response in expectation.responses) { val responseDefinitionBuilder: ResponseDefinitionBuilder = aResponse() - .withStatus(response.status) + .withStatus(response.status) if (response.body != null) { responseDefinitionBuilder.withBody(mapper.writeValueAsBytes(response.body)) - .withHeaders(HttpHeaders( - response.headers.entries.map { e -> HttpHeader(e.key, e.value) })) + .withHeaders( + HttpHeaders( + response.headers.entries.map { e -> HttpHeader(e.key, e.value) } + ) + ) } // TODO: MockServer verification for multiple responses should be done using Wiremock scenarios diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt index 4f7ef0ec2..f00eb9d5f 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt @@ -35,10 +35,11 @@ import kotlin.test.assertTrue @RunWith(SpringRunner::class) @ContextConfiguration( - classes = [ErrorCatalogTestConfiguration::class] + classes = [ErrorCatalogTestConfiguration::class] ) @TestPropertySource(locations = ["classpath:application-test.properties"]) class ErrorCatalogServiceTest { + @Autowired lateinit var errorCatalogService: ErrorCatalogService @@ -52,46 +53,74 @@ class ErrorCatalogServiceTest { @BeforeTest fun setup() { errorType = ErrorCatalogCodes.GENERIC_FAILURE - errorCatalogHttp = ErrorCatalog(errorType, domain, 500, - "Contact CDS administrator team.", "Internal error in Blueprint Processor run time.") - errorCatalogGrpc = ErrorCatalog(errorType, domain, 2, - "Contact CDS administrator team.", "Internal error in Blueprint Processor run time.") + errorCatalogHttp = ErrorCatalog( + errorType, domain, 500, + "Contact CDS administrator team.", "Internal error in Blueprint Processor run time." + ) + errorCatalogGrpc = ErrorCatalog( + errorType, domain, 2, + "Contact CDS administrator team.", "Internal error in Blueprint Processor run time." + ) - errorPayloadHttp = ErrorPayload(500, ErrorCatalogCodes.GENERIC_FAILURE, - "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.", - errorMessage = ErrorMessage("org.onap.ccsdk.cds.blueprintsprocessor", - "Internal error in Blueprint Processor run time.", "")) - errorPayloadGrpc = ErrorPayload(2, ErrorCatalogCodes.GENERIC_FAILURE, - "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.", - errorMessage = ErrorMessage("org.onap.ccsdk.cds.blueprintsprocessor", - "Internal error in Blueprint Processor run time.", "")) + errorPayloadHttp = ErrorPayload( + 500, ErrorCatalogCodes.GENERIC_FAILURE, + "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.", + errorMessage = ErrorMessage( + "org.onap.ccsdk.cds.blueprintsprocessor", + "Internal error in Blueprint Processor run time.", "" + ) + ) + errorPayloadGrpc = ErrorPayload( + 2, ErrorCatalogCodes.GENERIC_FAILURE, + "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.", + errorMessage = ErrorMessage( + "org.onap.ccsdk.cds.blueprintsprocessor", + "Internal error in Blueprint Processor run time.", "" + ) + ) } @Test fun errorPayloadHttp() { - val errorPayload = errorCatalogService.errorPayload(httpProcessorException(errorType, domain, - "Internal error in Blueprint Processor run time.")) + val errorPayload = errorCatalogService.errorPayload( + httpProcessorException( + errorType, domain, + "Internal error in Blueprint Processor run time." + ) + ) assertTrue { errorPayload.isEqualTo(errorPayloadHttp) } } @Test fun errorPayloadGrpc() { - val errorPayload = errorCatalogService.errorPayload(grpcProcessorException(errorType, domain, - "Internal error in Blueprint Processor run time.")) + val errorPayload = errorCatalogService.errorPayload( + grpcProcessorException( + errorType, domain, + "Internal error in Blueprint Processor run time." + ) + ) assertTrue { errorPayload.isEqualTo(errorPayloadGrpc) } } @Test fun getErrorCatalogHttp() { - val errorCatalog = errorCatalogService.getErrorCatalog(httpProcessorException(errorType, domain, - "Internal error in Blueprint Processor run time.")) + val errorCatalog = errorCatalogService.getErrorCatalog( + httpProcessorException( + errorType, domain, + "Internal error in Blueprint Processor run time." + ) + ) assertTrue { errorCatalog == errorCatalogHttp } } @Test fun getErrorCatalogGrpc() { - val errorCatalog = errorCatalogService.getErrorCatalog(grpcProcessorException(errorType, domain, - "Internal error in Blueprint Processor run time.")) + val errorCatalog = errorCatalogService.getErrorCatalog( + grpcProcessorException( + errorType, domain, + "Internal error in Blueprint Processor run time." + ) + ) assertTrue { errorCatalog == errorCatalogGrpc } } } diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/SmartColorDiscriminator.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/SmartColorDiscriminator.kt index cad235450..e5d924d36 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/SmartColorDiscriminator.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/SmartColorDiscriminator.kt @@ -24,6 +24,7 @@ import ch.qos.logback.core.sift.AbstractDiscriminator import org.onap.ccsdk.cds.blueprintsprocessor.uat.logging.LogColor.MDC_COLOR_KEY class SmartColorDiscriminator : AbstractDiscriminator<ILoggingEvent>() { + var defaultValue: String = "white" override fun getKey(): String { diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/ExtendedTemporaryFolder.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/ExtendedTemporaryFolder.kt index 9090361fb..dd31c0e8f 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/ExtendedTemporaryFolder.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/ExtendedTemporaryFolder.kt @@ -29,6 +29,7 @@ import java.nio.file.attribute.BasicFileAttributes import javax.annotation.PreDestroy class ExtendedTemporaryFolder { + private val tempFolder = createTempDir("uat") @PreDestroy @@ -49,12 +50,15 @@ class ExtendedTemporaryFolder { * Delete all files under the root temporary folder recursively. The folders are preserved. */ fun deleteAllFiles() { - Files.walkFileTree(tempFolder.toPath(), object : SimpleFileVisitor<Path>() { - @Throws(IOException::class) - override fun visitFile(file: Path?, attrs: BasicFileAttributes?): FileVisitResult { - file?.toFile()?.delete() - return FileVisitResult.CONTINUE + Files.walkFileTree( + tempFolder.toPath(), + object : SimpleFileVisitor<Path>() { + @Throws(IOException::class) + override fun visitFile(file: Path?, attrs: BasicFileAttributes?): FileVisitResult { + file?.toFile()?.delete() + return FileVisitResult.CONTINUE + } } - }) + ) } } diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/MarkedSlf4jNotifier.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/MarkedSlf4jNotifier.kt index e6198b1ba..a4320e654 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/MarkedSlf4jNotifier.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/MarkedSlf4jNotifier.kt @@ -38,6 +38,7 @@ class MarkedSlf4jNotifier(private val marker: Marker) : Notifier { } companion object { + private val log = LoggerFactory.getLogger("uat.WireMock") } } diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/TestSecuritySettings.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/TestSecuritySettings.kt index 888ab8dcd..eec36c88d 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/TestSecuritySettings.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/TestSecuritySettings.kt @@ -26,6 +26,7 @@ import org.springframework.util.Base64Utils class TestSecuritySettings { companion object { + private const val authUsername = "walter.white" private const val authPassword = "Heisenberg" @@ -34,6 +35,7 @@ class TestSecuritySettings { } class ServerContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> { + override fun initialize(context: ConfigurableApplicationContext) { TestPropertySourceUtils.addInlinedPropertiesToEnvironment( context, |