aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/job/command/VfmoduleCommandTest.kt
blob: ea67f2372dbfc71c9e0da23ed004ec3c9b1e2815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 }

}