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
17 import org.togglz.core.manager.FeatureManager
19 class VfmoduleCommandTest {
21 @Mock lateinit var asyncInstantiationBL: AsyncInstantiationBusinessLogic;
22 @Mock lateinit var restMso: RestMsoImplementation;
23 @Mock lateinit var msoRequestBuilder: MsoRequestBuilder;
24 @Mock lateinit var msoResultHandlerService: MsoResultHandlerService;
25 @Mock lateinit var inProgressStatusService: InProgressStatusService;
26 @Mock lateinit var watchChildrenJobsBL: WatchChildrenJobsBL;
27 @Mock lateinit var jobsBrokerService: JobsBrokerService;
28 @Mock lateinit var jobAdapter: JobAdapter;
29 @Mock lateinit var featureManager: FeatureManager;
32 @InjectMocks lateinit var vfModuleCommand: VfmoduleCommand;
34 private val uniqueCustomizationName = "my unique customization name"
38 initMockitoMocks(this)
42 fun `given correlated modelCustomizationName, selectVfms returns the vfm`() {
43 val newestModel = ServiceModel()
44 newestModel.vfModules = someVfModules()
45 .plus("my vfm" to vfModuleWithCustomizationName())
47 val selectedVfm = vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
49 assertThat(selectedVfm, samePropertyValuesAs(vfModuleWithCustomizationName()))
53 expectedExceptions = [IllegalStateException::class],
54 expectedExceptionsMessageRegExp =
55 """Cannot match vfModule for modelCustomizationName "my unique customization name": Collection contains no element matching the predicate.""")
56 fun `given no matching modelCustomizationName, selectVfms throws`() {
57 val newestModel = ServiceModel()
58 newestModel.vfModules = someVfModules()
60 vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
64 expectedExceptions = [IllegalStateException::class],
65 expectedExceptionsMessageRegExp =
66 """Cannot match vfModule for modelCustomizationName "my unique customization name": Collection contains more than one matching element.""")
67 fun `given a few matching modelCustomizationName, selectVfms throws`() {
69 val newestModel = ServiceModel()
70 newestModel.vfModules = someVfModules()
71 .plus("my vfm" to vfModuleWithCustomizationName())
72 .plus("my vfm2" to vfModuleWithCustomizationName())
74 vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
77 private fun modelInfoWithCustomizationName(customizationName: String = uniqueCustomizationName) =
78 ModelInfo().also { it.modelCustomizationName = customizationName }
80 private fun someVfModules(): Map<String, VfModule> = mapOf(
81 "any vfm 1" to vfModuleWithCustomizationName("any customization name 1"),
82 "any vfm 2" to vfModuleWithCustomizationName("any customization name 2")
85 private fun vfModuleWithCustomizationName(customizationName: String = uniqueCustomizationName) =
86 VfModule().also { it.modelCustomizationName = customizationName }