aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-11-03 19:43:20 +0200
committerIttay Stern <ittay.stern@att.com>2019-11-04 10:24:34 +0200
commit6de0af739f85377cf07f6f0ad8118d63e9e8578c (patch)
tree001ca1879be969855e1945f371d1605951d063da /vid-app-common/src/test
parent46d7ba49211c86e9208d6634461afc6ebac70f8d (diff)
vfModule upgrade: don't fallback on mismatching newest model
Issue-ID: VID-603 Change-Id: I96a0d4ed3a6717a4f1ee7c285dc71e2d7d695302 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/command/VfmoduleCommandTest.kt85
1 files changed, 85 insertions, 0 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/VfmoduleCommandTest.kt b/vid-app-common/src/test/java/org/onap/vid/job/command/VfmoduleCommandTest.kt
new file mode 100644
index 000000000..ea67f2372
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/job/command/VfmoduleCommandTest.kt
@@ -0,0 +1,85 @@
+package org.onap.vid.job.command
+
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs
+import org.mockito.InjectMocks
+import org.mockito.Mock
+import org.onap.vid.job.JobAdapter
+import org.onap.vid.job.JobsBrokerService
+import org.onap.vid.model.ServiceModel
+import org.onap.vid.model.VfModule
+import org.onap.vid.mso.RestMsoImplementation
+import org.onap.vid.mso.model.ModelInfo
+import org.onap.vid.services.AsyncInstantiationBusinessLogic
+import org.onap.vid.testUtils.TestUtils.initMockitoMocks
+import org.testng.annotations.BeforeMethod
+import org.testng.annotations.Test
+
+class VfmoduleCommandTest {
+
+ @Mock lateinit var asyncInstantiationBL: AsyncInstantiationBusinessLogic;
+ @Mock lateinit var restMso: RestMsoImplementation;
+ @Mock lateinit var msoRequestBuilder: MsoRequestBuilder;
+ @Mock lateinit var msoResultHandlerService: MsoResultHandlerService;
+ @Mock lateinit var inProgressStatusService: InProgressStatusService;
+ @Mock lateinit var watchChildrenJobsBL: WatchChildrenJobsBL;
+ @Mock lateinit var jobsBrokerService: JobsBrokerService;
+ @Mock lateinit var jobAdapter: JobAdapter;
+
+ @InjectMocks lateinit var vfModuleCommand: VfmoduleCommand;
+
+ private val uniqueCustomizationName = "my unique customization name"
+
+ @BeforeMethod
+ fun initMocks() {
+ initMockitoMocks(this)
+ }
+
+ @Test
+ fun `given correlated modelCustomizationName, selectVfms returns the vfm`() {
+ val newestModel = ServiceModel()
+ newestModel.vfModules = someVfModules()
+ .plus("my vfm" to vfModuleWithCustomizationName())
+
+ val selectedVfm = vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
+
+ assertThat(selectedVfm, samePropertyValuesAs(vfModuleWithCustomizationName()))
+ }
+
+ @Test(
+ expectedExceptions = [IllegalStateException::class],
+ expectedExceptionsMessageRegExp =
+ """Cannot match vfModule for modelCustomizationName "my unique customization name": Collection contains no element matching the predicate.""")
+ fun `given no matching modelCustomizationName, selectVfms throws`() {
+ val newestModel = ServiceModel()
+ newestModel.vfModules = someVfModules()
+
+ vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
+ }
+
+ @Test(
+ expectedExceptions = [IllegalStateException::class],
+ expectedExceptionsMessageRegExp =
+ """Cannot match vfModule for modelCustomizationName "my unique customization name": Collection contains more than one matching element.""")
+ fun `given a few matching modelCustomizationName, selectVfms throws`() {
+
+ val newestModel = ServiceModel()
+ newestModel.vfModules = someVfModules()
+ .plus("my vfm" to vfModuleWithCustomizationName())
+ .plus("my vfm2" to vfModuleWithCustomizationName())
+
+ vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
+ }
+
+ private fun modelInfoWithCustomizationName(customizationName: String = uniqueCustomizationName) =
+ ModelInfo().also { it.modelCustomizationName = customizationName }
+
+ private fun someVfModules(): Map<String, VfModule> = mapOf(
+ "any vfm 1" to vfModuleWithCustomizationName("any customization name 1"),
+ "any vfm 2" to vfModuleWithCustomizationName("any customization name 2")
+ )
+
+ private fun vfModuleWithCustomizationName(customizationName: String = uniqueCustomizationName) =
+ VfModule().also { it.modelCustomizationName = customizationName }
+
+} \ No newline at end of file