import com.fasterxml.jackson.databind.node.ObjectNode
import io.mockk.every
import io.mockk.mockk
+import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringRunner
+import java.lang.RuntimeException
import kotlin.test.BeforeTest
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
}
}
+ @Test
+ fun `applyNB should catch exceptions and call recoverNB`() {
+ val exception = RuntimeException("Intentional test exception")
+ every {
+ bluePrintRuntimeService.resolvePropertyAssignments(any(), any(), any())
+ } throws exception
+ every {
+ blueprintContext.nodeTemplateOperationImplementation(any(), any(), any())
+ } returns Implementation().apply {
+ this.lock = LockAssignment().apply { this.key = "testing-lock".asJsonType() }
+ }
+
+ val component: AbstractComponentFunction = spyk(SampleComponent())
+ component.bluePrintRuntimeService = bluePrintRuntimeService
+ component.bluePrintClusterService = blueprintClusterService
+ val input = getMockedInput(bluePrintRuntimeService)
+
+ runBlocking { component.applyNB(input) }
+ verify { runBlocking { component.recoverNB(exception, input) } }
+ }
+
@Test
fun `applyNB - when lock is present use ClusterLock`() {