aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java45
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/properties/Features.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java15
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java10
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/Logging.java29
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java19
-rw-r--r--vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties1
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java98
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/LocalWebConfig.java5
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AAIServiceIntegrativeTest.java6
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java15
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeTest.java3
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AAITreeNodeBuilderTest.java53
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java5
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/utils/LoggingTest.java54
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/utils/LoggingUtilsTest.java73
-rw-r--r--vid-app-common/src/test/resources/csars/portMirroringService.zipbin0 -> 31295 bytes
-rw-r--r--vid-app-common/src/test/resources/csars/service-Vocg1804Svc.zipbin0 -> 153401 bytes
20 files changed, 309 insertions, 137 deletions
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
new file mode 100644
index 000000000..c074f31bd
--- /dev/null
+++ b/vid-app-common/src/test/resources/csars/portMirroringService.zip
Binary files differ
diff --git a/vid-app-common/src/test/resources/csars/service-Vocg1804Svc.zip b/vid-app-common/src/test/resources/csars/service-Vocg1804Svc.zip
new file mode 100644
index 000000000..8902c5149
--- /dev/null
+++ b/vid-app-common/src/test/resources/csars/service-Vocg1804Svc.zip
Binary files differ