aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandlerTest.kt34
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt27
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/faulty-input.json15
3 files changed, 69 insertions, 7 deletions
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 d14761cc9..9cbd898dc 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
@@ -38,6 +38,7 @@ 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.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
@@ -71,11 +72,8 @@ class ExecutionServiceHandlerTest {
@Test
fun `test rest upload blueprint`() {
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"))) {
+ part("file", object : ByteArrayResource(Files.readAllBytes(loadTestCbaFile().toPath())) {
override fun getFilename(): String {
return "test-cba.zip"
}
@@ -98,9 +96,7 @@ class ExecutionServiceHandlerTest {
@Test
fun `test rest process`() {
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)
+ blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
val executionServiceInput = JacksonUtils
.readValueFromClassPathFile("execution-input/default-input.json",
@@ -114,4 +110,28 @@ class ExecutionServiceHandlerTest {
.expectStatus().isOk
}
}
+
+ @Test
+ fun `rest resource process should return status code 500 in case of server-side exception`() {
+ runBlocking {
+ blueprintCatalog.saveToDatabase(UUID.randomUUID().toString(), loadTestCbaFile())
+
+ val executionServiceInput = JacksonUtils
+ .readValueFromClassPathFile("execution-input/faulty-input.json",
+ ExecutionServiceInput::class.java)!!
+
+ webTestClient
+ .post()
+ .uri("/api/v1/execution-service/process")
+ .body(BodyInserters.fromObject(executionServiceInput))
+ .exchange()
+ .expectStatus().is5xxServerError
+ }
+ }
+
+ 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/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt
new file mode 100644
index 000000000..07d8ca4e1
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt
@@ -0,0 +1,27 @@
+package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils
+
+import org.junit.Assert.assertEquals
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.springframework.http.HttpStatus
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+class UtilsTest {
+
+ @Test
+ fun `valid Http status codes should be produced for valid parameters`() {
+ val httpStatusCode200 = determineHttpStatusCode(200)
+ assertEquals(HttpStatus.OK, httpStatusCode200)
+
+ val httpStatusCode500 = determineHttpStatusCode(500)
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, httpStatusCode500)
+ }
+
+ @Test
+ fun `Http status code 500 should be produced for any invalid parameter`() {
+ val nonExistentHttpStatusCode = determineHttpStatusCode(999999)
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, nonExistentHttpStatusCode)
+ }
+
+} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/faulty-input.json b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/faulty-input.json
new file mode 100644
index 000000000..999039e11
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/resources/execution-input/faulty-input.json
@@ -0,0 +1,15 @@
+{
+ "commonHeader": {
+ "originatorId": "System",
+ "requestId": "1234",
+ "subRequestId": "1234-12234"
+ },
+ "actionIdentifiers": {
+ "blueprintName": "baseconfiguration",
+ "blueprintVersion": "1.0.0",
+ "actionName": "activate",
+ "mode": "sync"
+ },
+ "payload": {
+ }
+} \ No newline at end of file