diff options
author | Eylon Malin <eylon.malin@intl.att.com> | 2020-02-16 15:17:29 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-02-16 15:17:29 +0000 |
commit | e0158e29648f7cc75d060b9b5ca0b90868da5d77 (patch) | |
tree | 36b4740d53885cb186e2b3c81e4ab5782c7bf126 | |
parent | 1ce256f06ca424fb3f81847da78547d1cb22e1a8 (diff) | |
parent | fa2918d945c6fad84055caca8912d2efe242ed6f (diff) |
Merge "Limit vfmodule tenant and region dictation to "create""
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt | 7 | ||||
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt | 19 |
2 files changed, 22 insertions, 4 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt index b008c1306..cada6055d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt @@ -12,7 +12,6 @@ import org.onap.vid.model.serviceInstantiation.Vnf import org.onap.vid.mso.RestMsoImplementation import org.onap.vid.properties.Features import org.onap.vid.services.AsyncInstantiationBusinessLogic -import org.onap.vid.utils.isNotActive import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope @@ -77,7 +76,7 @@ class VnfCommand @Autowired constructor( .map { childVfModuleWithVnfRegionAndTenant(it) } internal fun childVfModuleWithVnfRegionAndTenant(vfModule: VfModule): VfModule { - if (featureManager.isNotActive(Features.FLAG_2006_VFMODULE_TAKES_TENANT_AND_REGION_FROM_VNF)) { + if (!shouldEntailRegionAndTenantToVfModule(vfModule)) { return vfModule } @@ -86,6 +85,10 @@ class VnfCommand @Autowired constructor( return vfModule.cloneWith(vnfLcpCloudRegionId, vnfTenantId) } + private fun shouldEntailRegionAndTenantToVfModule(vfModule: VfModule) = + vfModule.action == Action.Create + && featureManager.isActive(Features.FLAG_2006_VFMODULE_TAKES_TENANT_AND_REGION_FROM_VNF) + private fun filterModuleByNeedToCreateBase(vfModule: VfModule): Boolean { return needToCreateBaseModule == commandUtils.isVfModuleBaseModule( diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt b/vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt index 660abe4d2..977966271 100644 --- a/vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt +++ b/vid-app-common/src/test/java/org/onap/vid/job/command/VnfCommandTest.kt @@ -37,6 +37,7 @@ import org.onap.vid.services.AsyncInstantiationBusinessLogic import org.onap.vid.testUtils.TestUtils import org.onap.vid.testUtils.TestUtils.initMockitoMocks import org.testng.annotations.BeforeMethod +import org.testng.annotations.DataProvider import org.testng.annotations.Test import org.togglz.core.manager.FeatureManager import org.mockito.Mockito.`when` as _when @@ -65,8 +66,22 @@ class VnfCommandTest { @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils::class) fun `childVfModuleWithVnfRegionAndTenant -- given vfmodule -- tenant and region are copied from vnf`(featureToggleOn: Boolean) { + runChildVfModuleWithVnfRegionAndTenant(featureToggleOn, Action.Create, featureToggleOn) + } + + @DataProvider + fun allPossibleActions(): Array<Array<out Any?>> { + return Action.values().map { arrayOf(it) }.toTypedArray() + } + + @Test(dataProvider = "allPossibleActions") + fun `childVfModuleWithVnfRegionAndTenant -- given vfmodule in different actions -- only "action_Create" copies tenant and region from vnf`(vfModuleAction: Action) { + runChildVfModuleWithVnfRegionAndTenant(true, vfModuleAction, vfModuleAction == Action.Create) + } + + private fun runChildVfModuleWithVnfRegionAndTenant(featureToggleOn: Boolean, vfModuleAction: Action, isCopyVnfToVfmoduleExpected: Boolean) { - val vfModule = FakeResourceCreator.createVfModule(Action.Create) + val vfModule = FakeResourceCreator.createVfModule(vfModuleAction) .cloneWith("vfmodule-lcp-cloud-region-id", "vfmodule-tenant-id") _when(featureManager.isActive(Features.FLAG_2006_VFMODULE_TAKES_TENANT_AND_REGION_FROM_VNF)).thenReturn(featureToggleOn) @@ -77,7 +92,7 @@ class VnfCommandTest { vnfCommand.init(jobSharedData, mapOf()) - val expectedSource = if (featureToggleOn) "vnf" else "vfmodule" + val expectedSource = if (isCopyVnfToVfmoduleExpected) "vnf" else "vfmodule" assertThat(vnfCommand.childVfModuleWithVnfRegionAndTenant(vfModule), allOf( |