package org.onap.vid.asdc.parser;
+import static java.util.Collections.emptyList;
+import static java.util.Collections.emptyMap;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.vid.model.VidNotions.InstantiationType;
+import static org.onap.vid.model.VidNotions.InstantiationUI;
+import static org.onap.vid.model.VidNotions.ModelCategory;
+import static org.testng.AssertJUnit.assertEquals;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.BiConsumer;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.mockito.InjectMocks;
import org.onap.sdc.toscaparser.api.NodeTemplate;
import org.onap.sdc.toscaparser.api.Property;
import org.onap.sdc.toscaparser.api.elements.Metadata;
-import org.onap.vid.model.*;
+import org.onap.vid.asdc.parser.ToscaParserImpl2.Constants;
+import org.onap.vid.model.CR;
+import org.onap.vid.model.Network;
+import org.onap.vid.model.Node;
+import org.onap.vid.model.Service;
+import org.onap.vid.model.ServiceModel;
+import org.onap.vid.model.VidNotions;
import org.onap.vid.properties.Features;
import org.onap.vid.testUtils.TestUtils;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.togglz.core.manager.FeatureManager;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.*;
-import java.util.function.BiConsumer;
-
-import static java.util.Collections.emptyList;
-import static java.util.Collections.emptyMap;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.is;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.onap.vid.model.VidNotions.*;
-import static org.testng.AssertJUnit.assertEquals;
-
public class VidNotionsBuilderTest {
+ private static final String MACRO_SERVICE_INVARIANT_UUID = "2efab359-cdd4-4da2-9b79-61df990796c2";
+ private static final String NOT_MACRO_SERVICE_INVARIANT_UUID = "5d854f6b-759c-4aa6-b472-7e4bb1c003d4";
+
@InjectMocks
VidNotionsBuilder vidNotionsBuilder;
public void VLNetworkWithPropertyNetworkTechnologyOVS_UIHintIsPositive() {
ISdcCsarHelper csarHelper = mockForNonLegacyInstantiationUI();
- assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS));
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ALaCarte), is(InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS));
assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL));
}
return csarHelper;
}
+ @DataProvider
+ public static Object[][] identifyInvariantFeatureFlagDataProvider() {
+ return new Object[][] {
+ {false, null, InstantiationType.ClientConfig},
+ {false, mock(ServiceModel.class), InstantiationType.ClientConfig},
+ {true, null, InstantiationType.ALaCarte},
+ {true, mock(ServiceModel.class), InstantiationType.ALaCarte},
+ };
+ }
+
+ @Test(dataProvider = "identifyInvariantFeatureFlagDataProvider")
+ public void whenCsarIsEmpty_suggestInstantiationType_byFeatureFlag(
+ boolean isFlagActive, ServiceModel serviceModel, InstantiationType expectedType) {
+ when(featureManagerMock.isActive(Features.FLAG_2002_IDENTIFY_INVARIANT_MACRO_UUID_BY_BACKEND)).thenReturn(isFlagActive);
+ if (serviceModel!=null) {
+ when(serviceModel.getService()).thenReturn(null);
+ }
+ assertEquals(expectedType, vidNotionsBuilder.suggestInstantiationType(serviceModel, null));
+ }
+
+ @DataProvider
+ public static Object[][] noMacroNoAlaCarteDataProvider() {
+ return new Object[][] {
+ {Constants.CLIENT_CONFIG},
+ {"don't know you"},
+ {null},
+ };
+ }
+
+ @Test(dataProvider = "noMacroNoAlaCarteDataProvider")
+ public void givenNoMacroNorALaCarte_when_FLAG_2002_IDENTIFY_INVARIANT_MACRO_UUID_BY_BACKEND_isOff_then_suggestInstantiationType_ClientConfig(String instantiationType) {
+ ServiceModel serviceModel = mockServiceModelInstantiationTypeAndInvariant(MACRO_SERVICE_INVARIANT_UUID, instantiationType);
+ when(featureManagerMock.isActive(Features.FLAG_2002_IDENTIFY_INVARIANT_MACRO_UUID_BY_BACKEND)).thenReturn(false);
+ assertEquals(InstantiationType.ClientConfig , vidNotionsBuilder.suggestInstantiationType(serviceModel, null));
+ }
+
+ @NotNull
+ private ServiceModel mockServiceModelInstantiationTypeAndInvariant(String invariantUUID, String instantiationType) {
+ ServiceModel serviceModel = mock(ServiceModel.class);
+ Service service = mock(Service.class);
+ when(serviceModel.getService()).thenReturn(service);
+ when(service.getInstantiationType()).thenReturn(instantiationType);
+ when(service.getInvariantUuid()).thenReturn(invariantUUID);
+ return serviceModel;
+ }
+
+ @DataProvider
+ public static Object[][] instantiationTypeByInvariantDataProvider() {
+ return new Object[][] {
+ {null, MACRO_SERVICE_INVARIANT_UUID, InstantiationType.Macro},
+ {null, NOT_MACRO_SERVICE_INVARIANT_UUID, InstantiationType.ALaCarte},
+ {Constants.CLIENT_CONFIG, MACRO_SERVICE_INVARIANT_UUID, InstantiationType.Macro},
+ {Constants.BOTH, NOT_MACRO_SERVICE_INVARIANT_UUID, InstantiationType.ALaCarte},
+ };
+ }
+
+ @Test(dataProvider = "instantiationTypeByInvariantDataProvider")
+ public void givenNoMacroNorALaCarte_givenFlagIsOn_suggestInstantiationTypeByInvariant(
+ String givenInstantiationType, String invariantUUID, InstantiationType expectedType
+ ) {
+ when(featureManagerMock.isActive(Features.FLAG_2002_IDENTIFY_INVARIANT_MACRO_UUID_BY_BACKEND)).thenReturn(true);
+ ServiceModel serviceModel = mockServiceModelInstantiationTypeAndInvariant(invariantUUID, givenInstantiationType);
+ assertEquals(expectedType, vidNotionsBuilder.suggestInstantiationType(serviceModel, null));
+ }
+
@DataProvider
public static Object[][] anyAlacarteDataProvider() {
return new Object[][] {
- {"A-La-Carte", InstantiationUI.ANY_ALACARTE_NEW_UI},
- {"Macro", InstantiationUI.LEGACY},
+ {InstantiationType.ALaCarte, InstantiationUI.ANY_ALACARTE_NEW_UI},
+ {InstantiationType.Macro, InstantiationUI.LEGACY},
};
}
@Test(dataProvider = "anyAlacarteDataProvider")
- public void FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI_is_active_UIHintIsPositive(String instantiationType, InstantiationUI expectedInstantiationUI) {
+ public void FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI_is_active_UIHintIsPositive(InstantiationType instantiationType, InstantiationUI expectedInstantiationUI) {
initServiceModelAndscarHelperWithMocks();
+ String instantiationTypeAsString = instantiationType==InstantiationType.ALaCarte ? "A-La-Carte" : "Macro";
+
when(featureManagerMock.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI)).thenReturn(true);
when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
- "instantiationType", instantiationType
+ "instantiationType", instantiationTypeAsString
)));
NodeTemplate nodeTemplate = mock(NodeTemplate.class);
when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
- assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(expectedInstantiationUI));
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, instantiationType), is(expectedInstantiationUI));
}
@Test
when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
- assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ALaCarte), is(InstantiationUI.LEGACY));
assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.OTHER));
}
assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "unexpected_property_name"), is(false));
assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV"), is(true));
- assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ClientConfig), is(InstantiationUI.LEGACY));
}
@Test
initServiceModelAndscarHelperWithRealCsar("/csars/service-fabric-configuration.zip");
assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
assertThat(vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(true));
- assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ClientConfig), is(InstantiationUI.LEGACY));
}
@Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
when(featureManagerMock.isActive(Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
- assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.TRANSPORT_SERVICE : InstantiationUI.LEGACY));
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ClientConfig), is(flagValue ? InstantiationUI.TRANSPORT_SERVICE : InstantiationUI.LEGACY));
assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.Transport));
}
public void withoutMocks_givenZippedToscaFileOfInfraStructureVpn_InstantiationUIIsRight(boolean flagValue) throws SdcToscaParserException, IOException {
initServiceModelAndscarHelperWithRealCsar("/csars/service-Infravpn-csar.zip");
when(featureManagerMock.isActive(Features.FLAG_1908_INFRASTRUCTURE_VPN)).thenReturn(flagValue);
- assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.INFRASTRUCTURE_VPN : InstantiationUI.LEGACY));
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ClientConfig), is(flagValue ? InstantiationUI.INFRASTRUCTURE_VPN : InstantiationUI.LEGACY));
assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.INFRASTRUCTURE_VPN));
}
+ @Test()
+ public void withoutMocks_givenToscaOfPortMirroring_InstantiationUIIsLegacyAndCategoryIsPortMirroring() throws SdcToscaParserException, IOException {
+ initServiceModelAndscarHelperWithRealCsar("/csars/portMirroringService.zip");
+ when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(true);
+ assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel),
+ equalTo(new VidNotions(InstantiationUI.LEGACY, ModelCategory.PORT_MIRRORING, InstantiationUI.LEGACY, InstantiationType.ClientConfig)));
+
+ }
+
+ @Test()
+ public void withoutMocks_givenToscaOfVLanTagging_InstantiationUIIsLegacyAndCategoryIsVlanTagging() throws SdcToscaParserException, IOException {
+ initServiceModelAndscarHelperWithRealCsar("/csars/service-VdorotheaSrv-csar.zip");
+ when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(true);
+ assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel),
+ equalTo(new VidNotions(InstantiationUI.LEGACY, ModelCategory.VLAN_TAGGING, InstantiationUI.LEGACY, InstantiationType.ALaCarte)));
+ }
+
+ @Test
+ public void withoutMocks_givenToscaWithoutTypeAndFlagOn_InstantiationUIisAlacarte()
+ throws SdcToscaParserException, IOException {
+ initServiceModelAndscarHelperWithRealCsar("/csars/service-Vocg1804Svc.zip");
+ when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(true);
+ assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel),
+ equalTo(new VidNotions(
+ InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED,
+ ModelCategory.OTHER,
+ InstantiationUI.LEGACY,
+ InstantiationType.ClientConfig)));
+ }
+
+ @DataProvider
+ public static Object[][] anyAlaCarteDataProvider() {
+ return new Object[][] {
+ {true, InstantiationType.ALaCarte, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED},
+ {false, InstantiationType.ALaCarte, InstantiationUI.LEGACY},
+ {true, InstantiationType.Macro, InstantiationUI.LEGACY},
+ {true, InstantiationType.ClientConfig, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED},
+ {true, null, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED},
+ };
+ }
+
+ @Test(dataProvider = "anyAlaCarteDataProvider")
+ public void testAnyAlaCarteNewUI_byInstantiationTypeAndFeatureFlag(boolean flag, InstantiationType instantiationType, InstantiationUI expected) {
+ initServiceModelAndscarHelperWithMocks();
+ //mockInstantiationType(serviceModel, instantiationType);
+ when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(flag);
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, instantiationType), is(expected));
+ }
+
@Test
public void uuidIsExactly1ffce89fEtc_UIHintIsPositive() {
initServiceModelAndscarHelperWithMocks();
"UUID", "95eb2c44-bff2-4e8b-ad5d-8266870b7717"
)));
when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
- assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de));
+ assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ClientConfig), is(InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de));
}
@Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel), hasProperty("instantiationUI", is(InstantiationUI.LEGACY)));
}
+ private void mockInstantiationType(ServiceModel serviceModel, String instantiationType) {
+ Service mockService = mock(Service.class);
+ when(serviceModel.getService()).thenReturn(mockService);
+ when(mockService.getInstantiationType()).thenReturn(instantiationType);
+ }
+
@DataProvider
public static Object[][] ServiceRoleTypesDataProvider() {
return new Object[][] {
"serviceRole", serviceRole
)));
- assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel), is(expectedViewEditUI));
- }
-
- @DataProvider
- public static Object[][] macroToViewEditDataProvider() {
- return new Object[][] {
- {"macro service + not excluded + needed flags are open", true, false, true, InstantiationUI.MACRO_SERVICE},
- {"not macro service", false, true, true, InstantiationUI.LEGACY},
- {"macro that shall be excluded because it has pnf", true, true, true, InstantiationUI.LEGACY},
- {"macro service + FLAG_1902_NEW_VIEW_EDIT off", true, false, false, InstantiationUI.LEGACY},
- };
- }
-
- @Test(dataProvider="macroToViewEditDataProvider")
- public void whenServiceIsMacro_viewEditIsRight(
- String testDescription,
- boolean isMacro,
- boolean isExcluded,
- boolean isFlag1902NewViewEdit,
- InstantiationUI expectedViewEditUi) {
-
- initServiceModelAndscarHelperWithMocks();
-
- //mock for is Macro
- String instantiationType = isMacro ? ToscaParserImpl2.Constants.MACRO : ToscaParserImpl2.Constants.A_LA_CARTE;
- Service service = mock(Service.class);
- when(serviceModel.getService()).thenReturn(service);
- when(service.getInstantiationType()).thenReturn(instantiationType);
- when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(isFlag1902NewViewEdit);
-
- //mock for isExcluded
- if (isExcluded) {
- when(serviceModel.getPnfs()).thenReturn(ImmutableMap.of("a", mock(Node.class)));
- }
-
- InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel);
- assertEquals(expectedViewEditUi, result);
+ assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ClientConfig), is(expectedViewEditUI));
}
@DataProvider
when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(isFlag1902NewViewEdit);
ServiceModel serviceModel = mock(ServiceModel.class);
- Service service = mock(Service.class);
- when(serviceModel.getService()).thenReturn(service);
- when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.A_LA_CARTE);
+ mockInstantiationType(serviceModel, Constants.A_LA_CARTE);
- InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel);
+ InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ClientConfig);
assertEquals(expectedViewEditUi, result);
}
@Test(dataProvider="toscaParserInstantiationTypeToVidNotion")
public void testSuggestInstantiationTypeWhenInstantiationUiLegacy(String toscaParserInstantiationType, InstantiationType expectedInstantiationType) {
ServiceModel serviceModel = mock(ServiceModel.class);
- Service service = mock(Service.class);
- when(serviceModel.getService()).thenReturn(service);
- when(service.getInstantiationType()).thenReturn(toscaParserInstantiationType);
+ mockInstantiationType(serviceModel, toscaParserInstantiationType);
assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
}
boolean isFeatureOn,
InstantiationType expectedInstantiationType) {
ServiceModel serviceModel = mock(ServiceModel.class);
- Service service = mock(Service.class);
- when(serviceModel.getService()).thenReturn(service);
- when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.A_LA_CARTE);
+ mockInstantiationType(serviceModel, Constants.A_LA_CARTE);
when(featureManagerMock.isActive(featureFlag)).thenReturn(isFeatureOn);
assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, instantiationUI));
}
assertEquals(InstantiationType.Macro, vidNotions.getInstantiationType());
}
- @DataProvider
- public static Object[][] givenCollectionResourceServiceDataProvider() {
- return new Object[][]{
- {false, true, InstantiationUI.LEGACY},
- {true, false, InstantiationUI.LEGACY},
- {true, true, InstantiationUI.SERVICE_WITH_COLLECTION_RESOURCE}
- };
- }
-
- @Test(dataProvider = "givenCollectionResourceServiceDataProvider")
- public void givenCollectionResourceService_whenSuggestViewEdit_thenResultAccordingFeatureFlag(
- boolean crFlag, boolean resumeFlag, VidNotions.InstantiationUI expectedViewEditUi) {
-
- //mock service with CR
- ServiceModel mockServiceModel = mock(ServiceModel.class);
- when(mockServiceModel.getCollectionResources()).thenReturn(ImmutableMap.of("a", mock(CR.class)));
-
- //mock feature flags
- when(featureManagerMock.isActive(Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI)).thenReturn(crFlag);
- when(featureManagerMock.isActive(Features.FLAG_1908_RESUME_MACRO_SERVICE)).thenReturn(resumeFlag);
-
- assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(mock(ISdcCsarHelper.class), mockServiceModel));
- }
-
@Test
public void whenServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(null, ModelCategory.OTHER));
@Test
public void whenInstantiationTypeInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
initServiceModelAndscarHelperWithMocks();
- Service service = mock(Service.class);
- when(serviceModel.getService()).thenReturn(service);
- when(service.getInstantiationType()).thenReturn(null);
+ mockInstantiationType(serviceModel, null);
assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
}
emptyMap() : ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_ROLE, serviceRole)
));
- assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel));
+ assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER, InstantiationType.ALaCarte));
}
private static NodeTemplate mockNodeTemplateChild(boolean withFabricConfiguration) {
public void hasFabricConfiguration(String desc, boolean shouldHaveFabricConfiguration, ISdcCsarHelper csarHelper) {
assertThat(desc, vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(shouldHaveFabricConfiguration));
}
-}
\ No newline at end of file
+
+ @DataProvider
+ public static Object[][] macroTransportDataProvider() {
+ return new Object[][]{
+ {"transport service flag is open", true, true, true, InstantiationUI.LEGACY},
+ {"macro service flag is open", true, false, true, InstantiationUI.MACRO_SERVICE},
+ {"macro service flag is closed", false, true, true, InstantiationUI.LEGACY},
+ {"transport service flag is closed", false, false, true, InstantiationUI.LEGACY},
+ {"not a macro service", true, false, false, InstantiationUI.LEGACY}
+ };
+ }
+
+ @Test (dataProvider = "macroTransportDataProvider")
+ public void viewEditMacroService_transportOrNotTransport(String desc, boolean flagActive, boolean isTransport, boolean isMacro, InstantiationUI expectedViewEditUi) {
+ initServiceModelAndscarHelperWithMocks();
+ Service service = mock(Service.class);
+
+ InstantiationType instantiationType = isMacro ? InstantiationType.Macro : InstantiationType.ALaCarte;
+ when(serviceModel.getService()).thenReturn(service);
+ when(featureManagerMock.isActive(Features.FLAG_1908_MACRO_NOT_TRANSPORT_NEW_VIEW_EDIT)).thenReturn(flagActive);
+ when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(false);
+ when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(isTransport ? ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_TYPE, "TRANSPORT") : emptyMap()
+ ));
+
+ assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER, instantiationType));
+ }
+
+ @DataProvider
+ public static Object[][] invariantUuidToMacroDataProvider() {
+ return new Object[][]{
+ {"117f5f1a-1b47-4ae1-ae04-489c9a7ada28", true},
+ {"117F5f1a-1b47-4AE1-ae04-489C9A7ada28", true},
+ {MACRO_SERVICE_INVARIANT_UUID, true},
+ {"67e09a1f-9e42-4b63-8dee-bc60bae50de1", false},
+ {"67e09A1F-9E42-4b63-8Dee-bc60bae50de1", false},
+ {NOT_MACRO_SERVICE_INVARIANT_UUID, false},
+ {"I'm not a uuid", false},
+ {null, false},
+ };
+ }
+
+ @Test(dataProvider = "invariantUuidToMacroDataProvider")
+ public void testIsMacroByInvariantUuid(String uuid, boolean expectedIsMacro) {
+ assertEquals(expectedIsMacro, vidNotionsBuilder.isMacroByInvariantUuid(uuid));
+ }
+}