From 34c424689a52614fb414d65899282497fe25b164 Mon Sep 17 00:00:00 2001 From: Serge Simard Date: Thu, 8 Aug 2019 10:55:57 -0400 Subject: Resource Configuration Snapshots Executor and API Issue-ID: CCSDK-1604 Signed-off-by: Serge Simard Change-Id: I349c649e941431b48a309123489d26fb22e0e50a Signed-off-by: Serge Simard --- .../api/ResourceConfigSnapshotControllerTest.kt | 175 +++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt (limited to 'ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin') diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt new file mode 100644 index 000000000..c3f18fcba --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt @@ -0,0 +1,175 @@ +/* + * 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.configs.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.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.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.util.* + +@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 ResourceConfigSnapshotControllerTest { + + private val log = LoggerFactory.getLogger(ResourceConfigSnapshotControllerTest::class.toString()) + + @Autowired + lateinit var webTestClient: WebTestClient + + val resourceId = "fcaa6ac3ff08" + val resourceType = "PNF" + val snapshotData = "PAYLOAD DATA" + + var requestArguments = "resourceId=$resourceId&resourceType=$resourceType" + + @Test + fun `ping return Success`() { + runBlocking { + webTestClient.get().uri("/api/v1/configs/health-check") + .exchange() + .expectStatus().isOk + .expectBody() + .equals("Success") + } + } + + @Test + fun `update configuration is allowed and updates timestamp`() { + runBlocking { + + webTestClient + .post() + .uri("/api/v1/configs/$resourceType/$resourceId/running") + .body(BodyInserters.fromObject(snapshotData)) + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.createdDate") + .value { println(it) } + + webTestClient + .post() + .uri("/api/v1/configs/$resourceType/$resourceId/running") + .body(BodyInserters.fromObject(snapshotData)) + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.createdDate") + .value { println(it)} + } + } + + @Test + fun `get returns requested JSON content-type`() { + runBlocking { + post(resourceType, "22", "RUNNING") + get("json", resourceType,"22", "RUNNING") + } + } + + @Test + fun `get returns requested XML content-type`() { + runBlocking { + post(resourceType, "3", "CANDIDATE") + get("xml", resourceType, "3", "CANDIDATE") + } + } + + @Test + fun `get returns 400 error if missing arg`() { + runBlocking { + val arguments = "artifactName=WRONGARG1&resolutionKey=WRONGARG1" + + webTestClient.get().uri("/api/v1/configs?$arguments") + .exchange() + .expectStatus().isBadRequest + } + } + + @Test + fun `get returns 400 error if wrong Status arg`() { + runBlocking { + val arguments = "resourceId=MISSING&resourceType=PNF&status=TOTALLY_WRONG" + + webTestClient.get().uri("/api/v1/configs?$arguments") + .exchange() + .expectStatus().isBadRequest + } + } + + @Test + fun `get returns 404 if entry not found`() { + runBlocking { + + webTestClient + .get() + .uri("/api/v1/configs?resourceId=MISSING&resourceType=PNF") + .exchange() + .expectStatus().isNotFound + } + } + + private fun post( resourceType: String, resourceId: String, status: String) { + webTestClient + .post() + .uri("/api/v1/configs/$resourceType/$resourceId/$status") + .body(BodyInserters.fromObject(snapshotData)) + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + } + + private fun get(expectedType : String, resourceType: String, resourceId: String, status: String) { + var requestArguments = "resourceId=$resourceId&resourceType=$resourceType&status=$status" + + if (expectedType.isNotEmpty()) { + requestArguments = "$requestArguments&format=$expectedType" + webTestClient + .get() + .uri("/api/v1/configs?$requestArguments") + .exchange() + .expectStatus().is2xxSuccessful + .expectHeader().contentType(MediaType.valueOf("application/$expectedType")) + .expectBody().equals(snapshotData) + } else { + webTestClient + .get() + .uri("/api/v1/configs?$requestArguments") + .exchange() + .expectStatus().is2xxSuccessful + .expectHeader().contentType(MediaType.TEXT_PLAIN) + .expectBody().equals(snapshotData) + } + } +} \ No newline at end of file -- cgit 1.2.3-korg