Merge "Removed logging of configuration snapshot as it might leak sensitive data...
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / resource-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / resource / api / ResourceControllerTest.kt
index 85ac7bd..dab9652 100644 (file)
@@ -22,26 +22,31 @@ import org.junit.Test
 import org.junit.runner.RunWith
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
 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.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.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-
 
 @RunWith(SpringRunner::class)
 @WebFluxTest
-@ContextConfiguration(classes = [ResourceController::class, ResourceResolutionDBService::class, SecurityProperties::class])
-@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
+@ContextConfiguration(
+    classes = [TestDatabaseConfiguration::class,
+        ResourceController::class, ResourceResolutionDBService::class]
+)
+@ComponentScan(
+    basePackages = ["org.onap.ccsdk.cds.controllerblueprints.core.service",
+        "org.onap.ccsdk.cds.blueprintsprocessor.resource.api",
+        "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution"]
+)
 @TestPropertySource(locations = ["classpath:application-test.properties"])
 class ResourceControllerTest {
 
@@ -88,8 +93,10 @@ class ResourceControllerTest {
                 .consumeWith {
                     val json = String(it.responseBody!!)
                     val typeFactory = JacksonUtils.objectMapper.typeFactory
-                    val list: List<ResourceResolution> = JacksonUtils.objectMapper.readValue(json,
-                        typeFactory.constructCollectionType(List::class.java, ResourceResolution::class.java))
+                    val list: List<ResourceResolution> = JacksonUtils.objectMapper.readValue(
+                        json,
+                        typeFactory.constructCollectionType(List::class.java, ResourceResolution::class.java)
+                    )
                     Assert.assertEquals(2, list.size)
                     assertEqual(ra1, list[0])
                     assertEqual(ra1, list[0])
@@ -119,8 +126,10 @@ class ResourceControllerTest {
                 .consumeWith {
                     val json = String(it.responseBody!!)
                     val typeFactory = JacksonUtils.objectMapper.typeFactory
-                    val list: List<ResourceResolution> = JacksonUtils.objectMapper.readValue(json,
-                        typeFactory.constructCollectionType(List::class.java, ResourceResolution::class.java))
+                    val list: List<ResourceResolution> = JacksonUtils.objectMapper.readValue(
+                        json,
+                        typeFactory.constructCollectionType(List::class.java, ResourceResolution::class.java)
+                    )
                     Assert.assertEquals(2, list.size)
                     assertEqual(ra1, list[0])
                     assertEqual(ra1, list[0])
@@ -128,7 +137,6 @@ class ResourceControllerTest {
         }
     }
 
-
     @Test
     fun getAllFromMissingParamTest() {
         runBlocking {
@@ -140,8 +148,10 @@ class ResourceControllerTest {
                 .expectBody()
                 .consumeWith {
                     val r = JacksonUtils.objectMapper.readValue(it.responseBody, ErrorMessage::class.java)
-                    Assert.assertEquals("Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.",
-                        r.message)
+                    Assert.assertEquals(
+                        "Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.",
+                        r.message
+                    )
                 }
         }
     }
@@ -157,8 +167,10 @@ class ResourceControllerTest {
                 .expectBody()
                 .consumeWith {
                     val r = JacksonUtils.objectMapper.readValue(it.responseBody, ErrorMessage::class.java)
-                    Assert.assertEquals("Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.",
-                        r.message)
+                    Assert.assertEquals(
+                        "Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.",
+                        r.message
+                    )
                 }
         }
     }
@@ -195,15 +207,21 @@ class ResourceControllerTest {
         }
     }
 
-    private suspend fun store(resourceAssignment: ResourceAssignment, resKey: String = "", resId: String = "",
-                              resType: String = "") {
-        resourceResolutionDBService.write(blueprintName,
+    private suspend fun store(
+        resourceAssignment: ResourceAssignment,
+        resKey: String = "",
+        resId: String = "",
+        resType: String = ""
+    ) {
+        resourceResolutionDBService.write(
+            blueprintName,
             blueprintVersion,
             resKey,
             resId,
             resType,
             templatePrefix,
-            resourceAssignment)
+            resourceAssignment
+        )
     }
 
     private fun createRA(prefix: String): ResourceAssignment {
@@ -221,8 +239,10 @@ class ResourceControllerTest {
     }
 
     private fun assertEqual(resourceAssignment: ResourceAssignment, resourceResolution: ResourceResolution) {
-        Assert.assertEquals(JacksonUtils.getValue(resourceAssignment.property?.value!!).toString(),
-            resourceResolution.value)
+        Assert.assertEquals(
+            JacksonUtils.getValue(resourceAssignment.property?.value!!).toString(),
+            resourceResolution.value
+        )
         Assert.assertEquals(resourceAssignment.status, resourceResolution.status)
         Assert.assertEquals(resourceAssignment.dictionarySource, resourceResolution.dictionarySource)
         Assert.assertEquals(resourceAssignment.dictionaryName, resourceResolution.dictionaryName)
@@ -230,6 +250,5 @@ class ResourceControllerTest {
         Assert.assertEquals(resourceAssignment.name, resourceResolution.name)
         Assert.assertEquals(blueprintVersion, resourceResolution.blueprintVersion)
         Assert.assertEquals(blueprintName, resourceResolution.blueprintName)
-
     }
-}
\ No newline at end of file
+}