1 package org.onap.vid.job.command
3 import org.hamcrest.MatcherAssert.assertThat
4 import org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs
5 import org.mockito.InjectMocks
6 import org.mockito.Mock
7 import org.onap.vid.job.JobAdapter
8 import org.onap.vid.job.JobsBrokerService
9 import org.onap.vid.model.ServiceModel
10 import org.onap.vid.model.VfModule
11 import org.onap.vid.mso.RestMsoImplementation
12 import org.onap.vid.mso.model.ModelInfo
13 import org.onap.vid.services.AsyncInstantiationBusinessLogic
14 import org.onap.vid.testUtils.TestUtils.initMockitoMocks
15 import org.testng.annotations.BeforeMethod
16 import org.testng.annotations.Test
18 class VfmoduleCommandTest {
20 @Mock lateinit var asyncInstantiationBL: AsyncInstantiationBusinessLogic;
21 @Mock lateinit var restMso: RestMsoImplementation;
22 @Mock lateinit var msoRequestBuilder: MsoRequestBuilder;
23 @Mock lateinit var msoResultHandlerService: MsoResultHandlerService;
24 @Mock lateinit var inProgressStatusService: InProgressStatusService;
25 @Mock lateinit var watchChildrenJobsBL: WatchChildrenJobsBL;
26 @Mock lateinit var jobsBrokerService: JobsBrokerService;
27 @Mock lateinit var jobAdapter: JobAdapter;
29 @InjectMocks lateinit var vfModuleCommand: VfmoduleCommand;
31 private val uniqueCustomizationName = "my unique customization name"
35 initMockitoMocks(this)
39 fun `given correlated modelCustomizationName, selectVfms returns the vfm`() {
40 val newestModel = ServiceModel()
41 newestModel.vfModules = someVfModules()
42 .plus("my vfm" to vfModuleWithCustomizationName())
44 val selectedVfm = vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
46 assertThat(selectedVfm, samePropertyValuesAs(vfModuleWithCustomizationName()))
50 expectedExceptions = [IllegalStateException::class],
51 expectedExceptionsMessageRegExp =
52 """Cannot match vfModule for modelCustomizationName "my unique customization name": Collection contains no element matching the predicate.""")
53 fun `given no matching modelCustomizationName, selectVfms throws`() {
54 val newestModel = ServiceModel()
55 newestModel.vfModules = someVfModules()
57 vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
61 expectedExceptions = [IllegalStateException::class],
62 expectedExceptionsMessageRegExp =
63 """Cannot match vfModule for modelCustomizationName "my unique customization name": Collection contains more than one matching element.""")
64 fun `given a few matching modelCustomizationName, selectVfms throws`() {
66 val newestModel = ServiceModel()
67 newestModel.vfModules = someVfModules()
68 .plus("my vfm" to vfModuleWithCustomizationName())
69 .plus("my vfm2" to vfModuleWithCustomizationName())
71 vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
74 private fun modelInfoWithCustomizationName(customizationName: String = uniqueCustomizationName) =
75 ModelInfo().also { it.modelCustomizationName = customizationName }
77 private fun someVfModules(): Map<String, VfModule> = mapOf(
78 "any vfm 1" to vfModuleWithCustomizationName("any customization name 1"),
79 "any vfm 2" to vfModuleWithCustomizationName("any customization name 2")
82 private fun vfModuleWithCustomizationName(customizationName: String = uniqueCustomizationName) =
83 VfModule().also { it.modelCustomizationName = customizationName }