vfmodule tenant and region are dictated by parent VNF values
[vid.git] / vid-app-common / src / test / java / org / onap / vid / job / command / VnfCommandTest.kt
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.job.command
22
23 import net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals
24 import org.hamcrest.MatcherAssert.assertThat
25 import org.hamcrest.core.AllOf.allOf
26 import org.mockito.Answers
27 import org.mockito.InjectMocks
28 import org.mockito.Mock
29 import org.onap.vid.job.JobAdapter
30 import org.onap.vid.job.JobsBrokerService
31 import org.onap.vid.job.command.ResourceCommandTest.FakeResourceCreator
32 import org.onap.vid.job.impl.JobSharedData
33 import org.onap.vid.model.Action
34 import org.onap.vid.mso.RestMsoImplementation
35 import org.onap.vid.properties.Features
36 import org.onap.vid.services.AsyncInstantiationBusinessLogic
37 import org.onap.vid.testUtils.TestUtils
38 import org.onap.vid.testUtils.TestUtils.initMockitoMocks
39 import org.testng.annotations.BeforeMethod
40 import org.testng.annotations.Test
41 import org.togglz.core.manager.FeatureManager
42 import org.mockito.Mockito.`when` as _when
43
44 class VnfCommandTest {
45
46     @Mock lateinit var asyncInstantiationBL: AsyncInstantiationBusinessLogic
47     @Mock lateinit var restMso: RestMsoImplementation
48     @Mock lateinit var msoRequestBuilder: MsoRequestBuilder
49     @Mock lateinit var msoResultHandlerService: MsoResultHandlerService
50     @Mock lateinit var inProgressStatusService:InProgressStatusService
51     @Mock lateinit var watchChildrenJobsBL: WatchChildrenJobsBL
52     @Mock lateinit var jobsBrokerService: JobsBrokerService
53     @Mock lateinit var jobAdapter: JobAdapter
54     @Mock lateinit var featureManager: FeatureManager
55
56     @Mock lateinit var jobSharedData: JobSharedData
57     @Mock(answer = Answers.RETURNS_MOCKS) lateinit var vnfJobRequest: org.onap.vid.model.serviceInstantiation.Vnf
58
59     @InjectMocks lateinit var vnfCommand: VnfCommand;
60
61     @BeforeMethod
62     fun initMocks() {
63         initMockitoMocks(this)
64     }
65
66     @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils::class)
67     fun `childVfModuleWithVnfRegionAndTenant -- given vfmodule -- tenant and region are copied from vnf`(featureToggleOn: Boolean) {
68
69         val vfModule = FakeResourceCreator.createVfModule(Action.Create)
70                         .cloneWith("vfmodule-lcp-cloud-region-id", "vfmodule-tenant-id")
71
72         _when(featureManager.isActive(Features.FLAG_2006_VFMODULE_TAKES_TENANT_AND_REGION_FROM_VNF)).thenReturn(featureToggleOn)
73
74         _when(vnfJobRequest.lcpCloudRegionId).thenReturn("vnf-lcp-cloud-region-id")
75         _when(vnfJobRequest.tenantId).thenReturn("vnf-tenant-id")
76         _when(jobSharedData.request).thenReturn(vnfJobRequest)
77
78         vnfCommand.init(jobSharedData, mapOf())
79
80         val expectedSource = if (featureToggleOn) "vnf" else "vfmodule"
81
82         assertThat(vnfCommand.childVfModuleWithVnfRegionAndTenant(vfModule),
83                 allOf(
84                         jsonPartEquals("lcpCloudRegionId", "${expectedSource}-lcp-cloud-region-id"),
85                         jsonPartEquals("tenantId", "${expectedSource}-tenant-id")
86                 )
87         )
88     }
89
90 }