diff options
author | 2019-03-29 12:55:06 +0000 | |
---|---|---|
committer | 2019-03-29 12:55:06 +0000 | |
commit | cf6a08425cc50b871cec9ae386e617388816b27d (patch) | |
tree | b28a25b623b143354364b4d778f01bdb4b0784c4 /ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test | |
parent | 837f8493fe6c7cd0569c43105b923e42549dcf7b (diff) | |
parent | c3811effed948926f8d94615df7530c99d490092 (diff) |
Merge "Improve blueprint save"
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test')
3 files changed, 84 insertions, 40 deletions
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 index a03ad9e47..fd764d78f 100644 --- 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 @@ -1,6 +1,7 @@ /* * 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. @@ -23,8 +24,11 @@ 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.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc +import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintRemoveInput +import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration @@ -32,7 +36,6 @@ 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 @@ -55,25 +58,23 @@ class BluePrintManagementGRPCHandlerTest { fun init() { // Create a server, add service, start, and register for automatic graceful shutdown. grpcServerRule.serviceRegistry.addService(bluePrintManagementGRPCHandler) + deleteDir("target", "blueprints") } @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() + deleteDir("target", "blueprints") } @Test fun `test upload blueprint`() { val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) val id = "123_upload" - val req = createInputRequest(id) + val req = createUploadInputRequest(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(")) + assertTrue(output.status.message.contains("Successfully uploaded CBA")) assertEquals(id, output.commonHeader.requestId) } @@ -81,19 +82,20 @@ class BluePrintManagementGRPCHandlerTest { fun `test delete blueprint`() { val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel) val id = "123_delete" - val req = createInputRequest(id) + val req = createUploadInputRequest(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(")) + assertTrue(output.status.message.contains("Successfully uploaded CBA")) assertEquals(id, output.commonHeader.requestId) - output = blockingStub.removeBlueprint(req) + val removeReq = createRemoveInputRequest(id) + output = blockingStub.removeBlueprint(removeReq) assertEquals(200, output.status.code) } - private fun createInputRequest(id: String): BluePrintManagementInput { - val file = File("./src/test/resources/test-cba.zip") + private fun createUploadInputRequest(id: String): BluePrintUploadInput { + val file = normalizedFile("./src/test/resources/test-cba.zip") assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") val commonHeader = CommonHeader @@ -106,11 +108,24 @@ class BluePrintManagementGRPCHandlerTest { val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes())) .build() - return BluePrintManagementInput.newBuilder() + return BluePrintUploadInput.newBuilder() + .setCommonHeader(commonHeader) + .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") - .setFileChunk(fileChunk) .build() } } 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 index b131fb7d1..d14761cc9 100644 --- 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 @@ -17,10 +17,13 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api +import kotlinx.coroutines.reactive.awaitSingle +import kotlinx.coroutines.runBlocking 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.deleteDir 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 @@ -33,9 +36,13 @@ 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.test.web.reactive.server.returnResult import org.springframework.web.reactive.function.BodyInserters import java.nio.file.Files import java.nio.file.Paths +import java.util.* +import kotlin.test.AfterTest +import kotlin.test.BeforeTest import kotlin.test.assertTrue @RunWith(SpringRunner::class) @@ -50,40 +57,61 @@ class ExecutionServiceHandlerTest { @Autowired lateinit var webTestClient: WebTestClient + @BeforeTest + fun init() { + deleteDir("target", "blueprints") + } + + @AfterTest + fun cleanDir() { + deleteDir("target", "blueprints") + } + @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}") + runBlocking { + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldn't 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() - 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 + .returnResult<String>() + .responseBody + .awaitSingle() + } - 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) + runBlocking { + val file = Paths.get("./src/test/resources/test-cba.zip").toFile() + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), file) + + val executionServiceInput = JacksonUtils + .readValueFromClassPathFile("execution-input/default-input.json", + ExecutionServiceInput::class.java)!! - 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 + 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/resources/application-test.properties b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/application-test.properties index 6d8b62ff9..6705523df 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 @@ -25,6 +25,7 @@ blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.Improve blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect # Controller Blueprints Core Configuration blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy +blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive # Python executor |