summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2022-10-13 14:12:47 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-10-24 15:06:02 +0000
commit2edea35f59360fbc8b4f451fc573e02dc5f65010 (patch)
tree1b1ead43f07d813562b55e9dbad80efcd5308ea8 /catalog-be/src/test/java/org
parentaa361f84ec4d137e7a64df8c7feaec6d2304c03e (diff)
Support import of VFCs with property constraints
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-4216 Change-Id: I19dce9f929535aa22cad6a1d95a213f42dd6e99c
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java50
1 files changed, 50 insertions, 0 deletions
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 a01831e70c..3260521084 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
@@ -41,6 +41,7 @@ import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
@@ -48,6 +49,15 @@ import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+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.InRangeConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LessThanConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.MaxLengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.MinLengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
@@ -61,6 +71,7 @@ import org.openecomp.sdc.test.utils.TestConfigurationProvider;
import java.util.List;
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;
@@ -771,6 +782,45 @@ public class ComponentsUtilsTest {
assertThat(response.left().value()).isEqualTo(assertuser);
}
+ @Test
+ public 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);
+
+ 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());
+ }
+
@Test
public void testconvertJsonToObject_NllData() {