From c90edac236dffb7c495e266dd04991de7e8f04b7 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 25 Mar 2019 13:04:18 -0400 Subject: Migrate ccsdk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: CCSDK-1177 Issue-ID: CCSDK-1178 Change-Id: I0c02702fbec52211ca367abbba72aebecee8cbaa Signed-off-by: Alexis de Talhouët --- .../api/BluePrintManagementGRPCHandlerTest.kt | 116 ------------------ .../api/BluePrintProcessingGRPCHandlerTest.kt | 124 ------------------- .../selfservice/api/ExecutionServiceHandlerTest.kt | 89 -------------- .../selfservice/api/mock/Mock.kt | 62 ---------- .../selfservice/api/utils/BluePrintMappingTests.kt | 132 --------------------- .../BluePrintRuntimeValidatorServiceTest.kt | 44 ------- .../api/BluePrintManagementGRPCHandlerTest.kt | 116 ++++++++++++++++++ .../api/BluePrintProcessingGRPCHandlerTest.kt | 124 +++++++++++++++++++ .../selfservice/api/ExecutionServiceHandlerTest.kt | 89 ++++++++++++++ .../selfservice/api/mock/Mock.kt | 62 ++++++++++ .../selfservice/api/utils/BluePrintMappingTests.kt | 132 +++++++++++++++++++++ .../BluePrintRuntimeValidatorServiceTest.kt | 44 +++++++ .../selfservice-api/src/test/resources/logback.xml | 2 +- 13 files changed, 568 insertions(+), 568 deletions(-) delete mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt delete mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test') diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt deleted file mode 100644 index 264e2aea6..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api - -import com.google.protobuf.ByteString -import io.grpc.testing.GrpcServerRule -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementInput -import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc -import org.onap.ccsdk.apps.controllerblueprints.management.api.FileChunk -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.annotation.DirtiesContext -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import java.io.File -import kotlin.test.AfterTest -import kotlin.test.BeforeTest -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -@RunWith(SpringRunner::class) -@EnableAutoConfiguration -@DirtiesContext -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -class BluePrintManagementGRPCHandlerTest { - - @get:Rule - val grpcServerRule = GrpcServerRule().directExecutor() - - @Autowired - lateinit var bluePrintManagementGRPCHandler: BluePrintManagementGRPCHandler - - @BeforeTest - fun init() { - // Create a server, add service, start, and register for automatic graceful shutdown. - grpcServerRule.serviceRegistry.addService(bluePrintManagementGRPCHandler) - } - - @AfterTest - fun cleanDir() { - //TODO It's giving fluctuating results, need to look for another way to cleanup - // works sometimes otherwise results IO Exception - // Most probably bufferReader stream is not getting closed when cleanDir is getting invoked - File("./target/blueprints").deleteRecursively() - } - - @Test - fun `test upload blueprint`() { - val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) - val id = "123_upload" - val req = createInputRequest(id) - val output = blockingStub.uploadBlueprint(req) - - assertEquals(200, output.status.code) - assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id(")) - assertEquals(id, output.commonHeader.requestId) - } - - @Test - fun `test delete blueprint`() { - val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) - val id = "123_delete" - val req = createInputRequest(id) - - var output = blockingStub.uploadBlueprint(req) - assertEquals(200, output.status.code) - assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id(")) - assertEquals(id, output.commonHeader.requestId) - - output = blockingStub.removeBlueprint(req) - assertEquals(200, output.status.code) - } - - private fun createInputRequest(id: String): BluePrintManagementInput { - val file = File("./src/test/resources/test-cba.zip") - assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - - val commonHeader = CommonHeader - .newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId(id) - .setSubRequestId("1234-56").build() - - val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) - .build() - - return BluePrintManagementInput.newBuilder() - .setCommonHeader(commonHeader) - .setBlueprintName("sample") - .setBlueprintVersion("1.0.0") - .setFileChunk(fileChunk) - .build() - } -} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt deleted file mode 100644 index 01984b21d..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api - - -import com.google.protobuf.util.JsonFormat -import io.grpc.stub.StreamObserver -import io.grpc.testing.GrpcServerRule -import org.junit.Assert -import org.junit.Ignore -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc -import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput -import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.annotation.DirtiesContext -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.BeforeTest - -@Ignore -@RunWith(SpringRunner::class) -@DirtiesContext -@EnableAutoConfiguration -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -class BluePrintProcessingGRPCHandlerTest { - private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java) - - @get:Rule - val grpcServerRule = GrpcServerRule().directExecutor() - - @Autowired - lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler - - lateinit var requestObs: StreamObserver - - @BeforeTest - fun init() { - grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler) - - val blockingStub = BluePrintProcessingServiceGrpc.newStub(grpcServerRule.channel) - - requestObs = blockingStub.process(object : StreamObserver { - override fun onNext(executionServiceOuput: ExecutionServiceOutput) { - log.debug("onNext {}", executionServiceOuput) - if ("1234".equals(executionServiceOuput.commonHeader.requestId)) { - Assert.assertEquals("Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", executionServiceOuput.status.errorMessage) - } - } - - override fun onError(error: Throwable) { - log.debug("Fail to process message", error) - Assert.assertEquals("INTERNAL: Could not find blueprint : from database", error.message) - } - - override fun onCompleted() { - log.info("Done") - } - }) - } - - @Test - fun testSelfServiceGRPCHandler() { - val commonHeader = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId("1234") - .setSubRequestId("1234-56").build() - - val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json") - val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder - JsonFormat.parser().merge(jsonContent, payloadBuilder) - - val input = ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader) - .setPayload(payloadBuilder.build()) - .build() - - requestObs.onNext(input) - - val commonHeader2 = CommonHeader.newBuilder() - .setTimestamp("2012-04-23T18:25:43.511Z") - .setOriginatorId("System") - .setRequestId("2345") - .setSubRequestId("1234-56").build() - - val actionIdentifier = ActionIdentifiers.newBuilder().setMode("sync").build() - - val input2 = ExecutionServiceInput.newBuilder() - .setCommonHeader(commonHeader2) - .setActionIdentifiers(actionIdentifier) - .setPayload(payloadBuilder.build()) - .build() - - requestObs.onNext(input2) - - requestObs.onCompleted() - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt deleted file mode 100644 index b730472e8..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.security.SecurityProperties -import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.ComponentScan -import org.springframework.core.io.ByteArrayResource -import org.springframework.http.client.MultipartBodyBuilder -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.test.web.reactive.server.WebTestClient -import org.springframework.web.reactive.function.BodyInserters -import java.nio.file.Files -import java.nio.file.Paths -import kotlin.test.assertTrue - -@RunWith(SpringRunner::class) -@WebFluxTest -@ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class, SecurityProperties::class]) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) -class ExecutionServiceHandlerTest { - - @Autowired - lateinit var blueprintCatalog: BluePrintCatalogService - @Autowired - lateinit var webTestClient: WebTestClient - - - @Test - fun `test rest upload blueprint`() { - val file = Paths.get("./src/test/resources/test-cba.zip").toFile() - assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - - val body = MultipartBodyBuilder().apply { - part("file", object : ByteArrayResource(Files.readAllBytes(Paths.get("./src/test/resources/test-cba.zip"))) { - override fun getFilename(): String { - return "test-cba.zip" - } - }) - }.build() - - webTestClient - .post() - .uri("/api/v1/execution-service/upload") - .body(BodyInserters.fromMultipartData(body)) - .exchange() - .expectStatus().isOk - } - - @Test - fun `test rest process`() { - val file = Paths.get("./src/test/resources/test-cba.zip").toFile() - assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") - blueprintCatalog.saveToDatabase(file) - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!! - webTestClient - .post() - .uri("/api/v1/execution-service/process") - .body(BodyInserters.fromObject(executionServiceInput)) - .exchange() - .expectStatus().isOk - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt deleted file mode 100644 index 19c624bc0..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/Mock.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2019 Bell Canada. - * - * 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. - */ -package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock - -import io.mockk.mockk -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive -import org.slf4j.LoggerFactory -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -@Configuration -open class MockComponentConfiguration { - - @Bean(name = ["component-resource-assignment", "component-netconf-executor", "component-jython-executor"]) - open fun createComponentFunction(): AbstractComponentFunction { - return MockComponentFunction() - } -} - -class MockComponentFunction : AbstractComponentFunction() { - - private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) - - override fun process(executionRequest: ExecutionServiceInput) { - log.info("Processing component : $operationInputs") - - bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, - "assignment-params", "params".asJsonPrimitive()) - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - log.info("Recovering component..") - } -} - -open class MockResourceSource { - @Bean(name = [ - "rr-processor-source-input", - "rr-processor-source-default", - "rr-processor-source-primary-db", - "rr-processor-source-rest"]) - open fun sourceInstance(): ResourceAssignmentProcessor { - return mockk() - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt deleted file mode 100644 index 770e4a9b3..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt +++ /dev/null @@ -1,132 +0,0 @@ -package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils - -import org.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags -import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers -import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader -import org.onap.ccsdk.apps.controllerblueprints.common.api.EventType -import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag -import org.springframework.test.context.junit4.SpringRunner -import java.text.SimpleDateFormat - -@RunWith(SpringRunner::class) -class BluePrintMappingsTest { - - val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - val dateString = "2019-01-16T18:25:43.511Z" - val dateForTest = formatter.parse(dateString) - - val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build() - - fun createFlag(): Flags { - val flag = Flags() - flag.isForce = false - flag.ttl = 1 - return flag - } - - @Test - fun flagToJavaTest() { - val flag2 = flag.toJava() - - Assert.assertEquals(flag.isForce, flag2.isForce) - Assert.assertEquals(flag.ttl, flag2.ttl) - } - - @Test - fun flagToProtoTest() { - val flag = createFlag() - val flag2 = flag.toProto() - - Assert.assertEquals(flag.isForce, flag2.isForce) - Assert.assertEquals(flag.ttl, flag2.ttl) - } - - fun createStatus(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status { - val status = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status() - status.code = 400 - status.errorMessage = "Concurrent modification exception" - status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name - status.message = "Error uploading data" - status.timestamp = dateForTest - return status - } - - @Test - fun statusToProtoTest() { - val status = createStatus() - val status2 = status.toProto() - - Assert.assertEquals(status.code, status2.code) - Assert.assertEquals(status.errorMessage, status2.errorMessage) - Assert.assertEquals(status.eventType, status2.eventType.name) - Assert.assertEquals(status.message, status2.message) - Assert.assertEquals(status.timestamp.toString(), status2.timestamp) - } - - @Test - fun commonHeaderToJavaTest() { - val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build() - - val commonHeader = CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString).setFlag(flag).build() - val commonHeader2 = commonHeader.toJava() - - Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) - Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) - Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) - Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp)) - } - - fun createCommonHeader(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader { - val commonHeader = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader() - commonHeader.flags = createFlag() - commonHeader.originatorId = "1234" - commonHeader.requestId = "2345" - commonHeader.subRequestId = "0123" - commonHeader.timestamp = dateForTest - return commonHeader - } - - @Test - fun commonHeaderToProtoTest() { - val commonHeader = createCommonHeader() - val commonHeader2 = commonHeader.toProto() - Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) - Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) - Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) - Assert.assertEquals(commonHeader.timestamp.toString(), commonHeader2.timestamp) - } - - @Test - fun actionIdentifierToJavaTest() { - val actionIdentifiers = ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0").setMode("Execution").build() - val actionIdentifiers2 = actionIdentifiers.toJava() - - Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) - Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) - Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) - Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) - } - - fun createActionIdentifier(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers { - val ac = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers() - ac.mode = "mode" - ac.blueprintVersion = "version" - ac.blueprintName = "name" - ac.actionName = "action" - return ac - } - - @Test - fun actionIdentifierToProtoTest() { - val actionIdentifiers = createActionIdentifier() - val actionIdentifiers2 = actionIdentifiers.toProto() - - Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) - Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) - Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) - Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt deleted file mode 100644 index 1cafead7f..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.validation - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockResourceSource -import org.onap.ccsdk.apps.controllerblueprints.validation.BluePrintValidationConfiguration -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintRuntimeValidatorService::class, - BluePrintValidationConfiguration::class, MockResourceSource::class]) -class BluePrintRuntimeValidatorServiceTest { - - @Autowired - lateinit var bluePrintRuntimeValidatorService: BluePrintRuntimeValidatorService - - @Test - fun testBlueprintRuntimeValidation() { - val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService") - - bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath) - - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt new file mode 100644 index 000000000..a03ad9e47 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt @@ -0,0 +1,116 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api + +import com.google.protobuf.ByteString +import io.grpc.testing.GrpcServerRule +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementInput +import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc +import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.annotation.DirtiesContext +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import java.io.File +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +@RunWith(SpringRunner::class) +@EnableAutoConfiguration +@DirtiesContext +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class BluePrintManagementGRPCHandlerTest { + + @get:Rule + val grpcServerRule = GrpcServerRule().directExecutor() + + @Autowired + lateinit var bluePrintManagementGRPCHandler: BluePrintManagementGRPCHandler + + @BeforeTest + fun init() { + // Create a server, add service, start, and register for automatic graceful shutdown. + grpcServerRule.serviceRegistry.addService(bluePrintManagementGRPCHandler) + } + + @AfterTest + fun cleanDir() { + //TODO It's giving fluctuating results, need to look for another way to cleanup + // works sometimes otherwise results IO Exception + // Most probably bufferReader stream is not getting closed when cleanDir is getting invoked + File("./target/blueprints").deleteRecursively() + } + + @Test + fun `test upload blueprint`() { + val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + val id = "123_upload" + val req = createInputRequest(id) + val output = blockingStub.uploadBlueprint(req) + + assertEquals(200, output.status.code) + assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id(")) + assertEquals(id, output.commonHeader.requestId) + } + + @Test + fun `test delete blueprint`() { + val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + val id = "123_delete" + val req = createInputRequest(id) + + var output = blockingStub.uploadBlueprint(req) + assertEquals(200, output.status.code) + assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id(")) + assertEquals(id, output.commonHeader.requestId) + + output = blockingStub.removeBlueprint(req) + assertEquals(200, output.status.code) + } + + private fun createInputRequest(id: String): BluePrintManagementInput { + val file = File("./src/test/resources/test-cba.zip") + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + + val commonHeader = CommonHeader + .newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(id) + .setSubRequestId("1234-56").build() + + val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) + .build() + + return BluePrintManagementInput.newBuilder() + .setCommonHeader(commonHeader) + .setBlueprintName("sample") + .setBlueprintVersion("1.0.0") + .setFileChunk(fileChunk) + .build() + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt new file mode 100644 index 000000000..f8b972e64 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt @@ -0,0 +1,124 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api + + +import com.google.protobuf.util.JsonFormat +import io.grpc.stub.StreamObserver +import io.grpc.testing.GrpcServerRule +import org.junit.Assert +import org.junit.Ignore +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.annotation.DirtiesContext +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.BeforeTest + +@Ignore +@RunWith(SpringRunner::class) +@DirtiesContext +@EnableAutoConfiguration +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class BluePrintProcessingGRPCHandlerTest { + private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java) + + @get:Rule + val grpcServerRule = GrpcServerRule().directExecutor() + + @Autowired + lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler + + lateinit var requestObs: StreamObserver + + @BeforeTest + fun init() { + grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler) + + val blockingStub = BluePrintProcessingServiceGrpc.newStub(grpcServerRule.channel) + + requestObs = blockingStub.process(object : StreamObserver { + override fun onNext(executionServiceOuput: ExecutionServiceOutput) { + log.debug("onNext {}", executionServiceOuput) + if ("1234".equals(executionServiceOuput.commonHeader.requestId)) { + Assert.assertEquals("Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", executionServiceOuput.status.errorMessage) + } + } + + override fun onError(error: Throwable) { + log.debug("Fail to process message", error) + Assert.assertEquals("INTERNAL: Could not find blueprint : from database", error.message) + } + + override fun onCompleted() { + log.info("Done") + } + }) + } + + @Test + fun testSelfServiceGRPCHandler() { + val commonHeader = CommonHeader.newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId("1234") + .setSubRequestId("1234-56").build() + + val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json") + val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder + JsonFormat.parser().merge(jsonContent, payloadBuilder) + + val input = ExecutionServiceInput.newBuilder() + .setCommonHeader(commonHeader) + .setPayload(payloadBuilder.build()) + .build() + + requestObs.onNext(input) + + val commonHeader2 = CommonHeader.newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId("2345") + .setSubRequestId("1234-56").build() + + val actionIdentifier = ActionIdentifiers.newBuilder().setMode("sync").build() + + val input2 = ExecutionServiceInput.newBuilder() + .setCommonHeader(commonHeader2) + .setActionIdentifiers(actionIdentifier) + .setPayload(payloadBuilder.build()) + .build() + + requestObs.onNext(input2) + + requestObs.onCompleted() + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt new file mode 100644 index 000000000..b131fb7d1 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt @@ -0,0 +1,89 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.security.SecurityProperties +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest +import org.springframework.context.annotation.ComponentScan +import org.springframework.core.io.ByteArrayResource +import org.springframework.http.client.MultipartBodyBuilder +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.test.web.reactive.server.WebTestClient +import org.springframework.web.reactive.function.BodyInserters +import java.nio.file.Files +import java.nio.file.Paths +import kotlin.test.assertTrue + +@RunWith(SpringRunner::class) +@WebFluxTest +@ContextConfiguration(classes = [ExecutionServiceHandler::class, BluePrintCoreConfiguration::class, BluePrintCatalogService::class, SecurityProperties::class]) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class ExecutionServiceHandlerTest { + + @Autowired + lateinit var blueprintCatalog: BluePrintCatalogService + @Autowired + lateinit var webTestClient: WebTestClient + + + @Test + fun `test rest upload blueprint`() { + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + + val body = MultipartBodyBuilder().apply { + part("file", object : ByteArrayResource(Files.readAllBytes(Paths.get("./src/test/resources/test-cba.zip"))) { + override fun getFilename(): String { + return "test-cba.zip" + } + }) + }.build() + + webTestClient + .post() + .uri("/api/v1/execution-service/upload") + .body(BodyInserters.fromMultipartData(body)) + .exchange() + .expectStatus().isOk + } + + @Test + fun `test rest process`() { + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + blueprintCatalog.saveToDatabase(file) + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/default-input.json", ExecutionServiceInput::class.java)!! + webTestClient + .post() + .uri("/api/v1/execution-service/process") + .body(BodyInserters.fromObject(executionServiceInput)) + .exchange() + .expectStatus().isOk + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt new file mode 100644 index 000000000..85e289ccc --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/mock/Mock.kt @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * 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. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.mock + +import io.mockk.mockk +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.slf4j.LoggerFactory +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +open class MockComponentConfiguration { + + @Bean(name = ["component-resource-assignment", "component-netconf-executor", "component-jython-executor"]) + open fun createComponentFunction(): AbstractComponentFunction { + return MockComponentFunction() + } +} + +class MockComponentFunction : AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) + + override fun process(executionRequest: ExecutionServiceInput) { + log.info("Processing component : $operationInputs") + + bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, + "assignment-params", "params".asJsonPrimitive()) + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Recovering component..") + } +} + +open class MockResourceSource { + @Bean(name = [ + "rr-processor-source-input", + "rr-processor-source-default", + "rr-processor-source-primary-db", + "rr-processor-source-rest"]) + open fun sourceInstance(): ResourceAssignmentProcessor { + return mockk() + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt new file mode 100644 index 000000000..230d1fde1 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt @@ -0,0 +1,132 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils + +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Flags +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType +import org.onap.ccsdk.cds.controllerblueprints.common.api.Flag +import org.springframework.test.context.junit4.SpringRunner +import java.text.SimpleDateFormat + +@RunWith(SpringRunner::class) +class BluePrintMappingsTest { + + val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + val dateString = "2019-01-16T18:25:43.511Z" + val dateForTest = formatter.parse(dateString) + + val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build() + + fun createFlag(): Flags { + val flag = Flags() + flag.isForce = false + flag.ttl = 1 + return flag + } + + @Test + fun flagToJavaTest() { + val flag2 = flag.toJava() + + Assert.assertEquals(flag.isForce, flag2.isForce) + Assert.assertEquals(flag.ttl, flag2.ttl) + } + + @Test + fun flagToProtoTest() { + val flag = createFlag() + val flag2 = flag.toProto() + + Assert.assertEquals(flag.isForce, flag2.isForce) + Assert.assertEquals(flag.ttl, flag2.ttl) + } + + fun createStatus(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status { + val status = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status() + status.code = 400 + status.errorMessage = "Concurrent modification exception" + status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name + status.message = "Error uploading data" + status.timestamp = dateForTest + return status + } + + @Test + fun statusToProtoTest() { + val status = createStatus() + val status2 = status.toProto() + + Assert.assertEquals(status.code, status2.code) + Assert.assertEquals(status.errorMessage, status2.errorMessage) + Assert.assertEquals(status.eventType, status2.eventType.name) + Assert.assertEquals(status.message, status2.message) + Assert.assertEquals(status.timestamp.toString(), status2.timestamp) + } + + @Test + fun commonHeaderToJavaTest() { + val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build() + + val commonHeader = CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString).setFlag(flag).build() + val commonHeader2 = commonHeader.toJava() + + Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) + Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) + Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) + Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp)) + } + + fun createCommonHeader(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader { + val commonHeader = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader() + commonHeader.flags = createFlag() + commonHeader.originatorId = "1234" + commonHeader.requestId = "2345" + commonHeader.subRequestId = "0123" + commonHeader.timestamp = dateForTest + return commonHeader + } + + @Test + fun commonHeaderToProtoTest() { + val commonHeader = createCommonHeader() + val commonHeader2 = commonHeader.toProto() + Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId) + Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId) + Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId) + Assert.assertEquals(commonHeader.timestamp.toString(), commonHeader2.timestamp) + } + + @Test + fun actionIdentifierToJavaTest() { + val actionIdentifiers = ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0").setMode("Execution").build() + val actionIdentifiers2 = actionIdentifiers.toJava() + + Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) + Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) + Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) + Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) + } + + fun createActionIdentifier(): org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers { + val ac = org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers() + ac.mode = "mode" + ac.blueprintVersion = "version" + ac.blueprintName = "name" + ac.actionName = "action" + return ac + } + + @Test + fun actionIdentifierToProtoTest() { + val actionIdentifiers = createActionIdentifier() + val actionIdentifiers2 = actionIdentifiers.toProto() + + Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName) + Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName) + Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion) + Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt new file mode 100644 index 000000000..08da9dc28 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt @@ -0,0 +1,44 @@ +/* + * Copyright © 2019 IBM. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.validation + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.mock.MockResourceSource +import org.onap.ccsdk.cds.controllerblueprints.validation.BluePrintValidationConfiguration +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BluePrintRuntimeValidatorService::class, + BluePrintValidationConfiguration::class, MockResourceSource::class]) +class BluePrintRuntimeValidatorServiceTest { + + @Autowired + lateinit var bluePrintRuntimeValidatorService: BluePrintRuntimeValidatorService + + @Test + fun testBlueprintRuntimeValidation() { + val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService") + + bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath) + + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml index a816a06c5..0c8d93bf0 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/logback.xml @@ -26,7 +26,7 @@ - + -- cgit 1.2.3-korg