Optimize spring data JPA UT.
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceResolutionComponentTest.kt
index 39076b4..83dd0ce 100644 (file)
@@ -17,6 +17,8 @@
 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
 
 import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.MissingNode
+import com.fasterxml.jackson.databind.node.NullNode
 import io.mockk.coEvery
 import io.mockk.every
 import io.mockk.mockk
@@ -29,7 +31,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
-import java.lang.RuntimeException
 import kotlin.test.assertEquals
 import kotlin.test.fail
 
@@ -49,7 +50,6 @@ class ResourceResolutionComponentTest {
 
     private val executionRequest = ExecutionServiceInput()
 
-
     @Before
     fun setup() {
 
@@ -70,6 +70,8 @@ class ResourceResolutionComponentTest {
         resourceResolutionComponent.stepName = "step"
         resourceResolutionComponent.interfaceName = "interfaceName"
         resourceResolutionComponent.operationName = "operationName"
+
+        every { bluePrintRuntimeService.setNodeTemplateAttributeValue(any(), any(), any()) } returns Unit
     }
 
     @Test
@@ -78,8 +80,10 @@ class ResourceResolutionComponentTest {
             try {
                 resourceResolutionComponent.processNB(executionRequest)
             } catch (e: BluePrintProcessorException) {
-                assertEquals("Can't proceed with the resolution: either provide resolution-key OR combination of resource-id and resource-type.",
-                    e.message)
+                assertEquals(
+                    "Can't proceed with the resolution: either provide resolution-key OR combination of resource-id and resource-type.",
+                    e.message
+                )
                 return@runBlocking
             }
             fail()
@@ -88,15 +92,17 @@ class ResourceResolutionComponentTest {
 
     @Test
     fun processNBWithResourceIdTestException() {
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = "".asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = NullNode.getInstance()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = NullNode.getInstance()
 
         runBlocking {
             try {
                 resourceResolutionComponent.processNB(executionRequest)
             } catch (e: BluePrintProcessorException) {
-                assertEquals("Can't proceed with the resolution: both resource-id and resource-type should be provided, one of them is missing.",
-                    e.message)
+                assertEquals(
+                    "Can't proceed with the resolution: both resource-id and resource-type should be provided, one of them is missing.",
+                    e.message
+                )
                 return@runBlocking
             }
             fail()
@@ -105,17 +111,19 @@ class ResourceResolutionComponentTest {
 
     @Test
     fun processNBWithEmptyResourceTypeResourceIdResolutionKeyTestException() {
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = "".asJsonPrimitive()
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = "".asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = MissingNode.getInstance()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = NullNode.getInstance()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = NullNode.getInstance()
 
         runBlocking {
             try {
                 resourceResolutionComponent.processNB(executionRequest)
             } catch (e: BluePrintProcessorException) {
-                assertEquals("Can't proceed with the resolution: can't persist resolution without a correlation key. " +
+                assertEquals(
+                    "Can't proceed with the resolution: can't persist resolution without a correlation key. " +
                         "Either provide a resolution-key OR combination of resource-id and resource-type OR set `storeResult` to false.",
-                    e.message)
+                    e.message
+                )
                 return@runBlocking
             }
             fail()
@@ -124,7 +132,7 @@ class ResourceResolutionComponentTest {
 
     @Test
     fun processNBTest() {
-        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = "".asJsonPrimitive()
+        props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = NullNode.getInstance()
 
         val properties = mutableMapOf<String, Any>()
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true
@@ -133,23 +141,23 @@ class ResourceResolutionComponentTest {
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
 
         coEvery {
-            resourceResolutionService.resolveResources(any<BluePrintRuntimeService<*>>(),
-                any<String>(),
+            resourceResolutionService.resolveResources(
+                any(),
+                any(),
                 any<List<String>>(),
-                any<MutableMap<String, Any>>())
+                any<MutableMap<String, Any>>()
+            )
         } returns mutableMapOf()
-        every { bluePrintRuntimeService.setNodeTemplateAttributeValue(any(), any(), any()) } returns Unit
-
 
         runBlocking {
             resourceResolutionComponent.processNB(executionRequest)
         }
 
-// FIXME add verification
-//        coVerify {
-//            resourceResolutionService.resolveResources(eq(bluePrintRuntimeService),
-//                eq(nodeTemplateName), eq(artifactNames), eq(properties))
-//        }
+        // FIXME add verification
+        //        coVerify {
+        //            resourceResolutionService.resolveResources(eq(bluePrintRuntimeService),
+        //                eq(nodeTemplateName), eq(artifactNames), eq(properties))
+        //        }
     }
 
     @Test
@@ -163,4 +171,4 @@ class ResourceResolutionComponentTest {
             assertEquals(1, blueprintError.errors.size)
         }
     }
-}
\ No newline at end of file
+}