summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java65
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java88
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java300
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java252
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java53
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java113
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java88
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java (renamed from catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java)177
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java513
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java80
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java511
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java56
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java9
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java282
22 files changed, 1333 insertions, 1323 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index 6752586b80..31281db0c7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -87,6 +87,7 @@ import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
@@ -96,7 +97,6 @@ import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.UploadArtifactInfo;
import org.openecomp.sdc.be.model.UploadCapInfo;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
@@ -105,13 +105,12 @@ import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.parser.ParserException;
/**
* A handler class designed to parse the YAML file of the service template for a JAVA object
*/
-@Component
+@org.springframework.stereotype.Component
public class YamlTemplateParsingHandler {
private static final Pattern propertyValuePattern = Pattern.compile("[ ]*\\{[ ]*(str_replace=|token=|get_property=|concat=|get_attribute=)+");
@@ -134,7 +133,7 @@ public class YamlTemplateParsingHandler {
public ParsedToscaYamlInfo parseResourceInfoFromYAML(String fileName, String resourceYml, Map<String, String> createdNodesToscaResourceNames,
Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName,
- org.openecomp.sdc.be.model.Component component, String interfaceTemplateYaml) {
+ Component component, String interfaceTemplateYaml) {
log.debug("#parseResourceInfoFromYAML - Going to parse yaml {} ", fileName);
Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName);
ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
@@ -145,15 +144,14 @@ public class YamlTemplateParsingHandler {
parsedToscaYamlInfo.setInputs(getInputs(mappedTopologyTemplateInputs));
parsedToscaYamlInfo.setInstances(getInstances(mappedToscaTemplate, createdNodesToscaResourceNames));
parsedToscaYamlInfo.setGroups(getGroups(mappedToscaTemplate, component.getModel()));
- if (component instanceof Resource) {
- parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate, component.getModel()));
- }
- if (getSubstitutionMappings(mappedToscaTemplate) != null) {
+ parsedToscaYamlInfo.setPolicies(getPolicies(mappedToscaTemplate, component.getModel()));
+ Map<String, Object> substitutionMappings = getSubstitutionMappings(mappedToscaTemplate);
+ if (substitutionMappings != null) {
if (component.isService() && !interfaceTemplateYaml.isEmpty()) {
parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml)));
parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate));
}
- parsedToscaYamlInfo.setSubstitutionMappingNodeType((String) getSubstitutionMappings(mappedToscaTemplate).get(NODE_TYPE.getElementName()));
+ parsedToscaYamlInfo.setSubstitutionMappingNodeType((String) substitutionMappings.get(NODE_TYPE.getElementName()));
}
log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName);
return parsedToscaYamlInfo;
@@ -230,10 +228,13 @@ public class YamlTemplateParsingHandler {
return constraints;
}
- private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson, String model) {
- Map<String, Object> foundPolicies = findFirstToscaMapElement(toscaJson, POLICIES).left().on(err -> logPoliciesNotFound(fileName));
+ private Map<String, PolicyDefinition> getPolicies(Map<String, Object> toscaJson, String model) {
+ Map<String, Object> mappedTopologyTemplate = (Map<String, Object>) findToscaElement(toscaJson, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL)
+ .left().on(err -> new HashMap<>());
+ Map<String, Object> foundPolicies = (Map<String, Object>) mappedTopologyTemplate.get(POLICIES.getElementName());
if (MapUtils.isNotEmpty(foundPolicies)) {
- return foundPolicies.entrySet().stream().map(policyToCreate -> createPolicy(policyToCreate, model)).collect(Collectors.toMap(PolicyDefinition::getName, p -> p));
+ return foundPolicies.entrySet().stream().map(policyToCreate -> createPolicy(policyToCreate, model))
+ .collect(Collectors.toMap(PolicyDefinition::getName, p -> p));
}
return Collections.emptyMap();
}
@@ -257,11 +258,6 @@ public class YamlTemplateParsingHandler {
return emptyPolicyDef;
}
- private Map<String, Object> logPoliciesNotFound(String fileName) {
- log.debug("#logPoliciesNotFound - Policies were not found in the yaml template {}.", fileName);
- return Collections.emptyMap();
- }
-
private void validateAndFillPolicy(PolicyDefinition emptyPolicyDefinition, Map<String, Object> policyTemplateJsonMap, String model) {
String policyTypeName = (String) policyTemplateJsonMap.get(TYPE.getElementName());
if (StringUtils.isEmpty(policyTypeName)) {
@@ -364,25 +360,6 @@ public class YamlTemplateParsingHandler {
return new HashMap<>();
}
- private boolean matcheKey(Map<String, Object> foundGroups) {
- if (foundGroups != null && !foundGroups.isEmpty()) {
- for (Map.Entry<String, Object> stringObjectEntry : foundGroups.entrySet()) {
- String key = stringObjectEntry.getKey();
- if (key.contains("group")) {
- if (foundGroups.get(key) instanceof Map) {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- private Map<String, Object> logGroupsNotFound(String fileName) {
- log.debug("#logGroupsNotFound - Groups were not found in the yaml template {}.", fileName);
- return new HashMap<>();
- }
-
private void updateCapabilitiesNames(GroupDefinition group, Map<String, String> capabilityNames) {
if (MapUtils.isNotEmpty(group.getCapabilities())) {
group.getCapabilities().values().stream().flatMap(Collection::stream).filter(cap -> capabilityNames.containsKey(cap.getName()))
@@ -593,7 +570,7 @@ public class YamlTemplateParsingHandler {
if (CollectionUtils.isNotEmpty(missingProperties)) {
if (log.isDebugEnabled()) {
log.debug("#validateProperties - Failed to validate properties. The properties {} are missing on {} of the type {}. ",
- missingProperties.toString(), name, type);
+ missingProperties.toString(), name, type);
}
rollbackWithException(actionStatus, missingProperties.toString(), missingProperties.toString(), name, type);
}
@@ -1045,7 +1022,7 @@ public class YamlTemplateParsingHandler {
@SuppressWarnings("unchecked")
private void findAndFillInputRecursively(Map<String, Object> propValue, UploadPropInfo propertyDef) {
- for (Map.Entry<String,Object> entry : propValue.entrySet()) {
+ for (Map.Entry<String, Object> entry : propValue.entrySet()) {
String propName = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map) {
@@ -1057,9 +1034,7 @@ public class YamlTemplateParsingHandler {
}
private void fillInputsRecursively(UploadPropInfo propertyDef, String propName, List<Object> inputs) {
- inputs.stream()
- .filter(Map.class::isInstance)
- .forEach(o -> fillInputRecursively(propName, (Map<String, Object>) o, propertyDef));
+ inputs.stream().filter(Map.class::isInstance).forEach(o -> fillInputRecursively(propName, (Map<String, Object>) o, propertyDef));
}
@SuppressWarnings("unchecked")
@@ -1102,8 +1077,8 @@ public class YamlTemplateParsingHandler {
private void failOnMissingCapabilityTypes(GroupDefinition groupDefinition, List<String> missingCapTypes) {
if (log.isDebugEnabled()) {
log.debug(
- "#failOnMissingCapabilityTypes - Failed to validate the capabilities of the group {}. The capability types {} are missing on the group type {}. ",
- groupDefinition.getName(), missingCapTypes.toString(), groupDefinition.getType());
+ "#failOnMissingCapabilityTypes - Failed to validate the capabilities of the group {}. The capability types {} are missing on the group type {}. ",
+ groupDefinition.getName(), missingCapTypes.toString(), groupDefinition.getType());
}
if (CollectionUtils.isNotEmpty(missingCapTypes)) {
rollbackWithException(ActionStatus.MISSING_CAPABILITY_TYPE, missingCapTypes.toString());
@@ -1113,8 +1088,8 @@ public class YamlTemplateParsingHandler {
private void failOnMissingCapabilityNames(GroupDefinition groupDefinition, List<String> missingCapNames) {
if (log.isDebugEnabled()) {
log.debug(
- "#failOnMissingCapabilityNames - Failed to validate the capabilities of the group {}. The capabilities with the names {} are missing on the group type {}. ",
- groupDefinition.getName(), missingCapNames.toString(), groupDefinition.getType());
+ "#failOnMissingCapabilityNames - Failed to validate the capabilities of the group {}. The capabilities with the names {} are missing on the group type {}. ",
+ groupDefinition.getName(), missingCapNames.toString(), groupDefinition.getType());
}
rollbackWithException(ActionStatus.MISSING_CAPABILITIES, missingCapNames.toString(), CapabilityDataDefinition.OwnerType.GROUP.getValue(),
groupDefinition.getName());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index 4268d91dc9..a1f28299a1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -42,9 +42,9 @@ import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
@@ -579,7 +579,7 @@ public abstract class BaseBusinessLogic {
DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
if (dataTypeDefinition == null) {
log.debug(INVALID_PROPERTY_TYPE, propertyType);
- return Either.right(false);
+ return Either.right(false);
}
ImmutablePair<JsonElement, Boolean> validateResult = dataTypeValidatorConverter
.validateAndUpdate(value, dataTypeDefinition, dataTypes);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
index 6625d72bcf..4372564bbd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
@@ -104,6 +104,7 @@ import org.springframework.beans.factory.annotation.Autowired;
public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
private static final Logger log = Logger.getLogger(ComponentBusinessLogic.class.getName());
+
protected final GroupBusinessLogic groupBusinessLogic;
protected ArtifactsBusinessLogic artifactsBusinessLogic;
protected GenericTypeBusinessLogic genericTypeBusinessLogic;
@@ -432,8 +433,9 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = null;
try {
validateUserExists(userId);
- nonCheckoutCompResponse = toscaOperationFacade
- .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName, includeNormativeExtensionModels);
+ nonCheckoutCompResponse = toscaOperationFacade
+ .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName,
+ includeNormativeExtensionModels);
if (nonCheckoutCompResponse.isLeft()) {
log.debug("Retrieved Resource successfully.");
return Either.left(nonCheckoutCompResponse.left().value());
@@ -441,7 +443,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return Either
.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())));
} finally {
- if(nonCheckoutCompResponse != null && nonCheckoutCompResponse.isLeft() ) {
+ if (nonCheckoutCompResponse != null && nonCheckoutCompResponse.isLeft()) {
janusGraphDao.commit();
}
}
@@ -547,7 +549,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
final ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream()
.filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().orElseThrow(() -> {
throw new ByResponseFormatComponentException(
- componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
+ componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
});
return artifactsBusinessLogic.handleDownloadToscaModelRequest(component, csarArtifact);
}
@@ -691,7 +693,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
});
return componentNonGenericInputs;
}
-
+
protected void generatePropertiesFromGenericType(final Component component, final Resource genericType) {
if (CollectionUtils.isEmpty(genericType.getProperties())) {
return;
@@ -708,6 +710,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
component.getProperties().forEach(propertyDefinition -> propertyDefinition.setUniqueId(null));
}
+
protected <T extends Component> Resource fetchAndSetDerivedFromGenericType(final T component) {
return fetchAndSetDerivedFromGenericType(component, null);
}
@@ -916,7 +919,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
if (validPropertiesMerge.isRight()) {
if (log.isDebugEnabled()) {
log.debug("property {} cannot be overriden, check out performed without upgrading to latest generic",
- validPropertiesMerge.right().value());
+ validPropertiesMerge.right().value());
}
return false;
}
@@ -926,7 +929,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
if (validAttributesMerge.isRight()) {
if (log.isDebugEnabled()) {
log.debug("attribute {} cannot be overriden, check out performed without upgrading to latest generic",
- validAttributesMerge.right().value());
+ validAttributesMerge.right().value());
}
return false;
}
@@ -998,7 +1001,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
protected Either<Component, ResponseFormat> updateCatalog(Component component, ChangeTypeEnum changeStatus) {
if (log.isDebugEnabled()) {
log.debug("update Catalog start with Component Type {} And Componet Name {} with change status {}",
- component.getComponentType().name(),component.getName(), changeStatus.name());
+ component.getComponentType().name(), component.getName(), changeStatus.name());
}
ActionStatus status = catalogOperations.updateCatalog(changeStatus, component);
if (status != ActionStatus.OK) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index 3a1c55a31f..7719187cda 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -177,10 +177,9 @@ public final class ImportUtils {
public static Either<Object, ResultStatusEnum> findToscaElement(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum elementName,
ToscaElementTypeEnum elementType) {
- List<Object> foundElements = new ArrayList<>();
- findToscaElements(toscaJson, elementName.getElementName(), elementType, foundElements);
- if (!isEmpty(foundElements)) {
- return Either.left(foundElements.get(0));
+ final var toscaElements = findToscaElements(toscaJson, elementName.getElementName(), elementType, new ArrayList<>());
+ if (toscaElements.isLeft() && CollectionUtils.isNotEmpty(toscaElements.left().value())) {
+ return Either.left(toscaElements.left().value().get(0));
}
return Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
index f8aab3def1..2f01ef3ecc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
@@ -46,6 +46,7 @@ import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.validation.PolicyUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -125,33 +126,32 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
}
}
- public Map<String, PolicyDefinition> createPoliciesFromParsedCsar(Component component,
- final Map<String, PolicyDefinition> incomingPolicyDefinitions) {
+ public Map<String, PolicyDefinition> createPolicies(final Component component,
+ final Map<String, PolicyDefinition> incomingPolicyDefinitions) {
if (MapUtils.isEmpty(incomingPolicyDefinitions)) {
return Collections.emptyMap();
}
- Map<String, PolicyDefinition> createdPolicies = new HashMap<>();
- for (Map.Entry<String, PolicyDefinition> policyEntry : incomingPolicyDefinitions.entrySet()) {
- PolicyDefinition incomingPolicyDefinition = policyEntry.getValue();
- String policyName = incomingPolicyDefinition.getName();
+ final Map<String, PolicyDefinition> createdPolicies = new HashMap<>();
+ for (final PolicyDefinition incomingPolicyDefinition : incomingPolicyDefinitions.values()) {
+ final String policyName = incomingPolicyDefinition.getName();
log.trace("Going to create policy {}", incomingPolicyDefinition);
loggerSupportability
.log(LoggerSupportabilityActions.CREATE_GROUP_POLICY, component.getComponentMetadataForSupportLog(), StatusCode.STARTED,
"Start to create policy: {} for component {}", policyName, component.getName());
- String policyType = incomingPolicyDefinition.getType();
+ final String policyType = incomingPolicyDefinition.getType();
if (StringUtils.isEmpty(policyType)) {
log.debug("Policy type '{}' for policy '{}' not found.", policyType, policyName);
throw new ByActionStatusComponentException(ActionStatus.POLICY_MISSING_POLICY_TYPE, policyName);
}
// create policyDefinition
- String policyTypeName = incomingPolicyDefinition.getPolicyTypeName();
+ final String policyTypeName = incomingPolicyDefinition.getPolicyTypeName();
PolicyDefinition createdPolicyDefinition = createPolicy(policyTypeName, component);
// set isFromCsar
createdPolicyDefinition.setToscaPresentationValue(JsonPresentationFields.IS_FROM_CSAR, true);
// link policy to component
component.addPolicy(createdPolicyDefinition);
// process targets
- Map<PolicyTargetType, List<String>> policyTargets = incomingPolicyDefinition.getTargets();
+ final Map<PolicyTargetType, List<String>> policyTargets = incomingPolicyDefinition.getTargets();
createdPolicyDefinition = setUpdatePolicyTargets(component, createdPolicyDefinition, policyTargets);
// process policy properties
List<PropertyDataDefinition> properties = incomingPolicyDefinition.getProperties();
@@ -179,38 +179,60 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
if (MapUtils.isEmpty(targets)) {
return policyDefinition;
}
- List<String> targetsToUpdate = targets.get(PolicyTargetType.COMPONENT_INSTANCES);
- if (CollectionUtils.isEmpty(targetsToUpdate)) {
+ final List<String> componentInstancesTargetsToUpdate = targets.get(PolicyTargetType.COMPONENT_INSTANCES);
+ final List<String> groupsTargetsToUpdate = targets.get(PolicyTargetType.GROUPS);
+ if (CollectionUtils.isEmpty(componentInstancesTargetsToUpdate) && CollectionUtils.isEmpty(groupsTargetsToUpdate)) {
return policyDefinition;
}
+
+ final List<String> allTargets = joinLists(componentInstancesTargetsToUpdate, groupsTargetsToUpdate);
+
// update targets to uniqueIds of respective component instance
- List<String> targetsUniqueIds = new ArrayList<>();
- for (String targetName : targetsToUpdate) {
- Optional<ComponentInstance> componentInstance = component.getComponentInstanceByName(targetName);
- String componentUniqueId = componentInstance
- .orElseThrow(() -> new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND)).getUniqueId();
- targetsUniqueIds.add(componentUniqueId);
- }
- EnumMap<PolicyTargetType, List<String>> updatedTargets = new EnumMap<>(PolicyTargetType.class);
- updatedTargets.put(PolicyTargetType.COMPONENT_INSTANCES, targetsUniqueIds);
+ final List<String> targetsGroupsUniqueIds = new ArrayList<>();
+ final List<String> targetsInstanceUniqueIds = new ArrayList<>();
+ for (final String targetName : allTargets) {
+ final String groupsTargetUniqueIdForTargetName = getTargetGroupUniqueIdByTargetName(component, targetName);
+ if (groupsTargetUniqueIdForTargetName != null) {
+ targetsGroupsUniqueIds.add(groupsTargetUniqueIdForTargetName);
+ }
+ final String instanceTargetUniqueIdForTargetName = getTargetInstanceUniqueIdByTargetName(component, targetName);
+ if (instanceTargetUniqueIdForTargetName != null) {
+ targetsInstanceUniqueIds.add(instanceTargetUniqueIdForTargetName);
+ }
+ }
+ if (targetsGroupsUniqueIds.isEmpty() && targetsInstanceUniqueIds.isEmpty()) {
+ throw new ByActionStatusComponentException(ActionStatus.POLICY_TARGET_DOES_NOT_EXIST);
+ }
+ final EnumMap<PolicyTargetType, List<String>> updatedTargets = new EnumMap<>(PolicyTargetType.class);
+ if (!targetsGroupsUniqueIds.isEmpty()) {
+ updatedTargets.put(PolicyTargetType.GROUPS, targetsGroupsUniqueIds);
+ }
+ if (!targetsInstanceUniqueIds.isEmpty()) {
+ updatedTargets.put(PolicyTargetType.COMPONENT_INSTANCES, targetsInstanceUniqueIds);
+ }
policyDefinition.setTargets(updatedTargets);
- policyDefinition = validateAndUpdatePolicyTargets(component, policyDefinition.getUniqueId(), policyDefinition.getTargets());
- return policyDefinition;
+ return validateAndUpdatePolicyTargets(component, policyDefinition.getUniqueId(), policyDefinition.getTargets());
}
- public Either<List<PolicyDefinition>, ResponseFormat> getPoliciesList(ComponentTypeEnum componentType, String componentId, String userId) {
- Either<List<PolicyDefinition>, ResponseFormat> result;
- log.trace("#getPolicies - starting to retrieve policies of component {}. ", componentId);
- try {
- Component component = validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId);
- result = Either.left(component.resolvePoliciesList());
- } catch (Exception e) {
- log.error("#getPolicy - the exception occurred upon retrieving policies list of component {}: ", componentId, e);
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ private List<String> joinLists(final List<String> a, final List<String> b) {
+ final List<String> result = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(a)) {
+ result.addAll(a);
+ }
+ if (CollectionUtils.isNotEmpty(b)) {
+ result.addAll(b);
}
return result;
}
+ private String getTargetGroupUniqueIdByTargetName(final Component component, final String targetName) {
+ return component.getGroupByInvariantName(targetName).map(GroupDataDefinition::getUniqueId).orElse(null);
+ }
+
+ private String getTargetInstanceUniqueIdByTargetName(final Component component, final String targetName) {
+ return component.getComponentInstanceByName(targetName).map(ComponentInstance::getUniqueId).orElse(null);
+ }
+
/**
* Retrieves the policy of the component by UniqueId
*
@@ -266,7 +288,6 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
* @return a policy or an error in a response format
*/
public PolicyDefinition deletePolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId, boolean shouldLock) {
- PolicyDefinition result = null;
log.trace("#deletePolicy - starting to update the policy {} on the component {}. ", policyId, componentId);
Component component = null;
boolean failed = false;
@@ -358,7 +379,6 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
public PolicyDefinition updatePolicyTargets(ComponentTypeEnum componentTypeEnum, String componentId, String policyId,
Map<PolicyTargetType, List<String>> targets, String userId) {
- Either<PolicyDefinition, ResponseFormat> result = null;
log.debug("updating the policy id {} targets with the components {}. ", policyId, componentId);
boolean failed = false;
try {
@@ -554,7 +574,7 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
}
private PolicyTypeDefinition validatePolicyTypeOnCreatePolicy(String policyTypeName, Component component) {
- Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyTypeByType = policyTypeOperation.getLatestPolicyTypeByType(policyTypeName, component.getModel());
+ final var latestPolicyTypeByType = policyTypeOperation.getLatestPolicyTypeByType(policyTypeName, component.getModel());
if (latestPolicyTypeByType.isRight()) {
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(latestPolicyTypeByType.right().value()));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 6d5829e0fd..1f107e4ec1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -1762,7 +1762,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Resource createPoliciesOnResource(Resource resource, Map<String, PolicyDefinition> policies) {
- policyBusinessLogic.createPoliciesFromParsedCsar(resource, policies);
+ policyBusinessLogic.createPolicies(resource, policies);
return resource;
}
@@ -1929,7 +1929,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
.addPropertyToComponent(propertyDefinition, resource);
if (addPropertyEither.isRight()) {
- final String error = String.format("failed to add properties from yaml: {}", addPropertyEither.right().value());
+ final String error = String.format("failed to add properties from yaml: %s", addPropertyEither.right().value());
loggerSupportability.log(LoggerSupportabilityActions.CREATE_PROPERTIES, resource.getComponentMetadataForSupportLog(),
StatusCode.ERROR,
error);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index 8dac6ffc08..2cccc31ded 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -100,9 +100,9 @@ import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceDistributionReqInfo;
import org.openecomp.sdc.be.impl.ForwardingPathUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
@@ -119,12 +119,12 @@ import org.openecomp.sdc.be.model.GroupInstanceProperty;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Model;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.Model;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ForwardingPathOperation;
@@ -184,22 +184,19 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private final ServiceDistributionValidation serviceDistributionValidation;
private final ForwardingPathValidator forwardingPathValidator;
private final UiComponentDataConverter uiComponentDataConverter;
+ private final ModelOperation modelOperation;
+ private final ServiceRoleValidator serviceRoleValidator;
+ private final ServiceInstantiationTypeValidator serviceInstantiationTypeValidator;
+ private final ServiceCategoryValidator serviceCategoryValidator;
+ private final ServiceValidator serviceValidator;
+ private final PolicyBusinessLogic policyBusinessLogic;
+ private final GroupBusinessLogic groupBusinessLogic;
private ForwardingPathOperation forwardingPathOperation;
private AuditCassandraDao auditCassandraDao;
private ServiceTypeValidator serviceTypeValidator;
private List<ServiceCreationPlugin> serviceCreationPluginList;
private ServiceFunctionValidator serviceFunctionValidator;
- @Autowired
- private ServiceRoleValidator serviceRoleValidator;
- @Autowired
- private ServiceInstantiationTypeValidator serviceInstantiationTypeValidator;
- @Autowired
- private ServiceCategoryValidator serviceCategoryValidator;
- @Autowired
- private ServiceValidator serviceValidator;
- private final ModelOperation modelOperation;
- @Autowired
public ServiceBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
IGroupTypeOperation groupTypeOperation, GroupBusinessLogic groupBusinessLogic, InterfaceOperation interfaceOperation,
InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsBusinessLogic artifactsBusinessLogic,
@@ -209,7 +206,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
ComponentContactIdValidator componentContactIdValidator, ComponentNameValidator componentNameValidator,
ComponentTagsValidator componentTagsValidator, ComponentValidator componentValidator,
ComponentIconValidator componentIconValidator, ComponentProjectCodeValidator componentProjectCodeValidator,
- ComponentDescriptionValidator componentDescriptionValidator, ModelOperation modelOperation) {
+ ComponentDescriptionValidator componentDescriptionValidator, ModelOperation modelOperation,
+ final ServiceRoleValidator serviceRoleValidator,
+ final ServiceInstantiationTypeValidator serviceInstantiationTypeValidator,
+ final ServiceCategoryValidator serviceCategoryValidator, final ServiceValidator serviceValidator,
+ final PolicyBusinessLogic policyBusinessLogic) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
@@ -219,6 +220,12 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
this.forwardingPathValidator = forwardingPathValidator;
this.uiComponentDataConverter = uiComponentDataConverter;
this.modelOperation = modelOperation;
+ this.serviceRoleValidator = serviceRoleValidator;
+ this.serviceInstantiationTypeValidator = serviceInstantiationTypeValidator;
+ this.serviceCategoryValidator = serviceCategoryValidator;
+ this.serviceValidator = serviceValidator;
+ this.policyBusinessLogic = policyBusinessLogic;
+ this.groupBusinessLogic = groupBusinessLogic;
}
@Autowired
@@ -637,16 +644,6 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.left(archiveAudit);
}
- @VisibleForTesting
- public void setServiceValidator(ServiceValidator serviceValidator) {
- this.serviceValidator = serviceValidator;
- }
-
- @VisibleForTesting
- public void setServiceCategoryValidator(ServiceCategoryValidator serviceCategoryValidator) {
- this.serviceCategoryValidator = serviceCategoryValidator;
- }
-
private List<Map<String, Object>> getAuditingFieldsList(List<? extends AuditingGenericEvent> prevVerAuditList) {
List<Map<String, Object>> prevVerAudit = new ArrayList<>();
for (AuditingGenericEvent auditEvent : prevVerAuditList) {
@@ -666,7 +663,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
public Either<Service, ResponseFormat> createService(Service service, User user) {
// get user details
user = validateUser(user, "Create Service", service, AuditingActionEnum.CREATE_RESOURCE, false);
- log.debug("User returned from validation: " + user.toString());
+ log.debug("User returned from validation: {}", user);
// validate user role
validateUserRole(user, service, new ArrayList<>(), AuditingActionEnum.CREATE_RESOURCE, null);
service.setCreatorUserId(user.getUserId());
@@ -683,7 +680,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
if (createServiceResponse.isRight()) {
return createServiceResponse;
}
- return createServiceByDao(service, user).left().bind(c -> updateCatalog(c, ChangeTypeEnum.LIFECYCLE).left().map(r -> (Service) r));
+ return createServiceByDao(service, user).left().bind(c -> updateCatalog(c, ChangeTypeEnum.LIFECYCLE).left().map(Service.class::cast));
}
private void checkFieldsForOverideAttampt(Service service) {
@@ -863,14 +860,14 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
BeEcompErrorManager.getInstance().logBeSystemError("Update Service Metadata");
log.debug("failed to update sevice {}", serviceToUpdate.getUniqueId());
return (componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }).left().bind(c -> updateCatalogAndCommit(c));
+ }).left().bind(this::updateCatalogAndCommit);
} finally {
graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
}
}
private Either<Service, ResponseFormat> updateCatalogAndCommit(Service service) {
- Either<Service, ResponseFormat> res = updateCatalog(service, ChangeTypeEnum.LIFECYCLE).left().map(s -> (Service) s);
+ Either<Service, ResponseFormat> res = updateCatalog(service, ChangeTypeEnum.LIFECYCLE).left().map(Service.class::cast);
janusGraphDao.commit();
return res;
}
@@ -1483,7 +1480,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
Boolean isServiceApi) {
ArtifactDefinition artifactInfo = artifactsBusinessLogic
.createArtifactPlaceHolderInfo(serviceId, logicalName, artifactInfoMap, user, ArtifactGroupTypeEnum.INFORMATIONAL);
- if (isServiceApi) {
+ if (Boolean.TRUE.equals(isServiceApi)) {
artifactInfo.setMandatory(false);
artifactInfo.setServiceApi(true);
}
@@ -1556,7 +1553,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.right(response);
}
Service service = serviceRes.left().value();
- if (service.isArchived()) {
+ if (Boolean.TRUE.equals(service.isArchived())) {
log.info("Component is archived. Component id: {}", serviceId);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_IS_ARCHIVED, service.getName()));
}
@@ -1658,123 +1655,6 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return asList;
}
- private List<GroupInstance> collectGroupsInstanceForCompInstance(ComponentInstance currVF) {
- Map<String, ArtifactDefinition> deploymentArtifacts = currVF.getDeploymentArtifacts();
- if (currVF.getGroupInstances() != null) {
- currVF.getGroupInstances().forEach(gi -> gi.alignArtifactsUuid(deploymentArtifacts));
- }
- return currVF.getGroupInstances();
- }
-
- private ArtifactDefinition getVfModuleInstArtifactForCompInstance(ComponentInstance currVF, Service service, Wrapper<String> payloadWrapper,
- Wrapper<ResponseFormat> responseWrapper) {
- ArtifactDefinition vfModuleAertifact = null;
- if (MapUtils.isNotEmpty(currVF.getDeploymentArtifacts())) {
- final Optional<ArtifactDefinition> optionalVfModuleArtifact = currVF.getDeploymentArtifacts().values().stream()
- .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.getType())).findAny();
- if (optionalVfModuleArtifact.isPresent()) {
- vfModuleAertifact = optionalVfModuleArtifact.get();
- }
- }
- if (vfModuleAertifact == null) {
- Either<ArtifactDefinition, ResponseFormat> createVfModuleArtifact = createVfModuleArtifact(currVF, service,
- payloadWrapper.getInnerElement());
- if (createVfModuleArtifact.isLeft()) {
- vfModuleAertifact = createVfModuleArtifact.left().value();
- } else {
- responseWrapper.setInnerElement(createVfModuleArtifact.right().value());
- }
- }
- return vfModuleAertifact;
- }
-
- private void fillVfModuleInstHeatEnvPayload(List<GroupInstance> groupsForCurrVF, Wrapper<String> payloadWrapper) {
- List<VfModuleArtifactPayload> vfModulePayloads = new ArrayList<>();
- if (groupsForCurrVF != null) {
- for (GroupInstance groupInstance : groupsForCurrVF) {
- VfModuleArtifactPayload modulePayload = new VfModuleArtifactPayload(groupInstance);
- vfModulePayloads.add(modulePayload);
- }
- vfModulePayloads.sort(VfModuleArtifactPayload::compareByGroupName);
- final Gson gson = new GsonBuilder().setPrettyPrinting().create();
- String vfModulePayloadString = gson.toJson(vfModulePayloads);
- payloadWrapper.setInnerElement(vfModulePayloadString);
- }
- }
-
- private Either<ArtifactDefinition, ResponseFormat> generateVfModuleInstanceArtifact(User modifier, ComponentInstance currVFInstance,
- Service service, boolean shouldLock, boolean inTransaction) {
- ArtifactDefinition vfModuleArtifact = null;
- Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
- Wrapper<String> payloadWrapper = new Wrapper<>();
- List<GroupInstance> groupsForCurrVF = collectGroupsInstanceForCompInstance(currVFInstance);
- if (responseWrapper.isEmpty()) {
- fillVfModuleInstHeatEnvPayload(groupsForCurrVF, payloadWrapper);
- }
- if (responseWrapper.isEmpty() && payloadWrapper.getInnerElement() != null) {
- vfModuleArtifact = getVfModuleInstArtifactForCompInstance(currVFInstance, service, payloadWrapper, responseWrapper);
- }
- if (responseWrapper.isEmpty() && vfModuleArtifact != null) {
- vfModuleArtifact = fillVfModulePayload(modifier, currVFInstance, vfModuleArtifact, shouldLock, inTransaction, payloadWrapper,
- responseWrapper, service);
- }
- Either<ArtifactDefinition, ResponseFormat> result;
- if (responseWrapper.isEmpty()) {
- result = Either.left(vfModuleArtifact);
- } else {
- result = Either.right(responseWrapper.getInnerElement());
- }
- return result;
- }
-
- private ArtifactDefinition fillVfModulePayload(User modifier, ComponentInstance currVF, ArtifactDefinition vfModuleArtifact, boolean shouldLock,
- boolean inTransaction, Wrapper<String> payloadWrapper, Wrapper<ResponseFormat> responseWrapper,
- Service service) {
- ArtifactDefinition result = null;
- Either<ArtifactDefinition, ResponseFormat> eitherPayload = artifactsBusinessLogic
- .generateArtifactPayload(vfModuleArtifact, ComponentTypeEnum.RESOURCE_INSTANCE, service, currVF.getName(), modifier, shouldLock,
- inTransaction, System::currentTimeMillis, () -> Either.left(
- artifactsBusinessLogic.createEsArtifactData(vfModuleArtifact, payloadWrapper.getInnerElement().getBytes(StandardCharsets.UTF_8))),
- currVF.getUniqueId());
- if (eitherPayload.isLeft()) {
- result = eitherPayload.left().value();
- } else {
- responseWrapper.setInnerElement(eitherPayload.right().value());
- }
- if (result == null) {
- result = vfModuleArtifact;
- }
- return result;
- }
-
- private Either<ArtifactDefinition, ResponseFormat> createVfModuleArtifact(ComponentInstance currVF, Service service,
- String vfModulePayloadString) {
- ArtifactDefinition vfModuleArtifactDefinition = new ArtifactDefinition();
- String newCheckSum = null;
- vfModuleArtifactDefinition.setDescription("Auto-generated VF Modules information artifact");
- vfModuleArtifactDefinition.setArtifactDisplayName("Vf Modules Metadata");
- vfModuleArtifactDefinition.setArtifactType(ArtifactTypeEnum.VF_MODULES_METADATA.getType());
- vfModuleArtifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
- vfModuleArtifactDefinition.setArtifactLabel("vfModulesMetadata");
- vfModuleArtifactDefinition.setTimeout(0);
- vfModuleArtifactDefinition.setArtifactName(currVF.getNormalizedName() + "_modules.json");
- vfModuleArtifactDefinition.setPayloadData(vfModulePayloadString);
- if (vfModulePayloadString != null) {
- newCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(vfModulePayloadString.getBytes());
- }
- vfModuleArtifactDefinition.setArtifactChecksum(newCheckSum);
- Either<ArtifactDefinition, StorageOperationStatus> addArtifactToComponent = artifactToscaOperation
- .addArtifactToComponent(vfModuleArtifactDefinition, service, NodeTypeEnum.ResourceInstance, true, currVF.getUniqueId());
- Either<ArtifactDefinition, ResponseFormat> result;
- if (addArtifactToComponent.isLeft()) {
- result = Either.left(addArtifactToComponent.left().value());
- } else {
- result = Either
- .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtifactToComponent.right().value())));
- }
- return result;
- }
-
public Either<Service, ResponseFormat> generateHeatEnvArtifacts(Service service, User modifier, boolean shouldLock, boolean inTransaction) {
Function<ComponentInstance, List<ArtifactGenerator<ArtifactDefinition>>> artifactTaskGeneratorCreator = resourceInstance ->
// Get All Deployment Artifacts
@@ -2063,7 +1943,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
log.error("Exception occured during update Group Instance property values: {}", e.getMessage(), e);
actionResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ if (lockResult != null && lockResult.isLeft() && Boolean.TRUE.equals(lockResult.left().value())) {
graphLockOperation.unlockComponentByName(component.getSystemName(), component.getUniqueId(), NodeTypeEnum.Service);
}
}
@@ -2249,12 +2129,12 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return latestByName.isLeft();
}
- abstract class ArtifactGenerator<CallVal> implements Callable<Either<CallVal, ResponseFormat>> {
+ interface ArtifactGenerator<CallVal> extends Callable<Either<CallVal, ResponseFormat>> {
}
@Getter
- class HeatEnvArtifactGenerator extends ArtifactGenerator<ArtifactDefinition> {
+ class HeatEnvArtifactGenerator implements ArtifactGenerator<ArtifactDefinition> {
private ArtifactDefinition artifactDefinition;
private Service service;
@@ -2283,7 +2163,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
}
- class VfModuleArtifactGenerator extends ArtifactGenerator<ArtifactDefinition> {
+ class VfModuleArtifactGenerator implements ArtifactGenerator<ArtifactDefinition> {
boolean shouldLock;
boolean inTransaction;
@@ -2301,6 +2181,126 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
this.inTransaction = inTransaction;
}
+ private Either<ArtifactDefinition, ResponseFormat> generateVfModuleInstanceArtifact(User modifier, ComponentInstance currVFInstance,
+ Service service, boolean shouldLock,
+ boolean inTransaction) {
+ ArtifactDefinition vfModuleArtifact = null;
+ Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
+ Wrapper<String> payloadWrapper = new Wrapper<>();
+ List<GroupInstance> groupsForCurrVF = collectGroupsInstanceForCompInstance(currVFInstance);
+ if (responseWrapper.isEmpty()) {
+ fillVfModuleInstHeatEnvPayload(groupsForCurrVF, payloadWrapper);
+ }
+ if (responseWrapper.isEmpty() && payloadWrapper.getInnerElement() != null) {
+ vfModuleArtifact = getVfModuleInstArtifactForCompInstance(currVFInstance, service, payloadWrapper, responseWrapper);
+ }
+ if (responseWrapper.isEmpty() && vfModuleArtifact != null) {
+ vfModuleArtifact = fillVfModulePayload(modifier, currVFInstance, vfModuleArtifact, shouldLock, inTransaction, payloadWrapper,
+ responseWrapper, service);
+ }
+ Either<ArtifactDefinition, ResponseFormat> result;
+ if (responseWrapper.isEmpty()) {
+ result = Either.left(vfModuleArtifact);
+ } else {
+ result = Either.right(responseWrapper.getInnerElement());
+ }
+ return result;
+ }
+
+ private void fillVfModuleInstHeatEnvPayload(List<GroupInstance> groupsForCurrVF, Wrapper<String> payloadWrapper) {
+ List<VfModuleArtifactPayload> vfModulePayloads = new ArrayList<>();
+ if (groupsForCurrVF != null) {
+ for (GroupInstance groupInstance : groupsForCurrVF) {
+ VfModuleArtifactPayload modulePayload = new VfModuleArtifactPayload(groupInstance);
+ vfModulePayloads.add(modulePayload);
+ }
+ vfModulePayloads.sort(VfModuleArtifactPayload::compareByGroupName);
+ final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ String vfModulePayloadString = gson.toJson(vfModulePayloads);
+ payloadWrapper.setInnerElement(vfModulePayloadString);
+ }
+ }
+
+ private ArtifactDefinition getVfModuleInstArtifactForCompInstance(ComponentInstance currVF, Service service, Wrapper<String> payloadWrapper,
+ Wrapper<ResponseFormat> responseWrapper) {
+ ArtifactDefinition vfModuleAertifact = null;
+ if (MapUtils.isNotEmpty(currVF.getDeploymentArtifacts())) {
+ final Optional<ArtifactDefinition> optionalVfModuleArtifact = currVF.getDeploymentArtifacts().values().stream()
+ .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.getType())).findAny();
+ if (optionalVfModuleArtifact.isPresent()) {
+ vfModuleAertifact = optionalVfModuleArtifact.get();
+ }
+ }
+ if (vfModuleAertifact == null) {
+ Either<ArtifactDefinition, ResponseFormat> createVfModuleArtifact = createVfModuleArtifact(currVF, service,
+ payloadWrapper.getInnerElement());
+ if (createVfModuleArtifact.isLeft()) {
+ vfModuleAertifact = createVfModuleArtifact.left().value();
+ } else {
+ responseWrapper.setInnerElement(createVfModuleArtifact.right().value());
+ }
+ }
+ return vfModuleAertifact;
+ }
+
+ private List<GroupInstance> collectGroupsInstanceForCompInstance(ComponentInstance currVF) {
+ Map<String, ArtifactDefinition> deploymentArtifacts = currVF.getDeploymentArtifacts();
+ if (currVF.getGroupInstances() != null) {
+ currVF.getGroupInstances().forEach(gi -> gi.alignArtifactsUuid(deploymentArtifacts));
+ }
+ return currVF.getGroupInstances();
+ }
+
+ private Either<ArtifactDefinition, ResponseFormat> createVfModuleArtifact(ComponentInstance currVF, Service service,
+ String vfModulePayloadString) {
+ ArtifactDefinition vfModuleArtifactDefinition = new ArtifactDefinition();
+ String newCheckSum = null;
+ vfModuleArtifactDefinition.setDescription("Auto-generated VF Modules information artifact");
+ vfModuleArtifactDefinition.setArtifactDisplayName("Vf Modules Metadata");
+ vfModuleArtifactDefinition.setArtifactType(ArtifactTypeEnum.VF_MODULES_METADATA.getType());
+ vfModuleArtifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ vfModuleArtifactDefinition.setArtifactLabel("vfModulesMetadata");
+ vfModuleArtifactDefinition.setTimeout(0);
+ vfModuleArtifactDefinition.setArtifactName(currVF.getNormalizedName() + "_modules.json");
+ vfModuleArtifactDefinition.setPayloadData(vfModulePayloadString);
+ if (vfModulePayloadString != null) {
+ newCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(vfModulePayloadString.getBytes());
+ }
+ vfModuleArtifactDefinition.setArtifactChecksum(newCheckSum);
+ Either<ArtifactDefinition, StorageOperationStatus> addArtifactToComponent = artifactToscaOperation
+ .addArtifactToComponent(vfModuleArtifactDefinition, service, NodeTypeEnum.ResourceInstance, true, currVF.getUniqueId());
+ Either<ArtifactDefinition, ResponseFormat> result;
+ if (addArtifactToComponent.isLeft()) {
+ result = Either.left(addArtifactToComponent.left().value());
+ } else {
+ result = Either
+ .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtifactToComponent.right().value())));
+ }
+ return result;
+ }
+
+ private ArtifactDefinition fillVfModulePayload(User modifier, ComponentInstance currVF, ArtifactDefinition vfModuleArtifact,
+ boolean shouldLock,
+ boolean inTransaction, Wrapper<String> payloadWrapper, Wrapper<ResponseFormat> responseWrapper,
+ Service service) {
+ ArtifactDefinition result = null;
+ Either<ArtifactDefinition, ResponseFormat> eitherPayload = artifactsBusinessLogic
+ .generateArtifactPayload(vfModuleArtifact, ComponentTypeEnum.RESOURCE_INSTANCE, service, currVF.getName(), modifier, shouldLock,
+ inTransaction, System::currentTimeMillis, () -> Either.left(
+ artifactsBusinessLogic.createEsArtifactData(vfModuleArtifact,
+ payloadWrapper.getInnerElement().getBytes(StandardCharsets.UTF_8))),
+ currVF.getUniqueId());
+ if (eitherPayload.isLeft()) {
+ result = eitherPayload.left().value();
+ } else {
+ responseWrapper.setInnerElement(eitherPayload.right().value());
+ }
+ if (result == null) {
+ result = vfModuleArtifact;
+ }
+ return result;
+ }
+
@Override
public Either<ArtifactDefinition, ResponseFormat> call() throws Exception {
return generateVfModuleInstanceArtifact(user, componentInstance, service, shouldLock, inTransaction);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index dd55ae8612..34460f46d5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -67,6 +67,7 @@ import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
@@ -97,6 +98,7 @@ import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RelationshipImpl;
import org.openecomp.sdc.be.model.RelationshipInfo;
@@ -119,6 +121,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
@@ -135,7 +138,6 @@ import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.beans.factory.annotation.Autowired;
import org.yaml.snakeyaml.Yaml;
@Getter
@@ -143,9 +145,9 @@ import org.yaml.snakeyaml.Yaml;
@org.springframework.stereotype.Component("serviceImportBusinessLogic")
public class ServiceImportBusinessLogic {
+ protected static final String CREATE_RESOURCE = "Create Resource";
private static final String INITIAL_VERSION = "0.1";
- private static final String CREATE_RESOURCE = "Create Resource";
- private static final String IN_RESOURCE = " in resource {} ";
+ private static final String IN_RESOURCE = " in resource {} ";
private static final String COMPONENT_INSTANCE_WITH_NAME = "component instance with name ";
private static final String COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE = "component instance with name {} in resource {} ";
private static final String CERTIFICATION_ON_IMPORT = "certification on import";
@@ -154,30 +156,25 @@ public class ServiceImportBusinessLogic {
private static final String CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES = "Create Resource - validateCapabilityTypesCreate";
private static final String CATEGORY_IS_EMPTY = "Resource category is empty";
private static final Logger log = Logger.getLogger(ServiceImportBusinessLogic.class);
+
+ private final ComponentsUtils componentsUtils;
+ private final ToscaOperationFacade toscaOperationFacade;
private final UiComponentDataConverter uiComponentDataConverter;
private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
- @Autowired
- protected ComponentsUtils componentsUtils;
- @Autowired
- protected ToscaOperationFacade toscaOperationFacade;
- @Autowired
- private ServiceBusinessLogic serviceBusinessLogic;
- @Autowired
- private CsarBusinessLogic csarBusinessLogic;
- @Autowired
- private CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic;
- @Autowired
- private LifecycleBusinessLogic lifecycleBusinessLogic;
- @Autowired
- private CompositionBusinessLogic compositionBusinessLogic;
- @Autowired
- private ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic;
- @Autowired
- private ServiceImportParseLogic serviceImportParseLogic;
- @Autowired
- private ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
-
- @Autowired
+ private final ServiceBusinessLogic serviceBusinessLogic;
+ private final CsarBusinessLogic csarBusinessLogic;
+ private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic;
+ private final LifecycleBusinessLogic lifecycleBusinessLogic;
+ private final CompositionBusinessLogic compositionBusinessLogic;
+ private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic;
+ private final ServiceImportParseLogic serviceImportParseLogic;
+ private final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
+ private final GroupBusinessLogic groupBusinessLogic;
+ private final PolicyBusinessLogic policyBusinessLogic;
+ private final JanusGraphDao janusGraphDao;
+ private final ArtifactsBusinessLogic artifactsBusinessLogic;
+ private final IGraphLockOperation graphLockOperation;
+
public ServiceImportBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
IGroupTypeOperation groupTypeOperation, GroupBusinessLogic groupBusinessLogic,
InterfaceOperation interfaceOperation, InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
@@ -189,17 +186,33 @@ public class ServiceImportBusinessLogic {
ComponentContactIdValidator componentContactIdValidator, ComponentNameValidator componentNameValidator,
ComponentTagsValidator componentTagsValidator, ComponentValidator componentValidator,
ComponentIconValidator componentIconValidator, ComponentProjectCodeValidator componentProjectCodeValidator,
- ComponentDescriptionValidator componentDescriptionValidator) {
+ ComponentDescriptionValidator componentDescriptionValidator, final ComponentsUtils componentsUtils,
+ final ToscaOperationFacade toscaOperationFacade, final ServiceBusinessLogic serviceBusinessLogic,
+ final CsarBusinessLogic csarBusinessLogic,
+ final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic,
+ final LifecycleBusinessLogic lifecycleBusinessLogic, final CompositionBusinessLogic compositionBusinessLogic,
+ final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic,
+ final ServiceImportParseLogic serviceImportParseLogic,
+ final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic,
+ final PolicyBusinessLogic policyBusinessLogic, final JanusGraphDao janusGraphDao,
+ final IGraphLockOperation graphLockOperation) {
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
this.uiComponentDataConverter = uiComponentDataConverter;
- }
-
- public ServiceBusinessLogic getServiceBusinessLogic() {
- return serviceBusinessLogic;
- }
-
- public void setServiceBusinessLogic(ServiceBusinessLogic serviceBusinessLogic) {
+ this.componentsUtils = componentsUtils;
+ this.toscaOperationFacade = toscaOperationFacade;
this.serviceBusinessLogic = serviceBusinessLogic;
+ this.csarBusinessLogic = csarBusinessLogic;
+ this.csarArtifactsAndGroupsBusinessLogic = csarArtifactsAndGroupsBusinessLogic;
+ this.lifecycleBusinessLogic = lifecycleBusinessLogic;
+ this.compositionBusinessLogic = compositionBusinessLogic;
+ this.resourceDataMergeBusinessLogic = resourceDataMergeBusinessLogic;
+ this.serviceImportParseLogic = serviceImportParseLogic;
+ this.componentNodeFilterBusinessLogic = componentNodeFilterBusinessLogic;
+ this.groupBusinessLogic = groupBusinessLogic;
+ this.policyBusinessLogic = policyBusinessLogic;
+ this.janusGraphDao = janusGraphDao;
+ this.artifactsBusinessLogic = artifactsBusinessLogic;
+ this.graphLockOperation = graphLockOperation;
}
public Service createService(Service service, AuditingActionEnum auditingAction, User user, Map<String, byte[]> csarUIPayload,
@@ -211,7 +224,10 @@ public class ServiceImportBusinessLogic {
service.setConformanceLevel(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel());
service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
try {
- serviceBusinessLogic.validateServiceBeforeCreate(service, user, auditingAction);
+ final var serviceBeforeCreate = serviceBusinessLogic.validateServiceBeforeCreate(service, user, auditingAction);
+ if (serviceBeforeCreate.isRight()) {
+ throw new ComponentException(ActionStatus.GENERAL_ERROR);
+ }
log.debug("enter createService,validateServiceBeforeCreate success");
String csarUUID = payloadName == null ? service.getCsarUUID() : payloadName;
log.debug("enter createService,get csarUUID:{}", csarUUID);
@@ -318,8 +334,8 @@ public class ServiceImportBusinessLogic {
service = createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap, topologyTemplateYaml,
nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName);
log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
- Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = serviceBusinessLogic.groupBusinessLogic
- .validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), service.getSystemName());
+ Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes
+ = groupBusinessLogic.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), service.getSystemName());
if (validateUpdateVfGroupNamesRes.isRight()) {
serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
@@ -337,6 +353,13 @@ public class ServiceImportBusinessLogic {
throw new ComponentException(createGroupsOnResource.right().value());
}
service = createGroupsOnResource.left().value();
+
+ Either<Service, ResponseFormat> createPoliciesOnResource = createPoliciesOnResource(service, parsedToscaYamlInfo.getPolicies());
+ if (createPoliciesOnResource.isRight()) {
+ serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
+ throw new ComponentException(createPoliciesOnResource.right().value());
+ }
+ service = createPoliciesOnResource.left().value();
log.trace("************* Going to add artifacts from yaml {}", yamlName);
NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToCreate);
Either<Service, ResponseFormat> createArtifactsEither = createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,
@@ -353,10 +376,10 @@ public class ServiceImportBusinessLogic {
throw e;
} finally {
if (!inTransaction) {
- serviceBusinessLogic.janusGraphDao.commit();
+ janusGraphDao.commit();
}
if (shouldLock) {
- serviceBusinessLogic.graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Resource);
+ graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Resource);
}
}
}
@@ -445,11 +468,11 @@ public class ServiceImportBusinessLogic {
Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, artifactOperation, null, true, shouldLock, inTransaction);
}
- protected Either<Resource, ResponseFormat> getResourceResponseFormatEither(Resource resource, CsarInfo csarInfo,
- List<ArtifactDefinition> createdArtifacts,
- ArtifactOperationInfo artifactOperation, boolean shouldLock,
- boolean inTransaction,
- Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus) {
+ private Either<Resource, ResponseFormat> getResourceResponseFormatEither(Resource resource, CsarInfo csarInfo,
+ List<ArtifactDefinition> createdArtifacts,
+ ArtifactOperationInfo artifactOperation, boolean shouldLock,
+ boolean inTransaction,
+ Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus) {
try {
String artifactsFileName = artifacsMetaCsarStatus.left().value().getKey();
String artifactsContents = artifacsMetaCsarStatus.left().value().getValue();
@@ -561,7 +584,7 @@ public class ServiceImportBusinessLogic {
if (operation.getArtifactOperationEnum() == ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE
|| operation.getArtifactOperationEnum() == ArtifactsBusinessLogic.ArtifactOperationEnum.DELETE) {
if (serviceImportParseLogic.isArtifactDeletionRequired(artifactId, artifactFileBytes, isFromCsar)) {
- Either<ArtifactDefinition, ResponseFormat> handleDelete = serviceBusinessLogic.artifactsBusinessLogic
+ Either<ArtifactDefinition, ResponseFormat> handleDelete = artifactsBusinessLogic
.handleDelete(component.getUniqueId(), artifactId, csarInfo.getModifier(), component, shouldLock, inTransaction);
if (handleDelete.isRight()) {
result = Either.right(handleDelete.right().value());
@@ -589,10 +612,10 @@ public class ServiceImportBusinessLogic {
return result;
}
- public Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource,
- Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
- List<ArtifactDefinition> createdArtifacts, User user,
- boolean inTransaction, boolean ignoreLifecycleState) {
+ private Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource,
+ Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
+ List<ArtifactDefinition> createdArtifacts, User user,
+ boolean inTransaction, boolean ignoreLifecycleState) {
List<ArtifactDefinition> handleNodeTypeArtifactsRequestRes;
Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = null;
Either<Resource, ResponseFormat> changeStateResponse;
@@ -610,7 +633,7 @@ public class ServiceImportBusinessLogic {
List<ArtifactDefinition> curArtifactsToHandle = curOperationEntry.getValue();
if (curArtifactsToHandle != null && !curArtifactsToHandle.isEmpty()) {
log.debug("************* Going to {} artifact to vfc {}", curOperation.name(), nodeTypeResource.getName());
- handleNodeTypeArtifactsRequestRes = serviceBusinessLogic.artifactsBusinessLogic
+ handleNodeTypeArtifactsRequestRes = artifactsBusinessLogic
.handleArtifactsRequestForInnerVfcComponent(curArtifactsToHandle, nodeTypeResource, user, createdArtifacts,
new ArtifactOperationInfo(false, ignoreLifecycleState, curOperation), false, inTransaction);
if (ArtifactsBusinessLogic.ArtifactOperationEnum.isCreateOrLink(curOperation)) {
@@ -630,7 +653,7 @@ public class ServiceImportBusinessLogic {
return handleNodeTypeArtifactsRes;
}
- protected Either<Resource, ResponseFormat> checkoutResource(Resource resource, User user, boolean inTransaction) {
+ private Either<Resource, ResponseFormat> checkoutResource(Resource resource, User user, boolean inTransaction) {
Either<Resource, ResponseFormat> checkoutResourceRes;
try {
if (!resource.getComponentMetadataDefinition().getMetadataDataDefinition().getState()
@@ -768,7 +791,7 @@ public class ServiceImportBusinessLogic {
return organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifacts, component, user);
}
- protected boolean isNonMetaArtifact(ArtifactDefinition artifact) {
+ private boolean isNonMetaArtifact(ArtifactDefinition artifact) {
boolean result = true;
if (artifact.getMandatory() || artifact.getArtifactName() == null || !isValidArtifactType(artifact)) {
result = false;
@@ -777,12 +800,10 @@ public class ServiceImportBusinessLogic {
}
private boolean isValidArtifactType(ArtifactDefinition artifact) {
- boolean result = true;
- if (artifact.getArtifactType() == null || ArtifactTypeEnum.findType(artifact.getArtifactType()).equals(ArtifactTypeEnum.VENDOR_LICENSE)
- || ArtifactTypeEnum.findType(artifact.getArtifactType()).equals(ArtifactTypeEnum.VF_LICENSE)) {
- result = false;
- }
- return result;
+ final String artifactType = artifact.getArtifactType();
+ return artifactType != null
+ && !ArtifactTypeEnum.VENDOR_LICENSE.getType().equals(ArtifactTypeEnum.findType(artifactType))
+ && !ArtifactTypeEnum.VF_LICENSE.getType().equals(ArtifactTypeEnum.findType(artifactType));
}
protected Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat> organizeVfCsarArtifactsByArtifactOperation(
@@ -815,12 +836,11 @@ public class ServiceImportBusinessLogic {
ResponseFormat responseFormat = ResponseFormatManager.getInstance()
.getResponseFormat(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, currNewArtifact.getArtifactName(),
currNewArtifact.getArtifactType(), foundArtifact.getArtifactType());
- AuditingActionEnum auditingAction = serviceBusinessLogic.artifactsBusinessLogic
- .detectAuditingType(new ArtifactOperationInfo(false, false, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE),
- foundArtifact.getArtifactChecksum());
- serviceBusinessLogic.artifactsBusinessLogic
- .handleAuditing(auditingAction, component, component.getUniqueId(), user, null, null, foundArtifact.getUniqueId(),
- responseFormat, component.getComponentType(), null);
+ AuditingActionEnum auditingAction = artifactsBusinessLogic.detectAuditingType(
+ new ArtifactOperationInfo(false, false, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE),
+ foundArtifact.getArtifactChecksum());
+ artifactsBusinessLogic.handleAuditing(auditingAction, component, component.getUniqueId(), user, null, null,
+ foundArtifact.getUniqueId(), responseFormat, component.getComponentType(), null);
responseWrapper.setInnerElement(responseFormat);
break;
}
@@ -863,14 +883,6 @@ public class ServiceImportBusinessLogic {
return nodeTypeArtifactsToHandleRes;
}
- public ComponentsUtils getComponentsUtils() {
- return this.componentsUtils;
- }
-
- public void setComponentsUtils(ComponentsUtils componentsUtils) {
- this.componentsUtils = componentsUtils;
- }
-
protected Either<List<CsarUtils.NonMetaArtifactInfo>, String> getValidArtifactNames(CsarInfo csarInfo,
Map<String, Set<List<String>>> collectedWarningMessages) {
List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = csarInfo.getCsar().entrySet().stream()
@@ -891,14 +903,27 @@ public class ServiceImportBusinessLogic {
List<GroupDefinition> groupsAsList = updateGroupsMembersUsingResource(groups, service);
serviceImportParseLogic.handleGroupsProperties(service, groups);
serviceImportParseLogic.fillGroupsFinalFields(groupsAsList);
- Either<List<GroupDefinition>, ResponseFormat> createGroups = serviceBusinessLogic.groupBusinessLogic
- .createGroups(service, groupsAsList, true);
+ Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.createGroups(service, groupsAsList, true);
if (createGroups.isRight()) {
return Either.right(createGroups.right().value());
}
} else {
return Either.left(service);
}
+ return getServiceResponseFormatEither(service);
+ }
+
+ private Either<Service, ResponseFormat> createPoliciesOnResource(Service service,
+ Map<String, PolicyDefinition> policies) {
+ if (MapUtils.isNotEmpty(policies)) {
+ policyBusinessLogic.createPolicies(service, policies);
+ } else {
+ return Either.left(service);
+ }
+ return getServiceResponseFormatEither(service);
+ }
+
+ private Either<Service, ResponseFormat> getServiceResponseFormatEither(Service service) {
Either<Service, StorageOperationStatus> updatedResource = toscaOperationFacade.getToscaElement(service.getUniqueId());
if (updatedResource.isRight()) {
ResponseFormat responseFormat = componentsUtils
@@ -1232,11 +1257,11 @@ public class ServiceImportBusinessLogic {
return result;
}
- public Map<String, Resource> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource, Map<String, Object> mappedToscaTemplate,
- boolean needLock,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
- Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo) {
+ private Map<String, Resource> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource, Map<String, Object> mappedToscaTemplate,
+ boolean needLock,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
+ Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo) {
Either<String, ImportUtils.ResultStatusEnum> toscaVersion = findFirstToscaStringElement(mappedToscaTemplate,
TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION);
if (toscaVersion.isRight()) {
@@ -1304,7 +1329,7 @@ public class ServiceImportBusinessLogic {
log.debug("************* Going to create all nodes {}", yamlName);
handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts,
nodeTypesInfo, csarInfo, nodeName);
- if (!MapUtils.isEmpty(uploadComponentInstanceInfoMap)) {
+ if (MapUtils.isNotEmpty(uploadComponentInstanceInfoMap)) {
log.debug("************* Going to create all resource instances {}", yamlName);
service = createServiceInstances(yamlName, service, uploadComponentInstanceInfoMap, csarInfo.getCreatedNodes());
log.debug("************* Going to create all relations {}", yamlName);
@@ -1364,7 +1389,6 @@ public class ServiceImportBusinessLogic {
service = getResourceAfterCreateRelations(service);
addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations);
serviceImportParseLogic.associateResourceInstances(yamlName, service, relations);
- handleSubstitutionMappings(service, uploadResInstancesMap);
log.debug("************* in create relations, getResource start");
Either<Service, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(service.getUniqueId());
log.debug("************* in create relations, getResource end");
@@ -1574,7 +1598,7 @@ public class ServiceImportBusinessLogic {
originResource.getCapabilities().forEach((k, v) -> serviceImportParseLogic.addCapabilities(originCapabilities, k, v));
uploadComponentInstanceInfo.getCapabilities().values()
.forEach(l -> serviceImportParseLogic.addCapabilitiesProperties(newPropertiesMap, l));
- updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap, originResource.getModel());
+ updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap);
} else {
originCapabilities = originResource.getCapabilities();
}
@@ -1583,7 +1607,7 @@ public class ServiceImportBusinessLogic {
protected void updateCapabilityPropertiesValues(Map<String, DataTypeDefinition> allDataTypes,
Map<String, List<CapabilityDefinition>> originCapabilities,
- Map<String, Map<String, UploadPropInfo>> newPropertiesMap, String model) {
+ Map<String, Map<String, UploadPropInfo>> newPropertiesMap) {
originCapabilities.values().stream().flatMap(Collection::stream).filter(c -> newPropertiesMap.containsKey(c.getName()))
.forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()), allDataTypes));
}
@@ -1630,25 +1654,6 @@ public class ServiceImportBusinessLogic {
return originResource;
}
- protected void handleSubstitutionMappings(Service service, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
- if (false) {
- Either<Resource, StorageOperationStatus> getResourceRes = toscaOperationFacade.getToscaFullElement(service.getUniqueId());
- if (getResourceRes.isRight()) {
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), service,
- ComponentTypeEnum.SERVICE);
- throw new ComponentException(responseFormat);
- }
- getResourceRes = updateCalculatedCapReqWithSubstitutionMappings(getResourceRes.left().value(), uploadResInstancesMap);
- if (getResourceRes.isRight()) {
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), service,
- ComponentTypeEnum.SERVICE);
- throw new ComponentException(responseFormat);
- }
- }
- }
-
protected Either<Resource, StorageOperationStatus> updateCalculatedCapReqWithSubstitutionMappings(Resource resource,
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
Either<Resource, StorageOperationStatus> updateRes = null;
@@ -1818,15 +1823,15 @@ public class ServiceImportBusinessLogic {
log.debug("try to find aviable Capability req name is {} ", validReq.getName());
CapabilityDefinition aviableCapForRel = serviceImportParseLogic
.findAvailableCapabilityByTypeOrName(validReq, currentCapCompInstance, uploadRegInfo);
- reqAndRelationshipPair.setCapability(aviableCapForRel.getName());
- reqAndRelationshipPair.setCapabilityUid(aviableCapForRel.getUniqueId());
- reqAndRelationshipPair.setCapabilityOwnerId(aviableCapForRel.getOwnerId());
if (aviableCapForRel == null) {
BeEcompErrorManager.getInstance().logInternalDataError(
"aviable capability was not found. req name is " + validReq.getName() + " component instance is " + currentCapCompInstance
.getUniqueId(), service.getUniqueId(), BeEcompErrorManager.ErrorSeverity.ERROR);
return componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
}
+ reqAndRelationshipPair.setCapability(aviableCapForRel.getName());
+ reqAndRelationshipPair.setCapabilityUid(aviableCapForRel.getUniqueId());
+ reqAndRelationshipPair.setCapabilityOwnerId(aviableCapForRel.getOwnerId());
CapabilityRequirementRelationship capReqRel = new CapabilityRequirementRelationship();
capReqRel.setRelation(reqAndRelationshipPair);
reqAndRelationshipPairList.add(capReqRel);
@@ -2144,8 +2149,8 @@ public class ServiceImportBusinessLogic {
.auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum);
throw e;
}
- Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = serviceBusinessLogic.groupBusinessLogic
- .validateUpdateVfGroupNames(uploadComponentInstanceInfoMap.getGroups(), preparedResource.getSystemName());
+ Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNames(
+ uploadComponentInstanceInfoMap.getGroups(), preparedResource.getSystemName());
if (validateUpdateVfGroupNamesRes.isRight()) {
throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
}
@@ -2237,8 +2242,8 @@ public class ServiceImportBusinessLogic {
nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName);
log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
// validate update vf module group names
- Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = serviceBusinessLogic.groupBusinessLogic
- .validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), resource.getSystemName());
+ Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic.validateUpdateVfGroupNames(
+ parsedToscaYamlInfo.getGroups(), resource.getSystemName());
if (validateUpdateVfGroupNamesRes.isRight()) {
serviceImportParseLogic.rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
@@ -2274,11 +2279,10 @@ public class ServiceImportBusinessLogic {
throw e;
} finally {
if (!inTransaction) {
- serviceBusinessLogic.janusGraphDao.commit();
+ janusGraphDao.commit();
}
if (shouldLock) {
- serviceBusinessLogic.graphLockOperation
- .unlockComponentByName(resource.getSystemName(), resource.getUniqueId(), NodeTypeEnum.Resource);
+ graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(), NodeTypeEnum.Resource);
}
}
}
@@ -2288,8 +2292,7 @@ public class ServiceImportBusinessLogic {
List<GroupDefinition> groupsAsList = updateGroupsMembersUsingResource(groups, resource);
serviceImportParseLogic.handleGroupsProperties(resource, groups);
serviceImportParseLogic.fillGroupsFinalFields(groupsAsList);
- Either<List<GroupDefinition>, ResponseFormat> createGroups = serviceBusinessLogic.groupBusinessLogic
- .createGroups(resource, groupsAsList, true);
+ Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.createGroups(resource, groupsAsList, true);
if (createGroups.isRight()) {
return Either.right(createGroups.right().value());
}
@@ -2407,13 +2410,13 @@ public class ServiceImportBusinessLogic {
} finally {
if (resourcePair == null) {
BeEcompErrorManager.getInstance().logBeSystemError("Change LifecycleState - Certify");
- serviceBusinessLogic.janusGraphDao.rollback();
+ janusGraphDao.rollback();
} else if (!inTransaction) {
- serviceBusinessLogic.janusGraphDao.commit();
+ janusGraphDao.commit();
}
if (needLock) {
log.debug("unlock resource {}", lockedResourceId);
- serviceBusinessLogic.graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
+ graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
}
}
}
@@ -2491,23 +2494,24 @@ public class ServiceImportBusinessLogic {
Resource vfcCreated = null;
while (nodesNameValueIter.hasNext()) {
Map.Entry<String, Object> nodeType = nodesNameValueIter.next();
+ String nodeTypeKey = nodeType.getKey();
Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle =
- nodeTypesArtifactsToHandle == null || nodeTypesArtifactsToHandle.isEmpty() ? null : nodeTypesArtifactsToHandle.get(nodeType.getKey());
- if (nodeTypesInfo.containsKey(nodeType.getKey())) {
+ nodeTypesArtifactsToHandle == null || nodeTypesArtifactsToHandle.isEmpty() ? null : nodeTypesArtifactsToHandle.get(nodeTypeKey);
+ if (nodeTypesInfo.containsKey(nodeTypeKey)) {
vfcCreated = handleNestedVfc(service, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
- nodeType.getKey());
- log.trace("************* Finished to handle nested vfc {}", nodeType.getKey());
+ nodeTypeKey);
+ log.trace("************* Finished to handle nested vfc {}", nodeTypeKey);
} else if (csarInfo.getCreatedNodesToscaResourceNames() != null && !csarInfo.getCreatedNodesToscaResourceNames()
- .containsKey(nodeType.getKey())) {
+ .containsKey(nodeTypeKey)) {
ImmutablePair<Resource, ActionStatus> resourceCreated = serviceImportParseLogic
.createNodeTypeResourceFromYaml(yamlName, nodeType, csarInfo.getModifier(), mapToConvert, service, needLock,
nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, true, csarInfo, true);
- log.debug("************* Finished to create node {}", nodeType.getKey());
+ log.debug("************* Finished to create node {}", nodeTypeKey);
vfcCreated = resourceCreated.getLeft();
- csarInfo.getCreatedNodesToscaResourceNames().put(nodeType.getKey(), vfcCreated.getName());
+ csarInfo.getCreatedNodesToscaResourceNames().put(nodeTypeKey, vfcCreated.getName());
}
if (vfcCreated != null) {
- csarInfo.getCreatedNodes().put(nodeType.getKey(), vfcCreated);
+ csarInfo.getCreatedNodes().put(nodeTypeKey, vfcCreated);
}
mapToConvert.remove(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName());
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
index 63abf26ef4..7a5b90976f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
@@ -32,7 +32,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import lombok.Getter;
-import lombok.Setter;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -118,7 +117,6 @@ import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@Getter
-@Setter
@org.springframework.stereotype.Component
public class ServiceImportParseLogic {
@@ -134,25 +132,46 @@ public class ServiceImportParseLogic {
private static final String CATEGORY_IS_EMPTY = "Resource category is empty";
private static final Logger log = Logger.getLogger(ServiceImportParseLogic.class);
@Autowired
- private ServiceBusinessLogic serviceBusinessLogic;
+ private final ServiceBusinessLogic serviceBusinessLogic;
@Autowired
- private ComponentsUtils componentsUtils;
+ private final ComponentsUtils componentsUtils;
@Autowired
- private ToscaOperationFacade toscaOperationFacade;
+ private final ToscaOperationFacade toscaOperationFacade;
@Autowired
- private LifecycleBusinessLogic lifecycleBusinessLogic;
+ private final LifecycleBusinessLogic lifecycleBusinessLogic;
@Autowired
- private InputsBusinessLogic inputsBusinessLogic;
+ private final InputsBusinessLogic inputsBusinessLogic;
@Autowired
- private ResourceImportManager resourceImportManager;
+ private final ResourceImportManager resourceImportManager;
@Autowired
- private ComponentSubstitutionFilterBusinessLogic substitutionFilterBusinessLogic;
+ private final ComponentSubstitutionFilterBusinessLogic substitutionFilterBusinessLogic;
@Autowired
- private IInterfaceLifecycleOperation interfaceTypeOperation = null;
+ private final IInterfaceLifecycleOperation interfaceTypeOperation;
@Autowired
- private ICapabilityTypeOperation capabilityTypeOperation = null;
+ private final ICapabilityTypeOperation capabilityTypeOperation;
@Autowired
- private ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
+ private final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
+ private final GroupBusinessLogic groupBusinessLogic;
+
+ public ServiceImportParseLogic(final ServiceBusinessLogic serviceBusinessLogic, final ComponentsUtils componentsUtils,
+ final ToscaOperationFacade toscaOperationFacade, final LifecycleBusinessLogic lifecycleBusinessLogic,
+ final InputsBusinessLogic inputsBusinessLogic, final ResourceImportManager resourceImportManager,
+ final ComponentSubstitutionFilterBusinessLogic substitutionFilterBusinessLogic,
+ final IInterfaceLifecycleOperation interfaceTypeOperation, final ICapabilityTypeOperation capabilityTypeOperation,
+ final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic,
+ final GroupBusinessLogic groupBusinessLogic) {
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ this.componentsUtils = componentsUtils;
+ this.toscaOperationFacade = toscaOperationFacade;
+ this.lifecycleBusinessLogic = lifecycleBusinessLogic;
+ this.inputsBusinessLogic = inputsBusinessLogic;
+ this.resourceImportManager = resourceImportManager;
+ this.substitutionFilterBusinessLogic = substitutionFilterBusinessLogic;
+ this.interfaceTypeOperation = interfaceTypeOperation;
+ this.capabilityTypeOperation = capabilityTypeOperation;
+ this.componentNodeFilterBusinessLogic = componentNodeFilterBusinessLogic;
+ this.groupBusinessLogic = groupBusinessLogic;
+ }
public Either<Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle(
Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, Service oldResource) {
@@ -1634,18 +1653,16 @@ public class ServiceImportParseLogic {
if (isNotEmpty(groupsToCreate)) {
fillGroupsFinalFields(groupsToCreate);
if (isNotEmpty(groupsFromResource)) {
- serviceBusinessLogic.groupBusinessLogic.addGroups(resource, groupsToCreate, true).left()
- .on(serviceBusinessLogic::throwComponentException);
+ groupBusinessLogic.addGroups(resource, groupsToCreate, true).left().on(serviceBusinessLogic::throwComponentException);
} else {
- serviceBusinessLogic.groupBusinessLogic.createGroups(resource, groupsToCreate, true).left()
- .on(serviceBusinessLogic::throwComponentException);
+ groupBusinessLogic.createGroups(resource, groupsToCreate, true).left().on(serviceBusinessLogic::throwComponentException);
}
}
if (isNotEmpty(groupsToDelete)) {
- serviceBusinessLogic.groupBusinessLogic.deleteGroups(resource, groupsToDelete).left().on(serviceBusinessLogic::throwComponentException);
+ groupBusinessLogic.deleteGroups(resource, groupsToDelete).left().on(serviceBusinessLogic::throwComponentException);
}
if (isNotEmpty(groupsToUpdate)) {
- serviceBusinessLogic.groupBusinessLogic.updateGroups(resource, groupsToUpdate, true).left()
+ groupBusinessLogic.updateGroups(resource, groupsToUpdate, true).left()
.on(serviceBusinessLogic::throwComponentException);
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
index a7bd4b62b2..8ba84b80a5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
@@ -28,9 +28,7 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.servers.Server;
-import io.swagger.v3.oas.annotations.servers.Servers;
import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.tags.Tags;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -81,8 +79,8 @@ import org.springframework.stereotype.Controller;
*/
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog")
-@Tags({@Tag(name = "SDCE-2 APIs")})
-@Servers({@Server(url = "/sdc2/rest")})
+@Tag(name = "SDCE-2 APIs")
+@Server(url = "/sdc2/rest")
@Controller
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
index bcedc60d40..c26f3ca522 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
@@ -19,6 +19,8 @@
*/
package org.openecomp.sdc.be.servlets;
+import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.reflect.TypeToken;
@@ -31,9 +33,7 @@ import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.servers.Server;
-import io.swagger.v3.oas.annotations.servers.Servers;
import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.tags.Tags;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -52,8 +52,8 @@ import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -99,7 +99,7 @@ import org.springframework.stereotype.Controller;
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog")
-@Servers({@Server(url = "/sdc2/rest")})
+@Server(url = "/sdc2/rest")
@Controller
public class ServiceServlet extends AbstractValidationsServlet {
@@ -110,8 +110,6 @@ public class ServiceServlet extends AbstractValidationsServlet {
private final ElementBusinessLogic elementBusinessLogic;
private final ServiceBusinessLogic serviceBusinessLogic;
- public enum Action {DELETE, MARK_AS_DELETE}
-
@Inject
public ServiceServlet(UserBusinessLogic userBusinessLogic, ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils,
ServletUtils servletUtils, ResourceImportManager resourceImportManager, ServiceBusinessLogic serviceBusinessLogic,
@@ -123,7 +121,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@POST
@Path("/services")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Create Service", method = "POST", summary = "Returns created service", responses = {
@@ -136,8 +134,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE, StatusCode.STARTED, "Starting to create a service by user {} ", userId);
validateNotEmptyBody(data);
@@ -163,7 +160,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@GET
@Path("/services/validate-name/{serviceName}")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "validate service name", method = "GET", summary = "checks if the chosen service name is available ", responses = {
@@ -174,9 +171,6 @@ public class ServiceServlet extends AbstractValidationsServlet {
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
log.debug(MODIFIER_ID_IS, userId);
try {
Either<Map<String, Boolean>, ResponseFormat> actionResponse = serviceBusinessLogic.validateServiceNameExists(serviceName, userId);
@@ -194,7 +188,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@GET
@Path("/audit-records/{componentType}/{componentUniqueId}")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "get component audit records", method = "GET", summary = "get audit records for a service or a resource", responses = {
@@ -209,8 +203,6 @@ public class ServiceServlet extends AbstractValidationsServlet {
ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
- User modifier = new User();
- modifier.setUserId(userId);
log.debug(MODIFIER_ID_IS, userId);
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<String> uuidWrapper = new Wrapper<>();
@@ -265,7 +257,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@DELETE
@Path("/services/{serviceId}")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Operation(description = "Delete Service", method = "DELETE", summary = "Return no content", responses = {
@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))),
@ApiResponse(responseCode = "204", description = "Service deleted"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
@@ -274,8 +266,8 @@ public class ServiceServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response deleteService(@PathParam("serviceId") final String serviceId,
@Parameter(description = "Optional parameter to determine the delete action: " +
- "DELETE, which will permanently delete theService from the system or " +
- "MARK_AS_DELETE, which will logically mark the service as deleted. Default action is to MARK_AS_DELETE")
+ "DELETE, which will permanently delete theService from the system or " +
+ "MARK_AS_DELETE, which will logically mark the service as deleted. Default action is to MARK_AS_DELETE")
@QueryParam("deleteAction") final Action deleteAction,
@Context final HttpServletRequest request) {
ServletContext context = request.getSession().getServletContext();
@@ -283,8 +275,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
String userId = request.getHeader(Constants.USER_ID_HEADER);
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
try {
String serviceIdLower = serviceId.toLowerCase();
@@ -315,7 +306,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@DELETE
@Path("/services/{serviceName}/{version}")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Operation(description = "Delete Service By Name And Version", method = "DELETE", summary = "Returns no content", responses = {
@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))),
@ApiResponse(responseCode = "204", description = "Service deleted"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
@@ -344,15 +335,14 @@ public class ServiceServlet extends AbstractValidationsServlet {
log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
String userId = request.getHeader(Constants.USER_ID_HEADER);
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
return modifier;
}
@PUT
@Path("/services/{serviceId}/metadata")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Update Service Metadata", method = "PUT", summary = "Returns updated service", responses = {
@@ -366,8 +356,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
throws IOException {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
try {
String serviceIdLower = serviceId.toLowerCase();
@@ -406,7 +395,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
*/
@PUT
@Path("/{containerComponentType}/{serviceId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Update Group Instance Property Values", method = "PUT", summary = "Returns updated group instance", responses = {
@@ -423,8 +412,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws JsonProcessingException {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
Either<List<GroupInstanceProperty>, ResponseFormat> actionResponse = null;
try {
@@ -452,14 +440,14 @@ public class ServiceServlet extends AbstractValidationsServlet {
return buildErrorResponse(actionResponse.right().value());
}
} catch (Exception e) {
- log.error("Exception occured during update Group Instance property values: {}", e.getMessage(), e);
+ log.error(BUSINESS_PROCESS_ERROR, this.getClass().getName(), "Exception occured during update Group Instance property values.", e);
throw e;
}
}
@GET
@Path("/services/{serviceId}")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Retrieve Service", method = "GET", summary = "Returns service according to serviceId", responses = {
@@ -472,8 +460,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
try {
String serviceIdLower = serviceId.toLowerCase();
@@ -495,7 +482,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@GET
@Path("/services/serviceName/{serviceName}/serviceVersion/{serviceVersion}")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Retrieve Service", method = "GET", summary = "Returns service according to name and version", responses = {
@@ -507,8 +494,6 @@ public class ServiceServlet extends AbstractValidationsServlet {
@PathParam("serviceVersion") final String serviceVersion, @Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
// get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
log.debug(MODIFIER_ID_IS, userId);
try {
Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId);
@@ -527,7 +512,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@POST
@Path("/services/{serviceId}/distribution/{env}/activate")
- @Tags({@Tag(name = "SDCE-5 APIs")})
+ @Tag(name = "SDCE-5 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Activate distribution", method = "POST", summary = "activate distribution", responses = {
@@ -541,8 +526,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
throws IOException {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.activateDistribution(serviceId, env, modifier, request);
if (distResponse.isRight()) {
@@ -563,7 +547,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@POST
@Path("/services/{serviceId}/distribution/{did}/markDeployed")
- @Tags({@Tag(name = "SDCE-5 APIs")})
+ @Tag(name = "SDCE-5 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Mark distribution as deployed", method = "POST", summary = "relevant audit record will be created", responses = {
@@ -579,8 +563,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
try {
Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.markDistributionAsDeployed(serviceId, did, modifier);
@@ -600,7 +583,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@POST
@Path("/services/{serviceId}/tempUrlToBeDeleted")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(responses = {@ApiResponse(responseCode = "200", description = "OK"),
@@ -608,11 +591,9 @@ public class ServiceServlet extends AbstractValidationsServlet {
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response tempUrlToBeDeleted(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
try {
Service service = (serviceBusinessLogic.getService(serviceId, modifier)).left().value();
@@ -631,7 +612,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@GET
@Path("/services/{serviceId}/linksMap")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Retrieve Service component relations map", method = "GET", summary = "Returns service components relations", responses = {
@@ -644,8 +625,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug(MODIFIER_ID_IS, userId);
try {
String serviceIdLower = serviceId.toLowerCase();
@@ -667,7 +647,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
@POST
@Path("/services/importService")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Import Service", method = "POST", summary = "Returns imported service", responses = {
@@ -679,26 +659,21 @@ public class ServiceServlet extends AbstractValidationsServlet {
userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER);
initSpringFromContext();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
- Response response;
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ log.debug(MODIFIER_ID_IS, userId);
try {
- Wrapper<Response> responseWrapper = new Wrapper<>();
- performUIImport(responseWrapper, data, request, userId, null);
+ final Wrapper<Response> responseWrapper = performUIImport(data, request, userId, null);
return responseWrapper.getInnerElement();
} catch (IOException | ZipException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Import Service");
log.debug("import service failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
- private void performUIImport(Wrapper<Response> responseWrapper, String data, final HttpServletRequest request, String userId,
- String ServiceUniqueId) throws FileNotFoundException, ZipException {
+ private Wrapper<Response> performUIImport(String data, final HttpServletRequest request, String userId,
+ String ServiceUniqueId) throws FileNotFoundException, ZipException {
+ Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();
Wrapper<UploadServiceInfo> uploadServiceInfoWrapper = new Wrapper<>();
Wrapper<String> yamlStringWrapper = new Wrapper<>();
@@ -710,6 +685,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
handleImportService(responseWrapper, userWrapper.getInnerElement(), uploadServiceInfoWrapper.getInnerElement(),
yamlStringWrapper.getInnerElement(), ServiceAuthorityEnum, true, ServiceUniqueId);
}
+ return responseWrapper;
}
/**
@@ -729,7 +705,7 @@ public class ServiceServlet extends AbstractValidationsServlet {
*/
@POST
@Path("/services/serviceUUID/{uuid}/importReplaceService")
- @Tags({@Tag(name = "SDCE-2 APIs")})
+ @Tag(name = "SDCE-2 APIs")
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Import Service", method = "POST", summary = "Returns imported service", responses = {
@ApiResponse(responseCode = "201", description = "Service created"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
@@ -751,11 +727,9 @@ public class ServiceServlet extends AbstractValidationsServlet {
String url = request.getMethod() + " " + requestURI;
log.debug("importReplaceService,Start handle request of {}", url);
// get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
+ User modifier = new User(userId);
log.debug("importReplaceService,modifier id is {}", userId);
log.debug("importReplaceService,get file:{},fileName:{}", file, file.getName());
- Response response;
ResponseFormat responseFormat = null;
AuditingActionEnum auditingActionEnum = AuditingActionEnum.Import_Replace_Service;
String assetType = "services";
@@ -808,8 +782,9 @@ public class ServiceServlet extends AbstractValidationsServlet {
} catch (IOException | ZipException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Import Service");
log.debug("import service failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
+
+ public enum Action {DELETE, MARK_AS_DELETE}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
index 692e8cce50..638eef6898 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/BaseServiceBusinessLogicTest.java
@@ -78,16 +78,29 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.springframework.web.context.WebApplicationContext;
public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogicMock {
+
+ protected static final String CERTIFIED_VERSION = "1.0";
+ protected static final String UNCERTIFIED_VERSION = "0.2";
+ protected static final String COMPONNET_ID = "myUniqueId";
+ protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
private static final String SERVICE_CATEGORY = "Mobility";
- private final ServletContext servletContext = Mockito.mock(ServletContext.class);
- private UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
- private WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
- private WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_CERTIFIED_VERSION = new HashMap<>();
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_CURR = new HashMap<>();
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_PREV = new HashMap<>();
+ protected static ForwardingPathDataDefinition forwardingPathDataDefinition;
protected final IDistributionEngine distributionEngine = Mockito.mock(IDistributionEngine.class);
protected final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
protected final ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
protected final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
protected final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ private final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
+ User user = null;
+ Service serviceResponse = null;
+ Resource genericService = null;
+ private UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ private WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ private WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
private ServiceBusinessLogic bl;
private ResponseFormatManager responseManager = null;
private IElementOperation mockElementDao;
@@ -98,20 +111,25 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
private JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
private ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
- private ForwardingPathOperation forwardingPathOperation = Mockito.mock(ForwardingPathOperation.class);
- private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
+ private ForwardingPathOperation forwardingPathOperation = Mockito.mock(ForwardingPathOperation.class);
- User user = null;
- Service serviceResponse = null;
- Resource genericService = null;
+ protected static ForwardingPathDataDefinition createMockPath() {
+ if (forwardingPathDataDefinition != null) {
+ return forwardingPathDataDefinition;
+ }
+ forwardingPathDataDefinition = new ForwardingPathDataDefinition("Yoyo");
+ forwardingPathDataDefinition.setUniqueId(java.util.UUID.randomUUID().toString());
+ forwardingPathDataDefinition.setDestinationPortNumber("414155");
+ forwardingPathDataDefinition.setProtocol("http");
+ org.openecomp.sdc.be.datatypes.elements.ListDataDefinition<org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition> forwardingPathElementDataDefinitionListDataDefinition = new org.openecomp.sdc.be.datatypes.elements.ListDataDefinition<>();
+ forwardingPathElementDataDefinitionListDataDefinition.add(
+ new ForwardingPathElementDataDefinition("fromNode", "toNode", "333", "444", "2222", "5555"));
+ forwardingPathElementDataDefinitionListDataDefinition.add(
+ new ForwardingPathElementDataDefinition("toNode", "toNode2", "4444", "44444", "4", "44"));
+ forwardingPathDataDefinition.setPathElements(forwardingPathElementDataDefinitionListDataDefinition);
+ return forwardingPathDataDefinition;
+ }
- protected static final String CERTIFIED_VERSION = "1.0";
- protected static final String UNCERTIFIED_VERSION = "0.2";
- protected static final String COMPONNET_ID = "myUniqueId";
- protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
- protected static Map<AuditingFieldsKey, Object> FILTER_MAP_CERTIFIED_VERSION = new HashMap<>();
- protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_CURR = new HashMap<>();
- protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_PREV = new HashMap<>();
@Before
public void setup() {
@@ -141,7 +159,8 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
// artifact bussinesslogic
ArtifactDefinition artifactDef = new ArtifactDefinition();
- when(artifactBl.createArtifactPlaceHolderInfo(Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class), Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
+ when(artifactBl.createArtifactPlaceHolderInfo(Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class),
+ Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
// createService
serviceResponse = createServiceObject(true);
@@ -157,9 +176,9 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_SERVICE_NAME)).thenReturn(findLatestGeneric);
//forwardingPath
- when(forwardingPathOperation.addForwardingPath(any(),any())).thenReturn(Either.left(createMockPath()));
- when(forwardingPathOperation.updateForwardingPath(any(),any())).thenReturn(Either.left(createMockPath()));
- when(forwardingPathOperation.deleteForwardingPath(any(),any())).thenReturn(Either.left(Sets.newHashSet("Wow-It-Works")));
+ when(forwardingPathOperation.addForwardingPath(any(), any())).thenReturn(Either.left(createMockPath()));
+ when(forwardingPathOperation.updateForwardingPath(any(), any())).thenReturn(Either.left(createMockPath()));
+ when(forwardingPathOperation.deleteForwardingPath(any(), any())).thenReturn(Either.left(Sets.newHashSet("Wow-It-Works")));
when(toscaOperationFacade.getToscaElement("delete_forward_test")).thenReturn(Either.left(createServiceObject(true)));
bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
@@ -168,7 +187,7 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator,
- modelOperation);
+ modelOperation, null, null, null, null, null);
bl.setUserAdmin(mockUserAdmin);
bl.setGraphLockOperation(graphLockOperation);
bl.setJanusGraphDao(mockJanusGraphDao);
@@ -192,15 +211,15 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
service.setUniqueId("serviceUniqueId");
List<ComponentInstance> componentInstances = new ArrayList<>();
ComponentInstance ci;
- for(int i= 0; i<listSize; ++i){
+ for (int i = 0; i < listSize; ++i) {
ci = new ComponentInstance();
ci.setName("ciName" + i);
ci.setUniqueId("ciId" + i);
- List<GroupInstance> groupInstances= new ArrayList<>();
+ List<GroupInstance> groupInstances = new ArrayList<>();
GroupInstance gi;
- for(int j = 0; j<listSize; ++j){
+ for (int j = 0; j < listSize; ++j) {
gi = new GroupInstance();
- gi.setName(ci.getName( )+ "giName" + j);
+ gi.setName(ci.getName() + "giName" + j);
gi.setUniqueId(ci.getName() + "giId" + j);
groupInstances.add(gi);
}
@@ -321,27 +340,10 @@ public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogi
return service;
}
- protected Resource setupGenericServiceMock(){
+ protected Resource setupGenericServiceMock() {
Resource genericService = new Resource();
genericService.setVersion("1.0");
genericService.setToscaResourceName(GENERIC_SERVICE_NAME);
return genericService;
}
-
- protected static ForwardingPathDataDefinition forwardingPathDataDefinition;
-
- protected static ForwardingPathDataDefinition createMockPath() {
- if (forwardingPathDataDefinition != null){
- return forwardingPathDataDefinition ;
- }
- forwardingPathDataDefinition = new ForwardingPathDataDefinition("Yoyo");
- forwardingPathDataDefinition.setUniqueId(java.util.UUID.randomUUID().toString());
- forwardingPathDataDefinition.setDestinationPortNumber("414155");
- forwardingPathDataDefinition.setProtocol("http");
- org.openecomp.sdc.be.datatypes.elements.ListDataDefinition<org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition> forwardingPathElementDataDefinitionListDataDefinition = new org.openecomp.sdc.be.datatypes.elements.ListDataDefinition<>();
- forwardingPathElementDataDefinitionListDataDefinition.add(new ForwardingPathElementDataDefinition("fromNode","toNode", "333","444","2222","5555"));
- forwardingPathElementDataDefinitionListDataDefinition.add(new ForwardingPathElementDataDefinition("toNode","toNode2", "4444","44444","4","44"));
- forwardingPathDataDefinition.setPathElements(forwardingPathElementDataDefinitionListDataDefinition);
- return forwardingPathDataDefinition;
- }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java
index 0b3973e584..602a3bb4ce 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/ServiceDistributionBLTest.java
@@ -76,7 +76,8 @@ class ServiceDistributionBLTest extends ComponentBusinessLogicMock {
serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
artifactToscaOperation, componentContactIdValidator,
componentNameValidator, componentTagsValidator, componentValidator, componentIconValidator,
- componentProjectCodeValidator, componentDescriptionValidator, modelOperation);
+ componentProjectCodeValidator, componentDescriptionValidator, modelOperation, null, null,
+ null, null, null);
private Service serviceToActivate;
private ActivationRequestInformation activationRequestInformation;
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
index 5f85b5134a..a2931a515b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
@@ -18,21 +18,35 @@
* ============LICENSE_END=================================================
*/
-package org.openecomp.sdc.be.components.impl.utils;
+package org.openecomp.sdc.be.components.csar;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
import mockit.Deencapsulation;
import org.apache.commons.collections.MapUtils;
import org.assertj.core.util.Lists;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.be.components.csar.CsarInfo;
-import org.openecomp.sdc.be.components.csar.YamlTemplateParsingHandler;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
@@ -54,27 +68,9 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
import org.openecomp.sdc.common.zip.ZipUtils;
import org.openecomp.sdc.common.zip.exception.ZipException;
-
-import java.io.File;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
import org.springframework.test.util.ReflectionTestUtils;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
-
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public class YamlTemplateParsingHandlerTest {
@Mock
@@ -117,9 +113,9 @@ public class YamlTemplateParsingHandlerTest {
private static final String NESTED_GROUP_NAME = "nested_mg_vepdg_group";
@InjectMocks
- YamlTemplateParsingHandler testSubject;
+ private YamlTemplateParsingHandler testSubject;
- @BeforeClass()
+ @BeforeAll
public static void prepareData() throws URISyntaxException, ZipException {
final File csarFile = new File(
YamlTemplateParsingHandlerTest.class.getClassLoader().getResource(CSAR_FILE_PATH).toURI());
@@ -132,34 +128,34 @@ public class YamlTemplateParsingHandlerTest {
resourceYml = new String(mainTemplateService);
}
- @Before
+ @BeforeEach
public void setup() {
AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
- annotationValidator);
+ annotationValidator);
handler = new YamlTemplateParsingHandler(janusGraphDao, groupTypeBusinessLogic, annotationBusinessLogic, policyTypeBusinessLogic);
ReflectionTestUtils.setField(handler, "policyTypeBusinessLogic", policyTypeBusinessLogic);
- stubGetGroupType();
- stubGetPolicyType();
}
@Test
- public void parseResourceInfoFromOneNodeTest() {
+ void parseResourceInfoFromOneNodeTest() {
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
- MAIN_TEMPLATE_NAME, main_template_content, true);
+ MAIN_TEMPLATE_NAME, main_template_content, true);
Resource resource = new Resource();
ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
- csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get());
+ csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get());
validateParsedYaml(parsedYaml, NESTED_GROUP_NAME,
- Lists.newArrayList("heat_file", "description"));
+ Lists.newArrayList("heat_file", "description"));
}
@Test
- public void parseServicePropertiesInfoFromYamlTest() {
+ void parseServicePropertiesInfoFromYamlTest() {
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
MAIN_TEMPLATE_NAME, main_template_content, true);
@@ -178,30 +174,32 @@ public class YamlTemplateParsingHandlerTest {
}
@Test
- public void parseResourceInfoFromYAMLTest() {
+ void parseResourceInfoFromYAMLTest() {
+ stubGetGroupType();
+ stubGetPolicyType();
Resource resource = new Resource();
ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
- new HashMap<>(), "", resource, null);
+ new HashMap<>(), "", resource, null);
validateParsedYamlWithCapability(parsedYaml);
}
@Test
- public void testSetArtifacts() {
+ void testSetArtifacts() {
UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
Map<String, Object> nodeTemplateJsonMap = new HashMap<>();
Map<String, String> nodeMap = new HashMap<>();
- nodeMap.put("name","test_name");
- nodeMap.put("type","test_type");
+ nodeMap.put("name", "test_name");
+ nodeMap.put("type", "test_type");
nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), nodeMap);
Deencapsulation.invoke(testSubject, "setArtifacts", nodeTemplateInfo, nodeTemplateJsonMap);
assertNotNull(nodeTemplateInfo.getArtifacts());
}
@Test
- public void testCreateArtifactsModuleFromYaml() {
+ void testCreateArtifactsModuleFromYaml() {
Map<String, Map<String, Map<String, String>>> nodeTemplateJsonMap = new HashMap<>();
- Map<String, Map<String,String>> map0 = new HashMap<>();
+ Map<String, Map<String, String>> map0 = new HashMap<>();
Map<String, String> map1 = new HashMap<>();
map1.put("file", "test_file");
map1.put("type", "test_type");
@@ -209,54 +207,56 @@ public class YamlTemplateParsingHandlerTest {
nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), map0);
Map<String, Map<String, UploadArtifactInfo>> result;
result = Deencapsulation.invoke(testSubject, "createArtifactsModuleFromYaml", nodeTemplateJsonMap);
- Assert.assertTrue(MapUtils.isNotEmpty(result));
- Assert.assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
- Assert.assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
- Assert.assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
+ assertTrue(MapUtils.isNotEmpty(result));
+ assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
+ assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
+ assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
}
@Test
- public void testAddModuleNodeTemplateArtifacts() {
+ void testAddModuleNodeTemplateArtifacts() {
Map<String, Map<String, UploadArtifactInfo>> result = new HashMap<>();
Map<String, String> map1 = new HashMap<>();
map1.put("file", "test_file");
map1.put("type", "test_type");
Deencapsulation.invoke(testSubject, "addModuleNodeTemplateArtifacts", result, map1, "test_art");
- Assert.assertTrue(MapUtils.isNotEmpty(result));
- Assert.assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
- Assert.assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
- Assert.assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
+ assertTrue(MapUtils.isNotEmpty(result));
+ assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
+ assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
+ assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
}
@Test
- public void testBuildModuleNodeTemplateArtifact() {
+ void testBuildModuleNodeTemplateArtifact() {
Map<String, String> map1 = new HashMap<>();
map1.put("file", "test_file");
map1.put("type", "test_type");
UploadArtifactInfo result;
result = Deencapsulation.invoke(testSubject, "buildModuleNodeTemplateArtifact", map1);
assertNotNull(result);
- Assert.assertEquals("test_file", result.getFile());
- Assert.assertEquals("test_type", result.getType());
+ assertEquals("test_file", result.getFile());
+ assertEquals("test_type", result.getType());
}
@Test
- public void testFillArtifact() {
+ void testFillArtifact() {
Map<String, String> map1 = new HashMap<>();
map1.put("file", "test_file");
map1.put("type", "test_type");
UploadArtifactInfo result = new UploadArtifactInfo();
Deencapsulation.invoke(testSubject, "fillArtifact", result, map1);
assertNotNull(result);
- Assert.assertEquals("test_file", result.getFile());
- Assert.assertEquals("test_type", result.getType());
+ assertEquals("test_file", result.getFile());
+ assertEquals("test_type", result.getType());
}
@Test
- public void parseResourceWithPoliciesDefined() {
+ void parseResourceWithPoliciesDefined() {
+ stubGetGroupType();
+ stubGetPolicyType();
Resource resource = new Resource();
ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
- new HashMap<>(), "", resource, "");
+ new HashMap<>(), "", resource, "");
validateParsedYamlWithPolicies(parsedYaml);
}
@@ -267,10 +267,10 @@ public class YamlTemplateParsingHandlerTest {
assertThat(parsedYaml.getGroups().get(group).getProperties()).isNotNull();
assertThat(parsedYaml.getGroups().get(group).getProperties()
- .stream()
- .map(PropertyDataDefinition::getName)
- .collect(Collectors.toList()))
- .containsAll(expectedProp);
+ .stream()
+ .map(PropertyDataDefinition::getName)
+ .collect(Collectors.toList()))
+ .containsAll(expectedProp);
assertThat(parsedYaml.getGroups().get(group).getMembers()).isNotNull();
}
@@ -278,13 +278,13 @@ public class YamlTemplateParsingHandlerTest {
private void validateParsedYamlWithCapability(ParsedToscaYamlInfo parsedYaml) {
final List<String> expectedProp = Lists.newArrayList("vfc_parent_port_role",
- "network_collection_function", "vfc_instance_group_function", "subinterface_role");
+ "network_collection_function", "vfc_instance_group_function", "subinterface_role");
validateParsedYaml(parsedYaml, MAIN_GROUP_NAME, expectedProp);
assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()
- .get(CAPABILITY_TYPE)
- .get(0).getProperties().get(0).getValue()).isEqualTo("success");
+ .get(CAPABILITY_TYPE)
+ .get(0).getProperties().get(0).getValue()).isEqualTo("success");
assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()).isNotNull();
assertThat(parsedYaml.getSubstitutionMappingNodeType()).isEqualTo("org.openecomp.resource.abstract.nodes.VF");
}
@@ -297,18 +297,18 @@ public class YamlTemplateParsingHandlerTest {
private static GroupTypeDefinition buildRootGroupType() {
return createGroupTypeDefinition(ROOT_GROUP_TYPE, null,
- "The TOSCA Group Type all other TOSCA Group Types derive from");
+ "The TOSCA Group Type all other TOSCA Group Types derive from");
}
private static GroupTypeDefinition buildHeatStackGroupType() {
GroupTypeDefinition groupType = createGroupTypeDefinition(HEAT_GROUP_TYPE, "tosca.groups.Root",
- "Grouped all heat resources which are in the same heat stack");
+ "Grouped all heat resources which are in the same heat stack");
GroupProperty property1 = createGroupProperty("heat_file",
- "Heat file which associate to this group/heat stack", "SUPPORTED");
+ "Heat file which associate to this group/heat stack", "SUPPORTED");
GroupProperty property2 = createGroupProperty("description",
- "Group description", "SUPPORTED");
+ "Group description", "SUPPORTED");
groupType.setProperties(Lists.newArrayList(property1, property2));
return groupType;
@@ -316,19 +316,19 @@ public class YamlTemplateParsingHandlerTest {
private static GroupTypeDefinition buildVfcInstanceGroupType() {
GroupTypeDefinition groupType = createGroupTypeDefinition(VFC_GROUP_TYPE, "tosca.groups.Root",
- "Groups of VFCs with same parent port role");
+ "Groups of VFCs with same parent port role");
GroupProperty property1 = createGroupProperty("vfc_instance_group_function",
- "Function of this VFC group", null);
+ "Function of this VFC group", null);
GroupProperty property2 = createGroupProperty("vfc_parent_port_role",
- "Common role of parent ports of VFCs in this group", null);
+ "Common role of parent ports of VFCs in this group", null);
GroupProperty property3 = createGroupProperty("network_collection_function",
- "Network collection function assigned to this group", null);
+ "Network collection function assigned to this group", null);
GroupProperty property4 = createGroupProperty("subinterface_role",
- "Common role of subinterfaces of VFCs in this group, criteria the group is created", null);
+ "Common role of subinterfaces of VFCs in this group, criteria the group is created", null);
groupType.setProperties(Lists.newArrayList(property1, property2, property3, property4));
@@ -346,11 +346,12 @@ public class YamlTemplateParsingHandlerTest {
return groupType;
}
- private static GroupTypeDefinition createGroupTypeDefinition(String type, String derivedFrom, String description){
+ private static GroupTypeDefinition createGroupTypeDefinition(String type, String derivedFrom, String description) {
GroupTypeDefinition property = new GroupTypeDefinition();
- if (type != null)
+ if (type != null) {
property.setType(type);
+ }
if (derivedFrom != null) {
property.setDerivedFrom(derivedFrom);
@@ -362,11 +363,13 @@ public class YamlTemplateParsingHandlerTest {
return property;
}
+
private static GroupProperty createGroupProperty(String name, String description,
- String status){
+ String status) {
GroupProperty property = new GroupProperty();
- if (name != null)
+ if (name != null) {
property.setName(name);
+ }
if (description != null) {
property.setDescription(description);
@@ -389,14 +392,14 @@ public class YamlTemplateParsingHandlerTest {
assertThat(parsedYaml.getPolicies().get(OPENECOMP_POLICY_NAME)).isInstanceOf(PolicyDefinition.class);
}
- private void stubGetPolicyType () {
- when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any())).thenReturn(
- OPENECOMP_POLICY_TYPE);
+ private void stubGetPolicyType() {
+ when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any()))
+ .thenReturn(OPENECOMP_POLICY_TYPE);
}
private static PolicyTypeDefinition buildOpenecompPolicyType() {
return createPolicyTypeDefinition(OPENECOMP_POLICY_NAME, OPENECOMP_ANTILOCATE_POLICY_TYPE, ROOT_POLICIES_TYPE,
- "The Openecomp Antilocate policy");
+ "The Openecomp Antilocate policy");
}
private static PolicyTypeDefinition createPolicyTypeDefinition(String policyName, String policyType, String derivedFrom, String description) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
index 7a8a15a905..15b7706598 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
@@ -16,16 +16,19 @@
package org.openecomp.sdc.be.components.impl;
-
-import static org.assertj.core.api.Java6Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.POLICY_TARGET_DOES_NOT_EXIST;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.PROPERTY_NOT_FOUND;
import fj.data.Either;
import java.util.ArrayList;
@@ -35,15 +38,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
@@ -53,8 +56,8 @@ import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -73,6 +76,7 @@ import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
@@ -85,9 +89,34 @@ import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
-@RunWith(MockitoJUnitRunner.class)
-public class PolicyBusinessLogicTest {
-
+@ExtendWith(MockitoExtension.class)
+class PolicyBusinessLogicTest {
+
+ private static final String COMPONENT_ID = "componentId";
+ private static final String NON_EXIST_COMPONENT_ID = "nonExistComponentId";
+ private static final String COMPONENT_NAME = "componentName";
+ private static final String POLICY_TYPE_NAME = "policyTypeName";
+ private static final String POLICY_ID = "policyId";
+ private static final String INVALID_POLICY_ID = "invalidPolicyId";
+ private static final String POLICY_NAME = "policyName";
+ private static final String OTHER_POLICY_NAME = "otherPolicyName";
+ private static final String USER_ID = "jh0003";
+ private static final String UNIQUE_ID_EXSISTS = "uniqueIdExists";
+ private static final String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
+ private static final String CREATE_POLICY = "create Policy";
+ private static final String PROPERTY_NAME = "propDefinition";
+ private static final User user = buildUser();
+ private static final PolicyDefinition policy = buildPolicy(POLICY_NAME);
+ private static final Resource resource = buildResource();
+ private static final PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
+ private static final PolicyTypeDefinition policyType = buildPolicyType();
+ private static Either<Component, StorageOperationStatus> componentSuccessEither;
+ private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
+ private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
+ private final ConfigurationManager configurationManager = new ConfigurationManager(
+ new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
+ @Mock
+ private PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
@InjectMocks
private PolicyBusinessLogic businessLogic;
@Mock
@@ -106,43 +135,72 @@ public class PolicyBusinessLogicTest {
private ApplicationDataTypeCache applicationDataTypeCache;
@Mock
private PropertyOperation propertyOperation;
- @Mock
- PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
-
- private final static String COMPONENT_ID = "componentId";
- private final static String NON_EXIST_COMPONENT_ID = "nonExistComponentId";
- private final static String COMPONENT_NAME = "componentName";
- private final static String POLICY_TYPE_NAME = "policyTypeName";
- private final static String POLICY_ID = "policyId";
- private final static String INVALID_POLICY_ID = "invalidPolicyId";
- private final static String POLICY_NAME = "policyName";
- private final static String OTHER_POLICY_NAME = "otherPolicyName";
- private final static String USER_ID = "jh0003";
- private final static String UNIQUE_ID_EXSISTS = "uniqueIdExists";
- private final static String UNIQUE_ID_DOESNT_EXSISTS = "uniqueIdDoesntExists";
- private final static String CREATE_POLICY = "create Policy";
- private final static String PROPERTY_NAME = "propDefinition";
- private final static User user = buildUser();
- private final static PolicyDefinition policy = buildPolicy(POLICY_NAME);
- private final static PolicyDefinition otherPolicy = buildPolicy(OTHER_POLICY_NAME);
- private final static Resource resource = buildResource();
- private final static PolicyTypeDefinition policyType = buildPolicyType();
-
- private static Either<Component, StorageOperationStatus> componentSuccessEither;
- private static Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeSuccessEither;
- private static Either<PolicyDefinition, StorageOperationStatus> policySuccessEither;
- private static ResponseFormat notFoundResponse;
- private static ResponseFormat invalidContentResponse;
- private static ResponseFormat nameExistsResponse;
- private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
- @BeforeClass
- public static void setup() {
+ @BeforeAll
+ static void setup() {
createResponses();
}
- @Before
- public void initBl() {
+ private static void createResponses() {
+ componentSuccessEither = Either.left(resource);
+ getPolicyTypeSuccessEither = Either.left(policyType);
+ policySuccessEither = Either.left(policy);
+ }
+
+ private static PolicyTypeDefinition buildPolicyType() {
+ PolicyTypeDefinition policyType = new PolicyTypeDefinition();
+ policyType.setType(POLICY_TYPE_NAME);
+ return policyType;
+ }
+
+ private static PolicyDefinition buildPolicy(String policyName) {
+ PolicyDefinition policy = new PolicyDefinition();
+ policy.setUniqueId(POLICY_ID);
+ policy.setPolicyTypeName(POLICY_TYPE_NAME);
+ policy.setComponentName(COMPONENT_NAME);
+ policy.setName(policyName);
+ return policy;
+ }
+
+ private static Resource buildResource() {
+ Resource resource = new Resource();
+ resource.setUniqueId(COMPONENT_ID);
+ resource.setName(COMPONENT_NAME);
+ resource.setCreatorUserId(USER_ID);
+ resource.setLastUpdaterUserId(USER_ID);
+ resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setIsDeleted(false);
+ resource.setResourceType(ResourceTypeEnum.VF);
+ resource.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ policies.put(POLICY_ID, policy);
+ resource.setPolicies(policies);
+ return resource;
+ }
+
+ private static Service buildService() {
+ Service service = new Service();
+ service.setUniqueId(COMPONENT_ID);
+ service.setName(COMPONENT_NAME);
+ service.setCreatorUserId(USER_ID);
+ service.setLastUpdaterUserId(USER_ID);
+ service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ service.setIsDeleted(false);
+ service.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
+ service.setComponentType(ComponentTypeEnum.SERVICE);
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ policies.put(POLICY_ID, policy);
+ service.setPolicies(policies);
+ return service;
+ }
+
+ private static User buildUser() {
+ return new User(USER_ID);
+ }
+
+ @BeforeEach
+ void initBl() {
MockitoAnnotations.openMocks(this);
businessLogic.setComponentsUtils(componentsUtils);
businessLogic.setToscaOperationFacade(toscaOperationFacade);
@@ -155,31 +213,18 @@ public class PolicyBusinessLogicTest {
businessLogic.setPropertyDeclarationOrchestrator(propertyDeclarationOrchestrator);
}
-
- private static void createResponses() {
- componentSuccessEither = Either.left(resource);
- getPolicyTypeSuccessEither = Either.left(policyType);
- policySuccessEither = Either.left(policy);
- notFoundResponse = new ResponseFormat();
- notFoundResponse.setStatus(404);
- invalidContentResponse = new ResponseFormat();
- invalidContentResponse.setStatus(400);
- nameExistsResponse = new ResponseFormat();
- nameExistsResponse.setStatus(409);
- }
-
@Test
- public void createPolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void createPolicySuccessTest() {
+ stubValidateAndLockSuccess();
when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(policySuccessEither);
stubUnlockAndCommit();
PolicyDefinition response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- assertThat(response.isEmpty()).isFalse();
+ assertFalse(response.isEmpty());
}
@Test
- public void createPolicyFromCsarDefinitionTest() {
+ void createPolicyOnResourceFromCsarDefinitionTest() {
String prop1 = "Prop_1";
String prop2 = "Prop_2";
Map<String, PolicyDefinition> policies = new HashMap<>();
@@ -199,186 +244,249 @@ public class PolicyBusinessLogicTest {
Resource newResource = buildResource();
newResource.setPolicies(policies);
newResource.setComponentInstances(instanceList);
-
+
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
+ when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
+ when(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(Either.left(newResource));
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ Either.left(policy));
+ when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
+ when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
+
+ Map<String, PolicyDefinition> createdPolicy = businessLogic.createPolicies(newResource, policies);
+
+ assertFalse(createdPolicy.isEmpty());
+ PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
+ assertNotNull(newPolicy);
+ assertTrue(newPolicy.getIsFromCsar());
+ assertNotNull(newPolicy.getTargets());
+ assertNotNull(newPolicy.getProperties());
+ assertEquals(2, newPolicy.getProperties().size());
+ assertEquals(1, newPolicy.getTargets().size());
+ }
+
+ @Test
+ void createPolicyOnServiceFromCsarDefinitionTest() {
+ String prop1 = "Prop_1";
+ String prop2 = "Prop_2";
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+ PolicyDefinition policy = buildPolicy(POLICY_NAME);
+ Map<PolicyTargetType, List<String>> targets = getTargets();
+ PropertyDataDefinition[] properties = getProperties(prop1, prop2);
+ policy.setTargets(targets);
+ policy.setProperties(Arrays.asList(properties));
+ policies.put(POLICY_NAME, policy);
+
+ List<ComponentInstance> instanceList = new ArrayList<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(UNIQUE_ID_EXSISTS);
+ componentInstance.setName(UNIQUE_ID_EXSISTS);
+ instanceList.add(componentInstance);
+
+ Service newService = buildService();
+ newService.setPolicies(policies);
+ newService.setComponentInstances(instanceList);
+
when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
- when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(Either.left(newResource));
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(Either.left(policy));
+ when(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(Either.left(newService));
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ Either.left(policy));
when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
- Map<String, PolicyDefinition> createdPolicy = businessLogic.createPoliciesFromParsedCsar(newResource, policies);
+ Map<String, PolicyDefinition> createdPolicy = businessLogic.createPolicies(newService, policies);
- assertThat(createdPolicy.isEmpty()).isFalse();
+ assertFalse(createdPolicy.isEmpty());
PolicyDefinition newPolicy = createdPolicy.get(POLICY_NAME);
assertNotNull(newPolicy);
+ assertTrue(newPolicy.getIsFromCsar());
assertNotNull(newPolicy.getTargets());
assertNotNull(newPolicy.getProperties());
assertEquals(2, newPolicy.getProperties().size());
assertEquals(1, newPolicy.getTargets().size());
+ assertTrue(newPolicy.getTargets().containsKey(PolicyTargetType.COMPONENT_INSTANCES));
+ assertEquals(2, newPolicy.getTargets().get(PolicyTargetType.COMPONENT_INSTANCES).size());
+ newPolicy.getTargets().get(PolicyTargetType.COMPONENT_INSTANCES).forEach(t -> assertTrue(t.equals(UNIQUE_ID_EXSISTS)));
+ newPolicy.getProperties().forEach(p -> assertTrue(p.getName().equals(prop1) || p.getName().equals(prop2)));
}
-
+
@Test
- public void createPolicyUserFailureTest(){
+ void createPolicyUserFailureTest() {
ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND);
- when(userValidations.validateUserExists(eq(USER_ID))).thenThrow(userNotFoundException);
- stubRollback();
- try{
+ when(userValidations.validateUserExists(USER_ID)).thenThrow(userNotFoundException);
+ try {
businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- } catch(ByActionStatusComponentException e){
+ } catch (ByActionStatusComponentException e) {
assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus());
}
}
- private void assertNotFound(Either<PolicyDefinition, ResponseFormat> response) {
- assertThat(response.isRight() && response.right().value().getStatus().equals(404)).isTrue();
- }
-
- @Test(expected = ComponentException.class)
- public void createPolicyComponentFailureTest(){
- when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
+ @Test
+ void createPolicyComponentFailureTest() {
+ when(userValidations.validateUserExists(USER_ID)).thenReturn(user);
Either<Component, StorageOperationStatus> componentNotFoundResponse = Either.right(StorageOperationStatus.NOT_FOUND);
- when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(
+ ActionStatus.RESOURCE_NOT_FOUND);
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentNotFoundResponse);
- businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
-
- @Test(expected = ComponentException.class)
- public void createPolicyPolicyTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+
+ @Test
+ void createPolicyPolicyTypeFailureTest() {
+ stubValidateAndLockSuccess();
Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND);
when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeFailed);
- when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
+ when(componentsUtils.convertFromStorageResponse(getPolicyTypeFailed.right().value())).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
stubUnlockAndRollback();
- businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
-
- @Test(expected = ComponentException.class)
- public void createPolicyComponentTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+
+ @Test
+ void createPolicyComponentTypeFailureTest() {
+ stubValidateAndLockSuccess();
when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes);
- when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT);
+ when(componentsUtils.convertFromStorageResponse(addPolicyRes.right().value())).thenReturn(ActionStatus.INVALID_CONTENT);
stubUnlockAndRollback();
- businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
+ assertThrows(ComponentException.class,
+ () -> businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true));
}
@Test
- public void updatePolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
+ void updatePolicySuccessTest() {
+ stubValidateAndLockSuccess();
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
stubUnlockAndCommit();
- PolicyDefinition response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
- assertThat(response.isEmpty()).isFalse();
+ PolicyDefinition response = businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, otherPolicy, USER_ID, true);
+ assertFalse(response.isEmpty());
}
-
- @Test(expected = ComponentException.class)
- public void updatePolicyNameFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+
+ @Test
+ void updatePolicyNameFailureTest() {
+ stubValidateAndLockSuccess();
stubUnlockAndRollback();
- businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true);
+ assertThrows(ComponentException.class, () -> businessLogic.updatePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, policy, USER_ID, true));
}
-
+
@Test
- public void getPolicySuccessTest(){
- stubValidationSuccess(CREATE_POLICY);
- stubCommit();
+ void getPolicySuccessTest() {
+ stubValidationSuccess();
PolicyDefinition response = businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID);
- assertThat(response.isEmpty()).isFalse();
+ assertFalse(response.isEmpty());
}
-
- @Test(expected = ComponentException.class)
- public void getPolicyFailureTest(){
- stubValidationSuccess(CREATE_POLICY);
- stubRollback();
- businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID);
+
+ @Test
+ void getPolicyFailureTest() {
+ stubValidationSuccess();
+ assertThrows(ComponentException.class, () -> businessLogic.getPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID));
}
-
+
@Test
- public void deletePolicySuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void deletePolicySuccessTest() {
+ stubValidateAndLockSuccess();
stubCommit();
- when(toscaOperationFacade.removePolicyFromComponent(eq(COMPONENT_ID),eq(POLICY_ID))).thenReturn(StorageOperationStatus.OK);
- PolicyDefinition response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
- assertThat(response.isEmpty()).isFalse();
- }
-
- @Test(expected = ComponentException.class)
- public void deletePolicyFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- stubCommit();
- businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true);
+ when(toscaOperationFacade.removePolicyFromComponent(COMPONENT_ID, POLICY_ID)).thenReturn(StorageOperationStatus.OK);
+ PolicyDefinition response = businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, USER_ID, true);
+ assertFalse(response.isEmpty());
}
+ @Test
+ void deletePolicyFailureTest() {
+ stubValidateAndLockSuccess();
+ assertThrows(ComponentException.class,
+ () -> businessLogic.deletePolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, INVALID_POLICY_ID, USER_ID, true));
+ }
@Test
- public void updatePolicyPropertiesSuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void updatePolicyPropertiesSuccessTest() {
+ stubValidateAndLockSuccess();
String prop1 = "Name";
String prop2 = "Type";
when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop1), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop1));
when(propertyOperation.validateAndUpdatePropertyValue(eq(null), eq(prop2), anyBoolean(), eq(null), anyMap())).thenReturn(Either.left(prop2));
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
stubUnlockAndCommit();
PropertyDataDefinition[] properties = getProperties(prop1, prop2);
policy.setProperties(Arrays.asList(properties));
- List<PropertyDataDefinition> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties , USER_ID, true);
+ List<PropertyDataDefinition> response = businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties,
+ USER_ID, true);
List<PropertyDataDefinition> updatedProperties = response;
- assertThat(updatedProperties.size()).isEqualTo(2);
+ assertEquals(2, updatedProperties.size());
}
@Test
- public void updatePolicyTargetsSuccessTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ void updatePolicyTargetsSuccessTest() {
+ stubValidateAndLockSuccess();
stubGetToscaFullElementSuccess();
stubUpdatePolicyOfComponentSuccess();
stubGetToscaElementSuccess();
PolicyDefinition policyResult = businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargets(), USER_ID);
Map<PolicyTargetType, List<String>> targets = getTargets();
- assertThat(policyResult.getTargets().values()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES));
+ assertTrue(policyResult.getTargets().values()
+ .containsAll(Arrays.asList(targets.get(PolicyTargetType.GROUPS), targets.get(PolicyTargetType.COMPONENT_INSTANCES))));
}
- @Test(expected = ComponentException.class)
- public void updatePolicyTargetsTargetIDFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ @Test
+ void updatePolicyTargetsTargetIDFailureTest() {
+ stubValidateAndLockSuccess();
stubGetToscaFullElementSuccess();
stubGetToscaElementSuccess();
- stubUpdatePolicyOfComponentSuccess();
stubRollback();
- businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeId(), USER_ID);
-
+ Map<PolicyTargetType, List<String>> targetListFakeId = getTargetListFakeId();
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, targetListFakeId, USER_ID));
+ assertNotNull(componentException);
+ assertEquals(POLICY_TARGET_DOES_NOT_EXIST, componentException.getActionStatus());
+ assertEquals(400, componentException.getResponseFormat().getStatus());
+ assertEquals(1, componentException.getParams().length);
+ assertEquals(UNIQUE_ID_DOESNT_EXSISTS, componentException.getParams()[0]);
}
-
- @Test(expected = ComponentException.class)
- public void updatePolicyTargetsTypeFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
+ @Test
+ void updatePolicyTargetsTypeFailureTest() {
+ stubValidateAndLockSuccess();
stubGetToscaFullElementSuccess();
stubGetToscaElementSuccess();
- stubUpdatePolicyOfComponentSuccess();
stubRollback();
- businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getTargetListFakeType(), USER_ID);
-
+ Map<PolicyTargetType, List<String>> targetListFakeType = getTargetListFakeType();
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyTargets(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, targetListFakeType, USER_ID));
+ assertNotNull(componentException);
+ assertEquals(POLICY_TARGET_DOES_NOT_EXIST, componentException.getActionStatus());
+ assertEquals(400, componentException.getResponseFormat().getStatus());
+ assertEquals(1, componentException.getParams().length);
+ assertEquals(UNIQUE_ID_EXSISTS, componentException.getParams()[0]);
}
private void stubUpdatePolicyOfComponentSuccess() {
- when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy), any(PromoteVersionEnum.class))).thenReturn(policySuccessEither);
+ when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), eq(policy), any(PromoteVersionEnum.class))).thenReturn(
+ policySuccessEither);
}
-
- @Test(expected = ComponentException.class)
- public void updatePolicyPropertiesFailureTest(){
- stubValidateAndLockSuccess(CREATE_POLICY);
- stubUnlockAndRollback();
+ @Test
+ void updatePolicyPropertiesFailureTest() {
+ stubValidateAndLockSuccess();
+ when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
policy.setProperties(null);
- businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, getProperties("Name", "Type") , USER_ID, true);
+ PropertyDataDefinition[] properties = getProperties("Name", "Type");
+ final var componentException = assertThrows(ComponentException.class,
+ () -> businessLogic.updatePolicyProperties(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_ID, properties, USER_ID, true));
+ assertNotNull(componentException);
+ assertEquals(PROPERTY_NOT_FOUND, componentException.getActionStatus());
+ assertEquals(404, componentException.getResponseFormat().getStatus());
+ assertEquals(0, componentException.getParams().length);
}
@Test
- public void testDeclarePropertiesAsPoliciesSuccess() {
+ void testDeclarePropertiesAsPoliciesSuccess() {
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(resource));
when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
when(graphLockOperation.unlockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
@@ -386,28 +494,30 @@ public class PolicyBusinessLogicTest {
when(propertyDeclarationOrchestrator.declarePropertiesToPolicies(any(), any())).thenReturn(Either.left(getDeclaredPolicies()));
Either<List<PolicyDefinition>, ResponseFormat> declaredPoliciesEither = businessLogic
- .declareProperties(USER_ID,
- resource.getUniqueId(),
- ComponentTypeEnum.RESOURCE,
- getInputForPropertyToPolicyDeclaration());
+ .declareProperties(USER_ID,
+ resource.getUniqueId(),
+ ComponentTypeEnum.RESOURCE,
+ getInputForPropertyToPolicyDeclaration());
- assertThat(declaredPoliciesEither.isLeft()).isTrue();
+ assertTrue(declaredPoliciesEither.isLeft());
List<PolicyDefinition> declaredPolicies = declaredPoliciesEither.left().value();
- assertThat(CollectionUtils.isNotEmpty(declaredPolicies)).isTrue();
+ assertTrue(CollectionUtils.isNotEmpty(declaredPolicies));
assertEquals(1, declaredPolicies.size());
}
@Test
- public void testDeclarePropertiesAsPoliciesFailure() {
- when(toscaOperationFacade.getToscaElement(eq(NON_EXIST_COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(ComponentTypeEnum.RESOURCE))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
+ void testDeclarePropertiesAsPoliciesFailure() {
+ when(toscaOperationFacade.getToscaElement(eq(NON_EXIST_COMPONENT_ID), Mockito.any(ComponentParametersView.class))).thenReturn(
+ Either.right(StorageOperationStatus.NOT_FOUND));
+ when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(
+ ActionStatus.RESOURCE_NOT_FOUND);
try {
businessLogic
- .declareProperties(USER_ID,
- NON_EXIST_COMPONENT_ID,
- ComponentTypeEnum.RESOURCE,
- getInputForPropertyToPolicyDeclaration());
+ .declareProperties(USER_ID,
+ NON_EXIST_COMPONENT_ID,
+ ComponentTypeEnum.RESOURCE,
+ getInputForPropertyToPolicyDeclaration());
} catch (ComponentException e) {
assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
return;
@@ -450,8 +560,7 @@ public class PolicyBusinessLogicTest {
property2.setValue(prop2);
return new PropertyDataDefinition[]{property1, property2};
}
-
-
+
private void stubUnlockAndRollback() {
when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
stubRollback();
@@ -469,23 +578,23 @@ public class PolicyBusinessLogicTest {
when(graphLockOperation.unlockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
stubCommit();
}
-
- private void stubValidateAndLockSuccess(String methodName) {
- stubValidationSuccess(methodName);
+
+ private void stubValidateAndLockSuccess() {
+ stubValidationSuccess();
when(graphLockOperation.lockComponent(eq(COMPONENT_ID), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
- }
+ }
- private void stubValidationSuccess(String methodName) {
- when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
+ private void stubValidationSuccess() {
+ when(userValidations.validateUserExists(USER_ID)).thenReturn(user);
when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(componentSuccessEither);
}
private void stubGetToscaFullElementSuccess() {
- when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(buildElementEither());
+ when(toscaOperationFacade.getToscaFullElement(COMPONENT_ID)).thenReturn(buildElementEither());
}
private void stubGetToscaElementSuccess() {
- when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID))).thenReturn(componentSuccessEither);
+ when(toscaOperationFacade.getToscaElement(COMPONENT_ID)).thenReturn(componentSuccessEither);
}
private Either<Component, StorageOperationStatus> buildElementEither() {
@@ -503,46 +612,6 @@ public class PolicyBusinessLogicTest {
return targets;
}
-
-
- private static PolicyTypeDefinition buildPolicyType() {
- PolicyTypeDefinition policyType = new PolicyTypeDefinition();
- policyType.setType(POLICY_TYPE_NAME);
- return policyType;
- }
-
- private static PolicyDefinition buildPolicy(String policyName) {
- PolicyDefinition policy = new PolicyDefinition();
- policy.setUniqueId(POLICY_ID);
- policy.setPolicyTypeName(POLICY_TYPE_NAME);
- policy.setComponentName(COMPONENT_NAME);
- policy.setName(policyName);
- return policy;
- }
-
- private static Resource buildResource() {
- Resource resource = new Resource();
- resource.setUniqueId(COMPONENT_ID);
- resource.setName(COMPONENT_NAME);
- resource.setCreatorUserId(USER_ID);
- resource.setLastUpdaterUserId(USER_ID);
- resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- resource.setIsDeleted(false);
- resource.setResourceType(ResourceTypeEnum.VF);
- resource.setToscaType(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
- resource.setComponentType(ComponentTypeEnum.RESOURCE);
- Map<String, PolicyDefinition> policies = new HashMap<>();
- policies.put(POLICY_ID, policy);
- resource.setPolicies(policies);
- return resource;
- }
-
- private static User buildUser() {
- User user = new User();
- user.setUserId(USER_ID);
- return user;
- }
-
private Map<PolicyTargetType, List<String>> getTargetListFakeType() {
Map<PolicyTargetType, List<String>> targets = new HashMap<>();
targets.put(PolicyTargetType.TYPE_DOES_NOT_EXIST, Collections.singletonList(UNIQUE_ID_EXSISTS));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
index 5b4585136f..049f8a5541 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicBaseTestSetup.java
@@ -91,10 +91,18 @@ import org.springframework.web.context.WebApplicationContext;
class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
- protected ServiceBusinessLogic bl;
protected static final String SERVICE_CATEGORY = "Mobility";
protected static final String INSTANTIATION_TYPE = "A-la-carte";
+ protected static final String CERTIFIED_VERSION = "1.0";
+ protected static final String UNCERTIFIED_VERSION = "0.2";
+ protected static final String COMPONNET_ID = "myUniqueId";
+ protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
+ protected static final String SERVICE_ROLE = JsonPresentationFields.SERVICE_ROLE.getPresentation();
+ protected static final String SERVICE_TYPE = JsonPresentationFields.SERVICE_TYPE.getPresentation();
+ protected static final String SERVICE_FUNCTION = JsonPresentationFields.SERVICE_FUNCTION.getPresentation();
protected final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ protected final ComponentValidator componentValidator = Mockito.mock(ComponentValidator.class);
+ protected ServiceBusinessLogic bl;
protected UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
protected WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
protected WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
@@ -112,37 +120,26 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
protected ResourceAdminEvent auditArchive2 = Mockito.mock(ResourceAdminEvent.class);
protected ResourceAdminEvent auditRestore = Mockito.mock(ResourceAdminEvent.class);
protected ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
- IElementOperation mockElementDao = new ElementOperationMock();
- DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
- ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
- ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
- ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
- UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
- protected ServiceCategoryValidator serviceCategoryValidator = new ServiceCategoryValidator(componentsUtils, mockElementDao);
protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
protected ServiceFunctionValidator serviceFunctionValidator = new ServiceFunctionValidator(componentsUtils);
protected ServiceInstantiationTypeValidator serviceInstantiationTypeValidator = new ServiceInstantiationTypeValidator(componentsUtils);
- protected ComponentDescriptionValidator componentDescriptionValidator = new ComponentDescriptionValidator(componentsUtils);
- protected ComponentProjectCodeValidator componentProjectCodeValidator = new ComponentProjectCodeValidator(componentsUtils);
+ protected ComponentDescriptionValidator componentDescriptionValidator = new ComponentDescriptionValidator(componentsUtils);
+ protected ComponentProjectCodeValidator componentProjectCodeValidator = new ComponentProjectCodeValidator(componentsUtils);
protected ComponentIconValidator componentIconValidator = new ComponentIconValidator(componentsUtils);
protected ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
protected ComponentTagsValidator componentTagsValidator = new ComponentTagsValidator(componentsUtils);
protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
- protected final ComponentValidator componentValidator = Mockito.mock(ComponentValidator.class);
- protected ServiceValidator serviceValidator = createServiceValidator();
-
protected User user = null;
protected Resource genericService = null;
-
- protected static final String CERTIFIED_VERSION = "1.0";
- protected static final String UNCERTIFIED_VERSION = "0.2";
- protected static final String COMPONNET_ID = "myUniqueId";
- protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
-
- protected static final String SERVICE_ROLE = JsonPresentationFields.SERVICE_ROLE.getPresentation();
- protected static final String SERVICE_TYPE = JsonPresentationFields.SERVICE_TYPE.getPresentation();
- protected static final String SERVICE_FUNCTION = JsonPresentationFields.SERVICE_FUNCTION.getPresentation();
+ IElementOperation mockElementDao = new ElementOperationMock();
+ protected ServiceCategoryValidator serviceCategoryValidator = new ServiceCategoryValidator(componentsUtils, mockElementDao);
+ protected ServiceValidator serviceValidator = createServiceValidator();
+ DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
+ ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
+ ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
+ ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
+ UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
public ServiceBusinessLogicBaseTestSetup() {
@@ -150,19 +147,17 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
protected ServiceValidator createServiceValidator() {
List<ComponentFieldValidator> componentFieldValidators = Arrays.asList(componentContactIdValidator,
- componentDescriptionValidator,
- componentIconValidator, componentNameValidator,
- new ComponentProjectCodeValidator(componentsUtils),
- componentTagsValidator);
+ componentDescriptionValidator,
+ componentIconValidator, componentNameValidator,
+ new ComponentProjectCodeValidator(componentsUtils),
+ componentTagsValidator);
List<ServiceFieldValidator> serviceFieldValidators = Arrays.asList(serviceCategoryValidator, new ServiceEnvironmentContextValidator(),
- serviceInstantiationTypeValidator, new ServiceNamingPolicyValidator(componentsUtils),
- serviceRoleValidator, serviceTypeValidator);
+ serviceInstantiationTypeValidator, new ServiceNamingPolicyValidator(componentsUtils),
+ serviceRoleValidator, serviceTypeValidator);
return new ServiceValidator(componentsUtils, componentFieldValidators, serviceFieldValidators);
}
-
-
@BeforeEach
public void setup() {
@@ -188,7 +183,8 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
when(catalogOperation.updateCatalog(Mockito.any(), Mockito.any())).thenReturn(ActionStatus.OK);
// artifact bussinesslogic
ArtifactDefinition artifactDef = new ArtifactDefinition();
- when(artifactBl.createArtifactPlaceHolderInfo(Mockito.any(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class), Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
+ when(artifactBl.createArtifactPlaceHolderInfo(Mockito.any(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class),
+ Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
// createService
Service serviceResponse = createServiceObject(true);
@@ -204,27 +200,22 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
Either<Resource, StorageOperationStatus> findLatestGeneric = Either.left(genericService);
when(toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(GENERIC_SERVICE_NAME)).thenReturn(findLatestGeneric);
-
- bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
- groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation,
- artifactBl, distributionEngine, componentInstanceBusinessLogic,
- serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
- artifactToscaOperation, componentContactIdValidator,
- componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator, modelOperation);
+ bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
+ interfaceLifecycleTypeOperation, artifactBl, distributionEngine, componentInstanceBusinessLogic, serviceDistributionValidation,
+ forwardingPathValidator, uiComponentDataConverter, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
+ componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator,
+ modelOperation, serviceRoleValidator, serviceInstantiationTypeValidator, serviceCategoryValidator, serviceValidator, null);
bl.setComponentContactIdValidator(componentContactIdValidator);
bl.setComponentIconValidator(componentIconValidator);
bl.setComponentTagsValidator(componentTagsValidator);
bl.setComponentNameValidator(componentNameValidator);
bl.setComponentDescriptionValidator(componentDescriptionValidator);
bl.setComponentProjectCodeValidator(componentProjectCodeValidator);
- bl.setServiceCategoryValidator(serviceCategoryValidator);
bl.setServiceTypeValidator(serviceTypeValidator);
bl.setServiceFunctionValidator(serviceFunctionValidator);
bl.setElementDao(mockElementDao);
bl.setUserAdmin(mockUserAdmin);
bl.setArtifactBl(artifactBl);
- bl.setServiceValidator(createServiceValidator());
bl.setGraphLockOperation(graphLockOperation);
bl.setJanusGraphDao(mockJanusGraphDao);
bl.setToscaOperationFacade(toscaOperationFacade);
@@ -241,7 +232,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
}
- protected Resource setupGenericServiceMock(){
+ protected Resource setupGenericServiceMock() {
Resource genericService = new Resource();
genericService.setVersion("1.0");
genericService.setToscaResourceName(GENERIC_SERVICE_NAME);
@@ -377,7 +368,8 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
Either<List<DistributionDeployEvent>, ActionStatus> emptyEventList = Either.left(Collections.emptyList());
- Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq("DResult"), Mockito.anyString())).thenReturn(emptyEventList);
+ Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq("DResult"), Mockito.anyString()))
+ .thenReturn(emptyEventList);
}
private void assertResponse(Either<Service, ResponseFormat> createResponse, ActionStatus expectedStatus, String... variables) {
@@ -386,7 +378,7 @@ class ServiceBusinessLogicBaseTestSetup extends BaseBusinessLogicMock {
protected void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
ResponseFormat actualResponse = e.getResponseFormat() != null ?
- e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
assertResponse(actualResponse, expectedStatus, variables);
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
index ac73a0da99..1d6a3ff673 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java
@@ -19,15 +19,15 @@ package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyList;
import static org.mockito.Mockito.anyMap;
import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.components.impl.ServiceImportBusinessLogic.CREATE_RESOURCE;
import fj.data.Either;
import java.io.IOException;
@@ -50,8 +50,8 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
@@ -61,9 +61,9 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.externalapi.servlet.ArtifactExternalServlet;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts;
import org.openecomp.sdc.be.model.ArtifactDefinition;
@@ -96,13 +96,11 @@ import org.openecomp.sdc.be.model.UploadPropInfo;
import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
import org.openecomp.sdc.be.tosca.CsarUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
@@ -111,19 +109,14 @@ import org.openecomp.sdc.exception.ResponseFormat;
class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTestSetup {
@InjectMocks
- private static ServiceImportBusinessLogic serviceImportBusinessLogic;
-
- private ServiceBusinessLogic serviceBusinessLogic = mock(ServiceBusinessLogic.class);
- private CsarBusinessLogic csarBusinessLogic = mock(CsarBusinessLogic.class);
- private ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class);
- private ServiceImportParseLogic serviceImportParseLogic = mock(ServiceImportParseLogic.class);
- private ArtifactDefinition artifactDefinition = mock(ArtifactDefinition.class);
- private UserBusinessLogic userBusinessLogic = mock(UserBusinessLogic.class);
- private ComponentInstanceBusinessLogic componentInstanceBusinessLogic = mock(ComponentInstanceBusinessLogic.class);
- private ComponentsUtils componentsUtils = mock(ComponentsUtils.class);
- private ServletUtils servletUtils = mock(ServletUtils.class);
- private ResourceImportManager resourceImportManager = mock(ResourceImportManager.class);
- private ArtifactsBusinessLogic artifactsBusinessLogic = mock(ArtifactsBusinessLogic.class);
+ private ServiceImportBusinessLogic sIBL;
+
+ @Mock
+ private ArtifactDefinition artifactDefinition;
+ @Mock
+ private ServletUtils servletUtils;
+ @Mock
+ private ResourceImportManager resourceImportManager;
private AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic,
componentInstanceBusinessLogic, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic);
@@ -145,28 +138,69 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(artifactDefinition.getMandatory()).thenReturn(true);
when(artifactDefinition.getArtifactName()).thenReturn("creatorFullName");
when(artifactDefinition.getArtifactType()).thenReturn("TOSCA_CSAR");
-
- sIB1.setServiceBusinessLogic(serviceBusinessLogic);
- sIB1.setCsarBusinessLogic(csarBusinessLogic);
- sIB1.setServiceImportParseLogic(serviceImportParseLogic);
- sIB1.setToscaOperationFacade(toscaOperationFacade);
- sIB1.setComponentsUtils(componentsUtils);
- sIB1.setCsarArtifactsAndGroupsBusinessLogic(csarArtifactsAndGroupsBusinessLogic);
-
}
@Test
- void testGetComponentsUtils() {
- assertNotNull(serviceImportBusinessLogic.getComponentsUtils());
- }
+ void testCreateService_OK() {
+ Service oldService = createServiceObject(true);
+ String payloadName = "valid_vf";
+ Map<String, byte[]> payload = crateCsarFromPayload();
+ Service newService = createServiceObject(true);
+ newService.setComponentInstances(creatComponentInstances());
- @Test
- void testSetComponentsUtils() {
- assertNotNull(serviceImportBusinessLogic);
+ when(serviceBusinessLogic.validateServiceBeforeCreate(eq(newService), any(User.class), any(AuditingActionEnum.class)))
+ .thenReturn(Either.left(newService));
+ when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK);
+ CsarInfo csarInfo = getCsarInfo();
+ when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(csarInfo);
+ when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class)))
+ .thenReturn(Either.left(new HashMap<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>>()));
+ when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class)))
+ .thenReturn(getParsedToscaYamlInfo());
+ when(serviceBusinessLogic.lockComponentByName(newService.getSystemName(), oldService, CREATE_RESOURCE)).thenReturn(Either.left(true));
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(createOldResource()));
+ when(serviceImportParseLogic.createServiceTransaction(oldService, csarInfo.getModifier(), false)).thenReturn(newService);
+ when(serviceImportParseLogic.createInputsOnService(eq(oldService), anyMap())).thenReturn(newService);
+ Assertions.assertDoesNotThrow(() -> {
+ when(serviceImportParseLogic.createSubstitutionFilterOnService(eq(oldService), any())).thenReturn(newService);
+ });
+ when(serviceImportParseLogic.getNodeTypesFromTemplate(anyMap())).thenReturn(getNodeTypes());
+ when(serviceImportParseLogic.createNodeTypeResourceFromYaml(anyString(), any(Map.Entry.class), any(User.class), anyMap(), any(Service.class),
+ anyBoolean(), any(), anyList(), anyBoolean(), any(CsarInfo.class), anyBoolean())).thenReturn(
+ new ImmutablePair<>(new Resource(), ActionStatus.OK));
+ when(serviceImportParseLogic.getComponentWithInstancesFilter()).thenReturn(new ComponentParametersView());
+ when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))).thenReturn(Either.left(newService));
+ when(serviceImportParseLogic.getComponentFilterAfterCreateRelations()).thenReturn(new ComponentParametersView());
+ when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))).thenReturn(Either.left(newService));
+ when(serviceImportParseLogic.findAvailableRequirement(anyString(), anyString(), any(UploadComponentInstanceInfo.class),
+ any(ComponentInstance.class), anyString())).thenReturn(Either.left(new RequirementDefinition()));
+ when(serviceImportParseLogic.findAvailableCapabilityByTypeOrName(any(RequirementDefinition.class), any(ComponentInstance.class),
+ any(UploadReqInfo.class))).thenReturn(new CapabilityDefinition());
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.OK), anyString())).thenReturn(new ResponseFormat(200));
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(newService));
+ doNothing().when(compositionBusinessLogic).setPositionsForComponentInstances(any(Service.class), anyString());
+ when(groupBusinessLogic.validateUpdateVfGroupNames(anyMap(), anyString())).thenReturn(Either.left(new HashMap<>()));
+ when(csarArtifactsAndGroupsBusinessLogic.deleteVFModules(any(Service.class), any(CsarInfo.class), anyBoolean(), anyBoolean()))
+ .thenReturn(Either.left(newService));
+ when(serviceImportParseLogic.getServiceWithGroups(anyString())).thenReturn(newService);
+ when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
+ when(graphLockOperation.unlockComponentByName(anyString(), anyString(), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK);
+
+ Service result = sIBL.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName);
+ assertNotNull(result);
+ assertNotNull(result.getComponentInstances());
+ assertEquals(1, result.getComponentInstances().size());
+ assertNotNull(result.getComponentInstances().get(0));
+ assertNotNull(result.getComponentInstances().get(0).getCapabilities());
+ assertEquals(1, result.getComponentInstances().get(0).getCapabilities().size());
+ assertNotNull(result.getComponentInstances().get(0).getRequirements());
+ assertEquals(1, result.getComponentInstances().get(0).getRequirements().size());
+ assertNotNull(result.getCategories());
+ assertEquals(1, result.getCategories().size());
}
@Test
- void testCreateService() {
+ void testCreateService_Fail_NotFoundNodeTypesArtifacts() {
Service oldService = createServiceObject(true);
String payloadName = "valid_vf";
Map<String, byte[]> payload = crateCsarFromPayload();
@@ -175,16 +209,14 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceBusinessLogic.validateServiceBeforeCreate(any(Service.class), any(User.class), any(AuditingActionEnum.class)))
.thenReturn(Either.left(newService));
when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK);
- when(csarBusinessLogic.getCsarInfo(any(Service.class), any(),
- any(User.class), any(Map.class), anyString())).thenReturn(getCsarInfo());
- when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class),
- any(Service.class))).thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
- when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(),
- any(CsarInfo.class), anyString(), any(Service.class))).thenReturn(getParsedToscaYamlInfo());
-
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createService(oldService,
- AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName));
+ when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(getCsarInfo());
+ when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class)))
+ .thenReturn(Either.right(ActionStatus.GENERAL_ERROR));
+ when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), anyString(),
+ any(Service.class))).thenReturn(getParsedToscaYamlInfo());
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName));
}
@Test
@@ -200,7 +232,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
any(Map.class), anyString())).thenReturn(csarInfo);
when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class),
any(Service.class))).thenReturn(Either.left(map));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceFromCsar(oldService,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromCsar(oldService,
user, payload, csarUUID));
}
@@ -219,14 +251,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
map.put("tosca_definitions_version", "123");
nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map);
ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo();
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(Map.class),
eq(csarInfo), anyString(), any(Component.class))).thenReturn(parsedToscaYamlInfo);
when(serviceBusinessLogic.lockComponentByName(anyString(), any(Service.class), anyString()))
.thenReturn(Either.left(true));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceFromYaml(oldService,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromYaml(oldService,
topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo,
nodeTypesArtifactsToCreate, false, true, nodeName));
}
@@ -245,9 +276,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo();
csfyp.setNodeTypesInfo(nodeTypesInfo);
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceAndRIsFromYaml(oldService,
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService,
false, nodeTypesArtifactsToCreate, false, true, csfyp));
}
@@ -265,9 +295,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo();
csfyp.setNodeTypesInfo(nodeTypesInfo);
csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo);
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceAndRIsFromYaml(oldService,
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService,
false, nodeTypesArtifactsToCreate, false, true, csfyp));
}
@@ -295,11 +324,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
nodeTypeInfoToUpdateArtifacts.setNodeTypesArtifactsToHandle(nodeTypesArtifactsToHandle);
Assertions.assertNotNull(
- sIB1.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
+ sIBL.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
preparedResource, nodeTypeInfoToUpdateArtifacts, true, true)
);
-
-
}
@Test
@@ -324,7 +351,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
.createResourceArtifactsFromCsar(any(CsarInfo.class), any(Resource.class), anyString(), anyString(),
anyList())).thenReturn(Either.left(resource));
Assertions.assertNotNull(
- sIB1.handleVfCsarArtifacts(resource,
+ sIBL.handleVfCsarArtifacts(resource,
csarInfo, createdArtifacts, artifactOperation, true, true));
}
@@ -350,7 +377,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
.createResourceArtifactsFromCsar(any(CsarInfo.class), any(Resource.class), anyString(), anyString(),
anyList())).thenReturn(Either.left(resource));
Assertions.assertNotNull(
- sIB1.handleVfCsarArtifacts(resource,
+ sIBL.handleVfCsarArtifacts(resource,
csarInfo, createdArtifacts, artifactOperation, true, true));
}
@@ -366,7 +393,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
resource.setDeploymentArtifacts(deploymentArtifacts);
Assertions.assertNotNull(resource);
Assertions.assertNotNull(csarInfo);
- sIB1.createOrUpdateSingleNonMetaArtifactToComstants(resource, csarInfo, artifactOperation, true, true);
+ sIBL.createOrUpdateSingleNonMetaArtifactToComstants(resource, csarInfo, artifactOperation, true, true);
}
@@ -377,7 +404,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE);
- Either<Resource, ResponseFormat> result = sIB1.createOrUpdateNonMetaArtifacts(csarInfo, resource,
+ Either<Resource, ResponseFormat> result = sIBL.createOrUpdateNonMetaArtifacts(csarInfo, resource,
createdArtifacts, true, true, artifactOperation);
assertEquals(result.left().value(), resource);
}
@@ -402,23 +429,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>,
- ResponseFormat> result = sIB1.findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, user);
+ ResponseFormat> result = sIBL.findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, user);
assertNotNull(result.left().value());
}
@Test
- void testIsNonMetaArtifact() {
- ArtifactDefinition artifactDefinition = new ArtifactDefinition();
- artifactDefinition.setMandatory(false);
- artifactDefinition.setArtifactName("creatorFullName");
- artifactDefinition.setArtifactType("TOSCA_CSAR");
-
- boolean nonMetaArtifact = sIB1.isNonMetaArtifact(artifactDefinition);
- assertTrue(nonMetaArtifact);
-
- }
-
- @Test
void testOrganizeVfCsarArtifactsByArtifactOperation() {
List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
artifactPathAndNameList.add(getNonMetaArtifactInfo());
@@ -431,7 +446,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createParseResourceObject(false);
Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
- enumMapResponseFormatEither = sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle,
+ enumMapResponseFormatEither = sIBL.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList,
+ existingArtifactsToHandle,
resource, user);
assertNotNull(enumMapResponseFormatEither.left().value());
}
@@ -448,8 +464,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
existingArtifactsToHandle.add(artifactDefinition);
Resource resource = createParseResourceObject(false);
Assertions.assertNotNull(
- sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, resource, user));
-
+ sIBL.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, resource,
+ user));
}
@Test
@@ -464,9 +480,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class);
vfCsarArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactPathAndNameList);
Assertions.assertNotNull(
- sIB1.processCsarArtifacts(csarInfo,
+ sIBL.processCsarArtifacts(csarInfo,
resource, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle));
-
}
@Test
@@ -494,31 +509,16 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Either<ArtifactDefinition, Operation> artifactDefinitionOperationEither = Either.left(artifactDefinition);
when(csarArtifactsAndGroupsBusinessLogic.createOrUpdateCsarArtifactFromJson(any(Resource.class), any(User.class),
any(Map.class), any(ArtifactOperationInfo.class))).thenReturn(Either.left(artifactDefinitionOperationEither));
+ when(artifactsBusinessLogic.handleDelete(anyString(), anyString(), any(User.class), any(Component.class), anyBoolean(), anyBoolean()))
+ .thenReturn(Either.left(artifactDefinition));
Assertions.assertNotNull(
- sIB1.createOrUpdateSingleNonMetaArtifact(resource, csarInfo, artifactPath,
+ sIBL.createOrUpdateSingleNonMetaArtifact(resource, csarInfo, artifactPath,
artifactFileName, artifactType, artifactGroupType, artifactLabel,
artifactDisplayName, artifactDescription, artifactId, artifactOperation,
createdArtifacts, true, true, true));
}
@Test
- void testHandleNodeTypeArtifacts() {
- Resource nodeTypeResource = createParseResourceObject(true);
- nodeTypeResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
- Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = new HashMap<>();
- List<ArtifactDefinition> artifactDefinitions = new ArrayList<>();
- ArtifactDefinition artifactDefinition = new ArtifactDefinition();
- artifactDefinition.setArtifactName("artifactName");
- artifactDefinitions.add(artifactDefinition);
- nodeTypeArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,
- artifactDefinitions);
- List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- Assertions.assertNotNull(
- sIB1.handleNodeTypeArtifacts(nodeTypeResource, nodeTypeArtifactsToHandle,
- createdArtifacts, user, true, true));
- }
-
- @Test
void testCreateOrUpdateServiceArtifacts() throws IOException {
ArtifactsBusinessLogic.ArtifactOperationEnum operation = ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE;
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
@@ -543,7 +543,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(csarArtifactsAndGroupsBusinessLogic.updateResourceArtifactsFromCsar(any(CsarInfo.class), any(Service.class),
anyString(), anyString(), anyList(), anyBoolean(), anyBoolean())).thenReturn(Either.left(preparedService));
Assertions.assertNotNull(
- sIB1.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
+ sIBL.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo,
preparedService, nodeTypeInfoToUpdateArtifacts, true, true));
}
@@ -563,8 +563,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(csarArtifactsAndGroupsBusinessLogic.deleteVFModules(any(Service.class), any(CsarInfo.class), anyBoolean(), anyBoolean())).thenReturn(
Either.left(service));
Assertions.assertNotNull(
- sIB1.handleVfCsarArtifacts(service, csarInfo, createdArtifacts, artifactOperation, true, true));
-
+ sIBL.handleVfCsarArtifacts(service, csarInfo, createdArtifacts, artifactOperation, true, true));
}
@Test
@@ -588,7 +587,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(csarArtifactsAndGroupsBusinessLogic.createResourceArtifactsFromCsar(any(CsarInfo.class), any(Service.class),
anyString(), anyString(), anyList())).thenReturn(Either.left(service));
Assertions.assertNotNull(
- sIB1.handleVfCsarArtifacts(service,
+ sIBL.handleVfCsarArtifacts(service,
csarInfo, createdArtifacts, artifactOperation, true, true));
}
@@ -599,7 +598,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE);
- Either<Service, ResponseFormat> result = sIB1.createOrUpdateNonMetaArtifacts(csarInfo,
+ Either<Service, ResponseFormat> result = sIBL.createOrUpdateNonMetaArtifacts(csarInfo,
service, createdArtifacts, true, true, artifactOperation);
assertEquals(result.left().value(), service);
}
@@ -624,7 +623,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>,
- ResponseFormat> result = sIB1.findVfCsarArtifactsToHandle(service, artifactPathAndNameList, user);
+ ResponseFormat> result = sIBL.findVfCsarArtifactsToHandle(service, artifactPathAndNameList, user);
assertNotNull(result.left().value());
}
@@ -641,7 +640,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Service service = createServiceObject(true);
Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
- enumMapResponseFormatEither = sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList,
+ enumMapResponseFormatEither = sIBL.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList,
existingArtifactsToHandle, service, user);
assertNotNull(enumMapResponseFormatEither.left().value());
}
@@ -658,7 +657,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
existingArtifactsToHandle.add(artifactDefinition);
Service service = createServiceObject(true);
Assertions.assertNotNull(
- sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, service, user));
+ sIBL.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, service, user));
}
@@ -674,16 +673,15 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
objects.add(getNonMetaArtifactInfo());
vfCsarArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, objects);
Assertions.assertNotNull(
- sIB1.processCsarArtifacts(csarInfo,
- service, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle));
-
+ sIBL.processCsarArtifacts(csarInfo, service, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle));
}
@Test
void testGetValidArtifactNames() {
CsarInfo csarInfo = getCsarInfo();
Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
- Either<List<CsarUtils.NonMetaArtifactInfo>, String> result = sIB1.getValidArtifactNames(csarInfo, collectedWarningMessages);
+ Either<List<CsarUtils.NonMetaArtifactInfo>, String> result = sIBL.getValidArtifactNames(csarInfo,
+ collectedWarningMessages);
assertNotNull(result.left().value());
}
@@ -713,8 +711,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Either<ArtifactDefinition, Operation> artifactDefinitionOperationEither = Either.left(artifactDefinition);
when(csarArtifactsAndGroupsBusinessLogic.createOrUpdateCsarArtifactFromJson(any(Service.class), any(User.class),
anyMap(), any(ArtifactOperationInfo.class))).thenReturn(Either.left(artifactDefinitionOperationEither));
+ when(artifactsBusinessLogic.handleDelete(anyString(), anyString(), any(User.class), any(Component.class), anyBoolean(), anyBoolean()))
+ .thenReturn(Either.left(artifactDefinition));
Assertions.assertNotNull(
- sIB1.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName,
+ sIBL.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName,
artifactType, artifactGroupType, artifactLabel, artifactDisplayName,
artifactDescription, artifactId, artifactOperation, createdArtifacts,
true, true, true));
@@ -729,8 +729,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
String artifactLabel = "", artifactDisplayName = "", artifactDescription = "", artifactId = "artifactId";
ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE);
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
+ when(artifactsBusinessLogic.handleDelete(anyString(), anyString(), any(User.class), any(Component.class), anyBoolean(), anyBoolean()))
+ .thenReturn(Either.left(artifactDefinition));
Assertions.assertNotNull(
- sIB1.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName,
+ sIBL.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName,
artifactType, artifactGroupType, artifactLabel, artifactDisplayName,
artifactDescription, artifactId, artifactOperation, createdArtifacts,
true, true, true));
@@ -740,29 +742,28 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
void testCreateGroupsOnResource() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = new HashMap<>();
- Assertions.assertNotNull(
- sIB1.createGroupsOnResource(service, groups));
+ Assertions.assertNotNull(sIBL.createGroupsOnResource(service, groups));
}
@Test
void testCreateGroupsOnResourceNull() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = new HashMap<>();
- Assertions.assertNotNull(sIB1.createGroupsOnResource(service, groups));
+ Assertions.assertNotNull(sIBL.createGroupsOnResource(service, groups));
}
@Test
void testUpdateGroupsMembersUsingResource() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIB1.updateGroupsMembersUsingResource(groups, service));
+ Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, service));
}
@Test
void testUpdateGroupsMembersUsingResource_left() {
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIB1.updateGroupsMembersUsingResource(groups, service));
+ Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, service));
}
@Test
@@ -782,7 +783,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
CsarInfo csarInfo = getCsarInfo();
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createRIAndRelationsFromYaml(yamlName, resource, uploadComponentInstanceInfoMap,
topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
csarInfo, nodeTypesArtifactsToCreate, nodeName));
@@ -795,10 +796,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
resource.setComponentInstances(creatComponentInstances());
resource.setResourceType(ResourceTypeEnum.VF);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- uploadResInstancesMap.put("uploadResInstancesMap", getuploadComponentInstanceInfo());
+ uploadResInstancesMap.put("uploadResInstancesMap", getUploadComponentInstanceInfo());
when(serviceImportParseLogic.getResourceAfterCreateRelations(any(Resource.class))).thenReturn(resource);
when(toscaOperationFacade.getToscaFullElement(anyString())).thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createResourceInstancesRelations(user, yamlName, resource, uploadResInstancesMap));
}
@@ -809,10 +810,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
resource.setComponentInstances(creatComponentInstances());
resource.setResourceType(ResourceTypeEnum.VF);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- uploadResInstancesMap.put("uploadResInstancesMap", getuploadComponentInstanceInfo());
+ uploadResInstancesMap.put("uploadResInstancesMap", getUploadComponentInstanceInfo());
when(serviceImportParseLogic.getResourceAfterCreateRelations(any(Resource.class))).thenReturn(resource);
when(toscaOperationFacade.getToscaFullElement(anyString())).thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createResourceInstancesRelations(user, yamlName, resource, uploadResInstancesMap));
}
@@ -842,7 +843,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
uploadComponentInstanceInfo.setName("zxjTestImportServiceAb");
Assertions.assertNotNull(resource);
Assertions.assertNotNull(yamlName);
- sIB1.processComponentInstance(yamlName, resource, componentInstancesList, allDataTypes.left().value(), instProperties,
+ sIBL.processComponentInstance(yamlName, resource, componentInstancesList, allDataTypes.left().value(), instProperties,
instCapabilties, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes,
originCompMap, instInputs, instNodeFilter, uploadComponentInstanceInfo);
}
@@ -867,7 +868,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
uploadComponentInstanceInfo.setName("zxjTestImportServiceAb0");
- Assertions.assertThrows(ComponentException.class, () -> sIB1.processComponentInstance(yamlName,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.processComponentInstance(yamlName,
resource, componentInstancesList, null, instProperties, instCapabilties,
instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap,
instInputs, instNodeFilter, uploadComponentInstanceInfo));
@@ -896,7 +897,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
dataTypeDefinition.setName("dataTypeDefinitionName");
allDataTypes.put("dataTypeDefinitionMap", dataTypeDefinition);
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource,
currentCompInstance, instInputs, allDataTypes));
}
@@ -919,7 +920,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<UploadPropInfo> propertyList = getPropertyList();
Assertions.assertNotNull(resource);
Assertions.assertNotNull(currPropertiesMap);
- sIB1.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
+ sIBL.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
}
@Test
@@ -930,8 +931,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(toscaOperationFacade.getToscaFullElement(anyString()))
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .handleSubstitutionMappings(resource, uploadResInstancesMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.handleSubstitutionMappings(resource, uploadResInstancesMap));
}
@Test
@@ -942,8 +943,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(toscaOperationFacade.getToscaFullElement(anyString()))
.thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .handleSubstitutionMappings(resource, uploadResInstancesMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.handleSubstitutionMappings(resource, uploadResInstancesMap));
}
@Test
@@ -959,8 +960,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Resource> nodeNamespaceMap = new HashMap<>();
nodeNamespaceMap.put("resources", originResource);
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createResourceInstances(yamlName, resource, uploadResInstancesMap, nodeNamespaceMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.createResourceInstances(yamlName, resource, uploadResInstancesMap, nodeNamespaceMap));
}
@Test
@@ -980,7 +981,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
CsarInfo csarInfo = getCsarInfo();
Assertions.assertNotNull(resource);
- sIB1.handleNodeTypes(yamlName, resource, topologyTemplateYaml, needLock, nodeTypesArtifactsToHandle,
+ sIBL.handleNodeTypes(yamlName, resource, topologyTemplateYaml, needLock, nodeTypesArtifactsToHandle,
nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeName);
}
@@ -997,7 +998,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
nodesInfo.put(nodeName, nodeTypeInfo);
CsarInfo csarInfo = getCsarInfo();
- Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVfc(resource,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.handleNestedVfc(resource,
nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName));
}
@@ -1017,28 +1018,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.validateNestedDerivedFromDuringUpdate(any(Resource.class), any(Resource.class),
anyBoolean())).thenReturn(Either.left(true));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.handleComplexVfc(resource,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.handleComplexVfc(resource,
nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName));
}
@Test
- void testCreateResourcesFromYamlNodeTypesList1() {
- String yamlName = "group.yml";
- Resource resource = createParseResourceObject(false);
- Map<String, Object> mappedToscaTemplate = new HashMap<>();
- boolean needLock = true;
- Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
- Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
- CsarInfo csarInfo = getCsarInfo();
-
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock,
- nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo));
-
- }
-
- @Test
void testCreateNodeTypes1() {
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
String yamlName = "group.yml";
@@ -1067,7 +1051,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
nodeTypes.put(nodeName, "");
Assertions.assertNotNull(resource);
- sIB1.createNodeTypes(yamlName,
+ sIBL.createNodeTypes(yamlName,
resource, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
nodeTypesInfo, csarInfo, mapToConvert, nodeTypes);
}
@@ -1101,7 +1085,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
anyMap(), anyList(), anyBoolean(), any(CsarInfo.class),
anyString(), anyBoolean())).thenReturn(immutablePair);
Assertions.assertNotNull(
- sIB1.createNodeTypeResourceFromYaml(yamlName, nodeNameValue, user, mapToConvert,
+ sIBL.createNodeTypeResourceFromYaml(yamlName, nodeNameValue, user, mapToConvert,
resourceVf, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts,
forceCertificationAllowed, csarInfo, isNested));
}
@@ -1119,7 +1103,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- Assertions.assertNotNull(sIB1
+ Assertions.assertNotNull(sIBL
.createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap,
topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
csarInfo, nodeTypesArtifactsToCreate, nodeName));
@@ -1150,8 +1134,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
any(ComponentInstance.class), any(UploadReqInfo.class))).thenReturn(capabilityDefinition);
when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat);
when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(service));
- Assertions.assertNotNull(sIB1
- .createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap));
+ Assertions.assertNotNull(sIBL.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap));
}
@Test
@@ -1161,8 +1144,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
service.setComponentInstances(creatComponentInstances());
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap));
}
@Test
@@ -1191,7 +1174,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
uploadComponentInstanceInfo.setName("zxjTestImportServiceAb");
Assertions.assertNotNull(service);
- sIB1.processComponentInstance(yamlName, service, componentInstancesList, allDataTypes.left().value(),
+ sIBL.processComponentInstance(yamlName, service, componentInstancesList, allDataTypes.left().value(),
instProperties, instCapabilties, instRequirements, instDeploymentArtifacts,
instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter,
uploadComponentInstanceInfo);
@@ -1217,7 +1200,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
uploadComponentInstanceInfo.setName("zxjTestImportServiceAb0");
- Assertions.assertThrows(ComponentException.class, () -> sIB1.processComponentInstance(yamlName,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.processComponentInstance(yamlName,
service, componentInstancesList, null, instProperties, instCapabilties,
instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap,
instInputs, instNodeFilter, uploadComponentInstanceInfo));
@@ -1245,7 +1228,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource,
currentCompInstance, instInputs, allDataTypes));
}
@@ -1277,7 +1260,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
propertyList.add(propertyInfo);
Assertions.assertNotNull(resource);
- sIB1.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
+ sIBL.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
}
@Test
@@ -1286,8 +1269,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<InputDefinition> inputs = new ArrayList<>();
GetInputValueDataDefinition getInputIndex = new GetInputValueDataDefinition();
- Assertions.assertThrows(ComponentException.class, () -> sIB1.processGetInput(getInputValues,
- inputs, getInputIndex));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.processGetInput(getInputValues, inputs, getInputIndex));
}
@Test
@@ -1302,7 +1284,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
getInputIndex.setInputName("InputName");
Assertions.assertNotNull(inputs);
- sIB1.processGetInput(getInputValues, inputs, getInputIndex);
+ sIBL.processGetInput(getInputValues, inputs, getInputIndex);
}
@Test
@@ -1323,11 +1305,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>();
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
ResponseFormat responseFormat = new ResponseFormat();
- when(serviceImportParseLogic.findInputByName(anyList(), any(GetInputValueDataDefinition.class)))
+ when(serviceImportParseLogic.findInputByName(eq(inputs), any(GetInputValueDataDefinition.class)))
.thenReturn(inputDefinition);
when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat);
Assertions.assertNotNull(
- sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource,
+ sIBL.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource,
currentCompInstance, instProperties, allDataTypes));
}
@@ -1343,9 +1325,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ResponseFormat responseFormat = new ResponseFormat();
when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat);
Assertions.assertNotNull(
- sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance,
+ sIBL.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance,
instProperties, allDataTypes));
-
}
@Test
@@ -1370,7 +1351,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.findInputByName(anyList(), any(GetInputValueDataDefinition.class)))
.thenReturn(inputDefinition);
Assertions.assertNotNull(
- sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource,
+ sIBL.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource,
currentCompInstance, instProperties, allDataTypes));
}
@@ -1386,7 +1367,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ResponseFormat responseFormat = new ResponseFormat();
when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat);
Assertions.assertNotNull(
- sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance,
+ sIBL.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance,
instProperties, allDataTypes));
}
@@ -1399,8 +1380,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
ComponentInstance currentCompInstance = new ComponentInstance();
Resource originResource = createParseResourceObject(false);
Assertions.assertNotNull(originResource);
- sIB1.processComponentInstanceCapabilities(null, instCapabilties,
- uploadComponentInstanceInfo, currentCompInstance, originResource);
+ sIBL.processComponentInstanceCapabilities(null, instCapabilties, uploadComponentInstanceInfo, currentCompInstance,
+ originResource);
}
@Test
@@ -1412,8 +1393,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource originResource = createParseResourceObject(false);
Assertions.assertNotNull(originResource);
- sIB1.processComponentInstanceCapabilities(null, instCapabilties, uploadComponentInstanceInfo,
- currentCompInstance, originResource);
+ sIBL.processComponentInstanceCapabilities(null, instCapabilties, uploadComponentInstanceInfo, currentCompInstance,
+ originResource);
}
@Test
@@ -1422,7 +1403,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, List<CapabilityDefinition>> originCapabilities = new HashMap<>();
Map<String, Map<String, UploadPropInfo>> newPropertiesMap = new HashMap<>();
Assertions.assertNull(allDataTypes);
- sIB1.updateCapabilityPropertiesValues(null, originCapabilities, newPropertiesMap, null);
+ sIBL.updateCapabilityPropertiesValues(null, originCapabilities, newPropertiesMap);
}
@Test
@@ -1431,7 +1412,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, UploadPropInfo> newProperties = new HashMap<>();
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
Assertions.assertNotNull(allDataTypes);
- sIB1.updatePropertyValues(properties, newProperties, allDataTypes);
+ sIBL.updatePropertyValues(properties, newProperties, allDataTypes);
}
@Test
@@ -1443,8 +1424,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
when(serviceBusinessLogic.validatePropValueBeforeCreate(any(IPropertyInputCommon.class), anyString(), anyBoolean(), anyMap())).thenReturn(
"qw");
- Assertions.assertNotNull(
- sIB1.updatePropertyValue(property, propertyInfo, allDataTypes));
+ Assertions.assertNotNull(sIBL.updatePropertyValue(property, propertyInfo, allDataTypes));
}
@Test
@@ -1455,17 +1435,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
currentCompInstance.setComponentUid("currentCompInstance");
when(toscaOperationFacade.getToscaFullElement(anyString()))
.thenReturn(Either.left(createParseResourceObject(true)));
- Assertions.assertNotNull(
- sIB1.getOriginResource(yamlName, originCompMap, currentCompInstance));
- }
-
- @Test
- void testHandleSubstitutionMappings2() {
- Service service = createServiceObject(true);
- Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- Assertions.assertNotNull(service);
-
- sIB1.handleSubstitutionMappings(service, uploadResInstancesMap);
+ Assertions.assertNotNull(sIBL.getOriginResource(yamlName, originCompMap, currentCompInstance));
}
@Test
@@ -1475,8 +1445,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = getUploadResInstancesMap();
when(toscaOperationFacade.deleteAllCalculatedCapabilitiesRequirements(any())).thenReturn(StorageOperationStatus.OK);
- Assertions.assertNotNull(
- sIB1.updateCalculatedCapReqWithSubstitutionMappings(resource, uploadResInstancesMap));
+ Assertions.assertNotNull(sIBL.updateCalculatedCapReqWithSubstitutionMappings(resource, uploadResInstancesMap));
}
@Test
@@ -1487,7 +1456,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirement = new HashMap<>();
Assertions.assertNotNull(componentInstances);
- sIB1.fillUpdatedInstCapabilitiesRequirements(componentInstances, uploadResInstancesMap,
+ sIBL.fillUpdatedInstCapabilitiesRequirements(componentInstances, uploadResInstancesMap,
updatedInstCapabilities, updatedInstRequirement);
}
@@ -1506,7 +1475,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
capabilitiesNamesToUpdate.put("mme_ipu_vdu.feature", "capabilitiesNamesToUpdate");
Assertions.assertNotNull(instance);
- sIB1.fillUpdatedInstCapabilities(updatedInstCapabilties, instance, capabilitiesNamesToUpdate);
+ sIBL.fillUpdatedInstCapabilities(updatedInstCapabilties, instance, capabilitiesNamesToUpdate);
}
@Test
@@ -1526,7 +1495,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
"requirementsNamesToUpdate");
Assertions.assertNotNull(instance);
- sIB1.fillUpdatedInstRequirements(updatedInstRequirements, instance, requirementsNamesToUpdate);
+ sIBL.fillUpdatedInstRequirements(updatedInstRequirements, instance, requirementsNamesToUpdate);
}
@Test
@@ -1535,7 +1504,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Service service = createServiceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
List<ComponentInstance> componentInstancesList = creatComponentInstances();
ComponentInstance componentInstance = new ComponentInstance();
@@ -1561,7 +1530,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat);
Assertions.assertNotNull(service);
- sIB1.addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations);
+ sIBL.addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations);
}
@Test
@@ -1569,12 +1538,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
String yamlName = "group.yml";
Service service = createServiceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
List<ComponentInstance> componentInstancesList = new ArrayList<>();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1.addRelationsToRI(yamlName,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.addRelationsToRI(yamlName,
service, uploadResInstancesMap, componentInstancesList, relations));
}
@@ -1584,7 +1553,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Service service = createServiceObject(true);
service.setComponentInstances(creatComponentInstances());
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
RequirementDefinition requirementDefinition = new RequirementDefinition();
requirementDefinition.setName("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test");
@@ -1598,8 +1567,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.findAvailableCapabilityByTypeOrName(any(RequirementDefinition.class),
any(ComponentInstance.class), any(UploadReqInfo.class))).thenReturn(capabilityDefinition);
when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat);
- Assertions.assertNotNull(
- sIB1.addRelationToRI(yamlName, service, nodesInfoValue, relations));
+ Assertions.assertNotNull(sIBL.addRelationToRI(yamlName, service, nodesInfoValue, relations));
}
@Test
@@ -1609,11 +1577,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
List<ComponentInstance> componentInstancesList = new ArrayList<>();
service.setComponentInstances(componentInstancesList);
ResponseFormat responseFormat = new ResponseFormat();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat);
- Assertions.assertNotNull(
- sIB1.addRelationToRI(yamlName, service, nodesInfoValue, relations));
+ Assertions.assertNotNull(sIBL.addRelationToRI(yamlName, service, nodesInfoValue, relations));
}
@@ -1624,8 +1591,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.getComponentFilterAfterCreateRelations()).thenReturn(componentParametersView);
when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class)))
.thenReturn(Either.left(createServiceObject(true)));
- Assertions.assertNotNull(
- sIB1.getResourceAfterCreateRelations(service));
+ Assertions.assertNotNull(sIBL.getResourceAfterCreateRelations(service));
}
@Test
@@ -1633,20 +1599,20 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
String yamlName = "group.yml";
Service service = createServiceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
uploadResInstancesMap.put("uploadResInstancesMap", nodesInfoValue);
Map<String, Resource> nodeNamespaceMap = new HashMap<>();
Resource resource = createParseResourceObject(true);
resource.setToscaResourceName("toscaResourceName");
nodeNamespaceMap.put("nodeNamespaceMap", resource);
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createServiceInstances(yamlName, service, uploadResInstancesMap, nodeNamespaceMap));
+ Assertions.assertThrows(ComponentException.class,
+ () -> sIBL.createServiceInstances(yamlName, service, uploadResInstancesMap, nodeNamespaceMap));
}
@Test
void testCreateAndAddResourceInstance() {
- UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
String yamlName = "group.yml";
Resource resource = createParseResourceObject(false);
Resource originResource = createParseResourceObject(true);
@@ -1656,14 +1622,14 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Resource> existingnodeTypeMap = new HashMap<>();
Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createAndAddResourceInstance(uploadComponentInstanceInfo, yamlName, resource,
nodeNamespaceMap, existingnodeTypeMap, resourcesInstancesMap));
}
@Test
void testCreateAndAddResourceInstances() {
- UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
String yamlName = "group.yml";
Service service = createServiceObject(true);
service.setServiceType("services");
@@ -1674,7 +1640,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, Resource> existingnodeTypeMap = new HashMap<>();
Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createAndAddResourceInstance(uploadComponentInstanceInfo, yamlName, service,
nodeNamespaceMap, existingnodeTypeMap, resourcesInstancesMap));
}
@@ -1682,7 +1648,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
@Test
void testValidateResourceInstanceBeforeCreate() {
String yamlName = "group.yml";
- UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
Resource originResource = createParseResourceObject(true);
ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition();
componentMetadataDataDefinition.setState(LifecycleStateEnum.CERTIFIED.name());
@@ -1694,10 +1660,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
originResource.setResourceType(ResourceTypeEnum.VF);
Map<String, Resource> nodeNamespaceMap = new HashMap<>();
nodeNamespaceMap.put("resources", originResource);
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(originResource));
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(originResource));
Assertions.assertNotNull(
- sIB1.validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, nodeNamespaceMap));
+ sIBL.validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, nodeNamespaceMap));
}
@Test
@@ -1712,20 +1677,19 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo();
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
- .thenReturn(Either.left(createOldResource()));
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(createOldResource()));
Assertions.assertNotNull(service);
- sIB1.handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, needLock,
- nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
- csarInfo, nodeName);
+ sIBL.handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, needLock, nodeTypesArtifactsToHandle,
+ nodeTypesNewCreatedArtifacts,
+ nodeTypesInfo, csarInfo, nodeName);
}
@Test
void testValidateResourceNotExisted() {
String type = "org.openecomp.resource.vf";
- Assertions.assertThrows(ComponentException.class, () -> sIB1.validateResourceNotExisted(type));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.validateResourceNotExisted(type));
}
@Test
@@ -1737,7 +1701,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVF(service,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.handleNestedVF(service,
nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName));
}
@@ -1750,7 +1714,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
- Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVfc(service,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.handleNestedVfc(service,
nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName));
}
@@ -1769,7 +1733,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceImportParseLogic.validateNestedDerivedFromDuringUpdate(any(Resource.class), any(Resource.class), anyBoolean()))
.thenReturn(Either.left(true));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo,
csarInfo, nodeName, yamlName));
}
@@ -1787,7 +1751,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(toscaOperationFacade.getFullLatestComponentByToscaResourceName(anyString()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo,
csarInfo, nodeName, yamlName));
}
@@ -1806,7 +1770,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource oldComplexVfc = createParseResourceObject(false);
Resource newComplexVfc = createParseResourceObject(true);
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo,
csarInfo, nodeName, yamlName, oldComplexVfc, newComplexVfc));
}
@@ -1836,7 +1800,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
any(Resource.class), any(AuditingActionEnum.class), anyBoolean())).thenReturn(Either.left(true));
when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
.thenReturn(Either.left(newResource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.updateResourceFromYaml(oldResource, newResource, actionEnum, createdArtifacts,
yamlFileName, yamlFileContent, csarInfo, nodeTypesInfo,
nodeTypesArtifactsToHandle, nodeName, isNested));
@@ -1861,14 +1825,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), anyMap(), any(CsarInfo.class),
anyString(), any(Component.class))).thenReturn(getParsedToscaYamlInfo());
- when(serviceBusinessLogic.fetchAndSetDerivedFromGenericType(any(Resource.class))).thenReturn(resource);
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class)
- , any(ComponentTypeEnum.class))).thenReturn(Either.left(false));
+ when(serviceBusinessLogic.fetchAndSetDerivedFromGenericType(any(Component.class))).thenReturn(resource);
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class), any(ComponentTypeEnum.class)))
+ .thenReturn(Either.left(false));
when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createResourceFromYaml(resource,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createResourceFromYaml(resource,
topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo,
nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName));
-
}
@Test
@@ -1898,12 +1861,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
when(serviceBusinessLogic.lockComponentByName(anyString(), any(), anyString()))
.thenReturn(Either.left(true));
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class)
- , any(ComponentTypeEnum.class))).thenReturn(Either.left(false));
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class), any(ComponentTypeEnum.class)))
+ .thenReturn(Either.left(false));
when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo, actionEnum,
isNormative, createdArtifacts, topologyTemplateYaml, nodeTypesInfo, csarInfo,
nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName));
@@ -1918,7 +1881,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
groupDefinition.setUniqueId("groupDefinitionUniqueId");
groupDefinition.setName("groupDefinition");
groupDefinitionList.add(groupDefinition);
- Assertions.assertNotNull(sIB1.createGroupsOnResource(resource, groups));
+ Assertions.assertNotNull(sIBL.createGroupsOnResource(resource, groups));
}
@Test
@@ -1926,7 +1889,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createParseResourceObject(false);
Map<String, GroupDefinition> groups = null;
- Either<Resource, ResponseFormat> result = sIB1.createGroupsOnResource(resource, groups);
+ Either<Resource, ResponseFormat> result = sIBL.createGroupsOnResource(resource, groups);
assertEquals(result.left().value(), resource);
}
@@ -1934,14 +1897,14 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
void testUpdateGroupsMembersUsingResource2() {
Resource resource = createParseResourceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIB1.updateGroupsMembersUsingResource(groups, resource));
+ Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, resource));
}
@Test
void testUpdateGroupsMembersUsingResource_left2() {
Resource resource = createParseResourceObject(true);
Map<String, GroupDefinition> groups = getGroups();
- Assertions.assertNotNull(sIB1.updateGroupsMembersUsingResource(groups, resource));
+ Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, resource));
}
@Test
@@ -1955,7 +1918,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
members.put("zxjTestImportServiceAb", getGroupsYaml());
Assertions.assertNotNull(component);
- sIB1.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
+ sIBL.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
}
@Test
@@ -1968,7 +1931,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, String> members = new HashMap<>();
members.put("zxjTestImportServiceAb", getGroupsYaml());
- Assertions.assertThrows(ComponentException.class, () -> sIB1.updateGroupMembers(groups,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.updateGroupMembers(groups,
updatedGroupDefinition, component, componentInstances, groupName, members));
}
@@ -1977,11 +1940,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createParseResourceObject(false);
resource.setComponentType(ComponentTypeEnum.RESOURCE);
boolean isNormative = true;
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any()))
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class), any(ComponentTypeEnum.class)))
.thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createResourceTransaction(resource,
- user, isNormative));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createResourceTransaction(resource, user, isNormative));
}
@Test
@@ -1989,22 +1951,18 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource resource = createParseResourceObject(false);
resource.setComponentType(ComponentTypeEnum.RESOURCE);
boolean isNormative = true;
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any()))
- .thenReturn(Either.left(true));
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any())).thenReturn(Either.left(true));
- Assertions.assertThrows(ComponentException.class, () -> sIB1
- .createResourceTransaction(resource, user, isNormative));
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createResourceTransaction(resource, user, isNormative));
}
@Test
void setCreateResourceTransaction_Left() {
Resource resource = createParseResourceObject(false);
resource.setComponentType(ComponentTypeEnum.RESOURCE);
- when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any()))
- .thenReturn(Either.left(false));
+ when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any())).thenReturn(Either.left(false));
when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource));
- Assertions.assertNotNull(
- sIB1.createResourceTransaction(resource, user, false));
+ Assertions.assertNotNull(sIBL.createResourceTransaction(resource, user, false));
}
@Test
@@ -2017,9 +1975,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
any(Resource.class), any(AuditingActionEnum.class), anyBoolean())).thenReturn(Either.left(true));
when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class)))
.thenReturn(Either.left(newResource));
- Assertions.assertNotNull(
- sIB1.updateExistingResourceByImport(newResource, oldResource, user,
- true, false, true));
+ Assertions.assertNotNull(sIBL.updateExistingResourceByImport(newResource, oldResource, user, true, false, true));
}
@Test
@@ -2027,7 +1983,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Resource newResource = createNewResource();
Resource oldResource = createOldResource();
- sIB1.createNewResourceToOldResource(newResource, oldResource, user);
+ sIBL.createNewResourceToOldResource(newResource, oldResource, user);
assertEquals(newResource.getSystemName(), oldResource.getSystemName());
}
@@ -2042,7 +1998,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
CsarInfo csarInfo = getCsarInfo();
- Assertions.assertThrows(ComponentException.class, () -> sIB1
+ Assertions.assertThrows(ComponentException.class, () -> sIBL
.createResourcesFromYamlNodeTypesList(yamlName, service, mappedToscaTemplate, needLock,
nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo));
}
@@ -2072,7 +2028,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
nodeTypes.put("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test",
nodeTypeInfo);
- Assertions.assertThrows(ComponentException.class, () -> sIB1.createNodeTypes(yamlName,
+ Assertions.assertThrows(ComponentException.class, () -> sIBL.createNodeTypes(yamlName,
service, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
nodeTypesInfo, csarInfo, mapToConvert, nodeTypes));
}
@@ -2111,10 +2067,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
anyBoolean())).thenReturn(getResourceCreated());
Assertions.assertNotNull(service);
- sIB1.createNodeTypes(yamlName,
+ sIBL.createNodeTypes(yamlName,
service, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
nodeTypesInfo, csarInfo, mapToConvert, nodeTypes);
-
}
protected ImmutablePair<Resource, ActionStatus> getResourceCreated() {
@@ -2206,7 +2161,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return propertyList;
}
- protected Map<String, NodeTypeInfo> getNodeTypesInfo() {
+ private Map<String, NodeTypeInfo> getNodeTypesInfo() {
Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
Map<String, Object> mappedToscaTemplate = new HashMap<>();
@@ -2218,9 +2173,21 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return nodeTypesInfo;
}
- protected Map<String, UploadComponentInstanceInfo> getUploadResInstancesMap() {
+ private Map<String, Object> getNodeTypes() {
+ Map<String, Object> nodeTypesInfo = new HashMap<>();
+ NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
+ Map<String, Object> mappedToscaTemplate = new HashMap<>();
+ nodeTypeInfo.setNested(true);
+ nodeTypeInfo.setTemplateFileName("templateFileName");
+ nodeTypeInfo.setMappedToscaTemplate(mappedToscaTemplate);
+ String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
+ nodeTypesInfo.put(nodeName, nodeTypeInfo);
+ return nodeTypesInfo;
+ }
+
+ private Map<String, UploadComponentInstanceInfo> getUploadResInstancesMap() {
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
Map<String, String> capabilitiesNamesToUpdate = new HashMap<>();
capabilitiesNamesToUpdate.put("mme_ipu_vdu.feature", "capabilitiesNamesToUpdate");
Map<String, String> requirementsNamesToUpdate = new HashMap<>();
@@ -2324,10 +2291,10 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return componentInstances;
}
- protected CreateServiceFromYamlParameter getCsfyp() {
+ private CreateServiceFromYamlParameter getCsfyp() {
CreateServiceFromYamlParameter csfyp = new CreateServiceFromYamlParameter();
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- Map<String, NodeTypeInfo> nodeTypesInfo = new HashedMap();
+ Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo();
csfyp.setNodeName("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test");
csfyp.setTopologyTemplateYaml(getMainTemplateContent("service_import_template.yml"));
@@ -2341,12 +2308,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
return csfyp;
}
- protected ParsedToscaYamlInfo getParsedToscaYamlInfo() {
+ private ParsedToscaYamlInfo getParsedToscaYamlInfo() {
ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
Map<String, InputDefinition> inputs = new HashMap<>();
Map<String, UploadComponentInstanceInfo> instances = new HashMap<>();
- UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
- uploadComponentInstanceInfo.setName("uploadComponentInstanceInfo");
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = getUploadComponentInstanceInfo();
instances.put("instances", uploadComponentInstanceInfo);
Map<String, GroupDefinition> groups = new HashMap<>();
Map<String, PolicyDefinition> policies = new HashMap<>();
@@ -2369,13 +2335,12 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest
protected CsarInfo getCsarInfo() {
String csarUuid = "0010";
- User user = new User();
+ User user = new User("jh0003");
Map<String, byte[]> csar = crateCsarFromPayload();
String vfReousrceName = "resouceName";
String mainTemplateName = "mainTemplateName";
String mainTemplateContent = getMainTemplateContent("service_import_template.yml");
- CsarInfo csarInfo = new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
- return csarInfo;
+ return new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false);
}
protected CsarUtils.NonMetaArtifactInfo getNonMetaArtifactInfo() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
index 5dfa28765b..8ff8163128 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java
@@ -37,15 +37,18 @@ import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import org.junit.jupiter.api.BeforeEach;
+import org.mockito.Mock;
import org.mockito.Mockito;
import org.openecomp.sdc.ElementOperationMock;
-import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
+import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.distribution.engine.DistributionEngine;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
import org.openecomp.sdc.be.components.path.ForwardingPathValidator;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.components.validation.ServiceDistributionValidation;
@@ -107,7 +110,6 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
-import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
@@ -133,24 +135,33 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
private static final String RESOURCE_SUBCATEGORY = "Router";
protected final ServletContext servletContext = Mockito.mock(ServletContext.class);
protected final ComponentValidator componentValidator = Mockito.mock(ComponentValidator.class);
- protected ServiceImportBusinessLogic sIB1;
- protected UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ final DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
+ final ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
+ final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
+ final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
+ final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ final NodeFilterOperation serviceFilterOperation = Mockito.mock(NodeFilterOperation.class);
+ final NodeFilterValidator serviceFilterValidator = Mockito.mock(NodeFilterValidator.class);
+ // final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
+ final CsarBusinessLogic csarBusinessLogic = Mockito.mock(CsarBusinessLogic.class);
+ final LifecycleBusinessLogic lifecycleBusinessLogic = Mockito.mock(LifecycleBusinessLogic.class);
+ final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class);
+ final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class);
+ final ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic = Mockito.mock(ComponentNodeFilterBusinessLogic.class);
+ protected UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
protected WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
protected WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
protected ResponseFormatManager responseManager = null;
- protected ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
+ protected ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
protected AuditCassandraDao auditingDao = Mockito.mock(AuditCassandraDao.class);
- protected ArtifactsBusinessLogic artifactBl = Mockito.mock(ArtifactsBusinessLogic.class);
+ protected ArtifactsBusinessLogic artifactsBusinessLogic = Mockito.mock(ArtifactsBusinessLogic.class);
protected GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
protected JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
protected ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
protected CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class);
protected GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
protected UserValidations userValidations = Mockito.mock(UserValidations.class);
- protected ResourceAdminEvent auditArchive1 = Mockito.mock(ResourceAdminEvent.class);
protected CatalogOperation catalogOperation = Mockito.mock(CatalogOperation.class);
- protected ResourceAdminEvent auditArchive2 = Mockito.mock(ResourceAdminEvent.class);
- protected ResourceAdminEvent auditRestore = Mockito.mock(ResourceAdminEvent.class);
protected ServiceImportParseLogic serviceImportParseLogic = Mockito.mock(ServiceImportParseLogic.class);
protected ServiceTypeValidator serviceTypeValidator = new ServiceTypeValidator(componentsUtils);
protected ServiceRoleValidator serviceRoleValidator = new ServiceRoleValidator(componentsUtils);
@@ -164,16 +175,11 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
protected User user = null;
protected Resource genericService = null;
+ @Mock
+ protected ServiceBusinessLogic serviceBusinessLogic;
IElementOperation mockElementDao = new ElementOperationMock();
protected ServiceCategoryValidator serviceCategoryValidator = new ServiceCategoryValidator(componentsUtils, mockElementDao);
protected ServiceValidator serviceValidator = createServiceValidator();
- DistributionEngine distributionEngine = Mockito.mock(DistributionEngine.class);
- ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
- ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
- ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
- UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
- NodeFilterOperation serviceFilterOperation = Mockito.mock(NodeFilterOperation.class);
- NodeFilterValidator serviceFilterValidator = Mockito.mock(NodeFilterValidator.class);
public ServiceImportBussinessLogicBaseTestSetup() {
@@ -205,7 +211,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
user.setLastName("Hendrix");
user.setRole(Role.ADMIN.name());
- when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
+ when(userBusinessLogic.getUser("jh0003", false)).thenReturn(user);
when(userValidations.validateUserExists("jh0003")).thenReturn(user);
when(userValidations.validateUserNotEmpty(eq(user), anyString())).thenReturn(user);
// Servlet Context attributes
@@ -218,7 +224,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
when(catalogOperation.updateCatalog(Mockito.any(), Mockito.any())).thenReturn(ActionStatus.OK);
// artifact bussinesslogic
ArtifactDefinition artifactDef = new ArtifactDefinition();
- when(artifactBl.createArtifactPlaceHolderInfo(Mockito.any(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class),
+ when(artifactsBusinessLogic.createArtifactPlaceHolderInfo(Mockito.any(), Mockito.anyString(), Mockito.anyMap(), Mockito.any(User.class),
Mockito.any(ArtifactGroupTypeEnum.class))).thenReturn(artifactDef);
// createService
@@ -250,14 +256,6 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
when(serviceImportParseLogic.isArtifactDeletionRequired(anyString(), any(), anyBoolean())).thenReturn(true);
- sIB1 = new ServiceImportBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
- groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation,
- artifactBl, distributionEngine, componentInstanceBusinessLogic,
- serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter, serviceFilterOperation,
- serviceFilterValidator, artifactToscaOperation, componentContactIdValidator,
- componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
-
mockAbstract();
responseManager = ResponseFormatManager.getInstance();
@@ -267,6 +265,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
Service service = new Service();
service.setUniqueId("sid");
service.setName("Service");
+ service.setSystemName("SystemName");
CategoryDefinition category = new CategoryDefinition();
category.setName(SERVICE_CATEGORY);
category.setIcons(Collections.singletonList("defaulticon"));
@@ -323,6 +322,7 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
protected Resource createParseResourceObject(boolean afterCreate) {
Resource resource = new Resource();
+ resource.setUniqueId(COMPONNET_ID);
resource.setName(RESOURCE_NAME);
resource.setToscaResourceName(RESOURCE_TOSCA_NAME);
resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY);
@@ -371,9 +371,9 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM
return groups;
}
- protected UploadComponentInstanceInfo getuploadComponentInstanceInfo() {
+ protected UploadComponentInstanceInfo getUploadComponentInstanceInfo() {
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
- uploadComponentInstanceInfo.setType("resources");
+ uploadComponentInstanceInfo.setType("My-Resource_Tosca_Name");
Collection<String> directives = new Collection<String>() {
@Override
public int size() {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
index f723a1523f..1b5b7d8a7e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java
@@ -18,6 +18,9 @@
package org.openecomp.sdc.be.components.impl;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -27,17 +30,13 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.UploadServiceInfo;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
@ExtendWith(MockitoExtension.class)
class ServiceImportManagerTest {
+ private final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
@InjectMocks
private ServiceImportManager serviceImportManager;
- public static final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class);
-
@BeforeEach
public void setup() {
serviceImportManager = new ServiceImportManager();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
index d16dc23905..0306ce082e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java
@@ -126,7 +126,9 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
private ServiceImportParseLogic testSubject;
private ServiceImportParseLogic createTestSubject() {
- return new ServiceImportParseLogic();
+ return new ServiceImportParseLogic(serviceBusinessLogic, componentsUtils, toscaOperationFacade, lifecycleBusinessLogic, inputsBusinessLogic,
+ null, null, interfaceTypeOperation, capabilityTypeOperation, componentNodeFilterBusinessLogic,
+ groupBusinessLogic);
}
@BeforeEach
@@ -145,15 +147,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
responseManager = ResponseFormatManager.getInstance();
testSubject = createTestSubject();
- testSubject.setComponentsUtils(componentsUtils);
- testSubject.setToscaOperationFacade(toscaOperationFacade);
serviceBusinessLogic.setElementDao(elementDao);
- testSubject.setServiceBusinessLogic(serviceBusinessLogic);
- testSubject.setCapabilityTypeOperation(capabilityTypeOperation);
- testSubject.setInterfaceTypeOperation(interfaceTypeOperation);
- testSubject.setInputsBusinessLogic(inputsBusinessLogic);
- testSubject.setLifecycleBusinessLogic(lifecycleBusinessLogic);
- testSubject.setComponentNodeFilterBusinessLogic(componentNodeFilterBusinessLogic);
}
@Test
@@ -1865,7 +1859,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
Resource resource = createResourceObject(false);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
nodesInfoValue.getRequirements().get("requirements").get(0).setName("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test");
uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
List<ComponentInstance> componentInstancesList = creatComponentInstances();
@@ -1897,7 +1891,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
String yamlName = "group.yml";
Resource resource = createParseResourceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
List<ComponentInstance> componentInstancesList = new ArrayList<>();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
@@ -1912,7 +1906,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
String yamlName = "yamlName";
Resource resource = createParseResourceObject(true);
resource.setComponentInstances(creatComponentInstances());
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
Assertions.assertNotNull(
@@ -1925,7 +1919,7 @@ class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSet
Resource resource = createParseResourceObject(false);
List<ComponentInstance> componentInstancesList = new ArrayList<>();
resource.setComponentInstances(componentInstancesList);
- UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ UploadComponentInstanceInfo nodesInfoValue = getUploadComponentInstanceInfo();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
Assertions.assertNotNull(
testSubject.addRelationToRI(yamlName, resource, nodesInfoValue, relations));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java
index e9c1d40121..ab4e638e6a 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/BaseForwardingPathTest.java
@@ -33,7 +33,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
@@ -41,7 +40,6 @@ import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
import org.openecomp.sdc.be.components.path.beans.JanusGraphTestSetup;
import org.openecomp.sdc.be.components.path.utils.GraphTestUtils;
import org.openecomp.sdc.be.components.validation.service.ServiceValidator;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
@@ -65,8 +63,6 @@ import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.tosca.CapabilityRequirementConverter;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.datastructure.UserContext;
-import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.common.util.ThreadLocalsHolder;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -123,7 +119,6 @@ public abstract class BaseForwardingPathTest extends BeConfDependentTest impleme
userRole.add(user.getRole());
UserContext userContext = new UserContext(user.getUserId(), userRole, user.getFirstName(), user.getLastName());
ThreadLocalsHolder.setUserContext(userContext);
- bl.setServiceValidator(serviceValidator);
}
private void initGraph() {
@@ -144,7 +139,6 @@ public abstract class BaseForwardingPathTest extends BeConfDependentTest impleme
private Service createTestService() {
when(catalogOperation.updateCatalog(any(), any())).thenReturn(ActionStatus.OK);
bl.setCatalogOperations(catalogOperation);
- bl.setServiceValidator(serviceValidator);
createCategory();
createServiceCategory(CATEGORY_NAME);
initGraph();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java
index d7f70ae8a7..25c1f76e78 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PolicyExportParserImplTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.tosca;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;
import fj.data.Either;
@@ -30,10 +31,10 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundException;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.model.Component;
@@ -44,140 +45,139 @@ import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
import org.openecomp.sdc.be.tosca.model.ToscaPolicyTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class PolicyExportParserImplTest {
-
- private static final String[] POLICY_KEYS = {"policy_key_1","policy_key_2"};
- private static final String[] VERSIONS = {"version_1","version_1"};
- private static final String[] POLICY_NAMES = {"name_1","name_2"};
- private static final String[] POLICY_UUIDS = {"policyUUID_1","policyUUID_2"};
- private static final String[] INVARIANT_UUIDS = {"invariantUUID_1","invariantUUID_2"};
- private static final String[] POLICY_TYPE_NAMES = {"policyTypeName_1","policyTypeName_2"};
- private static final String[] POLICY_COMPONENT_INSTANCES = {"policyComponentInstanceId"};
- private static final String POLICY_COMPONENT_INSTANCES_NAME = "policyComponentInstanceName";
- private static final String[] POLICY_GROUPS = {"policyGroupId"};
- private static final String POLICY_GROUP_NAME = "PolicyGroupName";
-
- private PolicyExportParser policiyExportParser;
-
- @Mock
- private ApplicationDataTypeCache applicationDataTypeCache;
- @Mock
- private PropertyConvertor propertyConvertor;
-
- @Mock
- private Component component;
-
- @Test
- public void failToGetAllDataTypes() {
-
- when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(null));
- assertThatExceptionOfType(SdcResourceNotFoundException.class).isThrownBy(() -> policiyExportParser = new PolicyExportParserImpl(
- applicationDataTypeCache,
- propertyConvertor));
- }
-
- @Test
- public void noPoliciesInComponent() {
-
- when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(null));
- when(component.getPolicies()).thenReturn(null);
- policiyExportParser = new PolicyExportParserImpl(applicationDataTypeCache, propertyConvertor);
- Map<String, ToscaPolicyTemplate> policies = policiyExportParser.getPolicies(component);
- assertThat(policies).isEqualTo(null);
- }
-
- @Test
- public void onePoliciesInComponent() {
-
- List<Integer> constIndexes = Arrays.asList(new Integer[] {0});
- testPoliciesInComponent(constIndexes);
- }
-
- @Test
- public void twoPoliciesInComponent() {
-
- List<Integer> constIndexes = Arrays.asList(new Integer[] {0,1});
- testPoliciesInComponent(constIndexes);
- }
-
- private void testPoliciesInComponent(List<Integer> constIndexes) {
- when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(null));
- Map<String, PolicyDefinition> policiesToAdd = getPolicies(constIndexes);
-
- when(component.getPolicies()).thenReturn(policiesToAdd);
- when(component.getComponentInstances()).thenReturn(getComponentInstances());
- when(component.getGroups()).thenReturn(getGroups());
- policiyExportParser = new PolicyExportParserImpl(applicationDataTypeCache, propertyConvertor);
-
- Map<String, ToscaPolicyTemplate> policies = policiyExportParser.getPolicies(component);
-
- for(Integer i : constIndexes) {
-
-
- ToscaPolicyTemplate toscaPolicyTemplate = policies.get(POLICY_NAMES[i]);
- ToscaMetadata metadata = (ToscaMetadata) toscaPolicyTemplate.getMetadata();
-
- assertThat(metadata.getInvariantUUID()).isEqualTo(INVARIANT_UUIDS[i]);
- assertThat(metadata.getUUID()).isEqualTo(POLICY_UUIDS[i]);
- assertThat(metadata.getName()).isEqualTo(POLICY_NAMES[i]);
- assertThat(metadata.getVersion()).isEqualTo(VERSIONS[i]);
-
- String type = toscaPolicyTemplate.getType();
- assertThat(type).isEqualTo(POLICY_TYPE_NAMES[i]);
-
- List<String> targets = toscaPolicyTemplate.getTargets();
- assertThat(targets.get(0)).isEqualTo(POLICY_COMPONENT_INSTANCES_NAME);
- assertThat(targets.get(1)).isEqualTo(POLICY_GROUP_NAME);
- }
- }
-
- private List<GroupDefinition> getGroups() {
- List<GroupDefinition> groups = new ArrayList<>();
- GroupDefinition groupDefinition = new GroupDefinition();
- groupDefinition.setUniqueId(POLICY_GROUPS[0]);
- groupDefinition.setName(POLICY_GROUP_NAME);
- groups.add(groupDefinition);
- return groups;
- }
-
- private List<ComponentInstance> getComponentInstances() {
- List<ComponentInstance> componentInstances = new ArrayList<>();
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setUniqueId(POLICY_COMPONENT_INSTANCES[0]);
- componentInstance.setName(POLICY_COMPONENT_INSTANCES_NAME);
- componentInstances.add(componentInstance);
- return componentInstances;
- }
-
- private Map<String, PolicyDefinition> getPolicies(List<Integer> indexes) {
- Map<String, PolicyDefinition> policies = new HashMap<>();
-
- for (int index : indexes) {
-
- PolicyDefinition policyDefinition = new PolicyDefinition();
-
- // Set type
- policyDefinition.setPolicyTypeName(POLICY_TYPE_NAMES[index]);
-
- // Set Metadata
- policyDefinition.setInvariantUUID(INVARIANT_UUIDS[index]);
- policyDefinition.setPolicyUUID(POLICY_UUIDS[index]);
- policyDefinition.setName(POLICY_NAMES[index]);
- policyDefinition.setVersion(VERSIONS[index]);
-
- // Set targets
- policyDefinition.setTargets(getTargers());
-
- policies.put(POLICY_KEYS[index],policyDefinition);
- }
- return policies;
- }
-
- private Map<PolicyTargetType, List<String>> getTargers() {
- Map<PolicyTargetType, List<String>> targets = new HashMap<>();
- targets.put(PolicyTargetType.COMPONENT_INSTANCES, Arrays.asList(POLICY_COMPONENT_INSTANCES));
- targets.put(PolicyTargetType.GROUPS, Arrays.asList(POLICY_GROUPS));
- return targets;
- }
+@ExtendWith(MockitoExtension.class)
+class PolicyExportParserImplTest {
+
+ private static final String[] POLICY_KEYS = {"policy_key_1", "policy_key_2"};
+ private static final String[] VERSIONS = {"version_1", "version_1"};
+ private static final String[] POLICY_NAMES = {"name_1", "name_2"};
+ private static final String[] POLICY_UUIDS = {"policyUUID_1", "policyUUID_2"};
+ private static final String[] INVARIANT_UUIDS = {"invariantUUID_1", "invariantUUID_2"};
+ private static final String[] POLICY_TYPE_NAMES = {"policyTypeName_1", "policyTypeName_2"};
+ private static final String[] POLICY_COMPONENT_INSTANCES = {"policyComponentInstanceId"};
+ private static final String POLICY_COMPONENT_INSTANCES_NAME = "policyComponentInstanceName";
+ private static final String[] POLICY_GROUPS = {"policyGroupId"};
+ private static final String POLICY_GROUP_NAME = "PolicyGroupName";
+
+ private PolicyExportParser policiyExportParser;
+
+ @Mock
+ private ApplicationDataTypeCache applicationDataTypeCache;
+ @Mock
+ private PropertyConvertor propertyConvertor;
+
+ @Mock
+ private Component component;
+
+ @Test
+ void failToGetAllDataTypes() {
+
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.right(null));
+ assertThatExceptionOfType(SdcResourceNotFoundException.class).isThrownBy(() -> policiyExportParser = new PolicyExportParserImpl(
+ applicationDataTypeCache,
+ propertyConvertor));
+ }
+
+ @Test
+ void noPoliciesInComponent() {
+
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(null));
+ when(component.getPolicies()).thenReturn(null);
+ policiyExportParser = new PolicyExportParserImpl(applicationDataTypeCache, propertyConvertor);
+ Map<String, ToscaPolicyTemplate> policies = policiyExportParser.getPolicies(component);
+ assertNull(policies);
+ }
+
+ @Test
+ void onePoliciesInComponent() {
+
+ List<Integer> constIndexes = Arrays.asList(new Integer[]{0});
+ testPoliciesInComponent(constIndexes);
+ }
+
+ @Test
+ void twoPoliciesInComponent() {
+
+ List<Integer> constIndexes = Arrays.asList(new Integer[]{0, 1});
+ testPoliciesInComponent(constIndexes);
+ }
+
+ private void testPoliciesInComponent(List<Integer> constIndexes) {
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(null));
+ Map<String, PolicyDefinition> policiesToAdd = getPolicies(constIndexes);
+
+ when(component.getPolicies()).thenReturn(policiesToAdd);
+ when(component.getComponentInstances()).thenReturn(getComponentInstances());
+ when(component.getGroups()).thenReturn(getGroups());
+ policiyExportParser = new PolicyExportParserImpl(applicationDataTypeCache, propertyConvertor);
+
+ Map<String, ToscaPolicyTemplate> policies = policiyExportParser.getPolicies(component);
+
+ for (Integer i : constIndexes) {
+
+ ToscaPolicyTemplate toscaPolicyTemplate = policies.get(POLICY_NAMES[i]);
+ ToscaMetadata metadata = (ToscaMetadata) toscaPolicyTemplate.getMetadata();
+
+ assertThat(metadata.getInvariantUUID()).isEqualTo(INVARIANT_UUIDS[i]);
+ assertThat(metadata.getUUID()).isEqualTo(POLICY_UUIDS[i]);
+ assertThat(metadata.getName()).isEqualTo(POLICY_NAMES[i]);
+ assertThat(metadata.getVersion()).isEqualTo(VERSIONS[i]);
+
+ String type = toscaPolicyTemplate.getType();
+ assertThat(type).isEqualTo(POLICY_TYPE_NAMES[i]);
+
+ List<String> targets = toscaPolicyTemplate.getTargets();
+ assertThat(targets.get(0)).isEqualTo(POLICY_COMPONENT_INSTANCES_NAME);
+ assertThat(targets.get(1)).isEqualTo(POLICY_GROUP_NAME);
+ }
+ }
+
+ private List<GroupDefinition> getGroups() {
+ List<GroupDefinition> groups = new ArrayList<>();
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setUniqueId(POLICY_GROUPS[0]);
+ groupDefinition.setName(POLICY_GROUP_NAME);
+ groups.add(groupDefinition);
+ return groups;
+ }
+
+ private List<ComponentInstance> getComponentInstances() {
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setUniqueId(POLICY_COMPONENT_INSTANCES[0]);
+ componentInstance.setName(POLICY_COMPONENT_INSTANCES_NAME);
+ componentInstances.add(componentInstance);
+ return componentInstances;
+ }
+
+ private Map<String, PolicyDefinition> getPolicies(List<Integer> indexes) {
+ Map<String, PolicyDefinition> policies = new HashMap<>();
+
+ for (int index : indexes) {
+
+ PolicyDefinition policyDefinition = new PolicyDefinition();
+
+ // Set type
+ policyDefinition.setPolicyTypeName(POLICY_TYPE_NAMES[index]);
+
+ // Set Metadata
+ policyDefinition.setInvariantUUID(INVARIANT_UUIDS[index]);
+ policyDefinition.setPolicyUUID(POLICY_UUIDS[index]);
+ policyDefinition.setName(POLICY_NAMES[index]);
+ policyDefinition.setVersion(VERSIONS[index]);
+
+ // Set targets
+ policyDefinition.setTargets(getTargets());
+
+ policies.put(POLICY_KEYS[index], policyDefinition);
+ }
+ return policies;
+ }
+
+ private Map<PolicyTargetType, List<String>> getTargets() {
+ Map<PolicyTargetType, List<String>> targets = new HashMap<>();
+ targets.put(PolicyTargetType.COMPONENT_INSTANCES, Arrays.asList(POLICY_COMPONENT_INSTANCES));
+ targets.put(PolicyTargetType.GROUPS, Arrays.asList(POLICY_GROUPS));
+ return targets;
+ }
}