Introduce FeatureManager to ResourceCommand
[vid.git] / vid-app-common / src / test / java / org / onap / vid / job / command / VfmoduleCommandTest.kt
1 package org.onap.vid.job.command
2
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
18
19 class VfmoduleCommandTest {
20
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;
30
31
32     @InjectMocks lateinit var vfModuleCommand: VfmoduleCommand;
33
34     private val uniqueCustomizationName = "my unique customization name"
35
36     @BeforeMethod
37     fun initMocks() {
38         initMockitoMocks(this)
39     }
40
41     @Test
42     fun `given correlated modelCustomizationName, selectVfms returns the vfm`() {
43         val newestModel = ServiceModel()
44         newestModel.vfModules = someVfModules()
45                 .plus("my vfm" to vfModuleWithCustomizationName())
46
47         val selectedVfm = vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
48
49         assertThat(selectedVfm, samePropertyValuesAs(vfModuleWithCustomizationName()))
50     }
51
52     @Test(
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()
59
60         vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
61     }
62
63     @Test(
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`() {
68
69         val newestModel = ServiceModel()
70         newestModel.vfModules = someVfModules()
71                 .plus("my vfm" to vfModuleWithCustomizationName())
72                 .plus("my vfm2" to vfModuleWithCustomizationName())
73
74         vfModuleCommand.selectVfm(newestModel, modelInfoWithCustomizationName())
75     }
76
77     private fun modelInfoWithCustomizationName(customizationName: String = uniqueCustomizationName) =
78             ModelInfo().also { it.modelCustomizationName = customizationName }
79
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")
83     )
84
85     private fun vfModuleWithCustomizationName(customizationName: String = uniqueCustomizationName) =
86             VfModule().also { it.modelCustomizationName = customizationName }
87
88 }