aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service/src/test/kotlin/org
diff options
context:
space:
mode:
authorVinal <vinal.narendrabhai.patel@ibm.com>2019-01-16 11:09:27 -0500
committerVinal <vinal.narendrabhai.patel@ibm.com>2019-01-24 13:54:09 -0500
commitc7b21d00e7087080b963a3eaabfe597c13582fac (patch)
treec9727aaa2444cecd86ce024714b42acb90fa0c9d /ms/controllerblueprints/modules/service/src/test/kotlin/org
parent8df3192330a6dc770d1ee3e0c68ec918c30aa6ff (diff)
Integration test at API level
Change-Id: I6f15b5693f494e39bf8d135a96730f2379f5e3fd Issue-ID: CCSDK-954 Signed-off-by: Vinal <vinal.narendrabhai.patel@ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/service/src/test/kotlin/org')
-rw-r--r--ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRestTest.kt192
1 files changed, 192 insertions, 0 deletions
diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRestTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRestTest.kt
new file mode 100644
index 00000000..f82aace4
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelRestTest.kt
@@ -0,0 +1,192 @@
+/*
+ * Copyright © 2019 Bell Canada Intellectual Property.
+ *
+ * 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.apps.controllerblueprints.service.controller
+
+import com.google.gson.Gson
+import org.json.JSONException
+import org.json.JSONObject
+import org.junit.After
+import org.junit.Before
+import org.junit.FixMethodOrder
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.MethodSorters
+import org.onap.ccsdk.apps.controllerblueprints.TestApplication
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.core.io.ByteArrayResource
+import org.springframework.http.HttpMethod
+import org.springframework.http.HttpStatus
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringRunner
+import org.springframework.test.web.reactive.server.WebTestClient
+import org.springframework.util.Base64Utils
+import org.springframework.web.reactive.function.BodyInserters
+import java.io.File
+import java.io.IOException
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+import java.nio.file.Paths
+
+/**
+ * BlueprintModelRestTest Purpose: Integration test at API level
+ *
+ * @author Vinal Patel
+ * @version 1.0
+ */
+
+@RunWith(SpringRunner::class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ContextConfiguration(classes = [TestApplication::class])
+@ComponentScan(basePackages = ["org.onap.ccsdk.apps.controllerblueprints"])
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@EnableAutoConfiguration
+class BlueprintModelRestTest {
+
+ companion object {
+
+ private var id: String? = null
+ private var name: String? = null
+ private var version: String? = null
+ private var tag: String? = null
+ private var result: String? = null
+ }
+
+ @Value("\${controllerblueprints.loadBluePrintPaths}")
+ private val loadBluePrintPaths: String? = null
+
+ @Autowired
+ private val webTestClient: WebTestClient? = null
+
+ @Value("\${controllerblueprints.loadBlueprintsExamplesPath}")
+ private val blueprintArchivePath: String? = null
+
+ private val filename = "test.zip"
+ private var blueprintFile: File? = null
+ private var zipBlueprintFile: File? = null
+
+ @Before
+ @Throws(Exception::class)
+ fun setUp() {
+ blueprintFile = File(loadBluePrintPaths+"/baseconfiguration")
+ if (blueprintFile!!.isDirectory) {
+ zipBlueprintFile = File(Paths.get(blueprintArchivePath).resolve(filename).toString())
+ BluePrintArchiveUtils.compress(blueprintFile!!, zipBlueprintFile!!, true)
+ }
+ }
+
+ @After
+ @Throws(Exception::class)
+ fun tearDown() {
+ zipBlueprintFile!!.delete()
+ }
+
+ @Test
+ @Throws(IOException::class, JSONException::class)
+ fun test1_saveBluePrint() {
+ webTestClient(HttpMethod.POST,
+ BodyInserters.fromMultipartData("file", object : ByteArrayResource(Files.readAllBytes(zipBlueprintFile!!.toPath())) {
+ override fun getFilename(): String? {
+ return "test.zip"
+ }
+ }),
+ "/api/v1/blueprint-model",
+ HttpStatus.OK, true)
+ }
+
+ @Test
+ @Throws(JSONException::class)
+ fun test2_getBluePrintByNameAndVersion() {
+ webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/by-name/$name/version/$version", HttpStatus.OK, false)
+ }
+
+
+ @Test
+ @Throws(JSONException::class)
+ fun test3_getBlueprintModel() {
+ webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/$id", HttpStatus.OK, false)
+ }
+
+ @Test
+ @Throws(JSONException::class)
+ fun test4_getAllBlueprintModel() {
+ webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model", HttpStatus.OK, false)
+ }
+
+ @Test
+ @Throws(JSONException::class)
+ fun test5_downloadBluePrint() {
+ webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/$id", HttpStatus.OK, false)
+ }
+
+ @Test
+ fun test6_publishBlueprintModel() {
+ }
+
+ @Test
+ @Throws(JSONException::class)
+ fun test7_searchBlueprintModels() {
+ webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/search/$name", HttpStatus.OK, false)
+ }
+
+ @Test
+ @Throws(JSONException::class)
+ fun test8_downloadBlueprintByNameAndVersion() {
+ webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/by-name/$name/version/$version", HttpStatus.OK, false)
+ }
+
+ @Test
+ fun test9_deleteBluePrint() {
+ //TODO: Use webTestClient function
+ //webTestClient(HttpMethod.DELETE, null, "/api/v1/blueprint-model/" + id, HttpStatus.OK, false);
+ webTestClient!!.delete().uri("/api/v1/blueprint-model/$id")
+ .header("Authorization", "Basic " + Base64Utils
+ .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8)))
+ .exchange()
+ .expectStatus().is2xxSuccessful
+ }
+
+ @Throws(JSONException::class)
+ private fun webTestClient(requestMethod: HttpMethod, body: BodyInserters.MultipartInserter?, uri: String, expectedResponceStatus: HttpStatus, setParam: Boolean) {
+
+ result = String(webTestClient!!.method(requestMethod).uri(uri)
+ .header("Authorization", "Basic " + Base64Utils
+ .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8)))
+ .body(body)
+ .exchange()
+ .expectStatus().isEqualTo(expectedResponceStatus)
+ .expectBody()
+ .returnResult().responseBody!!)
+
+ if (setParam) {
+ val jsonResponse = JSONObject(result)
+ val blueprintModelSearchJSON = jsonResponse.getJSONObject("blueprintModel")
+ val gson = Gson()
+ val blueprintModelSearch = gson.fromJson(blueprintModelSearchJSON.toString(), BlueprintModelSearch::class.java)
+ id = blueprintModelSearch.id
+ name = blueprintModelSearch.artifactName
+ version = blueprintModelSearch.artifactVersion
+ tag = blueprintModelSearch.tags
+ }
+ }
+
+} \ No newline at end of file