From f930d9ee670a6dce8977dcdb18643e48c7af33fd Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Thu, 5 Sep 2019 16:13:28 -0400 Subject: Move GRPC management api to designer api. Change-Id: I58ee303d361cf4f1996c966c094ec66886587b52 Issue-ID: CCSDK-1682 Signed-off-by: Brinda Santh --- .../api/BluePrintManagementGRPCHandlerTest.kt | 136 +++++++++++++++++++++ .../designer/api/BlueprintModelControllerTest.kt | 33 ++++- .../designer-api/src/test/resources/test-cba.zip | Bin 0 -> 9554 bytes 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/test-cba.zip (limited to 'ms/blueprintsprocessor/modules/inbounds/designer-api/src/test') diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt new file mode 100644 index 000000000..f0411b0d7 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BluePrintManagementGRPCHandlerTest.kt @@ -0,0 +1,136 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * Modifications 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.designer.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.ActionIdentifiers +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader +import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.management.api.* +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.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) + deleteDir("target", "blueprints") + } + + @AfterTest + fun cleanDir() { + deleteDir("target", "blueprints") + } + + @Test + fun `test upload blueprint`() { + val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + val id = "123_upload" + val req = createUploadInputRequest(id, UploadAction.PUBLISH.toString()) + val output = blockingStub.uploadBlueprint(req) + + assertEquals(200, output.status.code) + assertTrue(output.status.message.contains("Successfully uploaded CBA")) + assertEquals(id, output.commonHeader.requestId) + } + + @Test + fun `test delete blueprint`() { + val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) + val id = "123_delete" + val req = createUploadInputRequest(id, UploadAction.DRAFT.toString()) + + var output = blockingStub.uploadBlueprint(req) + assertEquals(200, output.status.code) + assertTrue(output.status.message.contains("Successfully uploaded CBA")) + assertEquals(id, output.commonHeader.requestId) + + val removeReq = createRemoveInputRequest(id) + output = blockingStub.removeBlueprint(removeReq) + assertEquals(200, output.status.code) + } + + private fun createUploadInputRequest(id: String, action: String): BluePrintUploadInput { + val file = normalizedFile("./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 actionIdentifier = ActionIdentifiers.newBuilder() + .setActionName(action) + .setBlueprintName("sample") + .setBlueprintVersion("1.0.0") + .build() + + val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) + .build() + + return BluePrintUploadInput.newBuilder() + .setCommonHeader(commonHeader) + .setActionIdentifiers(actionIdentifier) + .setFileChunk(fileChunk) + .build() + } + + private fun createRemoveInputRequest(id: String): BluePrintRemoveInput { + val commonHeader = CommonHeader + .newBuilder() + .setTimestamp("2012-04-23T18:25:43.511Z") + .setOriginatorId("System") + .setRequestId(id) + .setSubRequestId("1234-56").build() + + return BluePrintRemoveInput.newBuilder() + .setCommonHeader(commonHeader) + .setBlueprintName("sample") + .setBlueprintVersion("1.0.0") + .build() + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt index 877584ed6..149108087 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelControllerTest.kt @@ -176,6 +176,31 @@ class BlueprintModelControllerTest { @Test fun test07_publishBlueprintModel() { + bp = runBlocking { + val body = MultipartBodyBuilder().apply { + part("file", object : ByteArrayResource(testZipFile!!.readBytes()) { + override fun getFilename(): String { + return "test.zip" + } + }) + }.build() + + val publishBP = webTestClient + .post() + .uri("/api/v1/blueprint-model/publish") + .body(BodyInserters.fromMultipartData(body)) + .exchange() + .expectStatus().isOk + .returnResult() + .responseBody + .awaitSingle() + + assertNotNull(publishBP, "failed to get response") + assertEquals("baseconfiguration", publishBP.artifactName, "mismatch artifact name") + assertEquals("1.0.0", publishBP.artifactVersion, "mismatch artifact version") + assertEquals("Y", publishBP.published, "mismatch publish") + publishBP + } } @Test @@ -196,7 +221,13 @@ class BlueprintModelControllerTest { @Test fun test10_deleteBluePrint() { - webTestClient.delete().uri("/api/v1/blueprint-model/${bp!!.id}") +// webTestClient.delete().uri("/api/v1/blueprint-model/${bp!!.id}") +// .header("Authorization", "Basic " + Base64Utils +// .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) +// .exchange() +// .expectStatus().is2xxSuccessful + + webTestClient.delete().uri("/api/v1/blueprint-model/name/${bp!!.artifactName}/version/${bp!!.artifactVersion}") .header("Authorization", "Basic " + Base64Utils .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) .exchange() diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/test-cba.zip b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/test-cba.zip new file mode 100644 index 000000000..785ec6c00 Binary files /dev/null and b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/resources/test-cba.zip differ -- cgit 1.2.3-korg