From 341db21b2ac0a14a1ed2b8bf7930914dda054bfe Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Fri, 22 Nov 2019 18:06:08 -0500 Subject: Formatting Code base with ktlint No Business logic change, just the code format. Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3 To format run: mvn process-sources -P format Issue-ID: CCSDK-1947 Signed-off-by: Singal, Kapil (ks220y) Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331 --- .../execution/MockBluePrintProcessingServer.kt | 50 ++++++++--------- .../StreamingRemoteExecutionServiceTest.kt | 62 ++++++++++++---------- .../scripts/AbstractComponentFunctionTest.kt | 28 +++++----- .../scripts/BlueprintJythonServiceTest.kt | 33 ++++++------ .../execution/scripts/BlueprintPythonHostTest.kt | 13 ++--- .../services/execution/scripts/SampleComponent.kt | 24 ++++----- .../services/execution/scripts/SampleTest.kt | 3 +- 7 files changed, 110 insertions(+), 103 deletions(-) (limited to 'ms/blueprintsprocessor/modules/services/execution-service/src/test') diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/MockBluePrintProcessingServer.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/MockBluePrintProcessingServer.kt index 6bffffdb5..a0eaeca5f 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/MockBluePrintProcessingServer.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/MockBluePrintProcessingServer.kt @@ -31,15 +31,16 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOu private val log = logger(MockBluePrintProcessingServer::class) - class MockBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() { override fun process(responseObserver: StreamObserver): StreamObserver { return object : StreamObserver { override fun onNext(executionServiceInput: ExecutionServiceInput) { - log.info("Received requestId(${executionServiceInput.commonHeader.requestId}) " + - "subRequestId(${executionServiceInput.commonHeader.subRequestId})") + log.info( + "Received requestId(${executionServiceInput.commonHeader.requestId}) " + + "subRequestId(${executionServiceInput.commonHeader.subRequestId})" + ) runBlocking { launch(MDCContext()) { responseObserver.onNext(buildNotification(executionServiceInput)) @@ -52,9 +53,11 @@ class MockBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrintPr override fun onError(error: Throwable) { log.debug("Fail to process message", error) - responseObserver.onError(io.grpc.Status.INTERNAL + responseObserver.onError( + io.grpc.Status.INTERNAL .withDescription(error.message) - .asException()) + .asException() + ) } override fun onCompleted() { @@ -63,29 +66,27 @@ class MockBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrintPr } } - private fun buildNotification(input: ExecutionServiceInput): ExecutionServiceOutput { val status = Status.newBuilder() - .setEventType(EventType.EVENT_COMPONENT_NOTIFICATION) - .build() + .setEventType(EventType.EVENT_COMPONENT_NOTIFICATION) + .build() return ExecutionServiceOutput.newBuilder() - .setCommonHeader(input.commonHeader) - .setActionIdentifiers(input.actionIdentifiers) - .setStatus(status) - .build() + .setCommonHeader(input.commonHeader) + .setActionIdentifiers(input.actionIdentifiers) + .setStatus(status) + .build() } private fun buildResponse(input: ExecutionServiceInput): ExecutionServiceOutput { val status = Status.newBuilder().setCode(200) - .setEventType(EventType.EVENT_COMPONENT_EXECUTED) - .build() + .setEventType(EventType.EVENT_COMPONENT_EXECUTED) + .build() return ExecutionServiceOutput.newBuilder() - .setCommonHeader(input.commonHeader) - .setActionIdentifiers(input.actionIdentifiers) - .setStatus(status) - .build() - + .setCommonHeader(input.commonHeader) + .setActionIdentifiers(input.actionIdentifiers) + .setStatus(status) + .build() } } @@ -93,15 +94,14 @@ class MockBluePrintProcessingServer : BluePrintProcessingServiceGrpc.BluePrintPr fun main() { try { val server = ServerBuilder - .forPort(50052) - .intercept(GrpcServerLoggingInterceptor()) - .addService(MockBluePrintProcessingServer()) - .build() + .forPort(50052) + .intercept(GrpcServerLoggingInterceptor()) + .addService(MockBluePrintProcessingServer()) + .build() server.start() log.info("GRPC Serve started(${server.isShutdown}) on port(${server.port})...") server.awaitTermination() } catch (e: Exception) { e.printStackTrace() } - -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/StreamingRemoteExecutionServiceTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/StreamingRemoteExecutionServiceTest.kt index 9a5be0151..dede885c1 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/StreamingRemoteExecutionServiceTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/StreamingRemoteExecutionServiceTest.kt @@ -23,8 +23,13 @@ import io.grpc.testing.GrpcCleanupRule import io.mockk.coEvery import io.mockk.mockk import io.mockk.spyk -import kotlinx.coroutines.* +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.runBlocking import org.junit.Rule import org.junit.Test import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC @@ -37,11 +42,10 @@ import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput -import java.util.* +import java.util.UUID import kotlin.test.assertEquals import kotlin.test.assertNotNull - class StreamingRemoteExecutionServiceTest { val log = logger(StreamingRemoteExecutionServiceTest::class) @@ -82,16 +86,21 @@ class StreamingRemoteExecutionServiceTest { val request = getRequest(requestId) val invocationId = request.commonHeader.subRequestId val deferred = async { - val response = spyStreamingRemoteExecutionService.sendNonInteractive(tokenAuthGrpcClientProperties, - invocationId, request, 1000L) + val response = spyStreamingRemoteExecutionService.sendNonInteractive( + tokenAuthGrpcClientProperties, + invocationId, request, 1000L + ) assertNotNull(response, "failed to get non interactive response") - assertEquals(response.commonHeader.requestId, requestId, - "failed to match non interactive response id") - assertEquals(response.status.eventType, EventType.EVENT_COMPONENT_EXECUTED, - "failed to match non interactive response type") + assertEquals( + response.commonHeader.requestId, requestId, + "failed to match non interactive response id" + ) + assertEquals( + response.status.eventType, EventType.EVENT_COMPONENT_EXECUTED, + "failed to match non interactive response type" + ) } nonInteractiveDeferred.add(deferred) - } nonInteractiveDeferred.awaitAll() @@ -102,7 +111,7 @@ class StreamingRemoteExecutionServiceTest { val request = getRequest(requestId) val invocationId = request.commonHeader.requestId val responseFlow = spyStreamingRemoteExecutionService - .openSubscription(tokenAuthGrpcClientProperties, invocationId) + .openSubscription(tokenAuthGrpcClientProperties, invocationId) val deferred = async { responseFlow.collect { @@ -119,33 +128,30 @@ class StreamingRemoteExecutionServiceTest { responseFlowsDeferred.awaitAll() streamingRemoteExecutionService.closeChannel(tokenAuthGrpcClientProperties) } - } private fun getRequest(requestId: String): ExecutionServiceInput { val commonHeader = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId(requestId) - .setSubRequestId("$requestId-" + UUID.randomUUID().toString()).build() - + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(requestId) + .setSubRequestId("$requestId-" + UUID.randomUUID().toString()).build() val actionIdentifier = ActionIdentifiers.newBuilder() - .setActionName("SampleScript") - .setBlueprintName("sample-cba") - .setBlueprintVersion("1.0.0") - .setMode(ACTION_MODE_SYNC) - .build() + .setActionName("SampleScript") + .setBlueprintName("sample-cba") + .setBlueprintVersion("1.0.0") + .setMode(ACTION_MODE_SYNC) + .build() val jsonContent = """{ "key1" : "value1" }""" val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder JsonFormat.parser().merge(jsonContent, payloadBuilder) return ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader) - .setActionIdentifiers(actionIdentifier) - .setPayload(payloadBuilder.build()) - .build() - + .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) + .setPayload(payloadBuilder.build()) + .build() } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt index 2fc9a993b..d6720427e 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts; +package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper @@ -54,9 +54,11 @@ import kotlin.test.assertNotNull * Unit test cases for abstract component function. */ @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [ComponentFunctionScriptingService::class, - BluePrintScriptsServiceImpl::class, PythonExecutorProperty::class, - BlueprintJythonService::class]) +@ContextConfiguration( + classes = [ComponentFunctionScriptingService::class, + BluePrintScriptsServiceImpl::class, PythonExecutorProperty::class, + BlueprintJythonService::class] +) class AbstractComponentFunctionTest { lateinit var blueprintContext: BluePrintContext @@ -97,7 +99,8 @@ class AbstractComponentFunctionTest { val sampleComponent = SampleComponent() sampleComponent.workflowName = "sample-action" sampleComponent.executionServiceInput = JacksonUtils.readValueFromClassPathFile( - "payload/requests/sample-execution-request.json", ExecutionServiceInput::class.java)!! + "payload/requests/sample-execution-request.json", ExecutionServiceInput::class.java + )!! val payload = sampleComponent.requestPayload() assertNotNull(payload, "failed to get payload") val data = sampleComponent.requestPayloadActionProperty("data")?.first() @@ -153,14 +156,13 @@ class AbstractComponentFunctionTest { val operationInputs = hashMapOf() operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = - "activate-restconf".asJsonPrimitive() + "activate-restconf".asJsonPrimitive() operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = - "interfaceName".asJsonPrimitive() + "interfaceName".asJsonPrimitive() operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = - "operationName".asJsonPrimitive() + "operationName".asJsonPrimitive() operationInputs["dynamic-properties"] = rootNode - val stepInputData = StepData().apply { name = "activate-restconf" properties = operationInputs @@ -178,13 +180,15 @@ class AbstractComponentFunctionTest { every { bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs( - "activate-restconf", "interfaceName", "operationName") + "activate-restconf", "interfaceName", "operationName" + ) } returns operationInputs val operationOutputs = hashMapOf() every { bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs( - "activate-restconf", "interfaceName", "operationName") + "activate-restconf", "interfaceName", "operationName" + ) } returns operationOutputs every { bluePrintRuntime.bluePrintContext() } returns blueprintContext @@ -196,6 +200,4 @@ class AbstractComponentFunctionTest { val componentScriptExecutor = BluePrintTypes.nodeTypeComponentScriptExecutor() assertNotNull(componentScriptExecutor.interfaces, "failed to get interface operations") } - } - diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt index fd18baf52..a34794a85 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt @@ -33,9 +33,11 @@ import kotlin.test.assertNotNull @RunWith(SpringRunner::class) @ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::class]) -@TestPropertySource(properties = -["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"]) +@TestPropertySource( + properties = + ["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"] +) class BlueprintJythonServiceTest { lateinit var blueprintContext: BluePrintContext @@ -47,26 +49,27 @@ class BlueprintJythonServiceTest { blueprintContext = mockk() every { blueprintContext.rootPath } returns normalizedPathName("target") } - + @Test fun testGetAbstractPythonPlugin() { - val content = JacksonUtils.getClassPathFileContent("scripts/SamplePythonComponentNode.py") - val dependencies: MutableMap = hashMapOf() + val content = JacksonUtils.getClassPathFileContent("scripts/SamplePythonComponentNode.py") + val dependencies: MutableMap = hashMapOf() - val abstractPythonPlugin = blueprintJythonService - .jythonInstance(blueprintContext, "SamplePythonComponentNode", - content, dependencies) + val abstractPythonPlugin = blueprintJythonService + .jythonInstance( + blueprintContext, "SamplePythonComponentNode", + content, dependencies + ) - assertNotNull(abstractPythonPlugin, "failed to get python component") + assertNotNull(abstractPythonPlugin, "failed to get python component") } @Test fun testGetAbstractJythonComponent() { - val scriptInstance = "test-classes/scripts/SamplePythonComponentNode.py" - - val abstractJythonComponent = blueprintJythonService.jythonComponentInstance(blueprintContext, scriptInstance) + val scriptInstance = "test-classes/scripts/SamplePythonComponentNode.py" - assertNotNull(abstractJythonComponent, "failed to get Jython component") + val abstractJythonComponent = blueprintJythonService.jythonComponentInstance(blueprintContext, scriptInstance) + assertNotNull(abstractJythonComponent, "failed to get Jython component") } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHostTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHostTest.kt index 3c3efa252..9a93abe0c 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHostTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHostTest.kt @@ -16,21 +16,22 @@ package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts import org.junit.Test - import org.junit.runner.RunWith import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull import kotlin.test.BeforeTest +import kotlin.test.assertNotNull @RunWith(SpringRunner::class) @ContextConfiguration(classes = [BluePrintPython::class, PythonExecutorProperty::class, String::class]) -@TestPropertySource(properties = -["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"]) +@TestPropertySource( + properties = + ["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"] +) class BlueprintPythonHostTest { lateinit var blueprintPythonHost: BlueprintPythonHost @@ -59,4 +60,4 @@ class BlueprintPythonHostTest { assertNotNull(pythonObject, "failed to get python object") } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/SampleComponent.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/SampleComponent.kt index 000d8c09b..31b1a59c8 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/SampleComponent.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/SampleComponent.kt @@ -18,21 +18,18 @@ * ============LICENSE_END========================================================= */ - package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService - import org.slf4j.LoggerFactory open class SampleComponent : AbstractComponentFunction() { val log = LoggerFactory.getLogger(SampleComponent::class.java)!! - override suspend fun processNB(executionRequest: ExecutionServiceInput) { } @@ -40,20 +37,21 @@ open class SampleComponent : AbstractComponentFunction() { } } -open class SampleRestconfComponent (private var componentFunctionScriptingService: ComponentFunctionScriptingService) - : AbstractComponentFunction() { +open class SampleRestconfComponent(private var componentFunctionScriptingService: ComponentFunctionScriptingService) : + AbstractComponentFunction() { val log = LoggerFactory.getLogger(SampleScriptComponent::class.java)!! - override suspend fun processNB(executionRequest: ExecutionServiceInput) { var scriptComponent: AbstractScriptComponentFunction scriptComponent = componentFunctionScriptingService - .scriptInstance(this, - "internal", - "org.onap.ccsdk.cds.blueprintsprocessor.services" + - ".execution.scripts.SampleTest", - mutableListOf()) + .scriptInstance( + this, + "internal", + "org.onap.ccsdk.cds.blueprintsprocessor.services" + + ".execution.scripts.SampleTest", + mutableListOf() + ) scriptComponent.executeScript(executionServiceInput) } @@ -65,11 +63,9 @@ open class SampleScriptComponent : AbstractScriptComponentFunction() { val log = LoggerFactory.getLogger(SampleScriptComponent::class.java)!! - override suspend fun processNB(executionRequest: ExecutionServiceInput) { - } override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/SampleTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/SampleTest.kt index 6a95e29e7..b10f08dd4 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/SampleTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/SampleTest.kt @@ -29,7 +29,6 @@ open class SampleTest : AbstractScriptComponentFunction() { val log = LoggerFactory.getLogger(SampleTest::class.java)!! - override suspend fun processNB(executionRequest: ExecutionServiceInput) { val isPresent = checkDynamicProperties("type") assertTrue(isPresent) @@ -39,4 +38,4 @@ open class SampleTest : AbstractScriptComponentFunction() { override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { } -} \ No newline at end of file +} -- cgit 1.2.3-korg