From 631c45b3426df8ed93bdf45fa1f11a68c991abb4 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Sun, 13 Jan 2019 16:49:32 -0500 Subject: Implement BluePrintManagementServiceGrpc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I66a6a3c23b5a3c24ce8d61178f00f053cb8bbbdc Issue-ID: CCSDK-909 Signed-off-by: Alexis de Talhouët --- .../api/BluePrintManagementGRPCHandlerTest.kt | 42 ++++++++++------ .../api/BluePrintProcessingGRPCHandlerTest.kt | 17 +++---- .../selfservice/api/ExecutionServiceHandlerTest.kt | 35 ++++++++----- .../selfservice/api/mock/SelfServiceApiMocks.kt | 57 ---------------------- .../src/test/resources/application-test.properties | 11 +++++ 5 files changed, 69 insertions(+), 93 deletions(-) delete mode 100755 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.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 index c870bf7f..a48e699c 100644 --- 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 @@ -1,5 +1,6 @@ /* * 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. @@ -22,30 +23,30 @@ import org.apache.commons.io.FileUtils import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration +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.BluePrintUploadInput import org.onap.ccsdk.apps.controllerblueprints.management.api.CommonHeader import org.onap.ccsdk.apps.controllerblueprints.management.api.FileChunk -import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration +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 java.nio.file.Paths import kotlin.test.AfterTest import kotlin.test.BeforeTest -import kotlin.test.assertNotNull +import kotlin.test.assertEquals import kotlin.test.assertTrue @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintManagementGRPCHandler::class, BluePrintCoreConfiguration::class]) +@EnableAutoConfiguration +@DirtiesContext +@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintManagementGRPCHandlerTest { - private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!! - @get:Rule val grpcServerRule = GrpcServerRule().directExecutor() @@ -64,29 +65,42 @@ class BluePrintManagementGRPCHandlerTest { } @Test - fun testFileUpload() { + fun `test upload blueprint`() { val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + val id = "123" + val output = blockingStub.uploadBlueprint(createInputRequest(id)) + 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" + val req = createInputRequest(id) + blockingStub.uploadBlueprint(req) + blockingStub.removeBlueprint(req) + } + + private fun createInputRequest(id: String): BluePrintManagementInput { val file = Paths.get("./src/test/resources/test-cba.zip").toFile() assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") val commonHeader = CommonHeader.newBuilder() .setTimestamp("2012-04-23T18:25:43.511Z") .setOriginatorId("System") - .setRequestId("1234") + .setRequestId(id) .setSubRequestId("1234-56").build() val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) .build() - val input = BluePrintUploadInput.newBuilder() + return BluePrintManagementInput.newBuilder() .setCommonHeader(commonHeader) .setBlueprintName("sample") .setBlueprintVersion("1.0.0") .setFileChunk(fileChunk) .build() - - val output = blockingStub.uploadBlueprint(input) - assertNotNull(output, "failed to get upload response") } } \ 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/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt index cd871b4a..811bd953 100644 --- 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 @@ -1,5 +1,6 @@ /* * 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. @@ -22,30 +23,26 @@ import io.grpc.testing.GrpcServerRule import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBluePrintCatalogService -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBlueprintDGExecutionService 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.CommonHeader import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput -import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration +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 import kotlin.test.assertNotNull @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintProcessingGRPCHandler::class, ExecutionServiceHandler::class, - MockBlueprintDGExecutionService::class, MockBluePrintCatalogService::class, - BluePrintCoreConfiguration::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() 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 index e9e10307..15e6ca94 100644 --- 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 @@ -1,5 +1,6 @@ /* * 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. @@ -16,35 +17,45 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api +import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBluePrintCatalogService -import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBlueprintDGExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +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.test.context.ContextConfiguration +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.nio.file.Paths +import kotlin.test.assertTrue +@Ignore @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [MockBluePrintCatalogService::class, - MockBlueprintDGExecutionService::class, ExecutionServiceHandler::class]) +@DirtiesContext +@EnableAutoConfiguration +@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) class ExecutionServiceHandlerTest { @Autowired lateinit var executionServiceHandler: ExecutionServiceHandler + @Autowired + lateinit var blueprintCatalog: BluePrintCatalogService + @Test fun testProcess() { - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + 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)!! - executionServiceHandler.process(executionServiceInput) + executionServiceHandler.process(executionServiceInput) } -} - - +} \ 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/SelfServiceApiMocks.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt deleted file mode 100755 index e8f25a89..00000000 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/mock/SelfServiceApiMocks.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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 org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput -import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintDGExecutionService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.springframework.stereotype.Service -import java.io.File -import java.nio.file.Path -import java.nio.file.Paths -import kotlin.test.assertNotNull - -@Service -class MockBlueprintDGExecutionService : BlueprintDGExecutionService { - override fun executeDirectedGraph(bluePrintRuntimeService: BluePrintRuntimeService<*>, executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { - - assertNotNull(executionServiceInput, "failed to get executionServiceInput") - - val executionServiceOutput = ExecutionServiceOutput() - executionServiceOutput.commonHeader = executionServiceInput.commonHeader - return executionServiceOutput - } -} - -@Service -class MockBluePrintCatalogService : BluePrintCatalogService { - override fun deleteFromDatabase(name: String, version: String) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun saveToDatabase(blueprintFile: File, validate: Boolean): String { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun getFromDatabase(name: String, version: String, extract: Boolean): Path { - assertNotNull(name, "failed to get blueprint Name") - assertNotNull(version, "failed to get blueprint version") - return Paths.get("./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties index edb51022..8a26ee6e 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties @@ -13,5 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # +blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 +blueprintsprocessor.db.primary.username=sa +blueprintsprocessor.db.primary.password= +blueprintsprocessor.db.primary.driverClassName=org.h2.Driver +blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=create-drop +blueprintsprocessor.db.primary.hibernateDDLAuto=update +blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy +blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect +# Controller Blueprints Core Configuration blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive +# executor +blueprints.processor.functions.python.executor.executionPath="./target/" -- cgit 1.2.3-korg