* Modifications copyright (c) 2019 Nokia
* ================================================================================
*/
+
package org.openecomp.sdc.be.components.impl;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
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;
ComponentDescriptionValidator componentDescriptionValidator, ModelOperation modelOperation,
final ServiceRoleValidator serviceRoleValidator,
final ServiceInstantiationTypeValidator serviceInstantiationTypeValidator,
- final ServiceCategoryValidator serviceCategoryValidator, final ServiceValidator serviceValidator,
- final PolicyBusinessLogic policyBusinessLogic) {
+ final ServiceCategoryValidator serviceCategoryValidator, final ServiceValidator serviceValidator) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
this.serviceInstantiationTypeValidator = serviceInstantiationTypeValidator;
this.serviceCategoryValidator = serviceCategoryValidator;
this.serviceValidator = serviceValidator;
- this.policyBusinessLogic = policyBusinessLogic;
this.groupBusinessLogic = groupBusinessLogic;
}
log.info("Restricted operation for user: {}, on service: {}", user.getUserId(), currentService.getCreatorUserId());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
}
- Either<Service, ResponseFormat> validationRsponse = validateAndUpdateServiceMetadata(user, currentService, serviceUpdate);
- if (validationRsponse.isRight()) {
+ List<String> subNodePropsToBeRemoved = getSubstitutionNodePropertiesToBeRemoved(currentService, serviceUpdate);
+ List<PropertyDefinition> subNodePropsToBeAdded = getSubstitutionNodePropertiesToBeAdded(currentService, serviceUpdate);
+ boolean subNodeChanged = isSubstitutionNodeChanged(currentService, serviceUpdate);
+ Either<Service, ResponseFormat> validationResponse =
+ validateAndUpdateServiceMetadata(user, currentService, serviceUpdate, subNodeChanged, ListUtils.emptyIfNull(subNodePropsToBeRemoved));
+ if (validationResponse.isRight()) {
log.info("service update metadata: validations field.");
- return validationRsponse;
+ return validationResponse;
}
- Service serviceToUpdate = validationRsponse.left().value();
+ Service serviceToUpdate = validationResponse.left().value();
// lock resource
lockComponent(serviceId, currentService, "Update Service Metadata");
try {
+ if (subNodeChanged) {
+ if (!subNodePropsToBeRemoved.isEmpty()) {
+ removePropertiesFromService(currentService, subNodePropsToBeRemoved);
+ removeInputsFromService(currentService, subNodePropsToBeRemoved);
+ }
+ if (!subNodePropsToBeAdded.isEmpty()) {
+ addPropertiesToService(currentService, subNodePropsToBeAdded);
+ if (Constants.DEFAULT_MODEL_NAME.equals(currentService.getModel()) || currentService.getModel() == null) {
+ addInputsToService(currentService, subNodePropsToBeAdded);
+ }
+ }
+ }
return toscaOperationFacade.updateToscaElement(serviceToUpdate).right().map(rf -> {
janusGraphDao.rollback();
BeEcompErrorManager.getInstance().logBeSystemError("Update Service Metadata");
log.debug("failed to update sevice {}", serviceToUpdate.getUniqueId());
return (componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}).left().bind(this::updateCatalogAndCommit);
+ } catch (ComponentException e) {
+ janusGraphDao.rollback();
+ BeEcompErrorManager.getInstance().logBeSystemError("Update Service Metadata");
+ log.debug("failed to update sevice {}", serviceToUpdate.getUniqueId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
}
}
@VisibleForTesting
- Either<Service, ResponseFormat> validateAndUpdateServiceMetadata(User user, Service currentService, Service serviceUpdate) {
+ Either<Service, ResponseFormat> validateAndUpdateServiceMetadata(User user, Service currentService, Service serviceUpdate, boolean subNodeChanged,
+ List<String> subNodePropsToBeRemoved) {
try {
boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentService.getVersion());
+ if (subNodeChanged) {
+ if (!subNodePropsToBeRemoved.isEmpty()) {
+ areSubstitutionNodePropertiesInUse(currentService, subNodePropsToBeRemoved);
+ }
+ currentService.setDerivedFromGenericVersion(serviceUpdate.getDerivedFromGenericVersion());
+ currentService.setDerivedFromGenericType(serviceUpdate.getDerivedFromGenericType());
+ }
+
Either<Boolean, ResponseFormat> response = validateAndUpdateCategory(user, currentService, serviceUpdate, hasBeenCertified,
UPDATE_SERVICE_METADATA);
if (response.isRight()) {
}
}
+ private void addPropertiesToService(Service currentService, List<PropertyDefinition> subNodePropsToBeAdded) {
+ ListUtils.emptyIfNull(subNodePropsToBeAdded).forEach(prop -> {
+ Either<PropertyDefinition, StorageOperationStatus> addPropertyEither =
+ toscaOperationFacade.addPropertyToComponent(prop, currentService);
+ if (addPropertyEither.isRight()) {
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ });
+ }
+
+ private void addInputsToService(Service currentService, List<PropertyDefinition> subNodePropsToBeAdded) {
+ ListUtils.emptyIfNull(subNodePropsToBeAdded).forEach(prop -> {
+ InputDefinition inputDef = new InputDefinition(prop);
+ Either<InputDefinition, StorageOperationStatus> status =
+ toscaOperationFacade.addInputToComponent(prop.getName(), inputDef, currentService);
+ if (status.isRight()) {
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ });
+ }
+
+ private void removePropertiesFromService(Service currentService, List<String> subNodePropsToBeRemoved) {
+ List<PropertyDefinition> props = currentService.getProperties();
+ List<String> propsUniqueIdsToBeRemoved =
+ props.stream().filter(prop -> subNodePropsToBeRemoved.contains(prop.getName())).map(PropertyDefinition::getUniqueId)
+ .collect(Collectors.toList());
+ ListUtils.emptyIfNull(props).stream().filter(prop -> propsUniqueIdsToBeRemoved.contains(prop.getUniqueId())).forEach(prop -> {
+ StorageOperationStatus status = toscaOperationFacade.deletePropertyOfComponent(currentService, prop.getName());
+ if (status != StorageOperationStatus.OK) {
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ });
+ }
+
+ private void removeInputsFromService(Service currentService, List<String> subNodePropsToBeRemoved) {
+ List<PropertyDefinition> props = currentService.getProperties();
+ List<InputDefinition> inputs = currentService.getInputs();
+ List<String> propsUniqueIdsToBeRemoved =
+ props.stream().filter(prop -> subNodePropsToBeRemoved.contains(prop.getName())).map(PropertyDefinition::getUniqueId)
+ .collect(Collectors.toList());
+ ListUtils.emptyIfNull(inputs).stream().filter(input -> input.isMappedToComponentProperty() &&
+ (propsUniqueIdsToBeRemoved.contains(input.getPropertyId()) || subNodePropsToBeRemoved.contains(input.getName()))).forEach(input -> {
+ StorageOperationStatus status = toscaOperationFacade.deleteInputOfResource(currentService, input.getName());
+ if (status != StorageOperationStatus.OK) {
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ });
+ }
+
+ private void areSubstitutionNodePropertiesInUse(Service service, List<String> subNodePropsToBeRemoved) {
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProps = service.getComponentInstancesProperties();
+ List<String> propsUniqueIdsToBeRemoved =
+ ListUtils.emptyIfNull(service.getProperties()).stream().filter(prop -> subNodePropsToBeRemoved.contains(prop.getName()))
+ .map(PropertyDefinition::getUniqueId)
+ .collect(Collectors.toList());
+ List<String> inputsUniqueIdsToBeRemoved = ListUtils.emptyIfNull(service.getInputs()).stream()
+ .filter(input -> propsUniqueIdsToBeRemoved.contains(input.getPropertyId()) || subNodePropsToBeRemoved.contains(input.getName()))
+ .map(PropertyDefinition::getUniqueId)
+ .collect(Collectors.toList());
+ Map<String, List<String>> inUse = new HashMap<>();
+ if (componentInstancesProps != null && !componentInstancesProps.isEmpty()) {
+ componentInstancesProps.forEach((compInstanceId, listOfProps) -> {
+ List<String> propsInUse = new ArrayList<>();
+ listOfProps.stream()
+ .filter(PropertyDataDefinition::isToscaFunction)
+ .filter(compProp -> ToscaFunctionType.isGetFunction(compProp.getToscaFunction().getType()))
+ .forEach(compProp -> {
+ ToscaFunction toscaFunction = compProp.getToscaFunction();
+ ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) toscaFunction;
+ String propName = toscaGetFunction.getPropertyName();
+ String propUniqueId = toscaGetFunction.getPropertyUniqueId();
+ if (inputsUniqueIdsToBeRemoved.contains(propUniqueId) || propsUniqueIdsToBeRemoved.contains(propUniqueId) ||
+ subNodePropsToBeRemoved.contains(propName)) {
+ propsInUse.add(compProp.getName());
+ }
+ });
+ if (!propsInUse.isEmpty()) {
+ Optional<ComponentInstance> componentInstance = service.getComponentInstanceById(compInstanceId);
+ componentInstance.ifPresent(instance -> inUse.put(instance.getName(), propsInUse));
+ }
+
+ });
+ }
+ if (!inUse.isEmpty()) {
+ String propsInUse = inUse.entrySet().stream().map(entry -> {
+ String properties = entry.getValue().stream().map(Object::toString).collect(Collectors.joining(", "));
+ return properties + " on " + entry.getKey();
+ }).collect(Collectors.joining(", properties "));
+ throw new ByActionStatusComponentException(ActionStatus.SUBSTITUTION_NODE_TYPE_PROPERTY_IN_USE, propsInUse);
+ }
+ }
+
+
+ private boolean isSubstitutionNodeChanged(Service currentService, Service updatedService) {
+ String currentServiceType = currentService.getDerivedFromGenericType();
+ String updatedServiceType = updatedService.getDerivedFromGenericType();
+ String currentServiceVersion = currentService.getDerivedFromGenericVersion();
+ String updatedServiceVersion = updatedService.getDerivedFromGenericVersion();
+ return !(StringUtils.equals(currentServiceType, updatedServiceType) && StringUtils.equals(currentServiceVersion, updatedServiceVersion));
+ }
+
+ private List<String> getSubstitutionNodePropertiesToBeRemoved(Service currentService, Service serviceUpdate) {
+ List<PropertyDefinition> currentProps = ListUtils.emptyIfNull(fetchDerivedFromGenericType(currentService, null).getProperties());
+ List<PropertyDefinition> updatedProps = ListUtils.emptyIfNull(fetchDerivedFromGenericType(serviceUpdate, null).getProperties());
+ if (!StringUtils.equals(currentService.getDerivedFromGenericType(), serviceUpdate.getDerivedFromGenericType())) {
+ return currentProps.stream().map(PropertyDefinition::getName).collect(Collectors.toList());
+ }
+ List<String> updatedPropNames = updatedProps.stream().map(PropertyDefinition::getName).collect(Collectors.toList());
+ List<String> propNamesToBeRemoved = currentProps.stream().map(PropertyDefinition::getName).collect(Collectors.toList());
+ propNamesToBeRemoved.removeIf(updatedPropNames::contains);
+ return propNamesToBeRemoved;
+ }
+
+ private List<PropertyDefinition> getSubstitutionNodePropertiesToBeAdded(Service currentService, Service serviceUpdate) {
+ List<PropertyDefinition> currentProps = ListUtils.emptyIfNull(fetchDerivedFromGenericType(currentService, null).getProperties());
+ List<PropertyDefinition> updatedProps = ListUtils.emptyIfNull(fetchDerivedFromGenericType(serviceUpdate, null).getProperties());
+ if (!StringUtils.equals(currentService.getDerivedFromGenericType(), serviceUpdate.getDerivedFromGenericType())) {
+ return updatedProps;
+ }
+ Set<String> currentPropNames = currentProps.stream().map(PropertyDefinition::getName).collect(Collectors.toSet());
+ updatedProps.removeIf(prop -> currentPropNames.contains(prop.getName()));
+ return updatedProps;
+ }
+
+
private void verifyValuesAreIdentical(Object updatedValue, Object originalValue, String fieldName) {
if (updatedValue != null && !updatedValue.equals(originalValue)) {
log.info("update service: received request to update {} to {} the field is not updatable ignoring.", fieldName, updatedValue);
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.UUID;
import java.util.Set;
-import java.util.HashSet;
-
+import java.util.UUID;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInterface;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.Model;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.PropertyDefinition;
@Test
void testGetComponentAuditRecordsCertifiedVersion() {
- Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords = bl.getComponentAuditRecords(CERTIFIED_VERSION, COMPONNET_ID, user.getUserId());
+ Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords =
+ bl.getComponentAuditRecords(CERTIFIED_VERSION, COMPONNET_ID, user.getUserId());
assertTrue(componentAuditRecords.isLeft());
assertEquals(3, componentAuditRecords.left().value().size());
}
@Test
void testGetComponentAuditRecordsUnCertifiedVersion() {
- Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords = bl.getComponentAuditRecords(UNCERTIFIED_VERSION, COMPONNET_ID, user.getUserId());
+ Either<List<Map<String, Object>>, ResponseFormat> componentAuditRecords =
+ bl.getComponentAuditRecords(UNCERTIFIED_VERSION, COMPONNET_ID, user.getUserId());
assertTrue(componentAuditRecords.isLeft());
assertEquals(4, componentAuditRecords.left().value().size());
}
}
assertEqualsServiceObject(createServiceObject(true), createResponse.left().value());
}
+
private void assertEqualsServiceObject(final Service expectedService, final Service actualService) {
assertEquals(expectedService.getContactId(), actualService.getContactId());
assertEquals(expectedService.getCategories(), actualService.getCategories());
private void testServiceNameEmpty() {
Service serviceExccedsNameLimit = createServiceObject(false);
serviceExccedsNameLimit.setName(null);
- try{
+ try {
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue());
return;
}
// contains :
String nameWrongFormat = "ljg\\fd";
service.setName(nameWrongFormat);
- try{
+ try {
bl.createService(service, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue());
return;
}
private void testServiceDescriptionEmpty() {
Service serviceExist = createServiceObject(false);
serviceExist.setDescription("");
- try{
+ try {
bl.createService(serviceExist, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
return;
}
fail();
}
+
private void testServiceDescriptionMissing() {
Service serviceExist = createServiceObject(false);
serviceExist.setDescription(null);
- try{
+ try {
bl.createService(serviceExist, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
return;
}
Service serviceExccedsDescLimit = createServiceObject(false);
// 1025 chars, the limit is 1024
String tooLongServiceDesc = "1GUODojQ0sGzKR4NP7e5j82ADQ3KHTVOaezL95qcbuaqDtjZhAQGQ3iFwKAy580K4WiiXs3u3zq7RzXcSASl5fm0RsWtCMOIDP"
- + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
- + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
- + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
- + "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
- + "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
- + "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
- + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
+ + "AOf9Tf2xtXxPCuCIMCR5wOGnNTaFxgnJEHAGxilBhZDgeMNHmCN1rMK5B5IRJOnZxcpcL1NeG3APTCIMP1lNAxngYulDm9heFSBc8TfXAADq7703AvkJT0QPpGq2z2P"
+ + "tlikcAnIjmWgfC5Tm7UH462BAlTyHg4ExnPPL4AO8c92VrD7kZSgSqiy73cN3gLT8uigkKrUgXQFGVUFrXVyyQXYtVM6bLBeuCGQf4C2j8lkNg6M0J3PC0PzMRoinOxk"
+ + "Ae2teeCtVcIj4A1KQo3210j8q2v7qQU69Mabsa6DT9FgE4rcrbiFWrg0Zto4SXWD3o1eJA9o29lTg6kxtklH3TuZTmpi5KVp1NFhS1RpnqF83tzv4mZLKsx7Zh1fEgYvRFwx1"
+ +
+ "ar3RolyDfNoZiGBGTMsZzz7RPFBf2hTnLmNqVGQnHKhhGj0Y5s8t2cbqbO2nmHiJb9uaUVrCGypgbAcJL3KPOBfAVW8PcpmNj4yVjI3L4x5zHjmGZbp9vKshEQODcrmcgsYAoKqe"
+ +
+ "uu5u7jk8XVxEfQ0m5qL8UOErXPlJovSmKUmP5B5T0w299zIWDYCzSoNasHpHjOMDLAiDDeHbozUOn9t3Qou00e9POq4RMM0VnIx1H38nJoJZz2XH8CI5YMQe7oTagaxgQTF2aa0qaq2"
+ +
+ "V6nJsfRGRklGjNhFFYP2cS4Xv2IJO9DSX6LTXOmENrGVJJvMOZcvnBaZPfoAHN0LU4i1SoepLzulIxnZBfkUWFJgZ5wQ0Bco2GC1HMqzW21rwy4XHRxXpXbmW8LVyoA1KbnmVmROycU4"
+ + "scTZ62IxIcIWCVeMjBIcTviXULbPUyqlfEPXWr8IMJtpAaELWgyquPClAREMDs2b9ztKmUeXlMccFES1XWbFTrhBHhmmDyVReEgCwfokrUFR13LTUK1k8I6OEHOs";
serviceExccedsDescLimit.setDescription(tooLongServiceDesc);
- try{
+ try {
bl.createService(serviceExccedsDescLimit, user);
- } catch(ComponentException e){
- assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(),
+ "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
return;
}
fail();
// Not english
String tooLongServiceDesc = "\uC2B5";
notEnglish.setDescription(tooLongServiceDesc);
- try{
+ try {
bl.createService(notEnglish, user);
- } catch(ComponentException e){
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
return;
}
private void testServiceIconEmpty() {
Service serviceExist = createServiceObject(false);
serviceExist.setIcon("");
- Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(serviceExist,user,AuditingActionEnum.CREATE_SERVICE);
+ Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(serviceExist, user, AuditingActionEnum.CREATE_SERVICE);
assertThat(service.left().value().getIcon()).isEqualTo(DEFAULT_ICON);
}
+
private void testServiceIconMissing() {
Service serviceExist = createServiceObject(false);
serviceExist.setIcon(null);
- Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(serviceExist,user,AuditingActionEnum.CREATE_SERVICE);
+ Either<Service, ResponseFormat> service = bl.validateServiceBeforeCreate(serviceExist, user, AuditingActionEnum.CREATE_SERVICE);
assertThat(service.left().value().getIcon()).isEqualTo(DEFAULT_ICON);
}
List<String> tagsList = new ArrayList<>();
tagsList.add(tag1);
serviceExccedsNameLimit.setTags(tagsList);
- try{
+ try {
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
return;
}
List<String> tagsList = new ArrayList<>();
tagsList.add(tag1);
serviceExccedsNameLimit.setTags(tagsList);
- try{
+ try {
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, "Service", "tag");
return;
}
// 59 chars instead of 50
String contactIdTooLong = "thisNameIsVeryLongAndExeccedsTheNormalLengthForContactId";
serviceContactId.setContactId(contactIdTooLong);
- try{
+ try {
bl.createService(serviceContactId, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
return;
}
fail();
}
+
private void testContactIdWrongFormatCreate() {
Service serviceContactId = createServiceObject(false);
// 3 letters and 3 digits and special characters
String contactIdTooLong = "yrt134!!!";
serviceContactId.setContactId(contactIdTooLong);
- try{
+ try {
bl.createService(serviceContactId, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
return;
}
private void testResourceContactIdMissing() {
Service resourceExist = createServiceObject(false);
resourceExist.setContactId(null);
- try{
+ try {
bl.createService(resourceExist, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.SERVICE.getValue());
return;
}
private void testServiceCategoryExist() {
Service serviceExist = createServiceObject(false);
serviceExist.setCategories(null);
- try{
+ try {
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
return;
}
fail();
}
+
@Test
void markDistributionAsDeployedTestAlreadyDeployed() {
String notifyAction = "DNotify";
resultList.add(event);
Either<List<DistributionDeployEvent>, ActionStatus> eventList = Either.left(resultList);
- Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq(resultAction), Mockito.anyString())).thenReturn(eventList);
+ Mockito.when(auditingDao.getDistributionDeployByStatus(Mockito.anyString(), Mockito.eq(resultAction), Mockito.anyString()))
+ .thenReturn(eventList);
Either<Service, ResponseFormat> markDeployed = bl.markDistributionAsDeployed(did, did, user);
assertTrue(markDeployed.isLeft());
List<CategoryDefinition> categories = new ArrayList<>();
categories.add(category);
serviceExist.setCategories(categories);
- try{
+ try {
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch (ComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
return;
}
try {
bl.createService(serviceExist, user);
- } catch(ComponentException exp) {
- assertComponentException(exp, ActionStatus.INVALID_PROJECT_CODE);
+ } catch (ComponentException exp) {
+ assertComponentException(exp, ActionStatus.INVALID_PROJECT_CODE);
return;
}
fail();
try {
bl.createService(serviceExist, user);
- } catch(ComponentException exp) {
+ } catch (ComponentException exp) {
assertComponentException(exp, ActionStatus.INVALID_PROJECT_CODE);
return;
}
try {
bl.createService(serviceExist, user);
- } catch(ComponentException exp) {
+ } catch (ComponentException exp) {
assertComponentException(exp, ActionStatus.INVALID_PROJECT_CODE);
return;
}
void testDeleteArchivedService_DeleteServiceSpecificModel() throws ToscaOperationException {
String serviceId = "12345";
String model = "serviceSpecificModel";
- List<String> deletedServcies= new ArrayList<>();
+ List<String> deletedServcies = new ArrayList<>();
deletedServcies.add("54321");
Model normativeExtensionModel = new Model("normativeExtensionModel", ModelTypeEnum.NORMATIVE_EXTENSION);
Either<Component, StorageOperationStatus> eitherService = Either.left(createNewService());
Mockito.verify(modelOperation, Mockito.times(1)).deleteModel(normativeExtensionModel, false);
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Test
void testFindGroupInstanceOnRelatedComponentInstance() {
Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat> findGroupInstanceRes;
Object[] argObjects = {service, componentInstances.get(1).getUniqueId(), componentInstances.get(1).getGroupInstances().get(1).getUniqueId()};
- Class[] argClasses = {Component.class, String.class,String.class};
+ Class[] argClasses = {Component.class, String.class, String.class};
try {
Method method = targetClass.getDeclaredMethod(methodName, argClasses);
method.setAccessible(true);
findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjects);
assertNotNull(findGroupInstanceRes);
assertEquals(findGroupInstanceRes.left().value().getKey().getUniqueId(), componentInstances.get(1)
- .getUniqueId());
+ .getUniqueId());
assertEquals(findGroupInstanceRes.left().value().getValue().getUniqueId(), componentInstances.get(1)
- .getGroupInstances()
- .get(1)
- .getUniqueId());
+ .getGroupInstances()
+ .get(1)
+ .getUniqueId());
- Object[] argObjectsInvalidCiId = {service, invalidId , componentInstances.get(1).getGroupInstances().get(1).getUniqueId()};
+ Object[] argObjectsInvalidCiId = {service, invalidId, componentInstances.get(1).getGroupInstances().get(1).getUniqueId()};
- findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjectsInvalidCiId);
+ findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjectsInvalidCiId);
assertNotNull(findGroupInstanceRes);
assertTrue(findGroupInstanceRes.isRight());
assertEquals("SVC4593", findGroupInstanceRes.right().value().getMessageId());
- Object[] argObjectsInvalidGiId = {service, componentInstances.get(1).getUniqueId() , invalidId};
+ Object[] argObjectsInvalidGiId = {service, componentInstances.get(1).getUniqueId(), invalidId};
- findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjectsInvalidGiId);
+ findGroupInstanceRes = (Either<ImmutablePair<ComponentInstance, GroupInstance>, ResponseFormat>) method.invoke(bl, argObjectsInvalidGiId);
assertNotNull(findGroupInstanceRes);
assertTrue(findGroupInstanceRes.isRight());
assertEquals("SVC4653", findGroupInstanceRes.right().value().getMessageId());
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
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);
}
}
protected Service createNewService() {
- return (Service)createNewComponent();
+ return (Service) createNewComponent();
}
@Test
currentService.setEcompGeneratedNaming(false);
newService.setEcompGeneratedNaming(true);
newService.setNamingPolicy("policy");
- Either<Service, ResponseFormat> resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
Service updatedService = resultOfUpdate.left().value();
assertThat(updatedService.isEcompGeneratedNaming()).isTrue();
Service newService = createServiceObject(false);
currentService.setProjectCode("12345");
newService.setProjectCode("");
- Either<Service, ResponseFormat> resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
Service updatedService = resultOfUpdate.left().value();
assertThat(updatedService.getProjectCode()).isEmpty();
Service newService = createServiceObject(false);
currentService.setProjectCode("");
newService.setProjectCode("12345");
- Either<Service, ResponseFormat> resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
Service updatedService = resultOfUpdate.left().value();
assertThat(updatedService.getProjectCode()).isEqualTo("12345");
Service newService = createServiceObject(false);
currentService.setProjectCode("33333");
newService.setProjectCode("12345");
- Either<Service, ResponseFormat> resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
Service updatedService = resultOfUpdate.left().value();
assertThat(updatedService.getProjectCode()).isEqualTo("12345");
currentService.setServiceType("alice");
//valid English word
newService.setServiceType("bob");
- Either<Service, ResponseFormat> resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
Service updatedService = resultOfUpdate.left().value();
assertThat(updatedService.getServiceType()).isEqualToIgnoringCase("bob");
//empty string is invalid
newService.setServiceType("");
- resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
//null is invalid
newService.setServiceType(null);
- resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isRight()).isTrue();
}
currentService.setServiceFunction("alice");
//valid English word
newService.setServiceFunction("bob");
- Either<Service, ResponseFormat> resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
Service updatedService = resultOfUpdate.left().value();
assertThat(updatedService.getServiceFunction()).isEqualToIgnoringCase("bob");
//empty string is valid
newService.setServiceFunction("");
- resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
//null is valid and assigner to ""
newService.setServiceFunction(null);
- resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService);
+ resultOfUpdate = bl.validateAndUpdateServiceMetadata(user, currentService, newService, false, new ArrayList<>());
assertThat(resultOfUpdate.isLeft()).isTrue();
assertThat(updatedService.getServiceFunction()).isEqualTo("");
}
-
@Test
void testServiceFunctionExceedLength() {
String serviceName = "Service";
- String serviceFunction = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ String serviceFunction =
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
Service serviceFunctionExceedLength = createServiceObject(false);
serviceFunctionExceedLength.setName(serviceName);
serviceFunctionExceedLength.setServiceFunction(serviceFunction);
}
@Test
- void testServiceFunctionInvalidCharacter(){
+ void testServiceFunctionInvalidCharacter() {
String serviceName = "Service";
String serviceFunction = "a?";
Service serviceFunctionExceedLength = createServiceObject(false);
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", "2", "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", "2", "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", "2", "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", "2", "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
String weirdUniqueServiceInstanceId = UUID.randomUUID().toString();
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", weirdUniqueServiceInstanceId, "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", weirdUniqueServiceInstanceId, "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
Mockito.when(toscaOperationFacade.getToscaElement(Mockito.anyString())).thenReturn(eitherService);
Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap =
- Maps.newHashMap();
+ Maps.newHashMap();
componentInstancesInterfacesMap.put(aService.getUniqueId(),
- Lists.newArrayList(new ComponentInstanceInterface("1", new InterfaceInstanceDataDefinition())));
+ Lists.newArrayList(new ComponentInstanceInterface("1", new InterfaceInstanceDataDefinition())));
aService.setComponentInstancesInterfaces(componentInstancesInterfacesMap);
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), "3",
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
String operationId = "operationId";
ComponentInstanceInterface componentInstanceInterface =
- new ComponentInstanceInterface("interfaceId", new InterfaceInstanceDataDefinition());
+ new ComponentInstanceInterface("interfaceId", new InterfaceInstanceDataDefinition());
Map<String, Operation> operationsMap = Maps.newHashMap();
operationsMap.put(operationId, new Operation(new ArtifactDataDefinition(), "1",
- new ListDataDefinition<>(), new ListDataDefinition<>()));
+ new ListDataDefinition<>(), new ListDataDefinition<>()));
componentInstanceInterface.setOperationsMap(operationsMap);
Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = Maps.newHashMap();
aService.setComponentInstancesInterfaces(componentInstancesInterfacesMap);
Either<Operation, ResponseFormat> operationEither =
- bl.addPropertyServiceConsumption("1", aService.getUniqueId(), operationId,
- user.getUserId(), new ServiceConsumptionData());
+ bl.addPropertyServiceConsumption("1", aService.getUniqueId(), operationId,
+ user.getUserId(), new ServiceConsumptionData());
assertTrue(operationEither.isRight());
assertEquals(HttpStatus.NOT_FOUND.value(), operationEither.right().value().getStatus().intValue());
}
@Test
- void testCreateService_withMultitenancyInvalidTenant_Failure() {
+ void testCreateService_withMultitenancyInvalidTenant_Failure() {
Service service = createServiceObject(false);
service.setTenant("invalid_tenant");
when(genericTypeBusinessLogic.fetchDerivedFromGenericType(service, null)).thenReturn(Either.left(genericService));
assertEqualsServiceObject(createServiceObject(true), createResponse.left().value());
}
- private Set<String> getTestRoles(){
+ @Test
+ void testUpdateSubstitutionNodeTypeAndVersion() {
+ Service currentService = createServiceObject(true);
+ currentService.setDerivedFromGenericType("genericTypeOne");
+ currentService.setDerivedFromGenericVersion("1.0");
+ Service newService = createServiceObject(false);
+ newService.setDerivedFromGenericType("genericTypeTwo");
+ newService.setDerivedFromGenericVersion("2.0");
+ List<String> subNodePropsToBeRemoved = new ArrayList<>();
+ subNodePropsToBeRemoved.add("testProp");
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, true, subNodePropsToBeRemoved);
+ assertThat(resultOfUpdate.isLeft()).isTrue();
+ Service updatedService = resultOfUpdate.left().value();
+ assertEquals("genericTypeTwo", updatedService.getDerivedFromGenericType());
+ assertEquals("2.0", updatedService.getDerivedFromGenericVersion());
+ }
+
+ @Test
+ void testUpdateSubstitutionNodeTypePropsToRemoveThrowInUseGetProperty() {
+ Service currentService = createServiceObject(true);
+ setComponentInstanceOnServiceWithPropWithToscaFunction(currentService, ToscaGetFunctionType.GET_PROPERTY, "testProp");
+ Service newService = createServiceObject(false);
+ List<String> subNodePropsToBeRemoved = new ArrayList<>();
+ subNodePropsToBeRemoved.add("testProp");
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, true, subNodePropsToBeRemoved);
+ assertThat(resultOfUpdate.isRight()).isTrue();
+ ResponseFormat response = resultOfUpdate.right().value();
+ assertEquals(409, response.getStatus());
+ assertEquals("Cannot change substitution node type as properties of the existing type are referenced by properties %1.", response.getText());
+ }
+
+ @Test
+ void testUpdateSubstitutionNodeTypePropsToRemoveThrowInUseGetAttribute() {
+ Service currentService = createServiceObject(true);
+ setComponentInstanceOnServiceWithPropWithToscaFunction(currentService, ToscaGetFunctionType.GET_ATTRIBUTE, "testProp");
+ Service newService = createServiceObject(false);
+ List<String> subNodePropsToBeRemoved = new ArrayList<>();
+ subNodePropsToBeRemoved.add("testProp");
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, true, subNodePropsToBeRemoved);
+ assertThat(resultOfUpdate.isRight()).isTrue();
+ ResponseFormat response = resultOfUpdate.right().value();
+ assertEquals(409, response.getStatus());
+ assertEquals("Cannot change substitution node type as properties of the existing type are referenced by properties %1.", response.getText());
+ }
+
+ @Test
+ void testUpdateSubstitutionNodeTypePropsToRemoveThrowInUseGetInput() {
+ Service currentService = createServiceObject(true);
+ setComponentInstanceOnServiceWithPropWithToscaFunction(currentService, ToscaGetFunctionType.GET_INPUT, "testProp");
+ Service newService = createServiceObject(false);
+ List<String> subNodePropsToBeRemoved = new ArrayList<>();
+ subNodePropsToBeRemoved.add("testProp");
+ Either<Service, ResponseFormat> resultOfUpdate =
+ bl.validateAndUpdateServiceMetadata(user, currentService, newService, true, subNodePropsToBeRemoved);
+ assertThat(resultOfUpdate.isRight()).isTrue();
+ ResponseFormat response = resultOfUpdate.right().value();
+ assertEquals(409, response.getStatus());
+ assertEquals("Cannot change substitution node type as properties of the existing type are referenced by properties %1.", response.getText());
+ }
+
+ private void setComponentInstanceOnServiceWithPropWithToscaFunction(Service currentService, ToscaGetFunctionType toscaGetFunctionType,
+ String testPropName) {
+ ComponentInstance compInstance = new ComponentInstance();
+ compInstance.setUniqueId("resourceUid");
+
+ List<ComponentInstance> compInstances = new ArrayList<>();
+ compInstances.add(compInstance);
+ currentService.setComponentInstances(compInstances);
+
+ ToscaGetFunctionDataDefinition toscaFunc = new ToscaGetFunctionDataDefinition();
+ toscaFunc.setPropertyName(testPropName);
+ toscaFunc.setPropertyUniqueId(testPropName + "Uid");
+ toscaFunc.setFunctionType(toscaGetFunctionType);
+
+ if (ToscaGetFunctionType.GET_INPUT.equals(toscaGetFunctionType)) {
+ toscaFunc.setPropertyName(testPropName + "Input");
+ toscaFunc.setPropertyUniqueId(testPropName + "InputUid");
+ InputDefinition compInput = new InputDefinition();
+ compInput.setName(testPropName + "Input");
+ compInput.setUniqueId(testPropName + "InputUid");
+ compInput.setPropertyId(testPropName + "Uid");
+ List<InputDefinition> compInputs = new ArrayList<>();
+ compInputs.add(compInput);
+ currentService.setInputs(compInputs);
+ }
+
+ ComponentInstanceProperty compInstProp = new ComponentInstanceProperty();
+ compInstProp.setName("compInstProp");
+ compInstProp.setToscaFunction(toscaFunc);
+
+ List<ComponentInstanceProperty> compInstProps = new ArrayList<>();
+ compInstProps.add(compInstProp);
+
+ Map<String, List<ComponentInstanceProperty>> mapCompInstProps = new HashMap<>();
+ mapCompInstProps.put("resourceUid", compInstProps);
+
+ PropertyDefinition compProp = new PropertyDefinition();
+ compProp.setName(testPropName);
+ compProp.setUniqueId(testPropName + "Uid");
+ List<PropertyDefinition> compProps = new ArrayList<>();
+ compProps.add(compProp);
+ currentService.setProperties(compProps);
+
+ currentService.setComponentInstancesProperties(mapCompInstProps);
+ }
+
+ private Set<String> getTestRoles() {
Set<String> roles = new HashSet<>();
roles.add("test_admin");
roles.add("test_tenant");