Enabling Code Formatter
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / db / ResourceResolutionDBServiceTest.kt
index dcf2e64..fa59876 100644 (file)
@@ -18,6 +18,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
 
 import io.mockk.every
 import io.mockk.mockk
+import io.mockk.slot
 import kotlinx.coroutines.runBlocking
 import org.junit.Before
 import org.junit.Test
@@ -72,13 +73,15 @@ open class ResourceResolutionDBServiceTest {
         val list = listOf(rr1, rr2)
         every {
             resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
-                any(), any(), any(), any(), any())
+                any(), any(), any(), any(), any()
+            )
         } returns list
         runBlocking {
 
             val res =
                 resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
-                    bluePrintRuntimeService, resolutionKey, occurrence, artifactPrefix)
+                    bluePrintRuntimeService, resolutionKey, occurrence, artifactPrefix
+                )
 
             assertEquals(2, res.size)
         }
@@ -88,12 +91,14 @@ open class ResourceResolutionDBServiceTest {
     fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrenceTestException() {
         every {
             resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
-                any(), any(), any(), any(), any())
+                any(), any(), any(), any(), any()
+            )
         } throws EmptyResultDataAccessException(1)
         runBlocking {
             val res =
                 resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
-                    bluePrintRuntimeService, resolutionKey, occurrence, artifactPrefix)
+                    bluePrintRuntimeService, resolutionKey, occurrence, artifactPrefix
+                )
 
             assert(res.isEmpty())
         }
@@ -107,13 +112,15 @@ open class ResourceResolutionDBServiceTest {
         val list = listOf(rr1, rr2)
         every {
             resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
-                any(), any(), any(), any(), any(), any())
+                any(), any(), any(), any(), any(), any()
+            )
         } returns list
         runBlocking {
 
             val res =
                 resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
-                    bluePrintRuntimeService, resourceId, resourceType, occurrence, artifactPrefix)
+                    bluePrintRuntimeService, resourceId, resourceType, occurrence, artifactPrefix
+                )
 
             assertEquals(2, res.size)
         }
@@ -123,12 +130,14 @@ open class ResourceResolutionDBServiceTest {
     fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrenceTestException() {
         every {
             resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
-                any(), any(), any(), any(), any(), any())
+                any(), any(), any(), any(), any(), any()
+            )
         } throws EmptyResultDataAccessException(1)
         runBlocking {
             val res =
                 resourceResolutionDBService.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
-                    bluePrintRuntimeService, resourceId, resourceType, occurrence, artifactPrefix)
+                    bluePrintRuntimeService, resourceId, resourceType, occurrence, artifactPrefix
+                )
 
             assert(res.isEmpty())
         }
@@ -141,12 +150,14 @@ open class ResourceResolutionDBServiceTest {
         rr.value = "testValue"
         every {
             resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(
-                any(), any(), any(), any(), any())
+                any(), any(), any(), any(), any()
+            )
         } returns rr
         runBlocking {
             val res =
                 resourceResolutionDBService.readValue(
-                    blueprintName, blueprintVersion, artifactPrefix, resolutionKey, "bob")
+                    blueprintName, blueprintVersion, artifactPrefix, resolutionKey, "bob"
+                )
 
             assertEquals(rr.name, res.name)
             assertEquals(rr.value, res.value)
@@ -160,12 +171,14 @@ open class ResourceResolutionDBServiceTest {
         val list = listOf(rr1, rr2)
         every {
             resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
-                any(), any(), any(), any())
+                any(), any(), any(), any()
+            )
         } returns list
         runBlocking {
             val res =
                 resourceResolutionDBService.readWithResolutionKey(
-                    blueprintName, blueprintVersion, artifactPrefix, resolutionKey)
+                    blueprintName, blueprintVersion, artifactPrefix, resolutionKey
+                )
             assertEquals(2, res.size)
         }
     }
@@ -177,12 +190,14 @@ open class ResourceResolutionDBServiceTest {
         val list = listOf(rr1, rr2)
         every {
             resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
-                any(), any(), any(), any())
+                any(), any(), any(), any()
+            )
         } returns list
         runBlocking {
             val res =
                 resourceResolutionDBService.readWithResourceIdAndResourceType(
-                    blueprintName, blueprintVersion, resourceId, resourceType)
+                    blueprintName, blueprintVersion, resourceId, resourceType
+                )
             assertEquals(2, res.size)
         }
     }
@@ -203,9 +218,46 @@ open class ResourceResolutionDBServiceTest {
         runBlocking {
             val res =
                 resourceResolutionDBService.write(
-                    props, bluePrintRuntimeService, artifactPrefix, resourceAssignment)
+                    props, bluePrintRuntimeService, artifactPrefix, resourceAssignment
+                )
 
             assertEquals(resourceResolution, res)
         }
     }
-}
\ No newline at end of file
+
+    @Test
+    fun writeWithNullValue() {
+        val slot = slot<ResourceResolution>()
+        val resourceAssignment = ResourceAssignment()
+        resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS
+        resourceAssignment.dictionarySource = "ddSource"
+        resourceAssignment.dictionaryName = "ddName"
+        resourceAssignment.version = 1
+        resourceAssignment.name = "test"
+        every {
+            resourceResolutionRepository.saveAndFlush(capture(slot))
+        } returns ResourceResolution()
+        runBlocking {
+            resourceResolutionDBService.write(
+                props, bluePrintRuntimeService, artifactPrefix, resourceAssignment
+            )
+
+            val res = slot.captured
+
+            assertEquals("", res.value)
+        }
+    }
+
+    @Test
+    fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyTest() {
+        every {
+            resourceResolutionRepository.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(any(), any(), any(), any())
+        } returns Unit
+        runBlocking {
+            val res = resourceResolutionDBService.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+                blueprintName, blueprintVersion, artifactPrefix, resolutionKey
+            )
+            assertEquals(Unit, res)
+        }
+    }
+}