diff options
63 files changed, 1067 insertions, 593 deletions
diff --git a/features.properties.md b/features.properties.md index edf162d74..32b139ace 100644 --- a/features.properties.md +++ b/features.properties.md @@ -180,4 +180,7 @@ * FLAG_1911_INSTANTIATION_ORDER_BUTTON_IN_ASYNC_ALACARTE Let the user set the order of resource instantiation with the button (Move up / Move down) while using drawing board (new view edit) - for a-la-carte instantiation.
\ No newline at end of file + for a-la-carte instantiation. + +* FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI + Any a-la-carte new service deployment will be open in modern UI, besides excluded services : Port mirroring, VLAN Tagging diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java index d35c8df9c..76e911b4e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java @@ -34,6 +34,8 @@ import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.vid.model.ServiceModel; import org.onap.vid.model.VidNotions; +import org.onap.vid.model.VidNotions.InstantiationUI; +import org.onap.vid.model.VidNotions.ModelCategory; import org.onap.vid.properties.Features; import org.togglz.core.manager.FeatureManager; @@ -55,9 +57,9 @@ public class VidNotionsBuilder { VidNotions buildVidNotions(ISdcCsarHelper csarHelper, ServiceModel serviceModel) { VidNotions.ModelCategory modelCategory = suggestModelCategory(csarHelper, serviceModel); return new VidNotions( - suggestInstantiationUI(csarHelper, serviceModel), + suggestInstantiationUI(csarHelper, serviceModel, modelCategory), modelCategory, - suggestViewEditUI(csarHelper, serviceModel), + suggestViewEditUI(csarHelper, serviceModel, modelCategory), suggestInstantiationType(serviceModel, modelCategory)); } @@ -88,10 +90,17 @@ public class VidNotionsBuilder { //UI route a-la-carte services to old UI only if InstantiationUI is LEGACY //So any other value for InstantiationUI other than LEGACY make UI to route //a-la-carte services to new UI - VidNotions.InstantiationUI suggestInstantiationUI(ISdcCsarHelper csarHelper, ServiceModel serviceModel) { + VidNotions.InstantiationUI suggestInstantiationUI(ISdcCsarHelper csarHelper, ServiceModel serviceModel, ModelCategory modelCategory) { if(featureManager.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI) && isALaCarte(csarHelper)) { return VidNotions.InstantiationUI.ANY_ALACARTE_NEW_UI; } + + if (featureManager.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI) && + !isMacro(serviceModel) && + !isAlacarteExcludedByCategory(modelCategory)) { + return InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED; + } + if (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && isGrouping(csarHelper)) { return VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING; } @@ -115,6 +124,10 @@ public class VidNotionsBuilder { } + private boolean isAlacarteExcludedByCategory(ModelCategory modelCategory) { + return modelCategory==ModelCategory.PORT_MIRRORING || modelCategory==ModelCategory.VLAN_TAGGING ; + } + private boolean isVnfServiceRole(ISdcCsarHelper csarHelper) { final String serviceRole = csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.SERVICE_ROLE ); return StringUtils.equalsIgnoreCase("VNF" , serviceRole); @@ -153,6 +166,12 @@ public class VidNotionsBuilder { if(isALaCarte(csarHelper) && hasFabricConfiguration(csarHelper)) { return VidNotions.ModelCategory.IS_5G_FABRIC_CONFIGURATION_MODEL; } + if (isPortMirroringService(serviceModel)) { + return ModelCategory.PORT_MIRRORING; + } + if (isVlanTaggingService(serviceModel)) { + return ModelCategory.VLAN_TAGGING; + } if (isInfraStructureVpn(csarHelper)) { return VidNotions.ModelCategory.INFRASTRUCTURE_VPN; } @@ -165,7 +184,7 @@ public class VidNotionsBuilder { return VidNotions.ModelCategory.OTHER; } - VidNotions.InstantiationUI suggestViewEditUI(ISdcCsarHelper csarHelper, ServiceModel serviceModel) { + VidNotions.InstantiationUI suggestViewEditUI(ISdcCsarHelper csarHelper, ServiceModel serviceModel, ModelCategory modelCategory) { if (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && isGrouping(csarHelper)) { return VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING; } @@ -179,7 +198,7 @@ public class VidNotionsBuilder { } if (featureManager.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)) { - VidNotions.InstantiationUI instantiationUISuggestion = suggestInstantiationUI(csarHelper, serviceModel); + VidNotions.InstantiationUI instantiationUISuggestion = suggestInstantiationUI(csarHelper, serviceModel, modelCategory); if (instantiationUISuggestion!=VidNotions.InstantiationUI.LEGACY) { return instantiationUISuggestion; } @@ -232,4 +251,20 @@ public class VidNotionsBuilder { final String serviceRole = csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.SERVICE_ROLE); return StringUtils.equalsIgnoreCase(serviceRole, ToscaParserImpl2.Constants.GROUPING); } + + private boolean isPortMirroringService(ServiceModel serviceModel) { + return (serviceModel.getService()!=null && + StringUtils.equals(serviceModel.getService().getServiceType(), "PORT-MIRROR")); + } + + private boolean isVlanTaggingService(ServiceModel serviceModel) { + if (serviceModel==null || serviceModel.getVnfs()==null) { + return false; + } + + return serviceModel.getVnfs().values().stream().anyMatch( + vnf-> MapUtils.isNotEmpty(vnf.getVfcInstanceGroups()) + ); + + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java index 096dba39f..c50578e82 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java @@ -58,7 +58,6 @@ import org.onap.vid.properties.VidProperties; import org.onap.vid.scheduler.SchedulerService; import org.onap.vid.scheduler.SchedulerServiceImpl; import org.onap.vid.services.AAIServiceTree; -import org.onap.vid.services.AAITreeNodeBuilder; import org.onap.vid.services.AaiService; import org.onap.vid.services.AaiServiceImpl; import org.onap.vid.services.ChangeManagementService; @@ -101,8 +100,8 @@ public class WebConfig implements WebMvcConfigurer { @Bean public AaiService getAaiService(AaiClientInterface aaiClient, AaiResponseTranslator aaiResponseTranslator, - AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) { - return new AaiServiceImpl(aaiClient, aaiResponseTranslator, aaiServiceTree, executorService); + AAIServiceTree aaiServiceTree, Logging logging, ExecutorService executorService) { + return new AaiServiceImpl(aaiClient, aaiResponseTranslator, aaiServiceTree, executorService, logging); } @Bean diff --git a/vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt b/vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt index f67d8fbd9..c6de51c1a 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt +++ b/vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt @@ -25,7 +25,7 @@ import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import com.google.common.base.CaseFormat -class VidNotions(@get:JsonInclude(JsonInclude.Include.NON_NULL) +data class VidNotions(@get:JsonInclude(JsonInclude.Include.NON_NULL) val instantiationUI: InstantiationUI, val modelCategory: ModelCategory, val viewEditUI: InstantiationUI, @@ -41,7 +41,8 @@ class VidNotions(@get:JsonInclude(JsonInclude.Include.NON_NULL) TRANSPORT_SERVICE, SERVICE_WITH_COLLECTION_RESOURCE, A_LA_CARTE_VNF_SERVICE_ROLE, - INFRASTRUCTURE_VPN + INFRASTRUCTURE_VPN, + ANY_ALACARTE_WHICH_NOT_EXCLUDED, ; @JsonValue @@ -59,6 +60,8 @@ class VidNotions(@get:JsonInclude(JsonInclude.Include.NON_NULL) Transport, SERVICE_WITH_COLLECTION_RESOURCE, INFRASTRUCTURE_VPN, + PORT_MIRRORING, + VLAN_TAGGING, @JsonProperty("other") OTHER } diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java index abee30025..649a2ff87 100644 --- a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java +++ b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java @@ -80,7 +80,8 @@ public enum Features implements Feature { FLAG_FLASH_MORE_ACTIONS_BUTTON_IN_OLD_VIEW_EDIT, FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH, FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE, - FLAG_1911_INSTANTIATION_ORDER_BUTTON_IN_ASYNC_ALACARTE + FLAG_1911_INSTANTIATION_ORDER_BUTTON_IN_ASYNC_ALACARTE, + FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI, ; diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java index c8434609e..209f37025 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java @@ -59,6 +59,7 @@ import org.onap.vid.model.aaiTree.FailureAAITreeNode; import org.onap.vid.model.aaiTree.NodeType; import org.onap.vid.mso.model.CloudConfiguration; import org.onap.vid.properties.VidProperties; +import org.onap.vid.utils.Logging; import org.onap.vid.utils.Streams; import org.onap.vid.utils.Tree; import org.onap.vid.utils.Unchecked; @@ -71,7 +72,8 @@ import org.springframework.stereotype.Component; public class AAITreeNodeBuilder { private static final String RESULTS = "results"; - private AaiClientInterface aaiClient; + private final AaiClientInterface aaiClient; + private final Logging logging; private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AAITreeNodeBuilder.class); @@ -97,8 +99,9 @@ public class AAITreeNodeBuilder { } @Inject - public AAITreeNodeBuilder(AaiClientInterface aaiClient) { + public AAITreeNodeBuilder(AaiClientInterface aaiClient, Logging logging) { this.aaiClient = aaiClient; + this.logging = logging; } List<AAITreeNode> buildNode(NodeType nodeType, @@ -296,13 +299,7 @@ public class AAITreeNodeBuilder { } private <V> Callable<V> withCopyOfMDC(Callable<V> callable) { - //in order to be able to write the correct data while creating the node on a new thread - // save a copy of the current thread's context map, with keys and values of type String. - final Map<String, String> copyOfParentMDC = MDC.getCopyOfContextMap(); - return () -> { - MDC.setContextMap(copyOfParentMDC); - return callable.call(); - }; + return logging.withMDC(MDC.getCopyOfContextMap(), callable); } private List<AAITreeNode> getChildNode(ExecutorService threadPool, ConcurrentSkipListSet<AAITreeNode> nodesAccumulator, diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index b64a233c7..b3ac16884 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -87,7 +87,9 @@ import org.onap.vid.model.aaiTree.VpnBinding; import org.onap.vid.model.aaiTree.VpnBindingKt; import org.onap.vid.roles.RoleValidator; import org.onap.vid.utils.Intersection; +import org.onap.vid.utils.Logging; import org.onap.vid.utils.Tree; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; @@ -104,6 +106,7 @@ public class AaiServiceImpl implements AaiService { private AaiResponseTranslator aaiResponseTranslator; private AAIServiceTree aaiServiceTree; private ExecutorService executorService; + private final Logging logging; private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiServiceImpl.class); @@ -113,12 +116,13 @@ public class AaiServiceImpl implements AaiService { AaiClientInterface aaiClient, AaiResponseTranslator aaiResponseTranslator, AAIServiceTree aaiServiceTree, - ExecutorService executorService) + ExecutorService executorService, Logging logging) { this.aaiClient = aaiClient; this.aaiResponseTranslator = aaiResponseTranslator; this.aaiServiceTree = aaiServiceTree; this.executorService = executorService; + this.logging = logging; } private List<Service> convertModelToService(Model model) { @@ -523,10 +527,12 @@ public class AaiServiceImpl implements AaiService { .map(RelatedVnf::from) .collect(Collectors.toList()); + final Map<String, String> copyOfParentMDC = MDC.getCopyOfContextMap(); + try { return executorService.submit(() -> convertedVnfs.parallelStream() - .map(this::enrichRelatedVnfWithCloudRegionAndTenant) + .map(logging.withMDC(copyOfParentMDC, this::enrichRelatedVnfWithCloudRegionAndTenant)) .collect(Collectors.toList()) ).get(); } catch (Exception e) { diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java index 0d8e58878..43f059d54 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java @@ -33,8 +33,11 @@ import com.google.common.collect.ImmutableList; import io.joshworks.restclient.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.Map; import java.util.Optional; import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.function.Function; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import org.apache.commons.io.IOUtils; @@ -42,6 +45,8 @@ import org.apache.commons.lang3.StringUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.utils.Unchecked.UncheckedThrowingSupplier; +import org.slf4j.MDC; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; import org.springframework.web.context.request.RequestContextHolder; @@ -197,5 +202,29 @@ public class Logging { } } + /** + * in order to be able to write the correct data while creating the node on a new thread save a copy of the current + * thread's context map, with keys and values of type String. + */ + public <T> Callable<T> withMDC(Map<String, String> copyOfParentMDC, Callable<T> callable) { + return () -> withMDCInternal(copyOfParentMDC, callable::call); + } + + /** + * in order to be able to write the correct data while creating the node on a new thread save a copy of the current + * thread's context map, with keys and values of type String. + */ + public <T, U> Function<T, U> withMDC(Map<String, String> copyOfParentMDC, Function<T, U> function) { + return t -> withMDCInternal(copyOfParentMDC, () -> function.apply(t)); + } + + <T> T withMDCInternal(Map<String, String> copyOfParentMDC, UncheckedThrowingSupplier<T> supplier) { + try { + MDC.setContextMap(copyOfParentMDC); + return supplier.get(); + } finally { + MDC.clear(); + } + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java b/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java index 23127b61a..9fb15f690 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java @@ -20,10 +20,11 @@ package org.onap.vid.utils; -import org.onap.vid.exceptions.GenericUncheckedException; - import java.net.URI; import java.net.URISyntaxException; +import java.util.function.Supplier; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.onap.vid.exceptions.GenericUncheckedException; public class Unchecked { private Unchecked() { @@ -39,5 +40,19 @@ public class Unchecked { } } + @FunctionalInterface + public interface UncheckedThrowingSupplier<T> extends Supplier<T> { + + @Override + default T get() { + try { + return getThrows(); + } catch (Exception e) { + return ExceptionUtils.rethrow(e); + } + } + + T getThrows() throws Exception; + } } diff --git a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties index 0815accbb..7152d91d7 100644 --- a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties +++ b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties @@ -38,3 +38,4 @@ FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG = false FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE = false FLAG_SHOW_ORCHESTRATION_TYPE = false FLAG_1911_INSTANTIATION_ORDER_BUTTON_IN_ASYNC_ALACARTE = false +FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI = false diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java index edf7d0862..c136f36e4 100644 --- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java @@ -23,6 +23,7 @@ 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; @@ -56,6 +57,7 @@ import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; 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.asdc.parser.ToscaParserImpl2.Constants; import org.onap.vid.model.CR; import org.onap.vid.model.Network; import org.onap.vid.model.Node; @@ -96,7 +98,7 @@ public class VidNotionsBuilderTest { 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), is(InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS)); assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL)); } @@ -141,7 +143,7 @@ public class VidNotionsBuilderTest { when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate)); - assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(expectedInstantiationUI)); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(expectedInstantiationUI)); } @Test @@ -157,7 +159,7 @@ public class VidNotionsBuilderTest { when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate)); - assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY)); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(InstantiationUI.LEGACY)); assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.OTHER)); } @@ -167,7 +169,7 @@ public class VidNotionsBuilderTest { 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), is(InstantiationUI.LEGACY)); } @Test @@ -175,7 +177,7 @@ public class VidNotionsBuilderTest { 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), is(InstantiationUI.LEGACY)); } @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class) @@ -185,7 +187,7 @@ public class VidNotionsBuilderTest { 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), is(flagValue ? InstantiationUI.TRANSPORT_SERVICE : InstantiationUI.LEGACY)); assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.Transport)); } @@ -193,10 +195,60 @@ public class VidNotionsBuilderTest { 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), 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, Constants.A_LA_CARTE, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED}, + {false, Constants.A_LA_CARTE, InstantiationUI.LEGACY}, + {true, Constants.MACRO, InstantiationUI.LEGACY}, + {true, Constants.CLIENT_CONFIG, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED}, + {true, null, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED}, + {true, "", InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED} + }; + } + + @Test(dataProvider = "anyAlaCarteDataProvider") + public void testAnyAlaCarteNewUI_byInstantiationTypeAndFeatureFlag(boolean flag, String 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), is(expected)); + } + @Test public void uuidIsExactly1ffce89fEtc_UIHintIsPositive() { initServiceModelAndscarHelperWithMocks(); @@ -205,7 +257,7 @@ public class VidNotionsBuilderTest { "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), is(InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de)); } @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class) @@ -216,6 +268,12 @@ public class VidNotionsBuilderTest { 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[][] { @@ -232,7 +290,7 @@ public class VidNotionsBuilderTest { "serviceRole", serviceRole ))); - assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel), is(expectedViewEditUI)); + assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER), is(expectedViewEditUI)); } @DataProvider @@ -256,11 +314,9 @@ public class VidNotionsBuilderTest { 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); assertEquals(expectedViewEditUi, result); } @@ -302,9 +358,7 @@ public class VidNotionsBuilderTest { @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)); } @@ -326,9 +380,7 @@ public class VidNotionsBuilderTest { 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)); } @@ -378,9 +430,7 @@ public class VidNotionsBuilderTest { @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)); } @@ -420,7 +470,7 @@ public class VidNotionsBuilderTest { emptyMap() : ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_ROLE, serviceRole) )); - assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel)); + assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER)); } private static NodeTemplate mockNodeTemplateChild(boolean withFabricConfiguration) { @@ -482,6 +532,6 @@ public class VidNotionsBuilderTest { when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(isTransport ? ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_TYPE, "TRANSPORT") : emptyMap() )); - assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel)); + assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER)); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java b/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java index fcc314a3c..681f9d1ab 100644 --- a/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java +++ b/vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java @@ -40,7 +40,6 @@ import org.onap.vid.asdc.AsdcClient; import org.onap.vid.asdc.parser.ToscaParserImpl2; import org.onap.vid.asdc.parser.VidNotionsBuilder; import org.onap.vid.services.AAIServiceTree; -import org.onap.vid.services.AAITreeNodeBuilder; import org.onap.vid.services.AaiService; import org.onap.vid.services.AaiServiceImpl; import org.onap.vid.services.VidService; @@ -72,8 +71,8 @@ public class LocalWebConfig { @Bean public AaiService getAaiService(AaiClientInterface aaiClient, AaiResponseTranslator aaiResponseTranslator, - AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) { - return new AaiServiceImpl(aaiClient, aaiResponseTranslator, aaiServiceTree, executorService); + AAIServiceTree aaiServiceTree, Logging logging, ExecutorService executorService) { + return new AaiServiceImpl(aaiClient, aaiResponseTranslator, aaiServiceTree, executorService, logging); } @Bean diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java index a159efd30..3a05a841b 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java @@ -47,6 +47,7 @@ import org.onap.vid.aai.util.TestWithAaiClient; import org.onap.vid.model.aaiTree.Network; import org.onap.vid.model.aaiTree.VpnBinding; import org.onap.vid.testUtils.TestUtils; +import org.onap.vid.utils.Logging; import org.springframework.http.HttpMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; @@ -56,19 +57,20 @@ public class AAIServiceIntegrativeTest extends TestWithAaiClient { private AAIRestInterface aaiRestInterface; private AaiServiceImpl aaiServiceWithoutMocks; + private Logging logging = new Logging(); private AaiServiceImpl createAaiServiceWithoutMocks(AAIRestInterface aaiRestInterface, CacheProvider cacheProvider) { AaiClient aaiClient = new AaiClient(aaiRestInterface, null, cacheProvider); ExecutorService executorService = MoreExecutors.newDirectExecutorService(); AAIServiceTree aaiServiceTree = new AAIServiceTree( aaiClient, - new AAITreeNodeBuilder(aaiClient), + new AAITreeNodeBuilder(aaiClient, logging), new AAITreeConverter(), null, null, executorService ); - return new AaiServiceImpl(aaiClient, null, aaiServiceTree, executorService); + return new AaiServiceImpl(aaiClient, null, aaiServiceTree, executorService, logging); } @BeforeMethod diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java index a956468f3..d6ee62ce4 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java @@ -37,8 +37,10 @@ import java.io.IOException; import java.net.URI; import java.util.Arrays; import java.util.List; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.function.Function; import javax.ws.rs.core.Response; import org.mockito.Mock; import org.onap.vid.aai.AaiClientInterface; @@ -54,6 +56,7 @@ import org.onap.vid.model.aaiTree.FailureAAITreeNode; import org.onap.vid.model.aaiTree.ServiceInstance; import org.onap.vid.model.aaiTree.Vnf; import org.onap.vid.testUtils.TestUtils; +import org.onap.vid.utils.Logging; import org.springframework.http.HttpMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -75,6 +78,9 @@ public class AAIServiceTreeIntegrativeTest { @Mock ServiceModelInflator serviceModelInflator; + @Mock + Logging logging; + private AAITreeNodeBuilder aaiTreeNodeBuilder; private AAITreeConverter aaiTreeConverter = new AAITreeConverter(); @@ -87,7 +93,6 @@ public class AAIServiceTreeIntegrativeTest { private String serviceType = "vWINIFRED"; private String serviceInstanceId = "62888f15-6d24-4f7b-92a7-c3f35beeb215"; - //TODO Amichai: if in the future it is neede, add here the SUFFIX to the URL: "?format=simple" private String serviceInstanceRequestUri = "business/customers/customer/" + globalCustomerID + "/service-subscriptions/service-subscription/" + @@ -292,7 +297,13 @@ public class AAIServiceTreeIntegrativeTest { @BeforeMethod public void initMocks() { TestUtils.initMockitoMocks(this); - aaiTreeNodeBuilder = new AAITreeNodeBuilder(aaiClient); + reboundLoggingWithMdcMock(); + aaiTreeNodeBuilder = new AAITreeNodeBuilder(aaiClient, logging); + } + + private void reboundLoggingWithMdcMock() { + when(logging.withMDC(any(), any(Callable.class))).thenAnswer(invocation -> invocation.getArgument(1)); + when(logging.withMDC(any(), any(Function.class))).thenAnswer(invocation -> invocation.getArgument(1)); } public void getServiceInstanceTreeAndAssert(boolean isDuplicatedKeysInTenantRelation) throws IOException, AsdcCatalogException { diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java index ada1f857e..7457e480e 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java @@ -55,6 +55,7 @@ import org.onap.vid.model.aaiTree.AAITreeNode; import org.onap.vid.model.aaiTree.NodeType; import org.onap.vid.mso.model.CloudConfiguration; import org.onap.vid.testUtils.TestUtils; +import org.onap.vid.utils.Logging; import org.onap.vid.utils.Unchecked; import org.springframework.http.HttpMethod; import org.testng.annotations.BeforeTest; @@ -199,7 +200,7 @@ public class AAIServiceTreeTest { ExecutorService executorService = MoreExecutors.newDirectExecutorService(); AAIServiceTree aaiServiceTree = new AAIServiceTree( aaiClientMock, - new AAITreeNodeBuilder(aaiClientMock), + new AAITreeNodeBuilder(aaiClientMock, new Logging()), new AAITreeConverter(), null, null, diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodeBuilderTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodeBuilderTest.java index c2a3f5d61..2c954b297 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodeBuilderTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodeBuilderTest.java @@ -20,7 +20,20 @@ package org.onap.vid.services; -import com.fasterxml.jackson.core.JsonProcessingException; +import static java.util.Comparator.comparing; +import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; +import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER; +import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.onap.vid.services.AAIServiceTree.AAI_TREE_PATHS; +import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -28,7 +41,14 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.MoreExecutors; - +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.NotNull; import org.mockito.Mock; @@ -41,37 +61,15 @@ import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.aaiTree.AAITreeNode; import org.onap.vid.model.aaiTree.NodeType; import org.onap.vid.mso.model.CloudConfiguration; +import org.onap.vid.testUtils.TestUtils; +import org.onap.vid.utils.Logging; import org.onap.vid.utils.Tree; import org.onap.vid.utils.Unchecked; -import org.onap.vid.testUtils.TestUtils; import org.springframework.http.HttpMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentSkipListSet; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static java.util.Comparator.comparing; -import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; -import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER; -import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; -import static org.onap.vid.services.AAIServiceTree.AAI_TREE_PATHS; -import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - public class AAITreeNodeBuilderTest { private AAITreeNodeBuilder aaiTreeNodeBuilder; @@ -80,13 +78,14 @@ public class AAITreeNodeBuilderTest { private AaiClientInterface aaiClientMock; private ExecutorService executorService; + private Logging logging = new Logging(); private static final ObjectMapper mapper = new ObjectMapper(); @BeforeClass public void initMocks() { MockitoAnnotations.initMocks(this); - aaiTreeNodeBuilder = new AAITreeNodeBuilder(aaiClientMock); + aaiTreeNodeBuilder = new AAITreeNodeBuilder(aaiClientMock, logging); executorService = MoreExecutors.newDirectExecutorService(); } diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java index 9df99faa6..d3b2a48b1 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java @@ -42,6 +42,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.function.Function; import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.jetbrains.annotations.NotNull; @@ -88,6 +89,7 @@ import org.onap.vid.model.aaiTree.AAITreeNode; import org.onap.vid.model.aaiTree.RelatedVnf; import org.onap.vid.model.aaiTree.ServiceInstance; import org.onap.vid.roles.RoleValidator; +import org.onap.vid.utils.Logging; import org.springframework.http.HttpMethod; @RunWith(MockitoJUnitRunner.class) @@ -131,6 +133,8 @@ public class AaiServiceImplTest { @Mock private AaiResponseTranslator aaiResponseTranslator; @Mock + private Logging logging; + @Mock private AAIServiceTree aaiServiceTree; @Spy private ExecutorService executorService = Executors.newFixedThreadPool(1); @@ -504,6 +508,7 @@ public class AaiServiceImplTest { when(aaiServiceTree.buildAAITree(anyString(), isNull(), eq(HttpMethod.GET), any(), anyBoolean())) .thenReturn(Collections.singletonList(testedTree)); when(aaiClient.getCloudRegionAndTenantByVnfId(anyString())).thenReturn(regionsAndTenants); + when(logging.withMDC(any(), any(Function.class))).thenAnswer(invocation -> invocation.getArgument(1)); List<RelatedVnf> actualGroupMembers = aaiService.searchGroupMembers(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, INVARIANT_ID, GROUP_TYPE_FAILING, GROUP_ROLE_FAILING); diff --git a/vid-app-common/src/test/java/org/onap/vid/utils/LoggingTest.java b/vid-app-common/src/test/java/org/onap/vid/utils/LoggingTest.java deleted file mode 100644 index 87fe36372..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/utils/LoggingTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.utils; - -import com.att.eelf.configuration.EELFLogger; -import org.junit.Test; - -public class LoggingTest { - - @Test - public void testGetMethodName() throws Exception { - String result; - - // default test - result = Logging.getMethodName(); - } - - @Test - public void testGetMethodCallerName() throws Exception { - String result; - - // default test - result = Logging.getMethodCallerName(); - } - - @Test - public void testGetRequestsLogger() throws Exception { - String serverName = ""; - EELFLogger result; - - // default test - result = Logging.getRequestsLogger(serverName); - } - - -} diff --git a/vid-app-common/src/test/java/org/onap/vid/utils/LoggingUtilsTest.java b/vid-app-common/src/test/java/org/onap/vid/utils/LoggingUtilsTest.java index 6cbb14ac2..c2a1f2877 100644 --- a/vid-app-common/src/test/java/org/onap/vid/utils/LoggingUtilsTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/utils/LoggingUtilsTest.java @@ -21,7 +21,11 @@ package org.onap.vid.utils; import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.matchesPattern; import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.mock; @@ -33,12 +37,15 @@ import com.att.eelf.configuration.EELFLogger; import com.fasterxml.jackson.core.JsonLocation; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; +import com.google.common.collect.ImmutableMap; import io.joshworks.restclient.http.HttpResponse; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; +import java.util.concurrent.Callable; +import java.util.function.Function; import javax.crypto.BadPaddingException; import javax.net.ssl.SSLHandshakeException; import javax.ws.rs.ProcessingException; @@ -46,6 +53,7 @@ import org.apache.commons.io.IOUtils; import org.mockito.ArgumentCaptor; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.testUtils.TestUtils; +import org.slf4j.MDC; import org.springframework.http.HttpMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; @@ -196,6 +204,71 @@ public class LoggingUtilsTest { assertThat(Logging.exceptionToDescription(exceptionToDescribe), matchesRegEx(expectedButDotsEscaped)); } + @Test + public void testWithMDCInternal_whenGivenProvider_functionShouldBeExtractedWithMdc() { + Object myAnything = new Object(); + + Object result = logginService.withMDCInternal(ImmutableMap.of("my key", "my value"), + () -> { + assertThat("MDC values should be installed when extracting the supplier", + MDC.getCopyOfContextMap(), hasEntry("my key", "my value")); + return myAnything; + } + ); + + assertThat("withMDCInternal should extract my function", result, is(sameInstance(myAnything))); + assertThat("MDC values should be removed", MDC.getCopyOfContextMap(), not(hasEntry("k", "v"))); + } + + @Test + public void testWithMDC_whenGivenFunction_functionShouldBeEncapsulated() { + // Given + String[] stringsArray = {"before"}; + + Function<String, Integer> myFunction = s -> { + assertThat("MDC values should be installed when inside myFunction", + MDC.getCopyOfContextMap(), hasEntry("my key", "my value")); + stringsArray[0] = s; + return 42; + }; + + // When + Function<String, Integer> functionWithMDC = + logginService.withMDC(ImmutableMap.of("my key", "my value"), myFunction); + + + assertThat("invocation of function must not happen yet", stringsArray[0], is("before")); + + Integer result = functionWithMDC.apply("after"); + + assertThat("invocation of my function should have been deferred", stringsArray[0], is("after")); + assertThat("apply should return function's value", result, is(42)); + } + + @Test + public void testWithMDC_whenGivenCallable_callableShouldBeEncapsulated() throws Exception { + // Given + String[] stringsArray = {"before"}; + + Callable<Integer> myCallable = () -> { + assertThat("MDC values should be installed when inside myCallable", + MDC.getCopyOfContextMap(), hasEntry("my key", "my value")); + stringsArray[0] = "after"; + return 42; + }; + + // When + Callable<Integer> callableWithMDC = logginService.withMDC(ImmutableMap.of("my key", "my value"), myCallable); + + + assertThat("invocation of callable must not happen yet", stringsArray[0], is("before")); + + Integer result = callableWithMDC.call(); + + assertThat("invocation of my callable should have been deferred", stringsArray[0], is("after")); + assertThat("apply should return function's value", result, is(42)); + } + private static String escapeBrackets(String in) { return in.replaceAll("[\\(\\[\\{\\)]", "\\\\$0"); } diff --git a/vid-app-common/src/test/resources/csars/portMirroringService.zip b/vid-app-common/src/test/resources/csars/portMirroringService.zip Binary files differnew file mode 100644 index 000000000..c074f31bd --- /dev/null +++ b/vid-app-common/src/test/resources/csars/portMirroringService.zip diff --git a/vid-app-common/src/test/resources/csars/service-Vocg1804Svc.zip b/vid-app-common/src/test/resources/csars/service-Vocg1804Svc.zip Binary files differnew file mode 100644 index 000000000..8902c5149 --- /dev/null +++ b/vid-app-common/src/test/resources/csars/service-Vocg1804Svc.zip diff --git a/vid-automation/src/main/java/org/onap/sdc/ci/tests/execute/setup/SetupCDTest.java b/vid-automation/src/main/java/org/onap/sdc/ci/tests/execute/setup/SetupCDTest.java index bb6a19a36..b3be16a42 100644 --- a/vid-automation/src/main/java/org/onap/sdc/ci/tests/execute/setup/SetupCDTest.java +++ b/vid-automation/src/main/java/org/onap/sdc/ci/tests/execute/setup/SetupCDTest.java @@ -20,10 +20,12 @@ package org.onap.sdc.ci.tests.execute.setup; +import com.aventstack.extentreports.ExtentTest; +import com.aventstack.extentreports.Status; import java.io.File; import java.io.IOException; import java.util.UUID; - +import net.lightbody.bmp.core.har.Har; import org.onap.sdc.ci.tests.datatypes.Configuration; import org.onap.sdc.ci.tests.datatypes.User; import org.onap.sdc.ci.tests.datatypes.UserCredentials; @@ -44,11 +46,6 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - -import net.lightbody.bmp.core.har.Har; - public abstract class SetupCDTest extends DriverFactory { private static final String RE_RUN = "<html><font color=\"red\">ReRun - </font></html>"; @@ -172,7 +169,7 @@ public abstract class SetupCDTest extends DriverFactory { return url; } - public static void navigateToUrl(String url) throws Exception { + public static void navigateToUrl(String url) { try { System.out.println("Deleting cookies..."); deleteCookies(); @@ -282,7 +279,7 @@ public abstract class SetupCDTest extends DriverFactory { } } - public void navigateAndLogin(UserCredentials userCredentials) throws Exception { + public void navigateAndLogin(UserCredentials userCredentials) { int refreshAttempts = getWindowTest().getRefreshAttempts() != 0 ? getWindowTest().getRefreshAttempts() : 0; setRefreshAttempts(refreshAttempts); setUser(userCredentials); @@ -300,7 +297,7 @@ public abstract class SetupCDTest extends DriverFactory { return user; } - protected void reloginWithNewRole(UserCredentials userCredentials) throws Exception { + protected void reloginWithNewRole(UserCredentials userCredentials) { System.out.println(String.format("Setup before relogin with the userId %s", userCredentials.getUserId())); navigateAndLogin(userCredentials); } @@ -353,4 +350,4 @@ public abstract class SetupCDTest extends DriverFactory { StartTest.main(testSuiteArr); } -}
\ No newline at end of file +} diff --git a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/aaf/AAFGetUrlServicePreset.java b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/aaf/AAFGetUrlServicePreset.java index b3376e61a..c3914660e 100644 --- a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/aaf/AAFGetUrlServicePreset.java +++ b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/aaf/AAFGetUrlServicePreset.java @@ -2,6 +2,7 @@ package org.onap.simulator.presetGenerator.presets.aaf; import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset; import org.springframework.http.HttpMethod; +import vid.automation.test.services.SimulatorApi; public class AAFGetUrlServicePreset extends BasePreset { @Override @@ -11,7 +12,11 @@ public class AAFGetUrlServicePreset extends BasePreset { @Override public String getReqPath() { - return "/locate/com.att.aaf.service:2.0"; + return "/locate/" + regexAafServerName() + ":2.0"; + } + + private String regexAafServerName() { + return "([a-z-]+\\.)*[a-z-]+"; } @Override @@ -21,6 +26,22 @@ public class AAFGetUrlServicePreset extends BasePreset { @Override public Object getResponseBody() { - return "{\"endpoint\":[{\"name\":\"com.att.aaf.service\",\"major\": 2,\"minor\": 0,\"patch\": 19,\"pkg\": 21,\"latitude\": 38.627346,\"longitude\": -90.19377,\"protocol\": \"http\",\"subprotocol\": [],\"hostname\": \"127.0.0.1\",\"port\": 1080}]}"; + return "" + + "{" + + " \"endpoint\": [{" + + " \"name\": \"aaf-service\"," + + " \"major\": 2," + + " \"minor\": 0," + + " \"patch\": 19," + + " \"pkg\": 21," + + " \"latitude\": 38.627346," + + " \"longitude\": -90.19377," + + " \"protocol\": \"http\"," + + " \"subprotocol\": []," + + " \"port\": " + SimulatorApi.getSimulatedResponsesPort() + "," + + " \"hostname\": \"" + SimulatorApi.getSimulatorHost() + "\"" + + " }" + + " ]" + + "}"; } } diff --git a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/mso/PresetMSOCreateMacroPre1806Post.java b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/mso/PresetMSOCreateMacroPre1806Post.java index 29e1365af..e2f342f0e 100644 --- a/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/mso/PresetMSOCreateMacroPre1806Post.java +++ b/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/mso/PresetMSOCreateMacroPre1806Post.java @@ -25,7 +25,7 @@ public class PresetMSOCreateMacroPre1806Post extends PresetMSOBaseCreateInstance " }," + " \"modelInfo\": {" + " \"modelType\": \"service\"," + - " \"modelInvariantId\": \"d27e42cf-087e-4d31-88ac-6c4b7585f800\"," + + " \"modelInvariantId\": \"a8dcd72d-d44d-44f2-aa85-53aa9ca99cba\"," + " \"modelVersionId\": \"4d71990b-d8ad-4510-ac61-496288d9078e\"," + " \"modelName\": \"vidmacrofalsenaming\"," + " \"modelVersion\": \"1.0\"" + diff --git a/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java b/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java index 66bde727e..5e1310535 100644 --- a/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java +++ b/vid-automation/src/main/java/org/onap/vid/api/AsyncInstantiationBase.java @@ -1,8 +1,34 @@ package org.onap.vid.api; +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; +import static java.util.Collections.emptyList; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toMap; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasSize; +import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys; +import static org.testng.Assert.assertNotNull; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; +import static vid.automation.test.utils.ExtendedHamcrestMatcher.hasItemsFromCollection; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.Uninterruptibles; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -38,33 +64,6 @@ import vid.automation.test.model.ServiceAction; import vid.automation.test.services.AsyncJobsService; import vid.automation.test.services.SimulatorApi; -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -import static java.lang.Boolean.FALSE; -import static java.lang.Boolean.TRUE; -import static java.util.Collections.emptyList; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toMap; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasSize; -import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys; -import static org.testng.Assert.assertNotNull; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; -import static vid.automation.test.utils.ExtendedHamcrestMatcher.hasItemsFromCollection; - public class AsyncInstantiationBase extends BaseMsoApiTest { public static final String CREATE_BULK_OF_ALACARTE_REQUEST_WITH_VNF = "asyncInstantiation/vidRequestCreateALaCarteWithVnf.json"; @@ -507,7 +506,7 @@ public class AsyncInstantiationBase extends BaseMsoApiTest { .filter(serviceInfo -> serviceInfo.jobId.equals(jobId)) .findFirst().orElse(null); Assert.assertNotNull(serviceInfoFromDB); - Assert.assertEquals(serviceInfoDataReflected(expectedServiceInfo), serviceInfoDataReflected(serviceInfoFromDB)); + Assert.assertEquals(serviceInfoDataReflected(serviceInfoFromDB), serviceInfoDataReflected(expectedServiceInfo)); assertTrue("actual service instance doesn't contain template service name:" + expectedServiceInfo.serviceInstanceName, serviceInfoFromDB.serviceInstanceName.contains(expectedServiceInfo.serviceInstanceName)); diff --git a/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java b/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java index 060976ae4..4819b813f 100644 --- a/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java +++ b/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java @@ -20,7 +20,6 @@ import java.util.Properties; import java.util.Random; import java.util.TimeZone; import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; import org.apache.commons.io.IOUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -38,6 +37,7 @@ import vid.automation.reportportal.ReportPortalListenerDelegator; import vid.automation.test.infra.FeaturesTogglingConfiguration; import vid.automation.test.services.UsersService; import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor; +import vid.automation.test.utils.InsecureHttpsClient; @Listeners(ReportPortalListenerDelegator.class) public class BaseApiTest { @@ -50,16 +50,16 @@ public class BaseApiTest { @SuppressWarnings("WeakerAccess") protected Client client; protected Random random; - protected final RestTemplate restTemplate = new RestTemplate(); + protected final RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate(); protected final UsersService usersService = new UsersService(); - protected final RestTemplate restTemplateErrorAgnostic = new RestTemplate(); + protected final RestTemplate restTemplateErrorAgnostic = InsecureHttpsClient.newRestTemplate(); @BeforeClass public void init() { uri = getUri(); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - client = ClientBuilder.newClient(); + client = InsecureHttpsClient.newJaxrsClient(); client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); random = new Random(System.currentTimeMillis()); FeaturesTogglingConfiguration.initializeFeatureManager(); @@ -77,9 +77,20 @@ public class BaseApiTest { } public void login(UserCredentials userCredentials) { + final List<ClientHttpRequestInterceptor> interceptors = loginWithChosenRESTClient(userCredentials, restTemplate); + restTemplateErrorAgnostic.setInterceptors(interceptors); + restTemplateErrorAgnostic.setErrorHandler(new DefaultResponseErrorHandler() { + @Override + public boolean hasError(ClientHttpResponse response) { + return false; + } + }); + } + + public List<ClientHttpRequestInterceptor> loginWithChosenRESTClient(UserCredentials userCredentials,RestTemplate givenRestTemplate) { final List<ClientHttpRequestInterceptor> interceptors = singletonList(new CookieAndJsonHttpHeadersInterceptor(getUri(), userCredentials)); - restTemplate.setInterceptors(interceptors); - restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { + givenRestTemplate.setInterceptors(interceptors); + givenRestTemplate.setErrorHandler(new DefaultResponseErrorHandler() { @Override public void handleError(ClientHttpResponse response) throws IOException { try { @@ -90,14 +101,7 @@ public class BaseApiTest { } } }); - - restTemplateErrorAgnostic.setInterceptors(interceptors); - restTemplateErrorAgnostic.setErrorHandler(new DefaultResponseErrorHandler() { - @Override - public boolean hasError(ClientHttpResponse response) { - return false; - } - }); + return interceptors; } diff --git a/vid-automation/src/main/java/vid/automation/test/Constants.java b/vid-automation/src/main/java/vid/automation/test/Constants.java index 689c46387..66b8a9d25 100644 --- a/vid-automation/src/main/java/vid/automation/test/Constants.java +++ b/vid-automation/src/main/java/vid/automation/test/Constants.java @@ -303,7 +303,7 @@ public class Constants { }}; } - public static final String CREATE_SERVICE_INSTANCE_MACRO_MODAL = "Set a new service instance"; + } diff --git a/vid-automation/src/main/java/vid/automation/test/infra/Features.java b/vid-automation/src/main/java/vid/automation/test/infra/Features.java index 329bb4a89..b316fda1b 100644 --- a/vid-automation/src/main/java/vid/automation/test/infra/Features.java +++ b/vid-automation/src/main/java/vid/automation/test/infra/Features.java @@ -55,7 +55,8 @@ public enum Features implements Feature { FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG, FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH, FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE, - FLAG_1911_INSTANTIATION_ORDER_BUTTON_IN_ASYNC_ALACARTE + FLAG_1911_INSTANTIATION_ORDER_BUTTON_IN_ASYNC_ALACARTE, + FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI, ; public boolean isActive() { diff --git a/vid-automation/src/main/java/vid/automation/test/infra/ModelInfo.java b/vid-automation/src/main/java/vid/automation/test/infra/ModelInfo.java index 59e48013c..84b2cd922 100644 --- a/vid-automation/src/main/java/vid/automation/test/infra/ModelInfo.java +++ b/vid-automation/src/main/java/vid/automation/test/infra/ModelInfo.java @@ -54,12 +54,17 @@ public class ModelInfo { public static final ModelInfo pasqualeVmxVpeBvService488Annotations = new ModelInfo("f4d84bb4-a416-4b4e-997e-0059973630b9", "598e3f9e-3244-4d8f-a8e0-0e5d7a29eda9", "service-PasqualeVmxVpeBvService488-csar-annotations.zip"); public static final ModelInfo macroDrawingBoardComplexService = new ModelInfo("6e59c5de-f052-46fa-aa7e-2fca9d674c44","cfef8302-d90f-475f-87cc-3f49a62ef14c", "service-Complexservice-csar.zip" ); public static final ModelInfo aLaCarteServiceCreationTest = new ModelInfo("f913c5d0-206e-45c2-9284-1c68f4e67dc7", "45e61192-876c-4e28-9139-5a0c47410379", "serviceCreationTest.zip"); + public static final ModelInfo aLaCarteServiceOldVersionTest = new ModelInfo("04743c62-ab58-41a0-bc53-1052ef1c094a", "5d353b28-e5b7-419b-98e8-cad5d258be13", "serviceCreationTest04743c62-ab58-41a0-bc53-1052ef1c094a.zip"); public static final ModelInfo aLaCarteVnfGroupingService = new ModelInfo("4117a0b6-e234-467d-b5b9-fe2f68c8b0fc", "7ee41ce4-4827-44b0-a48e-2707a59905d2", "csar15782222_instantiationTypeAlacarte_VnfGrouping.zip"); public static final ModelInfo serviceFabricSriovService = new ModelInfo("253f1467-fe68-4e80-ba71-308000caec31", "c15fe228-7d40-4f99-afa7-10abeedf9aac", "service-fabric-SriovService-csar.zip"); public static final ModelInfo infrastructureVpnService = new ModelInfo("f028b2e2-7080-4b13-91b2-94944d4c42d8", "dfc2c44c-2429-44ca-ae26-1e6dc1f207fb", "service-Infravpn-csar.zip"); public static final ModelInfo collectionResourceService = new ModelInfo("abd0cb02-5f97-42cd-be93-7dd3e31a6a64", "04bdd793-32ed-4045-adea-4e096304a067", "csar_collection_resource.zip"); public static final ModelInfo collectionResourceForResume = new ModelInfo("6e0bec91-09f3-43aa-9cf3-e617cd0146be", "f6342be5-d66b-4d03-a1aa-c82c3094c4ea", "csar_collection_resource_for_resume.zip"); public static final ModelInfo transportWithPnfsService = new ModelInfo("12550cd7-7708-4f53-a09e-41d3d6327ebc", "561faa57-7bbb-40ec-a81c-c0d4133e98d4", "csarTransportWithPnfs.zip"); + public static final ModelInfo serviceWithInstantiationTypeMacro = new ModelInfo( + "fca0674c-f825-44bc-a87f-41ba7a0b4ab7", + "44173a37-0fce-486b-84be-40582bf3e40b", + "csar15782222_instantiationTypeMacro_invariantUUIDAlacarte_withoutNetworks.zip"); public static final ImmutableList<ModelInfo> superSetOfModelInfos = buildModelInfos(); public static ImmutableList<ModelInfo> buildModelInfos() { @@ -81,6 +86,7 @@ public class ModelInfo { .add(transportWithPnfsService) .add(collectionResourceService) .add(collectionResourceForResume) + .add(serviceWithInstantiationTypeMacro) .build(); } } diff --git a/vid-automation/src/main/java/vid/automation/test/sections/DeployMacroDialogBase.java b/vid-automation/src/main/java/vid/automation/test/sections/DeployMacroDialogBase.java deleted file mode 100644 index 270f53e97..000000000 --- a/vid-automation/src/main/java/vid/automation/test/sections/DeployMacroDialogBase.java +++ /dev/null @@ -1,12 +0,0 @@ -package vid.automation.test.sections; - -public abstract class DeployMacroDialogBase extends VidBasePage { - - public abstract void assertTitle(); - public abstract void closeDialog(); - public abstract void assertDialogExists(); - public abstract void clickOwningEntitySelect(); - public abstract void clickProjectSelect(); - - -} diff --git a/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployDialogBase.java b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployDialogBase.java new file mode 100644 index 000000000..5101a8438 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployDialogBase.java @@ -0,0 +1,21 @@ +package vid.automation.test.sections.deploy; + +import vid.automation.test.sections.VidBasePage; + +public abstract class DeployDialogBase extends VidBasePage { + + public abstract void closeDialog(); + + public abstract void assertDialog(); + + public abstract void waitForDialogToLoad(); + + public abstract String getModelVersionId(); + + public void waitForDialogAssertAndClose() { + waitForDialogToLoad(); + assertDialog(); + closeDialog(); + } + +} diff --git a/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIALaCarteDialog.java b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIALaCarteDialog.java new file mode 100644 index 000000000..c4338551b --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIALaCarteDialog.java @@ -0,0 +1,12 @@ +package vid.automation.test.sections.deploy; + +import static org.testng.AssertJUnit.assertFalse; + +public class DeployModernUIALaCarteDialog extends DeployModernUIBase { + + @Override + public void assertDialog() { + super.assertDialog(); + assertFalse(isLcpRegionExist()); + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/sections/DeployMacroDialog.java b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIBase.java index e7288ea79..6b2c1ecf4 100644 --- a/vid-automation/src/main/java/vid/automation/test/sections/DeployMacroDialog.java +++ b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIBase.java @@ -1,20 +1,28 @@ -package vid.automation.test.sections; +package vid.automation.test.sections.deploy; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.openqa.selenium.WebElement; import vid.automation.test.Constants; +import vid.automation.test.infra.Exists; +import vid.automation.test.infra.Get; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +public abstract class DeployModernUIBase extends DeployDialogBase { -public class DeployMacroDialog extends DeployMacroDialogBase { - String dialogTitle = Constants.BrowseASDC.CREATE_SERVICE_INSTANCE_MACRO_MODAL; @Override - public void assertTitle(){ + public void waitForDialogToLoad() { + goToIframe(); + } + + String dialogTitle = "Set a new service instance"; + public void assertTitle(){ WebElement modalTitle = GeneralUIUtils.getWebElementByTestID(Constants.CREATE_MODAL_TITLE_ID, 30); assertThat(modalTitle.getText(), containsString(dialogTitle)); } + @Override public void closeDialog(){ GeneralUIUtils.ultimateWait(); @@ -23,16 +31,23 @@ public class DeployMacroDialog extends DeployMacroDialogBase { } @Override - public void assertDialogExists() { + public void assertDialog() { assertTitle(); } @Override + public String getModelVersionId() { + return Get.byTestId("model-item-value-uuid").getText(); + } + + protected boolean isLcpRegionExist() { + return Exists.byTestId(Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID); + } + public void clickOwningEntitySelect() { GeneralUIUtils.clickOnElementByTestId(Constants.OwningEntity.OWNING_ENTITY_SELECT_TEST_ID); } - @Override public void clickProjectSelect() { GeneralUIUtils.clickOnElementByTestId(Constants.OwningEntity.PROJECT_SELECT_TEST_ID); } diff --git a/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIMacroDialog.java b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIMacroDialog.java new file mode 100644 index 000000000..33b4b05ef --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployModernUIMacroDialog.java @@ -0,0 +1,13 @@ +package vid.automation.test.sections.deploy; + +import static org.testng.Assert.assertTrue; + +public class DeployModernUIMacroDialog extends DeployModernUIBase { + + @Override + public void assertDialog() { + super.assertDialog(); + assertTrue(isLcpRegionExist()); + } + +} diff --git a/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployOldALaCarteDialog.java b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployOldALaCarteDialog.java new file mode 100644 index 000000000..aad4c9fb2 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployOldALaCarteDialog.java @@ -0,0 +1,9 @@ +package vid.automation.test.sections.deploy; + +public class DeployOldALaCarteDialog extends DeployOldDialogBase { + + @Override + public String getTitle() { + return "a la carte"; + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/sections/DeployMacroDialogOld.java b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployOldDialogBase.java index e0e391b4d..59c013a09 100644 --- a/vid-automation/src/main/java/vid/automation/test/sections/DeployMacroDialogOld.java +++ b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployOldDialogBase.java @@ -1,42 +1,42 @@ -package vid.automation.test.sections; +package vid.automation.test.sections.deploy; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import org.junit.Assert; import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.openqa.selenium.WebElement; import vid.automation.test.Constants; +import vid.automation.test.infra.Get; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; - -public class DeployMacroDialogOld extends DeployMacroDialogBase { - String dialogTitle = "macro"; +public abstract class DeployOldDialogBase extends DeployDialogBase { @Override - public void assertTitle(){ - WebElement modalTitle = GeneralUIUtils.getWebElementByTestID(Constants.CREATE_MODAL_TITLE_ID, 30); - assertThat(modalTitle.getText().toLowerCase(), containsString(dialogTitle)); + public void waitForDialogToLoad() { + GeneralUIUtils.ultimateWait(); } @Override public void closeDialog(){ - GeneralUIUtils.ultimateWait(); clickCancelButtonByTestID(); } @Override - public void assertDialogExists(){ + public void assertDialog(){ + assertTitle(); boolean byText = GeneralUIUtils.findAndWaitByText(Constants.BrowseASDC.CREATE_SERVICE_INSTANCE, 15); Assert.assertTrue(byText); } - @Override - public void clickOwningEntitySelect(){ - GeneralUIUtils.clickOnElementByTestId(Constants.OwningEntity.OWNING_ENTITY_SELECT_TEST_ID); + public void assertTitle(){ + WebElement modalTitle = GeneralUIUtils.getWebElementByTestID(Constants.CREATE_MODAL_TITLE_ID, 30); + assertThat(modalTitle.getText().toLowerCase(), containsString(getTitle())); } @Override - public void clickProjectSelect(){ - GeneralUIUtils.clickOnElementByTestId(Constants.OwningEntity.PROJECT_SELECT_TEST_ID); + public String getModelVersionId() { + return Get.byTestId("Service UUID").getText(); } + public abstract String getTitle(); } diff --git a/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployOldMacroDialog.java b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployOldMacroDialog.java new file mode 100644 index 000000000..73ae4c55a --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/sections/deploy/DeployOldMacroDialog.java @@ -0,0 +1,9 @@ +package vid.automation.test.sections.deploy; + +public class DeployOldMacroDialog extends DeployOldDialogBase { + + @Override + public String getTitle() { + return "macro"; + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java index 6e15b7b52..c8ac7ead9 100644 --- a/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java +++ b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java @@ -56,17 +56,24 @@ public class SimulatorApi { public List<StringWrapper> values; } + public static class BodyWrapper { + public String value; + } + public static class HttpRequest { public StringWrapper path; + public BodyWrapper body; public List<RecordedHeaders> headers; } public static class RecordedRequests { public String path; + public String body; public Map<String, List<String>> headers; - public RecordedRequests(String path, Map<String, List<String>> headers) { + public RecordedRequests(String path, String body, Map<String, List<String>> headers) { this.path = path; + this.body = body; this.headers = headers; } @@ -82,7 +89,7 @@ public class SimulatorApi { ImmutableList.of(dropTestApiFieldFromString(), dropFieldCloudOwnerFromString()); static { - String host = System.getProperty("SIM_HOST", System.getProperty("VID_HOST", "127.0.0.1")); + String host = getSimulatorHost(); Integer port = Integer.valueOf(System.getProperty("SIM_PORT", System.getProperty("VID_PORT", "8080"))); //port for registration uri = new JerseyUriBuilder().host(host).port(port).scheme("http").path("vidSimulator").build(); client = ClientBuilder.newClient(); @@ -94,10 +101,18 @@ public class SimulatorApi { jacksonJsonProvider.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); client.register(jacksonJsonProvider); - Integer simulationPort = Integer.valueOf(System.getProperty("SIMULATION_PORT", "1080")); //port getting simulated responses + Integer simulationPort = getSimulatedResponsesPort(); simulationUri = new JerseyUriBuilder().host(host).port(simulationPort).scheme("http").build(); } + public static String getSimulatorHost() { + return System.getProperty("SIM_HOST", System.getProperty("VID_HOST", "127.0.0.1")); + } + + public static Integer getSimulatedResponsesPort() { + return Integer.valueOf(System.getProperty("SIMULATION_PORT", "1080")); + } + public static URI getSimulationUri() { return simulationUri; } @@ -180,6 +195,7 @@ public class SimulatorApi { List<HttpRequest> rawRequests = retrieveRecordedHttpRequests(); return rawRequests.stream().map(request->new RecordedRequests( request.path.value, + request.body != null && request.body != null ? request.body.value : "", request.headers.stream().collect( Collectors.toMap( x->x.name.value, diff --git a/vid-automation/src/main/java/vid/automation/test/test/BrowseASDCTest.java b/vid-automation/src/main/java/vid/automation/test/test/BrowseASDCTest.java index eb08c1f2a..0671815bd 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/BrowseASDCTest.java +++ b/vid-automation/src/main/java/vid/automation/test/test/BrowseASDCTest.java @@ -1,49 +1,63 @@ package vid.automation.test.test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static vid.automation.test.infra.Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI; +import static vid.automation.test.infra.Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI; +import static vid.automation.test.infra.Features.FLAG_5G_IN_NEW_INSTANTIATION_UI; +import static vid.automation.test.infra.Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION; +import static vid.automation.test.infra.Features.FLAG_SHOW_ORCHESTRATION_TYPE; +import static vid.automation.test.infra.ModelInfo.aLaCarteForBrowseSdc; +import static vid.automation.test.infra.ModelInfo.aLaCarteServiceCreationTest; +import static vid.automation.test.infra.ModelInfo.instantiationTypeAlacarte_vidNotionsInstantiationUIByUUID; +import static vid.automation.test.infra.ModelInfo.macroForBrowseSdc; + import com.google.common.collect.ImmutableList; +import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hamcrest.Matchers; +import org.jetbrains.annotations.NotNull; +import org.onap.sdc.ci.tests.datatypes.UserCredentials; +import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetServicesGet; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIServiceDesignAndCreationPut; import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet; -import org.onap.sdc.ci.tests.datatypes.UserCredentials; -import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.testng.Assert; +import org.testng.TimeBombSkipException; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import vid.automation.test.Constants; -import vid.automation.test.infra.*; +import vid.automation.test.infra.Click; +import vid.automation.test.infra.Exists; +import vid.automation.test.infra.FeatureTogglingTest; +import vid.automation.test.infra.Get; +import vid.automation.test.infra.ModelInfo; +import vid.automation.test.infra.SelectOption; import vid.automation.test.model.Service; import vid.automation.test.model.User; -import vid.automation.test.sections.*; +import vid.automation.test.sections.BrowseASDCPage; +import vid.automation.test.sections.SideMenu; +import vid.automation.test.sections.ViewEditPage; +import vid.automation.test.sections.deploy.DeployDialogBase; +import vid.automation.test.sections.deploy.DeployModernUIALaCarteDialog; +import vid.automation.test.sections.deploy.DeployModernUIMacroDialog; +import vid.automation.test.sections.deploy.DeployOldALaCarteDialog; +import vid.automation.test.sections.deploy.DeployOldMacroDialog; import vid.automation.test.services.ServicesService; import vid.automation.test.services.SimulatorApi; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static vid.automation.test.infra.Features.FLAG_5G_IN_NEW_INSTANTIATION_UI; -import static vid.automation.test.infra.Features.FLAG_SHOW_ORCHESTRATION_TYPE; -import static vid.automation.test.infra.Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI; -import static vid.automation.test.infra.ModelInfo.*; - public class BrowseASDCTest extends CreateInstanceDialogBaseTest { private final String invariantUUIDAlacarte = aLaCarteForBrowseSdc.modelInvariantId; private final String invariantUUIDMacro = macroForBrowseSdc.modelInvariantId; - private final String instantiationTypeNameAlacarte = "a la carte"; - private final String instantiationTypeNameMacro = "macro"; - private final String oldMacro = "old macro"; - private final String newAlacarte = "new a la carte"; public static final String modelInvariantUUID1 = "aeababbc-010b-4a60-8df7-e64c07389466"; public static final String modelInvariantUUID2 = "aa2f8e9c-9e47-4b15-a95c-4a9385599abc"; public static final String modelInvariantUUID3 = "d849c57d-b6fe-4843-8349-4ab8bbb08d71"; @@ -69,7 +83,7 @@ public class BrowseASDCTest extends CreateInstanceDialogBaseTest { return new UserCredentials(user.credentials.userId, user.credentials.password, Constants.Users.EMANUEL_EMANUEL, "", ""); } - @Test(groups = {"shouldBeMigratedToWorkWithSimulator"}) + //@Test(groups = {"shouldBeMigratedToWorkWithSimulator"}) public void testPNFOnCreatePopup() { Service service = servicesService.getService("f39389e4-2a9c-4085-8ac3-04aea9c651be"); BrowseASDCPage browseASDCPage = new BrowseASDCPage(); @@ -85,12 +99,9 @@ public class BrowseASDCTest extends CreateInstanceDialogBaseTest { validateServiceCreationDialog(service); } -// @BeforeMethod -// public void clearSimulator() { -// SimulatorApi.clearAll(); -// } - @Test(groups = {"shouldBeMigratedToWorkWithSimulator"}) + + //@Test(groups = {"shouldBeMigratedToWorkWithSimulator"}) private void testPNFMacroInstantation() throws Exception { User user = usersService.getUser(Constants.Users.EMANUEL_EMANUEL); relogin(user.credentials); @@ -126,89 +137,97 @@ public class BrowseASDCTest extends CreateInstanceDialogBaseTest { } @Test - private void browseServiceModel_deployServiceALaCarteByBackendInput_creationPopupIsALaCarte() throws Exception { + private void browseServiceModel_deployServiceALaCarteByBackendInput_creationPopupIsALaCarte() { // model uuid should be of macro deployServiceAndAssertInstantiationType( "csar15782222_instantiationTypeAlacarte_invariantUUIDMacro.zip", invariantUUIDMacro, - instantiationTypeNameAlacarte + getAlacarteDialogByFlagValue() ); } + @NotNull + public static DeployDialogBase getAlacarteDialogByFlagValue() { + return FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI.isActive() ? + new DeployModernUIALaCarteDialog() : + new DeployOldALaCarteDialog(); + } + @Test @FeatureTogglingTest(FLAG_5G_IN_NEW_INSTANTIATION_UI) - private void browseServiceModel_deployServiceALaCarteByBackendInputHintNewUI_creationPopupIsAngular2() throws Exception { + private void browseServiceModel_deployServiceALaCarteByBackendInputHintNewUI_creationPopupIsAngular2() { deployServiceAndAssertInstantiationType( instantiationTypeAlacarte_vidNotionsInstantiationUIByUUID, - newAlacarte + new DeployModernUIALaCarteDialog() ); } @Test - private void browseServiceModel_deployServiceALaCarteBecauseNotOnMACRO_SERVICESConfig_creationPopupIsALaCarte() throws Exception { + private void browseServiceModel_deployServiceALaCarteBecauseNotOnMACRO_SERVICESConfig_creationPopupIsALaCarte() { deployServiceAndAssertInstantiationType( "csar15782222_instantiationTypeEmpty_invariantUUIDAlacarte.zip", invariantUUIDAlacarte, - instantiationTypeNameAlacarte + getAlacarteDialogByFlagValue() ); } @Test - private void browseServiceModel_deployServiceMacroByBackendInput_creationPopupIsMacro() throws Exception { + private void browseServiceModel_deployServiceMacroByBackendInput_creationPopupIsMacro() { deployServiceAndAssertInstantiationType( - "csar15782222_instantiationTypeMacro_invariantUUIDAlacarte_withoutNetworks.zip", - invariantUUIDAlacarte, - instantiationTypeNameMacro + ModelInfo.serviceWithInstantiationTypeMacro, + new DeployModernUIMacroDialog() ); } @Test - private void browseServiceModel_deployServiceMacroByMACRO_SERVICESConfig_creationPopupIsOldMacro() throws Exception { + private void browseServiceModel_deployServiceMacroByMACRO_SERVICESConfig_creationPopupIsOldMacro() { + if (FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI.isActive() ) { + throw new TimeBombSkipException("skipping identify macro by uuid for awhile", "2019/11/25"); + //also need to handle the simulator preset by using good ModelInfo instance + } deployServiceAndAssertInstantiationType( "csar15782222_invariantUUIDMacro.zip", invariantUUIDMacro, - oldMacro - + new DeployOldMacroDialog() ); } @Test - private void browseServiceModel_deployServiceMacroWithPnf_creationPopupIsOldMacro() throws Exception { + private void browseServiceModel_deployServiceMacroWithPnf_creationPopupIsOldMacro() { deployServiceAndAssertInstantiationType( "csar15782222_instantiationTypeMacroWithPnf.zip", invariantUUIDMacro, - oldMacro - + new DeployOldMacroDialog() ); } @Test - @FeatureTogglingTest(flagActive = false, value = FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI) - public void browseServiceModel_deployServiceMacroWithCR_creationPopupIsOldMacro() throws Exception { + public void browseServiceModel_deployServiceMacroWithCR_creationPopupIsOldMacro() { deployServiceAndAssertInstantiationType( - "csar15782222_instantiationTypeMacroWithCR.zip", - invariantUUIDMacro, - oldMacro - + ModelInfo.collectionResourceService, + FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI.isActive() ? + new DeployModernUIMacroDialog() : + new DeployOldMacroDialog() ); } @Test - private void browseServiceModel_deployServiceMacroWithNetwork_creationPopupIsMacroByFF() throws Exception { - String macroInstantiationAccordingFF = Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION.isActive() ? instantiationTypeNameMacro : oldMacro; + private void browseServiceModel_deployServiceMacroWithNetwork_creationPopupIsMacroByFF() { deployServiceAndAssertInstantiationType( "csar15782222_instantiationTypeMacroWithNetwork.zip", invariantUUIDMacro, - macroInstantiationAccordingFF + FLAG_NETWORK_TO_ASYNC_INSTANTIATION.isActive() ? + new DeployModernUIMacroDialog() : + new DeployOldMacroDialog() ); } - private void deployServiceAndAssertInstantiationType(String modelZipFileName, String modelInvariantId, String expectedInstantiationType) throws Exception { - deployServiceAndAssertInstantiationType(new ModelInfo("4d71990b-d8ad-4510-ac61-496288d9078e", modelInvariantId, modelZipFileName), expectedInstantiationType); + private void deployServiceAndAssertInstantiationType(String modelZipFileName, String modelInvariantId, DeployDialogBase deployDialog) { + deployServiceAndAssertInstantiationType(new ModelInfo("4d71990b-d8ad-4510-ac61-496288d9078e", modelInvariantId, modelZipFileName), deployDialog); } - private void deployServiceAndAssertInstantiationType(ModelInfo modelInfo, String expectedInstantiationType) throws Exception { + private void deployServiceAndAssertInstantiationType(ModelInfo modelInfo, DeployDialogBase deployDialog) { registerExpectationForLegacyServiceDeployment(modelInfo, "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"); User user = usersService.getUser(Constants.Users.EMANUEL_EMANUEL); @@ -219,19 +238,13 @@ public class BrowseASDCTest extends CreateInstanceDialogBaseTest { GeneralUIUtils.ultimateWait(); browseASDCPage.clickDeployServiceButtonByServiceUUID(modelInfo.modelVersionId); - DeployMacroDialogBase macroDialog = null; - if (expectedInstantiationType.equals(instantiationTypeNameAlacarte)) { - GeneralUIUtils.ultimateWait(); - browseASDCPage.clickCancelButtonByTestID(); - } else { //macro - macroDialog = expectedInstantiationType.equals(oldMacro) ? new DeployMacroDialogOld() : getMacroDialog(); - macroDialog.assertTitle(); - macroDialog.closeDialog(); - } + + deployDialog.waitForDialogAssertAndClose(); } + @FeatureTogglingTest(value = FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI, flagActive = false) @Test - private void testServiceInstantiationAlaCarte() throws Exception { + private void testServiceInstantiationAlaCarte() { User user = usersService.getUser(Constants.Users.EMANUEL_EMANUEL); relogin(user.credentials); @@ -303,8 +316,9 @@ public class BrowseASDCTest extends CreateInstanceDialogBaseTest { BrowseASDCPage browseASDCPage = registerSimulatorAndGoToBrowseSDC(); Service service = servicesService.getService("2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd"); browseASDCPage.clickDeployServiceButtonByServiceUUID(service.uuid); - DeployMacroDialogBase deployMacroDialog = getMacroDialog(); - deployMacroDialog.assertDialogExists(); + DeployModernUIMacroDialog deployMacroDialog = new DeployModernUIMacroDialog(); + deployMacroDialog.waitForDialogToLoad(); + deployMacroDialog.assertDialog(); deployMacroDialog.clickProjectSelect(); deployMacroDialog.clickOwningEntitySelect(); } @@ -324,7 +338,7 @@ public class BrowseASDCTest extends CreateInstanceDialogBaseTest { return new BrowseASDCPage(); } - @Test(groups = {"shouldBeMigratedToWorkWithSimulator"}) + //@Test(groups = {"shouldBeMigratedToWorkWithSimulator"}) private void testOwningEntityRequiredAndProjectOptional() throws Exception { User user = usersService.getUser(Constants.Users.SILVIA_ROBBINS_TYLER_SILVIA); relogin(user.credentials); @@ -358,7 +372,7 @@ public class BrowseASDCTest extends CreateInstanceDialogBaseTest { assertSuccessfulServiceInstanceCreation(); } - @Test(groups = {"shouldBeMigratedToWorkWithSimulator"}) + //@Test(groups = {"shouldBeMigratedToWorkWithSimulator"}) protected void testLineOfBusinessOptionalAndPlatformRequired() throws Exception { User user = usersService.getUser(Constants.Users.SILVIA_ROBBINS_TYLER_SILVIA); diff --git a/vid-automation/src/main/java/vid/automation/test/test/PreviousVersionsPopupTest.java b/vid-automation/src/main/java/vid/automation/test/test/PreviousVersionsPopupTest.java index c52dd6bac..beef5d966 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/PreviousVersionsPopupTest.java +++ b/vid-automation/src/main/java/vid/automation/test/test/PreviousVersionsPopupTest.java @@ -1,29 +1,36 @@ package vid.automation.test.test; +import static org.testng.Assert.assertEquals; +import static vid.automation.test.infra.ModelInfo.ModelInfoWithMultipleVersions.modelInfoWithMultipleVersions; +import static vid.automation.test.infra.ModelInfo.serviceWithOneVersion; + import com.google.common.collect.ImmutableList; import org.junit.Assert; +import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset; -import org.onap.simulator.presetGenerator.presets.aai.*; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkZones; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetServicesGet; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubDetailsGet; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubDetailsWithoutInstancesGet; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIServiceDesignAndCreationPut; import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet; import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstancePost; import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet; import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet; import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet; -import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.openqa.selenium.By; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import vid.automation.test.infra.Click; import vid.automation.test.infra.Get; +import vid.automation.test.infra.ModelInfo; import vid.automation.test.sections.BrowseASDCPage; -import vid.automation.test.sections.CreateNewInstancePage; import vid.automation.test.sections.PreviousVersionDialog; import vid.automation.test.sections.SideMenu; +import vid.automation.test.sections.deploy.DeployDialogBase; import vid.automation.test.services.SimulatorApi; -import static vid.automation.test.infra.ModelInfo.ModelInfoWithMultipleVersions.modelInfoWithMultipleVersions; -import static vid.automation.test.infra.ModelInfo.serviceWithOneVersion; - public class PreviousVersionsPopupTest extends CreateInstanceDialogBaseTest{ BrowseASDCPage browseASDCPage = new BrowseASDCPage(); @@ -79,17 +86,16 @@ public class PreviousVersionsPopupTest extends CreateInstanceDialogBaseTest{ } @Test private void openPreviousVersionPopup_deployOldVersion_creationPopupIsALaCarte(){ - String expectedPopupIsALaCarteName = "Create Service Instance -- a la carte"; prepareSimulatorWithThreeVersionsBeforeBrowseASDCService(); - CreateNewInstancePage newInstance= new CreateNewInstancePage(); + registerExpectationForLegacyServiceDeployment(ModelInfo.aLaCarteServiceOldVersionTest, "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"); newVersionDialog = new PreviousVersionDialog(); navigateToBrowseAsdcAndClickPreviousButton(); newVersionDialog.clickDeployServiceButtonByServiceUUID(modelVersionId2); - assertNewInstanceFormOpened(createModalTitleTestId,expectedPopupIsALaCarteName); - newInstance.clickCancelButtonByTestID(); - GeneralUIUtils.ultimateWait(); - newVersionDialog.clickCancelButton(); - + final DeployDialogBase deployDialog = BrowseASDCTest.getAlacarteDialogByFlagValue(); + deployDialog.waitForDialogToLoad(); + deployDialog.assertDialog(); + assertEquals(deployDialog.getModelVersionId(), modelVersionId2); + deployDialog.closeDialog(); } private void navigateToBrowseAsdcAndClickPreviousButton() { diff --git a/vid-automation/src/main/java/vid/automation/test/test/SanityMacroDeployTest.java b/vid-automation/src/main/java/vid/automation/test/test/SanityMacroDeployTest.java index ba951bc55..032e729a2 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/SanityMacroDeployTest.java +++ b/vid-automation/src/main/java/vid/automation/test/test/SanityMacroDeployTest.java @@ -1,5 +1,10 @@ package vid.automation.test.test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static vid.automation.test.infra.ModelInfo.macroForBrowseSdc; +import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND; + import com.google.common.collect.ImmutableList; import org.junit.Assert; import org.onap.sdc.ci.tests.datatypes.UserCredentials; @@ -17,11 +22,6 @@ import vid.automation.test.sections.BrowseASDCPage; import vid.automation.test.sections.SideMenu; import vid.automation.test.services.SimulatorApi; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static vid.automation.test.infra.ModelInfo.macroForBrowseSdc; -import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND; - public class SanityMacroDeployTest extends CreateInstanceDialogBaseTest { static final String NEW_INSTANCE_NAME = "New Instance Name"; @@ -150,7 +150,7 @@ public class SanityMacroDeployTest extends CreateInstanceDialogBaseTest { Assert.assertEquals(currElem.getText(), RESOURCE_DESCRIPTION); currElem = GeneralUIUtils.getWebElementByTestID(Constants.SERVICE_INVARIANT_UUID, 30); - Assert.assertEquals(currElem.getText(), macroForBrowseSdc.modelInvariantId); + Assert.assertEquals(currElem.getText(), "a8dcd72d-d44d-44f2-aa85-53aa9ca99cba"); currElem = GeneralUIUtils.getWebElementByTestID(Constants.SERVICE_VERSION, 30); Assert.assertEquals(currElem.getText(), SERVICE_VERSION); diff --git a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java index a45f25853..41ede9a3f 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java +++ b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java @@ -1,17 +1,59 @@ package vid.automation.test.test; -//import com.automation.common.report_portal_integration.annotations.Step; -//import com.automation.common.report_portal_integration.listeners.ReportPortalListener; -//import com.automation.common.report_portal_integration.screenshots.WebDriverScreenshotsProvider; +import static java.util.Collections.emptySet; +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.toSet; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.collection.IsEmptyCollection.empty; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE; +import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.fail; +import static vid.automation.test.utils.TestHelper.GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS; +import static vid.automation.test.utils.TestHelper.GET_TENANTS; + import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; +import java.io.File; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URISyntaxException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; import org.glassfish.jersey.uri.internal.JerseyUriBuilder; import org.junit.Assert; import org.onap.sdc.ci.tests.datatypes.Configuration; +import org.onap.sdc.ci.tests.datatypes.UserCredentials; +import org.onap.sdc.ci.tests.execute.setup.SetupCDTest; +import org.onap.sdc.ci.tests.utilities.FileHandling; +import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset; import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset; -import org.onap.simulator.presetGenerator.presets.aai.*; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAICloudRegionAndSourceFromConfigurationPut; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkZones; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetPortMirroringSourcePorts; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetServicesGet; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubDetailsGet; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubDetailsWithoutInstancesGet; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetTenants; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIPostNamedQueryForViewEdit; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIServiceDesignAndCreationPut; import org.onap.simulator.presetGenerator.presets.ecompportal_att.EcompPortalPresetsUtils; import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet; import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2; @@ -19,10 +61,6 @@ import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInst import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet; import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet; import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet; -import org.onap.sdc.ci.tests.datatypes.UserCredentials; -import org.onap.sdc.ci.tests.execute.setup.SetupCDTest; -import org.onap.sdc.ci.tests.utilities.FileHandling; -import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebElement; @@ -36,47 +74,36 @@ import org.testng.annotations.Test; import vid.automation.reportportal.ReportPortalListenerDelegator; import vid.automation.test.Constants; import vid.automation.test.Constants.ViewEdit; -import vid.automation.test.infra.*; +import vid.automation.test.infra.Click; +import vid.automation.test.infra.Exists; +import vid.automation.test.infra.Features; +import vid.automation.test.infra.Get; +import vid.automation.test.infra.ModelInfo; +import vid.automation.test.infra.SelectOption; +import vid.automation.test.infra.Wait; import vid.automation.test.model.Credentials; import vid.automation.test.model.User; -import vid.automation.test.sections.*; +import vid.automation.test.sections.LoginExternalPage; +import vid.automation.test.sections.SearchExistingPage; +import vid.automation.test.sections.SideMenu; +import vid.automation.test.sections.VidBasePage; +import vid.automation.test.sections.ViewEditPage; +import vid.automation.test.sections.deploy.DeployModernUIMacroDialog; import vid.automation.test.services.CategoryParamsService; import vid.automation.test.services.SimulatorApi; import vid.automation.test.services.UsersService; import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor; import vid.automation.test.utils.DB_CONFIG; +import vid.automation.test.utils.InsecureHttpsClient; import vid.automation.test.utils.TestConfigurationHelper; import vid.automation.test.utils.TestHelper; -import java.io.File; -import java.lang.reflect.Method; -import java.net.URI; -import java.net.URISyntaxException; -import java.sql.*; -import java.util.*; -import java.util.concurrent.TimeUnit; - -import static java.util.Collections.emptySet; -import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.*; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE; -import static org.testng.Assert.assertEquals; -import static org.testng.AssertJUnit.fail; -import static vid.automation.test.utils.TestHelper.GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS; -import static vid.automation.test.utils.TestHelper.GET_TENANTS; - @Listeners(ReportPortalListenerDelegator.class) public class VidBaseTestCase extends SetupCDTest{ protected final UsersService usersService = new UsersService(); protected final CategoryParamsService categoryParamsService = new CategoryParamsService(); - protected final RestTemplate restTemplate = new RestTemplate(); + protected final RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate(); protected final URI uri; protected final URI envUrI; @@ -229,7 +256,7 @@ public class VidBaseTestCase extends SetupCDTest{ return presets; } - protected void relogin(Credentials credentials) throws Exception { + protected void relogin(Credentials credentials) { // `getWindowTest().getPreviousUser()` is SetupCDTest's state of previous user used if (!credentials.userId.equals(getWindowTest().getPreviousUser())) { UserCredentials userCredentials = new UserCredentials(credentials.userId, @@ -485,12 +512,6 @@ public class VidBaseTestCase extends SetupCDTest{ assertThat(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE, elementTestId), infoItemText, is(value)); } - public DeployMacroDialogBase getMacroDialog(){ - VidBasePage vidBasePage =new VidBasePage(); - vidBasePage.goToIframe(); - return new DeployMacroDialog(); - } - protected void loadServicePopup(ModelInfo modelInfo) { loadServicePopup(modelInfo.modelVersionId); } @@ -503,7 +524,7 @@ public class VidBaseTestCase extends SetupCDTest{ } protected void loadServicePopupOnBrowseASDCPage(String modelVersionId ) { - DeployMacroDialog deployMacroDialog = new DeployMacroDialog(); + DeployModernUIMacroDialog deployMacroDialog = new DeployModernUIMacroDialog(); VidBasePage.goOutFromIframe(); deployMacroDialog.clickDeployServiceButtonByServiceUUID(modelVersionId); deployMacroDialog.goToIframe(); diff --git a/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java b/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java index c98b2428a..0117a8a99 100644 --- a/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java +++ b/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java @@ -1,19 +1,23 @@ package vid.automation.test.utils; +import java.io.IOException; +import java.net.URI; +import java.util.Collections; +import java.util.List; import org.junit.Assert; import org.onap.sdc.ci.tests.datatypes.UserCredentials; -import org.springframework.http.*; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpRequest; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.support.HttpRequestWrapper; import org.springframework.web.client.RestTemplate; -import java.io.IOException; -import java.net.URI; -import java.util.Collections; -import java.util.List; - public class CookieAndJsonHttpHeadersInterceptor implements ClientHttpRequestInterceptor { private final HttpHeaders cookieAndJsonHttpHeaders; @@ -33,7 +37,7 @@ public class CookieAndJsonHttpHeadersInterceptor implements ClientHttpRequestInt protected HttpHeaders getCookieAndJsonHttpHeaders(URI uri, UserCredentials userCredentials) { HttpHeaders loginRequestHeaders = new HttpHeaders(); loginRequestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - RestTemplate restTemplate = new RestTemplate(); + RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate(); ResponseEntity<String> loginRes = restTemplate.postForEntity(uri.toASCIIString() + "/login_external.htm", new HttpEntity<>("loginId=" + userCredentials.getUserId() + "&password=" + userCredentials.getPassword(), loginRequestHeaders), String.class); Assert.assertEquals("Login failed - wrong http status with user:" + userCredentials.getUserId() + " password:" + userCredentials.getPassword(), HttpStatus.FOUND, loginRes.getStatusCode()); Assert.assertNull("Failed to login with user:" + userCredentials.getUserId() + " password:" + userCredentials.getPassword(), loginRes.getBody()); diff --git a/vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java b/vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java new file mode 100644 index 000000000..6106ae4a2 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java @@ -0,0 +1,26 @@ +package vid.automation.test.utils; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +public class InsecureHttpsClient { + + public static RestTemplate newRestTemplate() { + CloseableHttpClient insecureTLSHttpClient + = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build(); + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(insecureTLSHttpClient); + return new RestTemplate(factory); + } + + public static Client newJaxrsClient() { + return ClientBuilder.newBuilder() + .hostnameVerifier(NoopHostnameVerifier.INSTANCE) + .build(); + } + +} diff --git a/vid-automation/src/main/resources/registration_to_simulator/sanity/get_sdc_catalog_services_4d71990b.json b/vid-automation/src/main/resources/registration_to_simulator/sanity/get_sdc_catalog_services_4d71990b.json index 56bce65c0..03b6eb71d 100644 --- a/vid-automation/src/main/resources/registration_to_simulator/sanity/get_sdc_catalog_services_4d71990b.json +++ b/vid-automation/src/main/resources/registration_to_simulator/sanity/get_sdc_catalog_services_4d71990b.json @@ -6,7 +6,7 @@ }, "simulatorResponse": { "responseCode": 200, - "file": "csar15782222_invariantUUIDMacro.zip" + "file": "csar15782222_instantiationTypeMacro_invariantUUIDAlacarte.zip" } }, { @@ -24,7 +24,7 @@ "invariantUUID": "d27e42cf-087e-4d31-88ac-6c4b7585f800", "name": "vidmacrofalsenaming", "version": "1.0", - "toscaModelURL": "./csar15782222_invariantUUIDMacro.zip", + "toscaModelURL": "./csar15782222_instantiationTypeMacro_invariantUUIDAlacarte.zip", "category": "Network Connectivityv", "lifecycleState": "CERTIFIED", "lastUpdaterUserId": "rg276b", @@ -35,4 +35,4 @@ } } } -]
\ No newline at end of file +] diff --git a/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java index 25b40ed6b..92d3f79c8 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/AsyncInstantiationALaCarteApiTest.java @@ -1,12 +1,14 @@ package org.onap.vid.api; import static java.util.Collections.emptyMap; +import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsInRelativeOrder; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset.DEFAULT_INSTANCE_ID; @@ -18,12 +20,14 @@ import static vid.automation.test.services.SimulatorApi.retrieveRecordedRequests import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; + import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.UUID; + import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset; import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId; @@ -408,6 +412,23 @@ public class AsyncInstantiationALaCarteApiTest extends AsyncInstantiationBase { } } + + @Test + public void deployServiceAfterDragAndDropVFModule__verifyOrderMsoCalls() { + final ImmutableMap<PresetMSOServiceInstanceGen2WithNames.Keys, String> names = ImmutableMap + .of(SERVICE_NAME, "serviceInstanceName"); + String vnfRequestId = UUID.randomUUID().toString(); + registerPresetsForRetryTest("none", names, vnfRequestId, false); + + final List<String> uuids = createBulkOfInstances(false, 1, names, + CREATE_BULK_OF_ALACARTE_NO_TESTAPI_REQUEST_CYPRESS); + + final String jobId = uuids.get(0); + + assertServiceInfoSpecific2(jobId, JobStatus.COMPLETED, names.get(SERVICE_NAME)); + assertMSOcalledWithOrder(); + } + @Test public void verifyMetricsLogInAsyncInstantiation() { @@ -525,6 +546,24 @@ public class AsyncInstantiationALaCarteApiTest extends AsyncInstantiationBase { )); } + + private void assertMSOcalledWithOrder() { + + List<RecordedRequests> requests = retrieveRecordedRequests(); + + String path = "/mso/serviceInstantiation/v7/serviceInstances/.*/vnfs/.*/vfModules"; + List<String> msoVFModulesRequests = + requests.stream().filter(x -> x.path.matches(path)).map(x -> x.body).collect(toList()); + + assertThat("request for vfNodule send with position order", + msoVFModulesRequests, + contains( + containsString("2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0"), + containsString("2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2"), + containsString("2017488PasqualeVpe..PASQUALE_vRE_BV..module-1") + )); + } + private ImmutableList<JobAuditStatus> vidAuditStatusesCompleted(String jobId) { return ImmutableList.of( vidAuditStatus(jobId, "PENDING", false), diff --git a/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java index 7490c0610..6625d2a41 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java @@ -1,50 +1,75 @@ package org.onap.vid.api; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.onap.vid.api.TestUtils.getNestedPropertyInMap; +import static org.testng.AssertJUnit.assertEquals; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.ws.rs.HttpMethod; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.onap.simulator.presetGenerator.presets.aaf.AAFGetBasicAuthPreset; +import org.onap.simulator.presetGenerator.presets.aaf.AAFGetUrlServicePreset; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId; +import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet; import org.onap.simulator.presetGenerator.presets.mso.changeManagement.PresetMsoChangeManagementBase; import org.onap.simulator.presetGenerator.presets.mso.changeManagement.PresetMsoVnfInPlaceSoftwareUpdate; import org.onap.simulator.presetGenerator.presets.mso.changeManagement.PresetMsoVnfReplace; import org.onap.simulator.presetGenerator.presets.mso.changeManagement.PresetMsoVnfUpdate; -import org.onap.simulator.presetGenerator.presets.aaf.*; -import org.onap.vid.model.mso.*; -import org.onap.vid.model.workflow.*; +import org.onap.vid.model.mso.ChangeManagementRequest; +import org.onap.vid.model.mso.ChangeManagementRequestDetails; +import org.onap.vid.model.mso.CloudConfiguration; +import org.onap.vid.model.mso.MsoExceptionResponse; +import org.onap.vid.model.mso.MsoResponseWrapper2; +import org.onap.vid.model.mso.RelatedInstance; +import org.onap.vid.model.mso.RelatedInstanceList; +import org.onap.vid.model.mso.RequestInfo; +import org.onap.vid.model.mso.RequestParameters; +import org.onap.vid.model.workflow.GetVnfWorkflowRelationRequest; +import org.onap.vid.model.workflow.GetWorkflowsResponse; +import org.onap.vid.model.workflow.VnfDetails; +import org.onap.vid.model.workflow.VnfDetailsWithWorkflows; +import org.onap.vid.model.workflow.VnfWorkflowRelationAllResponse; +import org.onap.vid.model.workflow.VnfWorkflowRelationRequest; +import org.onap.vid.model.workflow.VnfWorkflowRelationResponse; +import org.onap.vid.model.workflow.WorkflowsDetail; +import org.onap.vid.more.LoggerFormatTest; import org.springframework.http.HttpStatus; import org.springframework.util.StopWatch; +import org.springframework.web.client.RestTemplate; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import vid.automation.test.services.SimulatorApi; import vid.automation.test.services.SimulatorApi.RegistrationStrategy; +import vid.automation.test.utils.InsecureHttpsClient; import vid.automation.test.utils.ReadFile; -import javax.ws.rs.HttpMethod; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.GenericType; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.*; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.onap.vid.api.TestUtils.getNestedPropertyInMap; -import static org.testng.AssertJUnit.assertEquals; - //This is integration test that require running tomcat public class ChangeManagementApiTest extends BaseApiTest { @@ -470,6 +495,14 @@ public class ChangeManagementApiTest extends BaseApiTest { Response response = callChangeManagementUpdate(vnfIds, changeManagementRequest); MsoResponseWrapper2 body = response.readEntity(MsoResponseWrapper2.class); assertForHappyPath(vnfIds, body, requestType); + RestTemplate manualRestTemplate = InsecureHttpsClient.newRestTemplate(); + super.loginWithChosenRESTClient(getUserCredentials(), manualRestTemplate); + SimulatorApi.registerExpectationFromPreset( new PresetAAIGetSubscribersGet(), RegistrationStrategy.APPEND); + LoggerFormatTest + .verifyExistenceOfIncomingReqsInAuditLogs(manualRestTemplate, uri, + response.getHeaders().get("X-ECOMP-RequestID-echo").get(0).toString(), + "/vid/change-management/workflow/VidVnf"); + } private ChangeManagementRequest createChangeManagementRequest(VnfIds vnfDetails, String requestType) { diff --git a/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementUserApiLoggingTest.java b/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementUserApiLoggingTest.java index dd58e8198..ac8584406 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementUserApiLoggingTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementUserApiLoggingTest.java @@ -41,6 +41,7 @@ public class ChangeManagementUserApiLoggingTest extends BaseApiTest { String requestId = responseEntity.getHeaders().getFirst("X-ECOMP-RequestID-echo"); LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, requestId, "/mso/orchestrationRequests/", 2); + LoggerFormatTest.verifyExistenceOfIncomingReqsInAuditLogs(restTemplate, uri, requestId, CHANGE_MANAGEMENT + MSO); } @Test diff --git a/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java index 858b2f8ef..918c4131e 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/SdcApiTest.java @@ -23,6 +23,7 @@ package org.onap.vid.api; import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; import static net.javacrumbs.jsonunit.JsonMatchers.jsonStringEquals; import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNot.not; @@ -129,7 +130,9 @@ public class SdcApiTest extends BaseApiTest { ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MACRO_INSTANTIATION_TYPE_UUID), String.class); assertEquals(response.getStatusCode(), HttpStatus.OK); String emptyInstantiationTypeExpectedResponse = loadResourceAsString(EMPTY_INSTANTIATION_TYPE_EXPECTED_RESPONSE); - assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(emptyInstantiationTypeExpectedResponse)))); + assertThat(response.getBody(), jsonEquals(emptyInstantiationTypeExpectedResponse) + .when(IGNORING_ARRAY_ORDER) + .whenIgnoringPaths("service.vidNotions.instantiationUI")); } @Test @@ -149,7 +152,9 @@ public class SdcApiTest extends BaseApiTest { ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + MIN_MAX_INITIAL_UUID), String.class); assertEquals(response.getStatusCode(), HttpStatus.OK); String minMaxInitialExpectedResponse = loadResourceAsString("sdcApiTest/minMaxInitialExpectedResponse.json"); - assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(turnOffInstantiationUI(minMaxInitialExpectedResponse)))); + assertThat(response.getBody(), jsonEquals(minMaxInitialExpectedResponse) + .when(IGNORING_ARRAY_ORDER) + .whenIgnoringPaths("service.vidNotions.instantiationUI")); } @Test @@ -163,12 +168,18 @@ public class SdcApiTest extends BaseApiTest { @Test @FeatureTogglingTest(Features.FLAG_1902_VNF_GROUPING) - public void getServiceModelWithServiceRoleGrouping(){ + public void getServiceModelWithServiceRoleGrouping() throws Exception { registerToSimulatorWithPresets(GROUPING_SERVICE_ROLE_UUID, GROUPING_SERVICE_ROLE_INVARIANT_UUID, GROUPING_SERVICE_ROLE_FILE_PATH); ResponseEntity<String> response = restTemplate.getForEntity(buildUri(SDC_GET_SERVICE_MODEL + GROUPING_SERVICE_ROLE_UUID), String.class); assertEquals(response.getStatusCode(), HttpStatus.OK); String groupingServiceRoleExpectedResponse = loadResourceAsString(GROUPING_SERVICE_ROLE_EXPECTED_RESPONSE); - assertThat("The response is in the format of JSON", response.getBody(), is(jsonStringEquals(groupingServiceRoleExpectedResponse))); + assertThat(response.getBody(), jsonEquals(groupingServiceRoleExpectedResponse) + .when(IGNORING_ARRAY_ORDER) + .whenIgnoringPaths("service.vidNotions.instantiationUI")); + + //assert that instantiationUI is not legacy + JsonNode instantiationUI = objectMapper.readValue(response.getBody(), JsonNode.class).get("service").get("vidNotions").get("instantiationUI"); + assertThat(instantiationUI.asText(), not(equalTo("legacy"))); } private void registerToSimulatorWithPresets(String uuid, String invariantUuid, String pathPath){ @@ -178,15 +189,6 @@ public class SdcApiTest extends BaseApiTest { registerExpectationFromPresets(presets, CLEAR_THEN_SET); } - private String turnOffInstantiationUI(String expectedJson) { - if (!Features.FLAG_5G_IN_NEW_INSTANTIATION_UI.isActive()) { - // replaces the instantiationUI field-value with "legacy", whatever it was - return expectedJson.replaceFirst("(\"instantiationUI\": *\")[^\"]*(\",)", "$1legacy$2"); - } else { - return expectedJson; - } - } - @Test public void withModelFromE2eWithToscaParserButNewFlow_requestModels_expectVnfRelatedVfModulesNotNull() { diff --git a/vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java index f8bdc97e2..5d07a4ee8 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/ServiceTreeApiTest.java @@ -39,6 +39,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.testng.util.RetryAnalyzerCount; import vid.automation.test.services.SimulatorApi; +import vid.automation.test.services.SimulatorApi.RegistrationStrategy; public class ServiceTreeApiTest extends BaseApiTest { @@ -179,7 +180,12 @@ public class ServiceTreeApiTest extends BaseApiTest { .replace("VNF4_INSTANCE_TYPE", vnfPreset4.getInstanceType()); assertJsonEquals(response, expected); + + SimulatorApi.registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), RegistrationStrategy.APPEND); LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, echoedRequestId(responseEntity), "/network/generic-vnfs/generic-vnf/", 5); + // org.onap.vid.aai.AaiClient.getCloudRegionAndTenantByVnfId for presets PresetAAIGetCloudRegionFromVnf is + // PUTing to AAI, so path is just /aai/v../query + LoggerFormatTest.assertHeadersAndMetricLogs(restTemplate, uri, echoedRequestId(responseEntity), "/query", 4); } @Test diff --git a/vid-automation/src/test/java/org/onap/vid/api/VersionControllerApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/VersionControllerApiTest.java index 4dc799193..0574cec17 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/VersionControllerApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/VersionControllerApiTest.java @@ -1,19 +1,18 @@ package org.onap.vid.api; +import java.util.HashMap; import org.junit.Assert; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; import org.testng.annotations.Test; - -import java.util.HashMap; +import vid.automation.test.utils.InsecureHttpsClient; public class VersionControllerApiTest extends BaseApiTest { @Test public void probeRequest_returnsResponseAsExpected() { // without log-in - ResponseEntity<HashMap<String, String>> response = new RestTemplate().exchange( + ResponseEntity<HashMap<String, String>> response = InsecureHttpsClient.newRestTemplate().exchange( uri + "/version", org.springframework.http.HttpMethod.GET, null, diff --git a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java index 6c4058f1e..1105a3f4c 100644 --- a/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java +++ b/vid-automation/src/test/java/org/onap/vid/more/LoggerFormatTest.java @@ -162,9 +162,13 @@ public class LoggerFormatTest extends BaseApiTest { String path){ List<String> logLines = getRequestLogLines(requestId, LogName.audit2019, restTemplate, uri); String requestIdPrefix = "RequestID="; - assertThat("request id must be found in exactly two rows - entry & exit message in audit log, and include the req path", + assertThat("\nENTRY & EXIT logs are expected to include RequestId: " + requestId + + " \nAnd request path: " + + path + + "\nin exactly two rows - inside the audit log matching lines:\n" + + String.join("\n", logLines) + "\n", logLines, - containsInRelativeOrder( + contains( allOf( containsString(requestIdPrefix+requestId), containsString("ENTRY"), diff --git a/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java b/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java index 93ab14036..d4a1ce3f8 100644 --- a/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java +++ b/vid-automation/src/test/java/org/onap/vid/more/RequestIdFilterInstalled.java @@ -136,10 +136,14 @@ public class RequestIdFilterInstalled extends BaseApiTest { @Test public void healthcheck_doGET_RequestIdReceived() { + String path = "/healthCheck"; final Pair<HttpEntity, String> responseAndUuid = makeRequest( - HttpMethod.GET, "/healthCheck", null + HttpMethod.GET, path, null ); assertThatUuidInResponseAndUuidIsInARecentLog(LogName.audit2019, responseAndUuid); + LoggerFormatTest + .verifyExistenceOfIncomingReqsInAuditLogs(restTemplate, uri, + responseAndUuid.getKey().getHeaders().get("X-ECOMP-RequestID-echo").get(0).toString(), path); } private void assertThatUuidInResponseAndUuidIsInARecentLog(LogName logName, Pair<HttpEntity, String> responseAndUuid) { diff --git a/vid-automation/src/test/resources/a-la-carte/redux-a-la-carte-no-testapi.json b/vid-automation/src/test/resources/a-la-carte/redux-a-la-carte-no-testapi.json index a6c4dc16f..dfdab76f7 100644 --- a/vid-automation/src/test/resources/a-la-carte/redux-a-la-carte-no-testapi.json +++ b/vid-automation/src/test/resources/a-la-carte/redux-a-la-carte-no-testapi.json @@ -13,6 +13,7 @@ "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0": { "instanceName": "mimazepubi", "lcpCloudRegionId": "hvf6", + "position": "2", "tenantId": "624eb554b0d147c19ff8885341760481", "rollbackOnFailure": "false", "sdncPreLoad": false, @@ -37,6 +38,7 @@ "instanceName": "puwesovabe", "volumeGroupName": "puwesovabe_vol", "lcpCloudRegionId": "AAIAIC25", + "position": "3", "legacyRegion": "my region", "tenantId": "092eb9e8e4b7412e8787dd091bc58e86", "rollbackOnFailure": "true", @@ -68,6 +70,7 @@ "instanceName": "bnmgtrx", "volumeGroupName": "", "lcpCloudRegionId": "hvf6", + "position": "1", "tenantId": "624eb554b0d147c19ff8885341760481", "rollbackOnFailure": "false", "sdncPreLoad": false, diff --git a/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java b/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java index b6cc6759f..296d9fcbf 100644 --- a/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java +++ b/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Scanner; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.PostConstruct; @@ -253,7 +254,7 @@ public class SimulatorController { String userName = reqUri.substring(reqUri.lastIndexOf('/') + 1); TypedQuery<User> userQuery = entityManager.createQuery("select u from fn_user u where u.loginId = :userName", User.class); userQuery.setParameter("userName", userName); - User user = userQuery.getSingleResult(); + User user = doWithSingleRetry(userQuery::getSingleResult); Gson g = new Gson(); String jsonString = g.toJson(user); @@ -269,7 +270,7 @@ public class SimulatorController { return new ResponseEntity<>("Centralized Role Access is disabled", HttpStatus.SERVICE_UNAVAILABLE); } TypedQuery<Function> userQuery = entityManager.createQuery("select f from fn_function f", Function.class); - List<Function> functions = userQuery.getResultList(); + List<Function> functions = doWithSingleRetry(userQuery::getResultList); Gson g = new Gson(); String jsonString = g.toJson(functions); @@ -341,6 +342,16 @@ public class SimulatorController { return responseEntity; } + private <T> T doWithSingleRetry(Supplier<T> supplier) { + try { + return supplier.get(); + } catch (Exception e) { + logger.error("exception was thrown; will retry the same action one more time", e); + // here exceptions will be thrown + return supplier.get(); + } + } + private void register(SimulatorRequestResponseExpectation expectationModel) throws VidSimulatorException{ //Setting request according to what is passed HttpRequest request = HttpRequest.request(); diff --git a/vid-ext-services-simulator/src/main/resources/download_files/csar15782222_instantiationTypeMacroWithCR.zip b/vid-ext-services-simulator/src/main/resources/download_files/csar15782222_instantiationTypeMacroWithCR.zip Binary files differdeleted file mode 100644 index a189f206b..000000000 --- a/vid-ext-services-simulator/src/main/resources/download_files/csar15782222_instantiationTypeMacroWithCR.zip +++ /dev/null diff --git a/vid-ext-services-simulator/src/main/resources/download_files/csar15782222_instantiationTypeMacro_invariantUUIDAlacarte_withoutNetworks.zip b/vid-ext-services-simulator/src/main/resources/download_files/csar15782222_instantiationTypeMacro_invariantUUIDAlacarte_withoutNetworks.zip Binary files differindex 1f073b472..b3ba46098 100644 --- a/vid-ext-services-simulator/src/main/resources/download_files/csar15782222_instantiationTypeMacro_invariantUUIDAlacarte_withoutNetworks.zip +++ b/vid-ext-services-simulator/src/main/resources/download_files/csar15782222_instantiationTypeMacro_invariantUUIDAlacarte_withoutNetworks.zip diff --git a/vid-ext-services-simulator/src/main/resources/download_files/serviceCreationTest04743c62-ab58-41a0-bc53-1052ef1c094a.zip b/vid-ext-services-simulator/src/main/resources/download_files/serviceCreationTest04743c62-ab58-41a0-bc53-1052ef1c094a.zip Binary files differnew file mode 100644 index 000000000..c93a1cd88 --- /dev/null +++ b/vid-ext-services-simulator/src/main/resources/download_files/serviceCreationTest04743c62-ab58-41a0-bc53-1052ef1c094a.zip diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/available-models-tree/available-models-tree.component.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/available-models-tree/available-models-tree.component.ts index 145ee19da..daaacb55d 100644 --- a/vid-webpack-master/src/app/drawingBoard/service-planning/available-models-tree/available-models-tree.component.ts +++ b/vid-webpack-master/src/app/drawingBoard/service-planning/available-models-tree/available-models-tree.component.ts @@ -93,6 +93,7 @@ export class AvailableModelsTreeComponent { service = {name: ''}; options: ITreeOptions = { + allowDrop:false, nodeHeight: 36, dropSlotHeight: 0, nodeClass: (node: ITreeNode) => { diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.spec.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.spec.ts index 01ae898f5..425568b68 100644 --- a/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.spec.ts +++ b/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.spec.ts @@ -5,14 +5,15 @@ import {DragAndDropService} from "./dragAndDrop.service"; import {AppState} from "../../../../shared/store/reducers"; class MockAppStore<T> { - dispatch(){ + dispatch() { } + getState() { return { global: { flags: { - "FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE" : true + "FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE": true } }, service: { @@ -53,6 +54,7 @@ describe('Drag and drop service', () => { let service: DragAndDropService; let httpMock: HttpTestingController; let store: NgRedux<AppState>; + let nodes; beforeAll(done => (async () => { TestBed.configureTestingModule({ @@ -67,158 +69,142 @@ describe('Drag and drop service', () => { service = injector.get(DragAndDropService); httpMock = injector.get(HttpTestingController); store = injector.get(NgRedux); + + })().then(done).catch(done.fail)); + beforeEach(() => { + nodes = [ + { + "trackById": "ckfqe3sb3y8", + "componentInfoType": "VNF", + "parentType": "", + "type": "VF", + "typeName": "VNF", + "instanceName": "2017-488_PASQUALE-vPE", + "id": "04686zg11ur2", + "children": [ + { + "id": "1150884479608", + "action": "Create", + "instanceName": "puwesovabe", + "name": "puwesovabe", + "type": "VFmodule", + "trackById": "d5if1906rqa", + "parentType": "VNF", + "position": 1, + "componentInfoType": "VFModule", + "errors": {}, + "updatePoistionFunction": () => { + }, + }, + { + "id": "4637423092446", + "action": "Create", + "instanceName": "bnmgtrx", + "name": "bnmgtrx", + "type": "VFmodule", + "trackById": "9ei9adlh27e", + "parentType": "VNF", + "position": 2, + "componentInfoType": "VFModule", + "updatePoistionFunction": () => { + } + } + ], + "errors": {}, + } + ]; + }) + test('drag should execute array_move when the nodes parent are same', () => { - test('drag should move element position', () => { - let nodes = [{ - "modelCustomizationId": "91415b44-753d-494c-926a-456a9172bbb9", - "modelId": "d6557200-ecf2-4641-8094-5393ae3aae60", - "modelUniqueId": "91415b44-753d-494c-926a-456a9172bbb9", - "missingData": false, - "id": "tjjongy92jn", - "action": "Create", - "inMaint": false, - "name": "yoav2_001", - "modelName": "VF_vGeraldine 0", - "type": "VF", - "isEcompGeneratedNaming": true, - "networkStoreKey": "VF_vGeraldine 0:0001", - "vnfStoreKey": "VF_vGeraldine 0:0001", - "typeName": "VNF", - "menuActions": {"edit": {}, "showAuditInfo": {}, "duplicate": {}, "remove": {}, "delete": {}, "undoDelete": {}}, - "isFailed": false, - "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, { - "key": "Orch Status:", - "testId": "orchStatus" - }], - "trackById": "di9khuolht", - "parentType": "", - "position": 0, - "children": [{ - "modelCustomizationId": "f8c040f1-7e51-4a11-aca8-acf256cfd861", - "modelId": "a27f5cfc-7f12-4f99-af08-0af9c3885c87", - "modelUniqueId": "f8c040f1-7e51-4a11-aca8-acf256cfd861", - "missingData": false, - "id": 6654971919519, - "action": "Create", - "name": "VFModule1", - "modelName": "vf_vgeraldine0..VfVgeraldine..base_vflorence..module-0", - "type": "VFmodule", - "isEcompGeneratedNaming": true, - "dynamicInputs": [], - "dynamicModelName": "vf_vgeraldine0..VfVgeraldine..base_vflorence..module-0bykqx", - "typeName": "M", - "menuActions": {"edit": {}, "showAuditInfo": {}, "remove": {}, "delete": {}, "undoDelete": {}}, - "isFailed": false, - "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, { - "key": "Orch Status:", - "testId": "orchStatus" - }], - "trackById": "5pfyfah820h", - "parentType": "VNF", - "position": 0, - "errors": {} - }, { - "modelCustomizationId": "6add59e0-7fe1-4bc4-af48-f8812422ae7c", - "modelId": "41708296-e443-4c71-953f-d9a010f059e1", - "modelUniqueId": "6add59e0-7fe1-4bc4-af48-f8812422ae7c", - "missingData": false, - "id": 987761655742, - "action": "Create", - "name": "VNFModule3", - "modelName": "vf_vgeraldine0..VfVgeraldine..vflorence_gpb..module-2", - "type": "VFmodule", - "isEcompGeneratedNaming": true, - "dynamicInputs": [], - "dynamicModelName": "vf_vgeraldine0..VfVgeraldine..vflorence_gpb..module-2fjrrc", - "typeName": "M", - "menuActions": {"edit": {}, "showAuditInfo": {}, "remove": {}, "delete": {}, "undoDelete": {}}, - "isFailed": false, - "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, { - "key": "Orch Status:", - "testId": "orchStatus" - }], - "trackById": "i3dllio31bb", - "parentType": "VNF", - "position": 1, - "errors": {} - }, { - "modelCustomizationId": "55b1be94-671a-403e-a26c-667e9c47d091", - "modelId": "522159d5-d6e0-4c2a-aa44-5a542a12a830", - "modelUniqueId": "55b1be94-671a-403e-a26c-667e9c47d091", - "missingData": false, - "id": 873798901625, - "action": "Create", - "name": "VFModule2", - "modelName": "vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1", - "type": "VFmodule", - "isEcompGeneratedNaming": true, - "dynamicInputs": [], - "dynamicModelName": "vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1djjni", - "typeName": "M", - "menuActions": {"edit": {}, "showAuditInfo": {}, "remove": {}, "delete": {}, "undoDelete": {}}, - "isFailed": false, - "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, { - "key": "Orch Status:", - "testId": "orchStatus" - }], - "trackById": "w7bvw1nh47s", - "parentType": "VNF", - "position": 2, - "errors": {} - }], - "errors": {} - }, { - "modelCustomizationId": "91415b44-753d-494c-926a-456a9172bbb9", - "modelId": "d6557200-ecf2-4641-8094-5393ae3aae60", - "modelUniqueId": "91415b44-753d-494c-926a-456a9172bbb9", - "missingData": false, - "id": "dywch8hkomi", - "action": "Create", - "inMaint": false, - "name": "yoav2", - "modelName": "VF_vGeraldine 0", - "type": "VF", - "isEcompGeneratedNaming": true, - "networkStoreKey": "VF_vGeraldine 0", - "vnfStoreKey": "VF_vGeraldine 0", - "typeName": "VNF", - "menuActions": {"edit": {}, "showAuditInfo": {}, "duplicate": {}, "remove": {}, "delete": {}, "undoDelete": {}}, - "isFailed": false, - "statusProperties": [{"key": "Prov Status:", "testId": "provStatus"}, { - "key": "Orch Status:", - "testId": "orchStatus" - }], - "trackById": "fjczf1urdqo", - "parentType": "", - "position": 1, - "children": [], - "errors": {} - }]; let from = { + id: "04686zg11ur2", + index: 0, data: { - type: 'VF', - index: 1 + instanceName: 'puwesovabe', + }, + parent: { + data: { + type: 'VF', + index: 0, + trackById: 'ckfqe3sb3y8', + vnfStoreKey: '2017-488_PASQUALE-vPE 0', + } } }; let to = { parent: { + id: "4637423092446", + index: 1, data: { - type: 'VF', - index: 0 + instanceName: 'bnmgtrx', + }, + parent: { + data: { + type: 'VF', + trackById: 'ckfqe3sb3y8', + vnfStoreKey: '2017-488_PASQUALE-vPE 0', + } } } }; - jest.spyOn(service, 'array_move'); - service.drag(store, "serviceInstanceId", nodes, {from, to}); + jest.spyOn(service, 'array_move'); + service.drop(store, "serviceInstanceId", nodes, {from, to}); expect(service.array_move).toHaveBeenCalled(); }); + test('drag shouldnt execute array_move when the nodes parent are different', () => { + + let from = { + id: 1150884479608, + index: 0, + data: { + instanceName: '2017-488_PASQUALE-vPE', + }, + parent: {} + }; + + let to = { + parent: { + id: 4637423092446, + index: 1, + data: { + instanceName: 'bnmgtrx', + }, + parent: { + data: { + type: 'VF', + trackById: '1111', + vnfStoreKey: '2017-488_PASQUALE-vPE 0', + } + } + } + }; + + + jest.spyOn(service, 'array_move'); + + service.drop(store, "serviceInstanceId", nodes, {from, to}); + + jest.clearAllMocks(); + + expect(service.array_move).not.toHaveBeenCalled(); + + }); + + test('drop should change nodes index and position', () => { + + let arr: Array<any> = service.array_move(nodes[0].children, 0, 1, "serviceInstanceId", '') + + expect(arr[0]).toMatchObject({instanceName: "bnmgtrx", position: 1}); + expect(arr[1]).toMatchObject({instanceName: "puwesovabe", position: 2}); + + }); }); diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts index 15da89ad3..96e50178b 100644 --- a/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts +++ b/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts @@ -8,11 +8,29 @@ import * as _ from 'lodash'; @Injectable() export class DragAndDropService { - constructor(private store: NgRedux<AppState>){} + constructor(private store: NgRedux<AppState>) { + } - isAllow(): boolean { + isFlagOn(): boolean { return FeatureFlagsService.getFlagState(Features.FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE, this.store); } + + + /*********************************************************************************************** + if the falg is ON and nodes have same parent + ***********************************************************************************************/ + isAllowDrop(from: any, to: any): boolean { + return this.isFlagOn() && this.isSameParent(from, to); + } + + private isSameParent(from: any, to: any): boolean { + try { + return from.parent.data.trackById === to.parent.parent.data.trackById; + } catch (e) { //parent not found + return false; + } + } + /******************************************************************** * manage drawing-board drag and drop operation * @param nodes - array with elements data. @@ -22,57 +40,67 @@ export class DragAndDropService { * @param to - element to information ************************************************************/ - drag(store, instanceId : string , nodes, {from, to}) :void{ - if (!store.getState().global.flags["FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE"]) return; + drop(store, instanceId: string, nodes, {from, to}): void { + + if (!this.isFlagOn()) return; - let firstLevelNames : DragAndDropModel[] = [ + if (this.isAllowDrop(from, to)) { + let vfModules = nodes.find((parent) => { + return parent.trackById === to.parent.parent.data.trackById; + }).children; + this.array_move(vfModules, from.index, to.parent.index, instanceId, to.parent.parent.data.vnfStoreKey); + } + + /* let firstLevelNames : DragAndDropModel[] = [ new DragAndDropModel('VF',true), new DragAndDropModel('VL',true), new DragAndDropModel('VFmodule',false) - ]; - - const fromObject = _.find(firstLevelNames, ['type', from.data.type]); - const toObject = _.find(firstLevelNames, ['type', to.parent.data.type]); - - /*********************************************************************************************** - if the type are the same and there in same level + same parent -> then change element position - ***********************************************************************************************/ - if(fromObject.isFirstLevel === toObject.isFirstLevel){ // moving element in the same level and in the first level - if(fromObject.isFirstLevel){ - this.array_move(nodes, from.index , to.parent.index, instanceId); - } else if(fromObject.isFirstLevel === toObject.isFirstLevel){ - /* check if they have the same parent */ - if(from.parent.data.trackById === to.parent.parent.data.trackById){ - let vfModules = nodes.find((parents)=> { - return parents.trackById === to.parent.parent.data.trackById; - }).children; - this.array_move(vfModules, from.index , to.parent.index, instanceId, to.parent.parent.data.vnfStoreKey); + ]; + + const fromObject = _.find(firstLevelNames, ['type', from.data.type]); + const toObject = _.find(firstLevelNames, ['type', to.parent.data.type]); + + /!*********************************************************************************************** + if the type are the same and there in same level + same parent -> then change element position + ***********************************************************************************************!/ + if(fromObject.isFirstLevel === toObject.isFirstLevel){ // moving element in the same level and in the first level + if(fromObject.isFirstLevel){ + this.array_move(nodes, from.index , to.parent.index, instanceId); + } else if(fromObject.isFirstLevel === toObject.isFirstLevel){ + /!* check if they have the same parent *!/ + if(from.parent.data.trackById === to.parent.parent.data.trackById){ + let vfModules = nodes.find((parents)=> { + return parents.trackById === to.parent.parent.data.trackById; + }).children; + this.array_move(vfModules, from.index , to.parent.index, instanceId, to.parent.parent.data.vnfStoreKey); + } } - } - } + }*/ } - /******************************************************************** + /******************************************************************** * move element inside array with elements position * @param arr - array with elements data. * @param originalPosition - element original position * @param destPosition - element dest position * @param destPinstanceIdosition - instance id ******************************************************************/ - array_move(arr, originalPosition, destPosition, instanceId : string, parentStoreKey?) { - if (destPosition >= arr.length) { - let k = destPosition - arr.length + 1; - while (k--) { - arr.push(undefined); - } - } - arr.splice(destPosition, 0, arr.splice(originalPosition, 1)[0]); + array_move(arr, originalPosition, destPosition, instanceId: string, parentStoreKey?): Array<any> { + + let moved_node = arr[originalPosition] + + arr.splice(originalPosition, 1); + + arr.splice(destPosition, 0, moved_node); + arr.forEach((item, index) => { - if(item.position !== index){ - item.position = index; + if (item.position !== index + 1) { + item.position = index + 1; item.updatePoistionFunction(this, item, instanceId, parentStoreKey); } }); + + return arr; }; } diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/drawing-board-tree.component.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/drawing-board-tree.component.ts index 0e2d8e276..f3542573d 100644 --- a/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/drawing-board-tree.component.ts +++ b/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/drawing-board-tree.component.ts @@ -127,11 +127,11 @@ export class DrawingBoardTreeComponent implements OnInit, AfterViewInit { nodes = []; serviceModelId: string; options = { - allowDrag: this._dragAndDropService.isAllow(), + allowDrag: this._dragAndDropService.isFlagOn(), actionMapping: { mouse: { drop: (tree:TreeModel, node:TreeNode, $event:any, {from, to}) => { - this._dragAndDropService.drag(this.store, this.serviceModelId, this.nodes, {from, to}); + this._dragAndDropService.drop(this.store, this.serviceModelId, this.nodes, {from, to}); } } }, diff --git a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/service/service.popup.service.ts b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/service/service.popup.service.ts index 7694e6314..3fd44974a 100644 --- a/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/service/service.popup.service.ts +++ b/vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/service/service.popup.service.ts @@ -169,7 +169,7 @@ export class ServicePopupService implements GenericPopupInterface { }; setIsALaCarte = (formValues: any, instantiationType) => { - formValues.isALaCarte = instantiationType === 'ALaCarte'; + formValues.isALaCarte = instantiationType !== 'Macro'; }; setTestApi = (formValues: any) =>{ |