diff options
author | vasraz <vasyl.razinkov@est.tech> | 2022-12-23 16:56:21 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-01-03 14:19:17 +0000 |
commit | a81c40773b3c819f079bd741d472ee954572cb34 (patch) | |
tree | 24626c3affd27f8c03473275ddf89baa2ae3af60 | |
parent | 4871b522afd7dfee773dc891cb94d3f1eaafb040 (diff) |
Fix 'NPE thrown in editing constraints'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Ibbd8a3baa2a2bfdbd6e2c235db5a1d59875f3e6e
Issue-ID: SDC-4312
12 files changed, 1150 insertions, 1223 deletions
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 51444a2cc1..b773f1fbbc 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 @@ -22,6 +22,7 @@ package org.openecomp.sdc.be.components.impl; import static org.apache.commons.collections.CollectionUtils.isEmpty; import static org.openecomp.sdc.be.components.impl.ResourceImportManager.PROPERTY_NAME_PATTERN_IGNORE_LENGTH; import static org.openecomp.sdc.be.datatypes.elements.Annotation.setAnnotationsName; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; @@ -48,6 +49,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.Annotation; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; +import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.AnnotationTypeDefinition; @@ -62,9 +64,7 @@ import org.openecomp.sdc.be.model.heat.HeatParameterType; import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; -import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.model.tosca.constraints.AbstractComparablePropertyConstraint; -import org.openecomp.sdc.be.model.tosca.constraints.EqualConstraint; import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint; import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; @@ -336,17 +336,7 @@ public final class ImportUtils { } } catch (ConstraintValueDoNotMatchPropertyTypeException e) { throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS, propertyConstraint.getConstraintType().name(), - ((AbstractComparablePropertyConstraint) propertyConstraint).getConstraintValueAsString(), propertyType); - } - } else if (propertyConstraint instanceof EqualConstraint) { - try { - boolean valid = ((EqualConstraint) propertyConstraint).validateValueType(propertyType); - if (!valid) { - ((EqualConstraint) propertyConstraint).changeConstraintValueTypeTo(propertyType); - } - } catch (ConstraintValueDoNotMatchPropertyTypeException e) { - throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS, ConstraintType.EQUAL.name(), - String.valueOf(((EqualConstraint) propertyConstraint).getEqual()), propertyType); + propertyConstraint.toString(), propertyType); } } else if (propertyConstraint instanceof InRangeConstraint) { try { @@ -356,7 +346,7 @@ public final class ImportUtils { } } catch (ConstraintValueDoNotMatchPropertyTypeException e) { throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS, ConstraintType.IN_RANGE.name(), - String.valueOf(((InRangeConstraint) propertyConstraint).getInRange()), propertyType); + String.valueOf(((InRangeConstraint) propertyConstraint).getInRange()), propertyType); } } return propertyConstraint; @@ -712,7 +702,8 @@ public final class ImportUtils { public static boolean containsGetInput(Object propValue) { String value = getPropertyJsonStringValue(propValue, ToscaPropertyType.MAP.getType()); - return value != null && value.contains(TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName()) && !value.contains(TypeUtils.ToscaTagNamesEnum.CONCAT.getElementName()); + return value != null && value.contains(TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName()) && !value.contains( + TypeUtils.ToscaTagNamesEnum.CONCAT.getElementName()); } public static String getPropertyJsonStringValue(Object value, String type) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java index ae97b89b78..9b92adbe6a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java @@ -157,8 +157,8 @@ public class PropertyConvertor { if (constraint instanceof InRangeConstraint) { InRangeConstraint inRangeConstraint = (InRangeConstraint) constraint; List<Object> range = new ArrayList<>(); - range.add(inRangeConstraint.getRangeMinValue()); - range.add(inRangeConstraint.getRangeMaxValue()); + range.add(inRangeConstraint.getMin()); + range.add(inRangeConstraint.getMax()); convertedConstraints.add(new ToscaPropertyConstraintInRange(range)); } if (constraint instanceof ValidValuesConstraint) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java index 3260521084..310f4792c1 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java @@ -21,11 +21,18 @@ */ package org.openecomp.sdc.be.impl; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import fj.data.Either; import java.util.ArrayList; +import java.util.List; import org.apache.tinkerpop.gremlin.structure.T; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.openecomp.sdc.be.auditing.impl.AuditingManager; import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum; @@ -68,1063 +75,1073 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.openecomp.sdc.exception.ResponseFormat; import org.openecomp.sdc.test.utils.TestConfigurationProvider; -import java.util.List; +class ComponentsUtilsTest { -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; + private ComponentsUtils createTestSubject() { + return new ComponentsUtils(new AuditingManager(new AuditCassandraDao(mock(CassandraClient.class)), new TestConfigurationProvider())); + } + + @BeforeEach + public void init() { + String appConfigDir = "src/test/resources/config/catalog-be"; + ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); + ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); + ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); + } + + @Test + void testGetAuditingManager() { + ComponentsUtils testSubject; + AuditingManager result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getAuditingManager(); + assertThat(result).isInstanceOf(AuditingManager.class); + } + + @Test + void testGetResponseFormat() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + String[] params = new String[]{""}; + ResponseFormat result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResponseFormat(actionStatus, params); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus().toString()).startsWith("2"); + } + + @Test + void testGetResponseFormat_1() { + ComponentsUtils testSubject; + StorageOperationStatus storageStatus = null; + String[] params = new String[]{""}; + ResponseFormat result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResponseFormat(storageStatus, params); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus().toString()).startsWith("5"); + } + + @Test + void testConvertToResponseFormatOrNotFoundErrorToEmptyList() { + ComponentsUtils testSubject; + StorageOperationStatus storageOperationStatus = StorageOperationStatus.ARTIFACT_NOT_FOUND; + Either<List<T>, ResponseFormat> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertToResponseFormatOrNotFoundErrorToEmptyList(storageOperationStatus); + assertThat(result.isRight()).isTrue(); + } -public class ComponentsUtilsTest { - - private ComponentsUtils createTestSubject() { - return new ComponentsUtils(new AuditingManager(new AuditCassandraDao(mock(CassandraClient.class)), new TestConfigurationProvider())); - } - - @Before - public void init(){ - String appConfigDir = "src/test/resources/config/catalog-be"; - ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); - ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); - ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); - } - - @Test - public void testGetAuditingManager() { - ComponentsUtils testSubject; - AuditingManager result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAuditingManager(); - assertThat(result).isInstanceOf(AuditingManager.class); - } - - - @Test - public void testGetResponseFormat() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - String[] params = new String[] { "" }; - ResponseFormat result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormat(actionStatus, params); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus().toString().startsWith("2")).isTrue(); - } - - - @Test - public void testGetResponseFormat_1() { - ComponentsUtils testSubject; - StorageOperationStatus storageStatus = null; - String[] params = new String[] { "" }; - ResponseFormat result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormat(storageStatus, params); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus().toString().startsWith("5")).isTrue(); - } - - - @Test - public void testConvertToResponseFormatOrNotFoundErrorToEmptyList() { - ComponentsUtils testSubject; - StorageOperationStatus storageOperationStatus = StorageOperationStatus.ARTIFACT_NOT_FOUND; - Either<List<T>, ResponseFormat> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertToResponseFormatOrNotFoundErrorToEmptyList(storageOperationStatus); - assertThat(result.isRight()).isTrue(); - } - - @Test - public void testConvertToResponseFormatOrNotFoundErrorToEmptyList_1() { - ComponentsUtils testSubject; - StorageOperationStatus storageOperationStatus = StorageOperationStatus.NOT_FOUND; - Either<List<T>, ResponseFormat> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertToResponseFormatOrNotFoundErrorToEmptyList(storageOperationStatus); - assertThat(result.isLeft()).isTrue(); - } - - - @Test - public void testGetResponseFormatByResource() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - ResponseFormat result; - Resource resource = null; - // test 1 - testSubject = createTestSubject(); - result = testSubject.getResponseFormatByResource(actionStatus, resource); - - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - resource = new Resource(); - result = testSubject.getResponseFormatByResource(actionStatus, resource); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, resource); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - result = testSubject.getResponseFormatByResource(ActionStatus.RESOURCE_NOT_FOUND, resource); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(404); - - result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_IN_USE, resource); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(403); - } - - - @Test - public void testGetResponseFormatByResource_1() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - String resourceName = ""; - ResponseFormat result; - - // test 1 - testSubject = createTestSubject(); - resourceName = null; - result = testSubject.getResponseFormatByResource(actionStatus, resourceName); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - // test 2 - testSubject = createTestSubject(); - resourceName = "mock-name"; - result = testSubject.getResponseFormatByResource(actionStatus, resourceName); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - result = testSubject.getResponseFormatByResource(ActionStatus.RESOURCE_NOT_FOUND, resourceName); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(404); - } - - - @Test - public void testGetResponseFormatByCapabilityType() throws Exception { - ComponentsUtils testSubject; - CapabilityTypeDefinition capabilityType = new CapabilityTypeDefinition(); - ResponseFormat result; - - // test 1 - testSubject = createTestSubject(); - result = testSubject.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, null); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - result = testSubject.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - result = testSubject.getResponseFormatByCapabilityType(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, capabilityType); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(500); - } - - - @Test - public void testGetResponseFormatByElement() throws Exception { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - Object obj = null; - ResponseFormat result; - - // test 1 - testSubject = createTestSubject(); - - obj = null; - result = testSubject.getResponseFormatByElement(actionStatus, obj); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - obj = new Object(); - - result = testSubject.getResponseFormatByElement(actionStatus, obj); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - List<Object> obj1 = new ArrayList<>(); - obj1.add(new RequirementDefinition()); - - result = testSubject.getResponseFormatByElement(ActionStatus.MISSING_CAPABILITY_TYPE, obj1); - assertThat(result.getStatus()).isEqualTo(400); - } - - - @Test - public void testGetResponseFormatByUser() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - User user = null; - ResponseFormat result; - - // test 1 - testSubject = createTestSubject(); - user = null; - result = testSubject.getResponseFormatByUser(actionStatus, user); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - user = new User(); - result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_USER_ID, user); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - - result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_EMAIL_ADDRESS, user); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - - result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_ROLE, user); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - - result = testSubject.getResponseFormatByUser(ActionStatus.USER_NOT_FOUND, user); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(404); - - result = testSubject.getResponseFormatByUser(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, user); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - } - - - @Test - public void testGetResponseFormatByUserId() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - String userId = ""; - ResponseFormat result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormatByUserId(actionStatus, userId); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - } - - - @Test - public void testGetResponseFormatByDE() { - ComponentsUtils testSubject; - String serviceId = ""; - String envName = ""; - ResponseFormat result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormatByDE(ActionStatus.ACCEPTED, serviceId); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - result = testSubject.getResponseFormatByDE(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, serviceId); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(500); - - result = testSubject.getResponseFormatByDE(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, serviceId); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - } - - - @Test - public void testGetResponseFormatByArtifactId() throws Exception { - ComponentsUtils testSubject; - String artifactId = ""; - ResponseFormat result; - - // default test - testSubject = createTestSubject(); - - result = testSubject.getResponseFormatByArtifactId(ActionStatus.ACCEPTED, artifactId); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - result = testSubject.getResponseFormatByArtifactId(ActionStatus.RESOURCE_NOT_FOUND, artifactId); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(404); - } - - @Test - public void testAuditResource_1() throws Exception { - ComponentsUtils testSubject; - ResponseFormat responseFormat = new ResponseFormat(); - User modifier = null; - String resourceName = ""; - AuditingActionEnum actionEnum = null; - - // default test - testSubject = createTestSubject(); - testSubject.auditResource(responseFormat, modifier, resourceName, actionEnum); - } - - - - @Test - public void testAuditResource_3() throws Exception { - ComponentsUtils testSubject; - ResponseFormat responseFormat = null; - User modifier = null; - Resource resource = null; - String resourceName = ""; - AuditingActionEnum actionEnum = null; - - // default test - testSubject = createTestSubject(); - testSubject.auditResource(responseFormat, modifier, resource, resourceName, actionEnum); - } - - - @Test - public void testAuditResource_4() throws Exception { - ComponentsUtils testSubject; - ResponseFormat responseFormat = null; - User modifier = null; - Resource resource = null; - String resourceName = ""; - AuditingActionEnum actionEnum = null; - ResourceVersionInfo prevResFields = null; - String currentArtifactUuid = ""; - String artifactData = ""; - - // test 1 - testSubject = createTestSubject(); - actionEnum = null; - testSubject.auditResource(responseFormat, modifier, resource, resourceName, actionEnum, prevResFields, - currentArtifactUuid, null); - } - - @Test - public void testConvertFromStorageResponse() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = null; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponse(storageResponse); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testConvertFromStorageResponse_1() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = null; - ComponentTypeEnum type = null; - ActionStatus result; - - // test 1 - testSubject = createTestSubject(); - storageResponse = null; - result = testSubject.convertFromStorageResponse(storageResponse, type); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR);; - } - - - @Test - public void testConvertFromToscaError() { - ComponentsUtils testSubject; - ToscaError toscaError = null; - ActionStatus result; - - // test 1 - testSubject = createTestSubject(); - toscaError = null; - result = testSubject.convertFromToscaError(toscaError); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testConvertFromStorageResponseForCapabilityType() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponseForCapabilityType(storageResponse); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testConvertFromStorageResponseForLifecycleType() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponseForLifecycleType(storageResponse); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testConvertFromStorageResponseForResourceInstance() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; - boolean isRelation = false; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponseForResourceInstance(storageResponse, isRelation); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testGetResponseFormatForResourceInstance() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - String serviceName = ""; - String resourceInstanceName = ""; - ResponseFormat result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormatForResourceInstance(actionStatus, serviceName, resourceInstanceName); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - } - - - @Test - public void testGetResponseFormatForResourceInstanceProperty() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - String resourceInstanceName = ""; - ResponseFormat result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormatForResourceInstanceProperty(actionStatus, resourceInstanceName); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - } - - - @Test - public void testConvertFromStorageResponseForResourceInstanceProperty() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponseForResourceInstanceProperty(storageResponse); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testAuditComponent() throws Exception { - ComponentsUtils testSubject; - ResponseFormat responseFormat = null; - User modifier = null; - Component component = null; - AuditingActionEnum actionEnum = null; - ComponentTypeEnum type = null; - ResourceCommonInfo prevComponent = null; - ResourceVersionInfo info = null; - String comment = ""; - - // default test - testSubject = createTestSubject(); - testSubject.auditComponent(responseFormat, modifier, component, actionEnum, prevComponent,info); - } - - - @Test - public void testAuditComponent_1() throws Exception { - ComponentsUtils testSubject; - ResponseFormat responseFormat = null; - User modifier = null; - Component component = null; - AuditingActionEnum actionEnum = null; - ResourceCommonInfo type = null; - ResourceVersionInfo prevComponent = null; - - // default test - testSubject = createTestSubject(); - testSubject.auditComponent(responseFormat, modifier, component, actionEnum, type, prevComponent); - } - - - @Test - public void testValidateStringNotEmpty() { - ComponentsUtils testSubject; - String value = ""; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.validateStringNotEmpty(value); - assertThat(result).isFalse(); - } - - - @Test - public void testConvertFromStorageResponseForAdditionalInformation() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponseForAdditionalInformation(storageResponse); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testConvertFromResultStatusEnum() { - ComponentsUtils testSubject; - ResultStatusEnum resultStatus = ResultStatusEnum.ELEMENT_NOT_FOUND; - JsonPresentationFields elementType = null; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromResultStatusEnum(resultStatus, elementType); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testGetResponseFormatAdditionalProperty() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - AdditionalInfoParameterInfo additionalInfoParameterInfo = null; - NodeTypeEnum nodeType = null; - AdditionalInformationEnum labelOrValue = null; - ResponseFormat result; - - // test 1 - testSubject = createTestSubject(); - additionalInfoParameterInfo = null; - result = testSubject.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - - // test 2 - testSubject = createTestSubject(); - labelOrValue = null; - result = testSubject.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - } - - - @Test - public void testGetResponseFormatAdditionalProperty_1() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - ResponseFormat result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormatAdditionalProperty(actionStatus); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - } - - - @Test - public void testConvertFromStorageResponseForConsumer() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponseForConsumer(storageResponse); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testConvertFromStorageResponseForGroupType() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponseForGroupType(storageResponse); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testConvertFromStorageResponseForDataType() { - ComponentsUtils testSubject; - StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.convertFromStorageResponseForDataType(storageResponse); - assertThat(result) - .isInstanceOf(ActionStatus.class) - .isEqualTo(ActionStatus.GENERAL_ERROR); - } - - - @Test - public void testGetResponseFormatByGroupType() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - GroupTypeDefinition groupType = null; - ResponseFormat result; - - // test 1 - testSubject = createTestSubject(); - groupType = null; - result = testSubject.getResponseFormatByGroupType(actionStatus, groupType); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - } - - - @Test - public void testGetResponseFormatByPolicyType() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.ACCEPTED; - PolicyTypeDefinition policyType = new PolicyTypeDefinition(); - ResponseFormat result; - - // test 1 - testSubject = createTestSubject(); - result = testSubject.getResponseFormatByPolicyType(actionStatus, policyType); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - } - - - @Test - public void testGetResponseFormatByDataType() { - ComponentsUtils testSubject; - ActionStatus actionStatus = ActionStatus.AAI_ARTIFACT_GENERATION_FAILED; - DataTypeDefinition dataType = null; - List<String> properties = null; - ResponseFormat result; - - // test 1 - testSubject = createTestSubject(); - dataType = null; - result = testSubject.getResponseFormatByDataType(actionStatus, dataType, properties); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(500); - } - - @Test - public void testconvertJsonToObject() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - User user = new User(); - ComponentsUtils testSubject = createTestSubject(); - String data="{ firstName=\"xyz\", lastName=\"xyz\", userId=\"12\", email=\"demo.z@ymail.com\",role=\"123\", lastlogintime=20180201233412 }"; - - Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER); - User assertuser = new User("xyz","xyz","12","demo.z@ymail.com","123",null); - - assertThat(response.isLeft()).isTrue(); - assertThat(response.left().value()).isEqualTo(assertuser); - } + @Test + void testConvertToResponseFormatOrNotFoundErrorToEmptyList_1() { + ComponentsUtils testSubject; + StorageOperationStatus storageOperationStatus = StorageOperationStatus.NOT_FOUND; + Either<List<T>, ResponseFormat> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertToResponseFormatOrNotFoundErrorToEmptyList(storageOperationStatus); + assertThat(result.isLeft()).isTrue(); + } @Test - public void testconvertJsonToObjectUsingObjectMapper() { + void testGetResponseFormatByResource() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + ResponseFormat result; + Resource resource = null; + // test 1 + testSubject = createTestSubject(); + result = testSubject.getResponseFormatByResource(actionStatus, resource); + + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + resource = new Resource(); + result = testSubject.getResponseFormatByResource(actionStatus, resource); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, resource); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + result = testSubject.getResponseFormatByResource(ActionStatus.RESOURCE_NOT_FOUND, resource); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(404); + + result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + result = testSubject.getResponseFormatByResource(ActionStatus.COMPONENT_IN_USE, resource); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(403); + } + + @Test + void testGetResponseFormatByResource_1() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + String resourceName = ""; + ResponseFormat result; + + // test 1 + testSubject = createTestSubject(); + resourceName = null; + result = testSubject.getResponseFormatByResource(actionStatus, resourceName); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + // test 2 + testSubject = createTestSubject(); + resourceName = "mock-name"; + result = testSubject.getResponseFormatByResource(actionStatus, resourceName); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + result = testSubject.getResponseFormatByResource(ActionStatus.RESOURCE_NOT_FOUND, resourceName); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(404); + } + + @Test + void testGetResponseFormatByCapabilityType() throws Exception { + ComponentsUtils testSubject; + CapabilityTypeDefinition capabilityType = new CapabilityTypeDefinition(); + ResponseFormat result; + + // test 1 + testSubject = createTestSubject(); + result = testSubject.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, null); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + result = testSubject.getResponseFormatByCapabilityType(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + result = testSubject.getResponseFormatByCapabilityType(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, capabilityType); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(500); + } + + @Test + void testGetResponseFormatByElement() throws Exception { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + Object obj = null; + ResponseFormat result; + + // test 1 + testSubject = createTestSubject(); + + obj = null; + result = testSubject.getResponseFormatByElement(actionStatus, obj); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + obj = new Object(); + + result = testSubject.getResponseFormatByElement(actionStatus, obj); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + List<Object> obj1 = new ArrayList<>(); + obj1.add(new RequirementDefinition()); + + result = testSubject.getResponseFormatByElement(ActionStatus.MISSING_CAPABILITY_TYPE, obj1); + assertThat(result.getStatus()).isEqualTo(400); + } + + @Test + void testGetResponseFormatByUser() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + User user = null; + ResponseFormat result; + + // test 1 + testSubject = createTestSubject(); + user = null; + result = testSubject.getResponseFormatByUser(actionStatus, user); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + user = new User(); + result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_USER_ID, user); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + + result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_EMAIL_ADDRESS, user); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + + result = testSubject.getResponseFormatByUser(ActionStatus.INVALID_ROLE, user); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + + result = testSubject.getResponseFormatByUser(ActionStatus.USER_NOT_FOUND, user); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(404); + + result = testSubject.getResponseFormatByUser(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, user); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + } + + @Test + void testGetResponseFormatByUserId() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + String userId = ""; + ResponseFormat result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResponseFormatByUserId(actionStatus, userId); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + } + + @Test + void testGetResponseFormatByDE() { + ComponentsUtils testSubject; + String serviceId = ""; + String envName = ""; + ResponseFormat result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResponseFormatByDE(ActionStatus.ACCEPTED, serviceId); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + result = testSubject.getResponseFormatByDE(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, serviceId); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(500); + + result = testSubject.getResponseFormatByDE(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, serviceId); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + } + + @Test + void testGetResponseFormatByArtifactId() throws Exception { + ComponentsUtils testSubject; + String artifactId = ""; + ResponseFormat result; + + // default test + testSubject = createTestSubject(); + + result = testSubject.getResponseFormatByArtifactId(ActionStatus.ACCEPTED, artifactId); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + result = testSubject.getResponseFormatByArtifactId(ActionStatus.RESOURCE_NOT_FOUND, artifactId); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(404); + } + + @Test + void testAuditResource_1() throws Exception { + ComponentsUtils testSubject; + ResponseFormat responseFormat = new ResponseFormat(); + User modifier = null; + String resourceName = ""; + AuditingActionEnum actionEnum = null; + + // default test + testSubject = createTestSubject(); + testSubject.auditResource(responseFormat, modifier, resourceName, actionEnum); + } + + @Test + void testAuditResource_3() throws Exception { + ComponentsUtils testSubject; + ResponseFormat responseFormat = null; + User modifier = null; + Resource resource = null; + String resourceName = ""; + AuditingActionEnum actionEnum = null; + + // default test + testSubject = createTestSubject(); + testSubject.auditResource(responseFormat, modifier, resource, resourceName, actionEnum); + } + + @Test + void testAuditResource_4() throws Exception { + ComponentsUtils testSubject; + ResponseFormat responseFormat = null; + User modifier = null; + Resource resource = null; + String resourceName = ""; + AuditingActionEnum actionEnum = null; + ResourceVersionInfo prevResFields = null; + String currentArtifactUuid = ""; + String artifactData = ""; + + // test 1 + testSubject = createTestSubject(); + actionEnum = null; + testSubject.auditResource(responseFormat, modifier, resource, resourceName, actionEnum, prevResFields, + currentArtifactUuid, null); + } + + @Test + void testConvertFromStorageResponse() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = null; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponse(storageResponse); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testConvertFromStorageResponse_1() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = null; + ComponentTypeEnum type = null; + ActionStatus result; + + // test 1 + testSubject = createTestSubject(); + storageResponse = null; + result = testSubject.convertFromStorageResponse(storageResponse, type); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + ; + } + + @Test + void testConvertFromToscaError() { + ComponentsUtils testSubject; + ToscaError toscaError = null; + ActionStatus result; + + // test 1 + testSubject = createTestSubject(); + toscaError = null; + result = testSubject.convertFromToscaError(toscaError); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testConvertFromStorageResponseForCapabilityType() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponseForCapabilityType(storageResponse); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testConvertFromStorageResponseForLifecycleType() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponseForLifecycleType(storageResponse); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testConvertFromStorageResponseForResourceInstance() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; + boolean isRelation = false; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponseForResourceInstance(storageResponse, isRelation); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testGetResponseFormatForResourceInstance() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + String serviceName = ""; + String resourceInstanceName = ""; + ResponseFormat result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResponseFormatForResourceInstance(actionStatus, serviceName, resourceInstanceName); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + } + + @Test + void testGetResponseFormatForResourceInstanceProperty() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + String resourceInstanceName = ""; + ResponseFormat result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResponseFormatForResourceInstanceProperty(actionStatus, resourceInstanceName); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + } + + @Test + void testConvertFromStorageResponseForResourceInstanceProperty() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponseForResourceInstanceProperty(storageResponse); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testAuditComponent() throws Exception { + ComponentsUtils testSubject; + ResponseFormat responseFormat = null; + User modifier = null; + Component component = null; + AuditingActionEnum actionEnum = null; + ComponentTypeEnum type = null; + ResourceCommonInfo prevComponent = null; + ResourceVersionInfo info = null; + String comment = ""; + + // default test + testSubject = createTestSubject(); + testSubject.auditComponent(responseFormat, modifier, component, actionEnum, prevComponent, info); + } + + @Test + void testAuditComponent_1() throws Exception { + ComponentsUtils testSubject; + ResponseFormat responseFormat = null; + User modifier = null; + Component component = null; + AuditingActionEnum actionEnum = null; + ResourceCommonInfo type = null; + ResourceVersionInfo prevComponent = null; + + // default test + testSubject = createTestSubject(); + testSubject.auditComponent(responseFormat, modifier, component, actionEnum, type, prevComponent); + } + + @Test + void testValidateStringNotEmpty() { + ComponentsUtils testSubject; + String value = ""; + boolean result; + + // default test + testSubject = createTestSubject(); + result = testSubject.validateStringNotEmpty(value); + assertThat(result).isFalse(); + } + + @Test + void testConvertFromStorageResponseForAdditionalInformation() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponseForAdditionalInformation(storageResponse); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testConvertFromResultStatusEnum() { + ComponentsUtils testSubject; + ResultStatusEnum resultStatus = ResultStatusEnum.ELEMENT_NOT_FOUND; + JsonPresentationFields elementType = null; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromResultStatusEnum(resultStatus, elementType); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testGetResponseFormatAdditionalProperty() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + AdditionalInfoParameterInfo additionalInfoParameterInfo = null; + NodeTypeEnum nodeType = null; + AdditionalInformationEnum labelOrValue = null; + ResponseFormat result; + + // test 1 + testSubject = createTestSubject(); + additionalInfoParameterInfo = null; + result = testSubject.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + + // test 2 + testSubject = createTestSubject(); + labelOrValue = null; + result = testSubject.getResponseFormatAdditionalProperty(actionStatus, additionalInfoParameterInfo, nodeType, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + } + + @Test + void testGetResponseFormatAdditionalProperty_1() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + ResponseFormat result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getResponseFormatAdditionalProperty(actionStatus); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + } + + @Test + void testConvertFromStorageResponseForConsumer() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponseForConsumer(storageResponse); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testConvertFromStorageResponseForGroupType() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponseForGroupType(storageResponse); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testConvertFromStorageResponseForDataType() { + ComponentsUtils testSubject; + StorageOperationStatus storageResponse = StorageOperationStatus.ARTIFACT_NOT_FOUND; + ActionStatus result; + + // default test + testSubject = createTestSubject(); + result = testSubject.convertFromStorageResponseForDataType(storageResponse); + assertThat(result) + .isInstanceOf(ActionStatus.class) + .isEqualTo(ActionStatus.GENERAL_ERROR); + } + + @Test + void testGetResponseFormatByGroupType() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + GroupTypeDefinition groupType = null; + ResponseFormat result; + + // test 1 + testSubject = createTestSubject(); + groupType = null; + result = testSubject.getResponseFormatByGroupType(actionStatus, groupType); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + } + + @Test + void testGetResponseFormatByPolicyType() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.ACCEPTED; + PolicyTypeDefinition policyType = new PolicyTypeDefinition(); + ResponseFormat result; + + // test 1 + testSubject = createTestSubject(); + result = testSubject.getResponseFormatByPolicyType(actionStatus, policyType); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); + } + + @Test + void testGetResponseFormatByDataType() { + ComponentsUtils testSubject; + ActionStatus actionStatus = ActionStatus.AAI_ARTIFACT_GENERATION_FAILED; + DataTypeDefinition dataType = null; + List<String> properties = null; + ResponseFormat result; + + // test 1 + testSubject = createTestSubject(); + dataType = null; + result = testSubject.getResponseFormatByDataType(actionStatus, dataType, properties); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(500); + } + + @Test + void testconvertJsonToObject() { AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); when(auditingmanager.auditEvent(any())).thenReturn("OK"); User user = new User(); - String data = - "[{\"constraints\":[{\"equal\":\"value\"}]}," - + "{\"constraints\":[{\"greaterOrEqual\":5}]}," - + "{\"constraints\":[{\"lessThan\":7}]}," - + "{\"constraints\":[{\"lessOrEqual\":9}]}," - + "{\"constraints\":[{\"inRange\":[\"5\", \"10\"]}]}," - + "{\"constraints\":[{\"validValues\":[\"abc\", \"def\", \"hij\"]}]}," - + "{\"constraints\":[{\"length\":11}]}," - + "{\"constraints\":[{\"minLength\":13}]}," - + "{\"constraints\":[{\"maxLength\":15}]}" - +"]"; + ComponentsUtils testSubject = createTestSubject(); + String data = "{ firstName=\"xyz\", lastName=\"xyz\", userId=\"12\", email=\"demo.z@ymail.com\",role=\"123\", lastlogintime=20180201233412 }"; + Either<User, ResponseFormat> response = compUtils.convertJsonToObject(data, user, User.class, AuditingActionEnum.ADD_USER); + User assertuser = new User("xyz", "xyz", "12", "demo.z@ymail.com", "123", null); + + assertThat(response.isLeft()).isTrue(); + assertThat(response.left().value()).isEqualTo(assertuser); + } + + @Test + void testconvertJsonToObjectUsingObjectMapper() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + User user = new User(); + String data = + "[{\"constraints\":[{\"equal\":\"value\"}]}," + + "{\"constraints\":[{\"greaterOrEqual\":5}]}," + + "{\"constraints\":[{\"lessThan\":7}]}," + + "{\"constraints\":[{\"lessOrEqual\":9}]}," + + "{\"constraints\":[{\"inRange\":[\"5\", \"10\"]}]}," + + "{\"constraints\":[{\"validValues\":[\"abc\", \"def\", \"hij\"]}]}," + + "{\"constraints\":[{\"length\":11}]}," + + "{\"constraints\":[{\"minLength\":13}]}," + + "{\"constraints\":[{\"maxLength\":15}]}" + + "]"; Either<ComponentInstanceProperty[], ResponseFormat> response = compUtils.convertJsonToObjectUsingObjectMapper(data, user, - ComponentInstanceProperty[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE); + ComponentInstanceProperty[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE); assertThat(response.isLeft()).isTrue(); ComponentInstanceProperty[] properties = response.left().value(); assertEquals(9, properties.length); - assertEquals("value", ((EqualConstraint)properties[0].getConstraints().iterator().next()).getEqual()); - assertEquals("5", ((GreaterOrEqualConstraint)properties[1].getConstraints().iterator().next()).getGreaterOrEqual()); - assertEquals("7", ((LessThanConstraint)properties[2].getConstraints().iterator().next()).getLessThan()); - assertEquals("9", ((LessOrEqualConstraint)properties[3].getConstraints().iterator().next()).getLessOrEqual()); - assertEquals("5", ((InRangeConstraint)properties[4].getConstraints().iterator().next()).getRangeMinValue()); - assertEquals("10", ((InRangeConstraint)properties[4].getConstraints().iterator().next()).getRangeMaxValue()); - assertEquals(3, ((ValidValuesConstraint)properties[5].getConstraints().iterator().next()).getValidValues().size()); - assertEquals(11, ((LengthConstraint)properties[6].getConstraints().iterator().next()).getLength()); - assertEquals(13, ((MinLengthConstraint)properties[7].getConstraints().iterator().next()).getMinLength()); - assertEquals(15, ((MaxLengthConstraint)properties[8].getConstraints().iterator().next()).getMaxLength()); + assertEquals("value", ((EqualConstraint) properties[0].getConstraints().iterator().next()).getEqual()); + assertEquals("5", ((GreaterOrEqualConstraint) properties[1].getConstraints().iterator().next()).getGreaterOrEqual()); + assertEquals("7", ((LessThanConstraint) properties[2].getConstraints().iterator().next()).getLessThan()); + assertEquals("9", ((LessOrEqualConstraint) properties[3].getConstraints().iterator().next()).getLessOrEqual()); + assertEquals("5", ((InRangeConstraint) properties[4].getConstraints().iterator().next()).getMin().toString()); + assertEquals("10", ((InRangeConstraint) properties[4].getConstraints().iterator().next()).getMax().toString()); + assertEquals(3, ((ValidValuesConstraint) properties[5].getConstraints().iterator().next()).getValidValues().size()); + assertEquals(11, ((LengthConstraint) properties[6].getConstraints().iterator().next()).getLength()); + assertEquals(13, ((MinLengthConstraint) properties[7].getConstraints().iterator().next()).getMinLength()); + assertEquals(15, ((MaxLengthConstraint) properties[8].getConstraints().iterator().next()).getMaxLength()); + } + + @Test + void testconvertJsonToObject_NllData() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + User user = new User(); + String data = null; + Either<User, ResponseFormat> response = compUtils.convertJsonToObject(data, user, User.class, AuditingActionEnum.ADD_USER); + + assertThat(response.isRight()).isTrue(); + } + + @Test + void testconvertJsonToObjectInvalidData() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + User user = new User(); + + String data = "{ User [ firstName=\"xyz\", lastName=\"xyz\", userId=\"12\", email=\"demo.z@ymail.com\",role=\"123\", lastlogintime=20180201233412 }"; + + Either<User, ResponseFormat> response = compUtils.convertJsonToObject(data, user, User.class, AuditingActionEnum.ADD_USER); + + assertThat(response.isRight()).isTrue(); + } + + @Test + void testconvertToStorageOperationStatus() { + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.OK)).isEqualTo(StorageOperationStatus.OK); + assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.NOT_FOUND)).isEqualTo(StorageOperationStatus.NOT_FOUND); + assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.GENERAL_ERROR)).isEqualTo(StorageOperationStatus.GENERAL_ERROR); + assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.CLUSTER_NOT_CONNECTED)).isEqualTo( + StorageOperationStatus.CONNECTION_FAILURE); + assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED)).isEqualTo( + StorageOperationStatus.CONNECTION_FAILURE); + } + + @Test + void testgetResponseFormatByDataType() { + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + DataTypeDefinition dataType = new DataTypeDefinition(); + dataType.setName("demo"); + List<String> properties; + ResponseFormat result = compUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_ALREADY_EXIST, dataType, null); + + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + } + + @Test + void testGetResponseFormatByPolicyType_POLICY_TYPE_ALREADY_EXIST() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + PolicyTypeDefinition policyType = new PolicyTypeDefinition(); + policyType.setType("Demo"); + ResponseFormat result = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, policyType); + + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + } + + @Test + void testGetResponseFormatByPolicyType_PolicyID_NULL() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + ResponseFormat result = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, null); + + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + } + + @Test + void testGetResponseFormatByGroupType_GROUP_MEMBER_EMPTY() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + GroupTypeDefinition groupType = new GroupTypeDefinition(); + groupType.setType("Demo"); + + ResponseFormat result = compUtils.getResponseFormatByGroupType(ActionStatus.GROUP_MEMBER_EMPTY, groupType); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + + result = compUtils.getResponseFormatByGroupType(ActionStatus.GROUP_TYPE_ALREADY_EXIST, groupType); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + } + + @Test + void testConvertFromStorageResponseForDataType_ALL() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); + assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.CONNECTION_FAILURE)).isEqualTo(ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.GRAPH_IS_LOCK)).isEqualTo(ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.BAD_REQUEST)).isEqualTo(ActionStatus.INVALID_CONTENT); + assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.ENTITY_ALREADY_EXISTS)).isEqualTo( + ActionStatus.DATA_TYPE_ALREADY_EXIST); + assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.SCHEMA_VIOLATION)).isEqualTo( + ActionStatus.DATA_TYPE_ALREADY_EXIST); + assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY)).isEqualTo( + ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST); + } + + @Test + void testConvertFromStorageResponseForGroupType_ALL() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); + assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.CONNECTION_FAILURE)).isEqualTo(ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.GRAPH_IS_LOCK)).isEqualTo(ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.BAD_REQUEST)).isEqualTo(ActionStatus.INVALID_CONTENT); + assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.ENTITY_ALREADY_EXISTS)).isEqualTo( + ActionStatus.GROUP_TYPE_ALREADY_EXIST); + assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.SCHEMA_VIOLATION)).isEqualTo( + ActionStatus.GROUP_TYPE_ALREADY_EXIST); + } + + @Test + void testConvertFromStorageResponseForConsumer_ALL() { + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); + assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.CONNECTION_FAILURE)).isEqualTo(ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.GRAPH_IS_LOCK)).isEqualTo(ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.BAD_REQUEST)).isEqualTo(ActionStatus.INVALID_CONTENT); + assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.ENTITY_ALREADY_EXISTS)).isEqualTo( + ActionStatus.CONSUMER_ALREADY_EXISTS); + assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.SCHEMA_VIOLATION)).isEqualTo( + ActionStatus.CONSUMER_ALREADY_EXISTS); + assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.NOT_FOUND)).isEqualTo(ActionStatus.ECOMP_USER_NOT_FOUND); + } + + @Test + void testGetResponseFormatAdditionalProperty_ALL() { + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + AdditionalInfoParameterInfo additionalInfoParameterInfo = null; + NodeTypeEnum nodeType = null; + AdditionalInformationEnum labelOrValue = null; + + ResponseFormat result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, additionalInfoParameterInfo, + nodeType, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EXCEEDS_LIMIT, additionalInfoParameterInfo, + nodeType, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + + result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED, additionalInfoParameterInfo, + NodeTypeEnum.Group, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, + additionalInfoParameterInfo, nodeType, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + + result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS, + additionalInfoParameterInfo, nodeType, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + + result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS, + additionalInfoParameterInfo, nodeType, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(400); + + result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND, additionalInfoParameterInfo, nodeType, + labelOrValue); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + } + + @Test + void testConvertFromResultStatusEnum_ALL() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.OK, null)).isEqualTo(ActionStatus.OK); + assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_DEFAULT_VALUE, null)).isEqualTo( + ActionStatus.INVALID_PROPERTY); + assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_TYPE, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); + assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_VALUE, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); + assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); + assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.MISSING_ENTRY_SCHEMA_TYPE, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); + } + + @Test + void testconvertFromStorageResponseForAdditionalInformation() { + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + assertThat(compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); + assertThat(compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.ENTITY_ALREADY_EXISTS)).isEqualTo( + ActionStatus.COMPONENT_NAME_ALREADY_EXIST); + assertThat(compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.INVALID_ID)).isEqualTo( + ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND); + } + + @Test + void testgetResponseFormatByComponent() { + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + Component component = new Resource(); + ResponseFormat result = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, component, + ComponentTypeEnum.RESOURCE); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + result = compUtils.getResponseFormatByComponent(ActionStatus.RESOURCE_NOT_FOUND, component, ComponentTypeEnum.RESOURCE); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(404); + + result = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, component, ComponentTypeEnum.RESOURCE); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(409); + + result = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_IN_USE, component, ComponentTypeEnum.RESOURCE); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(403); + + result = compUtils.getResponseFormatByComponent(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND, component, ComponentTypeEnum.RESOURCE); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(403); + + result = compUtils.getResponseFormatByComponent(ActionStatus.ACCEPTED, component, ComponentTypeEnum.RESOURCE); + assertThat(result).isInstanceOf(ResponseFormat.class); + assertThat(result.getStatus()).isEqualTo(202); } - @Test - public void testconvertJsonToObject_NllData() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - User user = new User(); - String data=null; - Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER); - - assertThat(response.isRight()).isTrue(); - } - - @Test - public void testconvertJsonToObjectInvalidData() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - User user = new User(); - - String data="{ User [ firstName=\"xyz\", lastName=\"xyz\", userId=\"12\", email=\"demo.z@ymail.com\",role=\"123\", lastlogintime=20180201233412 }"; - - Either<User,ResponseFormat> response=compUtils.convertJsonToObject(data,user,User.class,AuditingActionEnum.ADD_USER); - - assertThat(response.isRight()).isTrue(); - } - - @Test - public void testconvertToStorageOperationStatus() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.OK)).isEqualTo(StorageOperationStatus.OK); - assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.NOT_FOUND)).isEqualTo(StorageOperationStatus.NOT_FOUND); - assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.GENERAL_ERROR)).isEqualTo(StorageOperationStatus.GENERAL_ERROR); - assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.CLUSTER_NOT_CONNECTED)).isEqualTo(StorageOperationStatus.CONNECTION_FAILURE); - assertThat(compUtils.convertToStorageOperationStatus(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED)).isEqualTo(StorageOperationStatus.CONNECTION_FAILURE); - } - - @Test - public void testgetResponseFormatByDataType() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - DataTypeDefinition dataType = new DataTypeDefinition(); - dataType.setName("demo"); - List<String> properties; - ResponseFormat result = compUtils.getResponseFormatByDataType(ActionStatus.DATA_TYPE_ALREADY_EXIST, dataType, null); - - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - } - - @Test - public void testGetResponseFormatByPolicyType_POLICY_TYPE_ALREADY_EXIST() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - PolicyTypeDefinition policyType = new PolicyTypeDefinition(); - policyType.setType("Demo"); - ResponseFormat result = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, policyType); - - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - } - - @Test - public void testGetResponseFormatByPolicyType_PolicyID_NULL() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - ResponseFormat result = compUtils.getResponseFormatByPolicyType(ActionStatus.POLICY_TYPE_ALREADY_EXIST, null); - - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - } - - @Test - public void testGetResponseFormatByGroupType_GROUP_MEMBER_EMPTY() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - GroupTypeDefinition groupType = new GroupTypeDefinition(); - groupType.setType("Demo"); - - ResponseFormat result = compUtils.getResponseFormatByGroupType(ActionStatus.GROUP_MEMBER_EMPTY, groupType); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - - result = compUtils.getResponseFormatByGroupType(ActionStatus.GROUP_TYPE_ALREADY_EXIST, groupType); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - } - - @Test - public void testConvertFromStorageResponseForDataType_ALL() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); - assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.CONNECTION_FAILURE)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.GRAPH_IS_LOCK)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.BAD_REQUEST)).isEqualTo(ActionStatus.INVALID_CONTENT); - assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.ENTITY_ALREADY_EXISTS)).isEqualTo(ActionStatus.DATA_TYPE_ALREADY_EXIST); - assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.SCHEMA_VIOLATION)).isEqualTo(ActionStatus.DATA_TYPE_ALREADY_EXIST); - assertThat(compUtils.convertFromStorageResponseForDataType(StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY)).isEqualTo(ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST); - } - - @Test - public void testConvertFromStorageResponseForGroupType_ALL() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); - assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.CONNECTION_FAILURE)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.GRAPH_IS_LOCK)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.BAD_REQUEST)).isEqualTo(ActionStatus.INVALID_CONTENT); - assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.ENTITY_ALREADY_EXISTS)).isEqualTo(ActionStatus.GROUP_TYPE_ALREADY_EXIST); - assertThat(compUtils.convertFromStorageResponseForGroupType(StorageOperationStatus.SCHEMA_VIOLATION)).isEqualTo(ActionStatus.GROUP_TYPE_ALREADY_EXIST); - } - - @Test - public void testConvertFromStorageResponseForConsumer_ALL() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); - assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.CONNECTION_FAILURE)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.GRAPH_IS_LOCK)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.BAD_REQUEST)).isEqualTo(ActionStatus.INVALID_CONTENT); - assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.ENTITY_ALREADY_EXISTS)).isEqualTo(ActionStatus.CONSUMER_ALREADY_EXISTS); - assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.SCHEMA_VIOLATION)).isEqualTo(ActionStatus.CONSUMER_ALREADY_EXISTS); - assertThat(compUtils.convertFromStorageResponseForConsumer(StorageOperationStatus.NOT_FOUND)).isEqualTo(ActionStatus.ECOMP_USER_NOT_FOUND); - } - - @Test - public void testGetResponseFormatAdditionalProperty_ALL() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - AdditionalInfoParameterInfo additionalInfoParameterInfo = null; - NodeTypeEnum nodeType = null; - AdditionalInformationEnum labelOrValue = null; - - ResponseFormat result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, additionalInfoParameterInfo, nodeType, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EXCEEDS_LIMIT, additionalInfoParameterInfo, nodeType, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - - result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED, additionalInfoParameterInfo, NodeTypeEnum.Group, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED, additionalInfoParameterInfo, nodeType, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - - result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS, additionalInfoParameterInfo, nodeType, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - - result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS, additionalInfoParameterInfo, nodeType, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(400); - - result = compUtils.getResponseFormatAdditionalProperty(ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND, additionalInfoParameterInfo, nodeType, - labelOrValue); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - } - - @Test - public void testConvertFromResultStatusEnum_ALL() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.OK, null)).isEqualTo(ActionStatus.OK); - assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_DEFAULT_VALUE, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); - assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_TYPE, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); - assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_VALUE, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); - assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); - assertThat(compUtils.convertFromResultStatusEnum(ResultStatusEnum.MISSING_ENTRY_SCHEMA_TYPE, null)).isEqualTo(ActionStatus.INVALID_PROPERTY); - } - - @Test - public void testconvertFromStorageResponseForAdditionalInformation() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - assertThat(compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); - assertThat(compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.ENTITY_ALREADY_EXISTS)).isEqualTo(ActionStatus.COMPONENT_NAME_ALREADY_EXIST); - assertThat(compUtils.convertFromStorageResponseForAdditionalInformation(StorageOperationStatus.INVALID_ID)).isEqualTo(ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND); - } - - @Test - public void testgetResponseFormatByComponent() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - Component component = new Resource(); - ResponseFormat result = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, component, ComponentTypeEnum.RESOURCE); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - result = compUtils.getResponseFormatByComponent(ActionStatus.RESOURCE_NOT_FOUND, component, ComponentTypeEnum.RESOURCE); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(404); - - result = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, component, ComponentTypeEnum.RESOURCE); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(409); - - result = compUtils.getResponseFormatByComponent(ActionStatus.COMPONENT_IN_USE, component, ComponentTypeEnum.RESOURCE); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(403); - - result = compUtils.getResponseFormatByComponent(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND, component, ComponentTypeEnum.RESOURCE); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(403); - - result = compUtils.getResponseFormatByComponent(ActionStatus.ACCEPTED, component, ComponentTypeEnum.RESOURCE); - assertThat(result).isInstanceOf(ResponseFormat.class); - assertThat(result.getStatus()).isEqualTo(202); - } - - - @Test - public void testConvertFromStorageResponseForResourceInstanceProperty_ALL() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); - assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.INVALID_ID)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST); - assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.GRAPH_IS_LOCK)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.BAD_REQUEST)).isEqualTo(ActionStatus.INVALID_CONTENT); - assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.MATCH_NOT_FOUND)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND); - assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.SCHEMA_VIOLATION)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST); - assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.NOT_FOUND)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND); - } - - @Test - public void testConvertFromStorageResponseForResourceInstance_ALL() { - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.ARTIFACT_NOT_FOUND, false)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.INVALID_ID, false)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST); - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.INVALID_PROPERTY, false)).isEqualTo(ActionStatus.INVALID_PROPERTY); - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.GRAPH_IS_LOCK, false)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.BAD_REQUEST, false)).isEqualTo(ActionStatus.INVALID_CONTENT); - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.MATCH_NOT_FOUND, false)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND); - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.SCHEMA_VIOLATION, false)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST); - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.NOT_FOUND, true)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND); - assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.NOT_FOUND, false)).isEqualTo(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND); - } - - @Test - public void testConvertFromStorageResponse_ALL() { - - AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); - ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); - when(auditingmanager.auditEvent(any())).thenReturn("OK"); - - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.CONNECTION_FAILURE, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.GRAPH_IS_LOCK, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.GENERAL_ERROR); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.INVALID_CONTENT); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.ENTITY_ALREADY_EXISTS, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.COMPONENT_NAME_ALREADY_EXIST); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.PARENT_RESOURCE_NOT_FOUND); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.MULTIPLE_PARENT_RESOURCE_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.COMPONENT_IN_USE); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_AVAILABLE, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_SENT_IS_INVALID, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_TYPE, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.INVALID_CONTENT); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.INVALID_CONTENT); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.CSAR_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.CSAR_NOT_FOUND); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.PROPERTY_NAME_ALREADY_EXISTS, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.MATCH_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.CATEGORY_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.COMPONENT_CATEGORY_NOT_FOUND); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_PROPERTY, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.INVALID_PROPERTY); - assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.COMPONENT_IS_ARCHIVED, ComponentTypeEnum.RESOURCE)).isEqualTo(ActionStatus.COMPONENT_IS_ARCHIVED); - } -}
\ No newline at end of file + @Test + void testConvertFromStorageResponseForResourceInstanceProperty_ALL() { + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.OK)).isEqualTo(ActionStatus.OK); + assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.INVALID_ID)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST); + assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.GRAPH_IS_LOCK)).isEqualTo( + ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.BAD_REQUEST)).isEqualTo( + ActionStatus.INVALID_CONTENT); + assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.MATCH_NOT_FOUND)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND); + assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.SCHEMA_VIOLATION)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST); + assertThat(compUtils.convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus.NOT_FOUND)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_NOT_FOUND); + } + + @Test + void testConvertFromStorageResponseForResourceInstance_ALL() { + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.ARTIFACT_NOT_FOUND, false)).isEqualTo( + ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.INVALID_ID, false)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST); + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.INVALID_PROPERTY, false)).isEqualTo( + ActionStatus.INVALID_PROPERTY); + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.GRAPH_IS_LOCK, false)).isEqualTo( + ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.BAD_REQUEST, false)).isEqualTo( + ActionStatus.INVALID_CONTENT); + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.MATCH_NOT_FOUND, false)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND); + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.SCHEMA_VIOLATION, false)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST); + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.NOT_FOUND, true)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND); + assertThat(compUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.NOT_FOUND, false)).isEqualTo( + ActionStatus.RESOURCE_INSTANCE_NOT_FOUND); + } + + @Test + void testConvertFromStorageResponse_ALL() { + + AuditingManager auditingmanager = Mockito.mock(AuditingManager.class); + ComponentsUtils compUtils = new ComponentsUtils(auditingmanager); + when(auditingmanager.auditEvent(any())).thenReturn("OK"); + + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.CONNECTION_FAILURE, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.GRAPH_IS_LOCK, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.GENERAL_ERROR); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.INVALID_CONTENT); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.ENTITY_ALREADY_EXISTS, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.COMPONENT_NAME_ALREADY_EXIST); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.PARENT_RESOURCE_NOT_FOUND); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.MULTIPLE_PARENT_RESOURCE_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.COMPONENT_IN_USE); + assertThat( + compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_AVAILABLE, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND); + assertThat( + compUtils.convertFromStorageResponse(StorageOperationStatus.DISTR_ENVIRONMENT_SENT_IS_INVALID, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_TYPE, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.INVALID_CONTENT); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.INVALID_CONTENT); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.CSAR_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.CSAR_NOT_FOUND); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.PROPERTY_NAME_ALREADY_EXISTS, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.PROPERTY_NAME_ALREADY_EXISTS); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.MATCH_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.CATEGORY_NOT_FOUND, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.COMPONENT_CATEGORY_NOT_FOUND); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_PROPERTY, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.INVALID_PROPERTY); + assertThat(compUtils.convertFromStorageResponse(StorageOperationStatus.COMPONENT_IS_ARCHIVED, ComponentTypeEnum.RESOURCE)).isEqualTo( + ActionStatus.COMPONENT_IS_ARCHIVED); + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java index 97f9874301..d68a7706b6 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java @@ -19,12 +19,14 @@ */ package org.openecomp.sdc.be.model.operations.impl; +import static org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil.convertToComparable; import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; @@ -91,6 +93,7 @@ import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation; import org.openecomp.sdc.be.model.operations.api.IPropertyOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; +import org.openecomp.sdc.be.model.tosca.ToscaType; import org.openecomp.sdc.be.model.tosca.constraints.EqualConstraint; import org.openecomp.sdc.be.model.tosca.constraints.GreaterOrEqualConstraint; import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint; @@ -2139,8 +2142,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe JsonArray jsonArray = new JsonArray(); if (src instanceof InRangeConstraint) { InRangeConstraint rangeConstraint = (InRangeConstraint) src; - jsonArray.add(JsonParser.parseString(String.valueOf(rangeConstraint.getRangeMinValue()))); - jsonArray.add(JsonParser.parseString(String.valueOf(rangeConstraint.getRangeMaxValue()))); + jsonArray.add(JsonParser.parseString(String.valueOf(rangeConstraint.getMin()))); + jsonArray.add(JsonParser.parseString(String.valueOf(rangeConstraint.getMax()))); result.add("inRange", jsonArray); } else if (src instanceof GreaterThanConstraint) { GreaterThanConstraint greaterThanConstraint = (GreaterThanConstraint) src; @@ -2163,8 +2166,6 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe public static class PropertyConstraintDeserialiser implements JsonDeserializer<PropertyConstraint> { - private static final String THE_VALUE_OF_GREATER_THAN_CONSTRAINT_IS_NULL = "The value of GreaterThanConstraint is null"; - @Override public PropertyConstraint deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { PropertyConstraint propertyConstraint = null; @@ -2184,45 +2185,40 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe if (typedValue != null) { log.debug("Before adding value to EqualConstraint object. value = {}", typedValue); propertyConstraint = new EqualConstraint(typedValue); - break; } else { - log.warn("The value of equal constraint is null"); + log.warn("The value of EqualConstraint is null"); } break; case IN_RANGE: - if (typedValue != null) { - if (typedValue instanceof ArrayList) { - ArrayList rangeArray = (ArrayList) typedValue; - if (rangeArray.size() != 2 || rangeArray.contains("")) { - log.error("The range constraint content is invalid. value = {}", typedValue); - throw new JsonSyntaxException("The range constraint content is invalid"); - } else { - InRangeConstraint rangeConstraint = new InRangeConstraint(); - Object minValue = rangeArray.get(0); - Object maxValue = rangeArray.get(1); - rangeConstraint.setRangeMinValue(minValue); - rangeConstraint.setRangeMaxValue(maxValue); - propertyConstraint = rangeConstraint; - } + if (typedValue instanceof ArrayList) { + List<Object> rangeArray = (ArrayList<Object>) typedValue; + if (rangeArray.size() != 2 || rangeArray.contains("")) { + log.error("The range constraint content is invalid. value = {}", typedValue); + throw new JsonSyntaxException("The range constraint content is invalid"); + } else { + Object minValue = rangeArray.get(0); + Object maxValue = rangeArray.get(1); + InRangeConstraint rangeConstraint = new InRangeConstraint(Lists.newArrayList(minValue, maxValue)); + rangeConstraint.setMin(convertToComparable(ToscaType.RANGE, String.valueOf(minValue))); + rangeConstraint.setMax(convertToComparable(ToscaType.RANGE, String.valueOf(maxValue))); + propertyConstraint = rangeConstraint; } } else { - log.warn(THE_VALUE_OF_GREATER_THAN_CONSTRAINT_IS_NULL); + log.warn("The value of InRangeConstraint is null"); } break; case GREATER_THAN: if (typedValue != null) { log.debug("Before adding value to GreaterThanConstraint object. value = {}", typedValue); propertyConstraint = new GreaterThanConstraint(typedValue); - break; } else { - log.warn(THE_VALUE_OF_GREATER_THAN_CONSTRAINT_IS_NULL); + log.warn("The value of GreaterThanConstraint is null"); } break; case LESS_THAN: if (typedValue != null) { log.debug("Before adding value to LessThanConstraint object. value = {}", typedValue); propertyConstraint = new LessThanConstraint(typedValue); - break; } else { log.warn("The value of LessThanConstraint is null"); } @@ -2231,7 +2227,6 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe if (typedValue != null) { log.debug("Before adding value to GreaterThanConstraint object. value = {}", typedValue); propertyConstraint = new GreaterOrEqualConstraint(typedValue); - break; } else { log.warn("The value of GreaterOrEqualConstraint is null"); } @@ -2241,12 +2236,12 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe log.debug("Before adding value to LessOrEqualConstraint object. value = {}", typedValue); propertyConstraint = new LessOrEqualConstraint(typedValue); } else { - log.warn(THE_VALUE_OF_GREATER_THAN_CONSTRAINT_IS_NULL); + log.warn("The value of LessOrEqualConstraint is null"); } break; case VALID_VALUES: - if (typedValue != null) { - ArrayList validValuesArray = (ArrayList) typedValue; + if (typedValue instanceof ArrayList) { + List<Object> validValuesArray = (ArrayList<Object>) typedValue; if (validValuesArray.size() == 0 || validValuesArray.contains("")) { log.error("The valid values constraint content is invalid. value = {}", typedValue); throw new JsonSyntaxException("The valid values constraint content is invalid"); @@ -2255,6 +2250,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe vvConstraint.setValidValues(validValuesArray); propertyConstraint = vvConstraint; } + } else { + log.warn("The value of ValidValuesConstraint is null"); } break; case LENGTH: @@ -2262,9 +2259,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe int asInt = value.getAsInt(); log.debug("Before adding value to length constraint. value = {}", asInt); propertyConstraint = new LengthConstraint(asInt); - break; } else { - log.warn("The value of length constraint is null"); + log.warn("The value of LengthConstraint is null"); } break; case MIN_LENGTH: @@ -2272,7 +2268,6 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe int asInt = value.getAsInt(); log.debug("Before adding value to Min Length object. value = {}", asInt); propertyConstraint = new MinLengthConstraint(asInt); - break; } else { log.warn("The value of MinLengthConstraint is null"); } @@ -2282,9 +2277,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe int asInt = value.getAsInt(); log.debug("Before adding value to max length constraint. value = {}", asInt); propertyConstraint = new MaxLengthConstraint(asInt); - break; } else { - log.warn("The value of max length constraint is null"); + log.warn("The value of MaxLengthConstraint is null"); } break; case PATTERN: @@ -2292,9 +2286,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe String asString = value.getAsString(); log.debug("Before adding value to PatternConstraint object. value = {}", asString); propertyConstraint = new PatternConstraint(asString); - break; } else { - log.warn("The value of pattern constraint is null"); + log.warn("The value of PatternConstraint is null"); } break; default: @@ -2448,17 +2441,11 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe if (rangeArray.size() != 2) { log.error("The range constraint content is invalid. value = {}", value); } else { - InRangeConstraint rangeConstraint = new InRangeConstraint(); String minValue = rangeArray.get(0).asText(); - String maxValue; - JsonNode maxElement = rangeArray.get(1); - if (maxElement.isNull()) { - maxValue = null; - } else { - maxValue = maxElement.asText(); - } - rangeConstraint.setRangeMinValue(minValue); - rangeConstraint.setRangeMaxValue(maxValue); + String maxValue = rangeArray.get(1).asText(); + InRangeConstraint rangeConstraint = new InRangeConstraint(Lists.newArrayList(minValue, maxValue)); + rangeConstraint.setMin(convertToComparable(ToscaType.RANGE, minValue)); + rangeConstraint.setMax(convertToComparable(ToscaType.RANGE, maxValue)); return rangeConstraint; } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractComparablePropertyConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractComparablePropertyConstraint.java index d7eb6e69c6..4a8c742de9 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractComparablePropertyConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractComparablePropertyConstraint.java @@ -50,8 +50,6 @@ public abstract class AbstractComparablePropertyConstraint extends AbstractPrope public abstract boolean validateValueType(String propertyType) throws ConstraintValueDoNotMatchPropertyTypeException; - public abstract String getConstraintValueAsString(); - public abstract void changeConstraintValueTypeTo(String propertyType) throws ConstraintValueDoNotMatchPropertyTypeException; @Override diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java index f5a9f847ff..e1c55ac829 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/EqualConstraint.java @@ -19,10 +19,9 @@ */ package org.openecomp.sdc.be.model.tosca.constraints; -import java.io.Serializable; import javax.validation.constraints.NotNull; -import lombok.Setter; import lombok.Getter; +import lombok.Setter; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.model.PropertyConstraint; import org.openecomp.sdc.be.model.tosca.ToscaType; @@ -32,7 +31,7 @@ import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolatio import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraintException; @SuppressWarnings("serial") -public class EqualConstraint extends AbstractPropertyConstraint implements Serializable { +public class EqualConstraint extends AbstractComparablePropertyConstraint { @Getter @Setter @@ -49,6 +48,7 @@ public class EqualConstraint extends AbstractPropertyConstraint implements Seria public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException { if (propertyType.isValidValue(String.valueOf(equal))) { typed = propertyType.convert(String.valueOf(equal)); + initialize(String.valueOf(equal), propertyType); } else { throw new ConstraintValueDoNotMatchPropertyTypeException( "constraintValue constraint has invalid value <" + equal + "> property type is <" + propertyType.toString() + ">"); @@ -56,19 +56,6 @@ public class EqualConstraint extends AbstractPropertyConstraint implements Seria } @Override - public void validate(Object propertyValue) throws ConstraintViolationException { - if (propertyValue == null) { - if (typed != null) { - fail(null); - } - } else if (typed == null) { - fail(propertyValue); - } else if (!typed.equals(propertyValue)) { - fail(propertyValue); - } - } - - @Override public ConstraintType getConstraintType() { return ConstraintType.EQUAL; } @@ -87,15 +74,33 @@ public class EqualConstraint extends AbstractPropertyConstraint implements Seria return getErrorMessage(toscaType, e, propertyName, "%s property value must be %s", String.valueOf(equal)); } + @Override + protected void doValidate(Object propertyValue) throws ConstraintViolationException { + if (propertyValue == null) { + if (typed != null) { + fail(null); + } + } else if (typed == null) { + fail(propertyValue); + } else if (!typed.equals(propertyValue)) { + fail(propertyValue); + } + } + + @Override + public String toString() { + return String.valueOf(equal); + } + public boolean validateValueType(String propertyType) throws ConstraintValueDoNotMatchPropertyTypeException { ToscaType toscaType = ToscaType.getToscaType(propertyType); if (toscaType == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "equal constraint has invalid values <" + equal.toString() + "> property type is <" + propertyType + ">"); + "equal constraint has invalid values <" + equal.toString() + "> property type is <" + propertyType + ">"); } if (equal == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "equal constraint has invalid value <> property type is <" + propertyType + ">"); + "equal constraint has invalid value <> property type is <" + propertyType + ">"); } return toscaType.isValueTypeValid(equal); } @@ -106,7 +111,7 @@ public class EqualConstraint extends AbstractPropertyConstraint implements Seria equal = toscaType.convert(String.valueOf(equal)); } catch (Exception e) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "equal constraint has invalid values <" + equal.toString() + "> property type is <" + propertyType + ">"); + "equal constraint has invalid values <" + equal.toString() + "> property type is <" + propertyType + ">"); } } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java index b45cf9791e..e90f1c0bf2 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterOrEqualConstraint.java @@ -70,17 +70,17 @@ public class GreaterOrEqualConstraint extends AbstractComparablePropertyConstrai ToscaType toscaType = ToscaType.getToscaType(propertyType); if (toscaType == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "greaterOrEqual constraint has invalid values <" + greaterOrEqual.toString() + "> property type is <" + propertyType + ">"); + "greaterOrEqual constraint has invalid values <" + greaterOrEqual.toString() + "> property type is <" + propertyType + ">"); } if (greaterOrEqual == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "greaterOrEqual constraint has invalid value <> property type is <" + propertyType + ">"); + "greaterOrEqual constraint has invalid value <> property type is <" + propertyType + ">"); } return toscaType.isValueTypeValid(greaterOrEqual); } @Override - public String getConstraintValueAsString() { + public String toString() { return String.valueOf(greaterOrEqual); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java index 9d638cfb3f..e1293d1bb1 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/GreaterThanConstraint.java @@ -70,17 +70,17 @@ public class GreaterThanConstraint<T> extends AbstractComparablePropertyConstrai ToscaType toscaType = ToscaType.getToscaType(propertyType); if (toscaType == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "greaterThan constraint has invalid values <" + greaterThan.toString() + "> property type is <" + propertyType + ">"); + "greaterThan constraint has invalid values <" + greaterThan.toString() + "> property type is <" + propertyType + ">"); } if (greaterThan == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "greaterThan constraint has invalid value <> property type is <" + propertyType + ">"); + "greaterThan constraint has invalid value <> property type is <" + propertyType + ">"); } return toscaType.isValueTypeValid(greaterThan); } @Override - public String getConstraintValueAsString() { + public String toString() { return String.valueOf(greaterThan); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java index 2567cec772..26d75bd134 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraint.java @@ -19,9 +19,8 @@ */ package org.openecomp.sdc.be.model.tosca.constraints; -import com.google.common.collect.Lists; +import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.List; -import javax.validation.constraints.NotNull; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -41,7 +40,9 @@ public class InRangeConstraint extends AbstractPropertyConstraint { @NonNull private List<Object> inRange; + @JsonIgnore private Comparable min; + @JsonIgnore private Comparable max; public InRangeConstraint(List<Object> inRange) { @@ -50,9 +51,7 @@ public class InRangeConstraint extends AbstractPropertyConstraint { @Override public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException { - // Perform verification that the property type is supported for - - // comparison + // Perform verification that the property type is supported for comparison ConstraintUtil.checkComparableType(propertyType); if (inRange == null || inRange.size() != 2) { throw new ConstraintValueDoNotMatchPropertyTypeException("In range constraint must have two elements."); @@ -94,40 +93,6 @@ public class InRangeConstraint extends AbstractPropertyConstraint { public void validateValueOnUpdate(PropertyConstraint newConstraint) throws PropertyConstraintException { } - @NotNull - public Object getRangeMinValue() { - if (inRange != null) { - return inRange.get(0); - } else { - return null; - } - } - - public void setRangeMinValue(Object minValue) { - if (inRange == null) { - inRange = Lists.newArrayList(minValue, null); - } else { - inRange.set(0, minValue); - } - } - - @NotNull - public Object getRangeMaxValue() { - if (inRange != null) { - return inRange.get(1); - } else { - return null; - } - } - - public void setRangeMaxValue(Object maxValue) { - if (inRange == null) { - inRange = Lists.newArrayList(null, maxValue); - } else { - inRange.set(1, maxValue); - } - } - @Override public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) { return getErrorMessage(toscaType, e, propertyName, "%s property value must be in a range of %s", String.valueOf(min), @@ -158,7 +123,7 @@ public class InRangeConstraint extends AbstractPropertyConstraint { inRange.replaceAll(obj -> toscaType.convert(String.valueOf(obj))); } catch (Exception e) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "inRange constraint has invalid values <" + inRange + "> property type is <" + propertyType + ">"); + "inRange constraint has invalid values <" + inRange + "> property type is <" + propertyType + ">"); } } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java index 0f64a4f9f5..3830ddf811 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessOrEqualConstraint.java @@ -70,17 +70,17 @@ public class LessOrEqualConstraint<T> extends AbstractComparablePropertyConstrai ToscaType toscaType = ToscaType.getToscaType(propertyType); if (toscaType == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "lessOrEqual constraint has invalid values <" + lessOrEqual.toString() + "> property type is <" + propertyType + ">"); + "lessOrEqual constraint has invalid values <" + lessOrEqual.toString() + "> property type is <" + propertyType + ">"); } if (lessOrEqual == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "lessOrEqual constraint has invalid value <> property type is <" + propertyType + ">"); + "lessOrEqual constraint has invalid value <> property type is <" + propertyType + ">"); } return toscaType.isValueTypeValid(lessOrEqual); } @Override - public String getConstraintValueAsString() { + public String toString() { return String.valueOf(lessOrEqual); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java index 92ab9278b2..f3e283c98e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/LessThanConstraint.java @@ -70,17 +70,17 @@ public class LessThanConstraint extends AbstractComparablePropertyConstraint { ToscaType toscaType = ToscaType.getToscaType(propertyType); if (toscaType == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "lessThan constraint has invalid values <" + lessThan.toString() + "> property type is <" + propertyType + ">"); + "lessThan constraint has invalid values <" + lessThan.toString() + "> property type is <" + propertyType + ">"); } if (lessThan == null) { throw new ConstraintValueDoNotMatchPropertyTypeException( - "lessThan constraint has invalid value <> property type is <" + propertyType + ">"); + "lessThan constraint has invalid value <> property type is <" + propertyType + ">"); } return toscaType.isValueTypeValid(lessThan); } @Override - public String getConstraintValueAsString() { + public String toString() { return String.valueOf(lessThan); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraintTest.java index 8eff6f7cdc..1491e0547d 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraintTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/InRangeConstraintTest.java @@ -30,7 +30,7 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException; -public class InRangeConstraintTest { +class InRangeConstraintTest { private InRangeConstraint createStringTestSubject() { List<Object> validValues = new ArrayList<>(); @@ -47,7 +47,7 @@ public class InRangeConstraintTest { } @Test - public void testGetInRange() { + void testGetInRange() { InRangeConstraint testSubject = createStringTestSubject(); List<Object> result = testSubject.getInRange(); @@ -57,7 +57,7 @@ public class InRangeConstraintTest { } @Test - public void testSetInRange() { + void testSetInRange() { InRangeConstraint testSubject = createStringTestSubject(); List<Object> validValues = new ArrayList<>(); validValues.add("test21"); @@ -71,43 +71,7 @@ public class InRangeConstraintTest { } @Test - public void testGetRangeMinValue() throws Exception { - InRangeConstraint testSubject = createIntegerTestSubject(); - Object result = testSubject.getRangeMinValue(); - - assertEquals(1, result); - } - - @Test - public void testSetRangeMinValue() throws Exception { - InRangeConstraint testSubject = createIntegerTestSubject(); - testSubject.setRangeMinValue(21); - - Object result = testSubject.getRangeMinValue(); - - assertEquals(21, result); - } - - @Test - public void testGetRangeMaxValue() throws Exception { - InRangeConstraint testSubject = createIntegerTestSubject(); - Object result = testSubject.getRangeMaxValue(); - - assertEquals(10, result); - } - - @Test - public void testSetRangeMaxValue() throws Exception { - InRangeConstraint testSubject = createIntegerTestSubject(); - testSubject.setRangeMaxValue(30); - - Object result = testSubject.getRangeMaxValue(); - - assertEquals(30, result); - } - - @Test - public void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + void testValidateValueTypeStringTrue() throws ConstraintValueDoNotMatchPropertyTypeException { InRangeConstraint testSubject = createStringTestSubject(); Boolean validTypes = testSubject.validateValueType("string"); @@ -115,7 +79,7 @@ public class InRangeConstraintTest { } @Test - public void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + void testValidateValueTypeStringFalse() throws ConstraintValueDoNotMatchPropertyTypeException { InRangeConstraint testSubject = createStringTestSubject(); Boolean validTypes = testSubject.validateValueType("integer"); @@ -123,7 +87,7 @@ public class InRangeConstraintTest { } @Test - public void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { + void testValidateValueTypeIntegerTrue() throws ConstraintValueDoNotMatchPropertyTypeException { InRangeConstraint testSubject = createIntegerTestSubject(); Boolean validTypes = testSubject.validateValueType("integer"); @@ -131,7 +95,7 @@ public class InRangeConstraintTest { } @Test - public void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { + void testValidateValueTypeIntegerFalse() throws ConstraintValueDoNotMatchPropertyTypeException { InRangeConstraint testSubject = createIntegerTestSubject(); Boolean validTypes = testSubject.validateValueType("string"); @@ -139,7 +103,7 @@ public class InRangeConstraintTest { } @Test - public void testChangeStringConstraintValueTypeToIntegerThrow() { + void testChangeStringConstraintValueTypeToIntegerThrow() { String propertyType = "integer"; InRangeConstraint testSubject = createStringTestSubject(); Exception exception = assertThrows(ConstraintValueDoNotMatchPropertyTypeException.class, () -> { @@ -153,7 +117,7 @@ public class InRangeConstraintTest { } @Test - public void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { + void testChangeIntegerConstraintValueTypeToString() throws ConstraintValueDoNotMatchPropertyTypeException { InRangeConstraint testSubject = createIntegerTestSubject(); testSubject.changeConstraintValueTypeTo("string"); List<Object> result = testSubject.getInRange(); |