summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
authorAmichai Hemli <amichai.hemli@intl.att.com>2019-11-05 06:53:37 +0000
committerGerrit Code Review <gerrit@onap.org>2019-11-05 06:53:37 +0000
commit1612c8702b6d48c4711bda86c4fa715ea2f1d880 (patch)
tree214b95fe7391bd8cf0bdee7fe0790429c7ce21ad /vid-app-common/src/test
parent5e0e88d7c19479494215af17d23e07b26dd62dbc (diff)
parent6de0af739f85377cf07f6f0ad8118d63e9e8578c (diff)
Merge "vfModule upgrade: don't fallback on mismatching newest model"
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