diff options
author | 2019-06-20 22:48:12 -0400 | |
---|---|---|
committer | 2019-07-04 15:53:42 -0400 | |
commit | c5276ff19122435871c3deedbf0d983962ac2537 (patch) | |
tree | 6a96054ac6863d641c836e14e76fb3fc7f3a1ece /ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin | |
parent | d4b56bc36db1169024fef1f54f924bf3b8f351b6 (diff) |
Refactor resolution controllers
tempalte and resources for get/put API
Change-Id: Ia00bdb08f5f52231481edc6de232f850c66874e9
Issue-ID: CCSDK-1423
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin')
3 files changed, 184 insertions, 215 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResolutionResultsServiceHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResolutionResultsServiceHandlerTest.kt deleted file mode 100644 index 813c900d7..000000000 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResolutionResultsServiceHandlerTest.kt +++ /dev/null @@ -1,215 +0,0 @@ -/* - * 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.resolutionresults.api - -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.controllerblueprints.core.deleteDir -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.slf4j.LoggerFactory -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.http.HttpStatus -import org.springframework.http.MediaType -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.io.File -import java.nio.file.Paths -import java.util.* -import kotlin.test.AfterTest -import kotlin.test.BeforeTest -import kotlin.test.assertTrue - -@RunWith(SpringRunner::class) -@WebFluxTest -@ContextConfiguration(classes = [ResolutionResultsServiceHandler::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 ResolutionResultsServiceHandlerTest { - - private val log = LoggerFactory.getLogger(ResolutionResultsServiceHandlerTest::class.toString()) - - @Autowired - lateinit var blueprintCatalog: BluePrintCatalogService - @Autowired - lateinit var webTestClient: WebTestClient - - var resolutionKey = "7cafa9f3-bbc8-49ec-8f25-fcaa6ac3ff08" - val blueprintName = "baseconfiguration" - val blueprintVersion = "1.0.0" - val templatePrefix = "activate" - val payloadDummyTemplateData = "PAYLOAD DATA" - - @BeforeTest - fun init() { - runBlocking { - deleteDir("target", "blueprints") - blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile()) - } - } - - @AfterTest - fun cleanDir() { - deleteDir("target", "blueprints") - } - - @Test - fun `ping return Success`() { - runBlocking { - - webTestClient.get().uri("/api/v1/resolution-results/ping") - .exchange() - .expectStatus().isOk - .expectBody().equals("Success") - } - } - - @Test - fun `store-retrieve-delete result by path or UUID`() { - runBlocking { - createRetrieveDelete() - } - } - - @Test - fun `get returns requested JSON content-type`() { - runBlocking { - createRetrieveDelete("json") - } - } - - @Test - fun `get returns requested XML content-type`() { - runBlocking { - createRetrieveDelete("xml") - } - } - - private fun createRetrieveDelete(expectedType : String? = null): WebTestClient.ResponseSpec { - var uuid = "MISSING" - - // Store new result for blueprint/artifact/resolutionkey - webTestClient - .post() - .uri("/api/v1/resolution-results/$blueprintName/$blueprintVersion/$templatePrefix/$resolutionKey/") - .body(BodyInserters.fromObject(payloadDummyTemplateData)) - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .consumeWith { - uuid = String(it.responseBody) - log.info("Stored result under UUID $uuid") - } - // Retrieve same payload - var requestArguments = "bpName=$blueprintName&bpVersion=$blueprintVersion" + - "&artifactName=$templatePrefix&resolutionKey=$resolutionKey" - if (expectedType != null) { - requestArguments = "$requestArguments&format=$expectedType" - webTestClient - .get() - .uri("/api/v1/resolution-results/?$requestArguments") - .exchange() - .expectStatus().is2xxSuccessful - .expectHeader().contentType(MediaType.valueOf("application/$expectedType")) - .expectBody().equals(payloadDummyTemplateData) - } else { - webTestClient - .get() - .uri("/api/v1/resolution-results/?$requestArguments") - .exchange() - .expectStatus().is2xxSuccessful - .expectHeader().contentType(MediaType.TEXT_PLAIN) - .expectBody().equals(payloadDummyTemplateData) - } - // And delete by UUID - return webTestClient - .delete() - .uri("/api/v1/resolution-results/$uuid/") - .exchange() - .expectStatus().is2xxSuccessful - } - - /* - * Error cases - */ - @Test - fun `get returns 400 error if missing arg`() { - runBlocking { - val arguments = "bpBADName=$blueprintName" + - "&bpBADVersion=$blueprintVersion" + - "&artifactName=$templatePrefix" + - "&resolutionKey=$resolutionKey" - - webTestClient.get().uri("/api/v1/resolution-results/?$arguments") - .exchange() - .expectStatus().isBadRequest - } - } - - @Test - fun `get returns 503 error if Blueprint not found`() { - runBlocking { - val arguments = "bpName=BAD_BP_NAME" + - "&bpVersion=BAD_BP_VERSION" + - "&artifactName=$templatePrefix" + - "&resolutionKey=$resolutionKey" - - webTestClient.get().uri("/api/v1/resolution-results/?$arguments") - .exchange() - .expectStatus().isEqualTo(HttpStatus.SERVICE_UNAVAILABLE) - } - } - - @Test - fun `get returns 404 if entry not found`() { - runBlocking { - - webTestClient - .get() - .uri("/api/v1/resolution-results/?bpName=$blueprintName&bpVersion=$blueprintVersion" + - "&artifactName=$templatePrefix&resolutionKey=$resolutionKey") - .exchange() - .expectStatus().isNotFound - } - } - - @Test - fun `get returns 404 if UUID not found`() { - runBlocking { - - webTestClient - .get() - .uri("/api/v1/resolution-results/234234234234/") - .exchange() - .expectStatus().isNotFound - } - } - - private fun loadTestCbaFile(): File { - val testCbaFile = Paths.get("./src/test/resources/test-cba.zip").toFile() - assertTrue(testCbaFile.exists(), "couldn't get file ${testCbaFile.absolutePath}") - return testCbaFile - } -}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt index fa8bf4459..cde71d86c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resolutionresults/api/ResourceControllerTest.kt @@ -51,6 +51,8 @@ import java.util.* import org.h2.value.DataType.readValue import org.python.bouncycastle.asn1.x500.style.RFC4519Style.l import org.h2.value.DataType.readValue +import org.onap.ccsdk.cds.blueprintsprocessor.resource.api.ErrorMessage +import org.onap.ccsdk.cds.blueprintsprocessor.resource.api.ResourceController import java.lang.reflect.Array diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt new file mode 100644 index 000000000..d12d05804 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateControllerTest.kt @@ -0,0 +1,182 @@ +/* + * 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.resource.api + +import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService +import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.slf4j.LoggerFactory +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.http.HttpStatus +import org.springframework.http.MediaType +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.io.File +import java.nio.file.Paths +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.assertTrue + +@RunWith(SpringRunner::class) +@WebFluxTest +@ContextConfiguration(classes = [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 TemplateControllerTest { + + private val log = LoggerFactory.getLogger(TemplateControllerTest::class.toString()) + + @Autowired + lateinit var webTestClient: WebTestClient + + var resolutionKey = "7cafa9f3-bbc8-49ec-8f25-fcaa6ac3ff08" + val blueprintName = "baseconfiguration" + val blueprintVersion = "1.0.0" + val templatePrefix = "activate" + val payloadDummyTemplateData = "PAYLOAD DATA" + + var requestArguments = "bpName=$blueprintName&bpVersion=$blueprintVersion" + + "&artifactName=$templatePrefix&resolutionKey=$resolutionKey" + + @AfterTest + fun cleanDir() { + deleteDir("target", "blueprints") + } + + @Test + fun `ping return Success`() { + runBlocking { + webTestClient.get().uri("/api/v1/template/ping") + .exchange() + .expectStatus().isOk + .expectBody() + .equals("Success") + } + } + + @Test + fun `store same value and tries to retrieve - duplicate entry execption`() { + runBlocking { + + resolutionKey = "1" + + post(resolutionKey) + post(resolutionKey) + + webTestClient + .get() + .uri("/api/v1/template?$requestArguments") + .exchange() + .expectStatus().is4xxClientError + .expectBody().equals(payloadDummyTemplateData) + } + } + + @Test + fun `get returns requested JSON content-type`() { + runBlocking { + resolutionKey = "2" + post(resolutionKey) + get("json", resolutionKey) + } + } + + @Test + fun `get returns requested XML content-type`() { + runBlocking { + resolutionKey = "3" + post(resolutionKey) + get("xml", resolutionKey) + } + } + + @Test + fun `get returns 400 error if missing arg`() { + runBlocking { + val arguments = "bpBADName=$blueprintName" + + "&bpBADVersion=$blueprintVersion" + + "&artifactName=$templatePrefix" + + "&resolutionKey=$resolutionKey" + + webTestClient.get().uri("/api/v1/template?$arguments") + .exchange() + .expectStatus().isBadRequest + } + } + + @Test + fun `get returns 404 if entry not found`() { + runBlocking { + + webTestClient + .get() + .uri("/api/v1/template?bpName=$blueprintName&bpVersion=$blueprintVersion" + + "&artifactName=$templatePrefix&resolutionKey=bob") + .exchange() + .expectStatus().isNotFound + } + } + + private fun post(resKey: String) { + webTestClient + .post() + .uri("/api/v1/template/$blueprintName/$blueprintVersion/$templatePrefix/$resKey") + .body(BodyInserters.fromObject(payloadDummyTemplateData)) + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .consumeWith { + log.info("Stored result under UUID ${it.responseBody}") + } + } + + private fun get(expectedType: String, resKey: String) { + var requestArguments = "bpName=$blueprintName&bpVersion=$blueprintVersion" + + "&artifactName=$templatePrefix&resolutionKey=$resKey" + + if (expectedType.isNotEmpty()) { + requestArguments = "$requestArguments&format=$expectedType" + webTestClient + .get() + .uri("/api/v1/template?$requestArguments") + .exchange() + .expectStatus().is2xxSuccessful + .expectHeader().contentType(MediaType.valueOf("application/$expectedType")) + .expectBody().equals(payloadDummyTemplateData) + } else { + webTestClient + .get() + .uri("/api/v1/template?$requestArguments") + .exchange() + .expectStatus().is2xxSuccessful + .expectHeader().contentType(MediaType.TEXT_PLAIN) + .expectBody().equals(payloadDummyTemplateData) + } + } +}
\ No newline at end of file |