summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2022-10-18 16:02:02 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-11-23 10:19:09 +0000
commit166d45efe6de92ce067bc7b6065a0d7de94a6388 (patch)
tree98beeddb9f19651137b9dedfd8a5c91566934f41 /catalog-be/src/test/java
parent83bbca087a66d5ea4cff1f5d066f7761948a2cb3 (diff)
Fix property constraints validation
Fix property constraints validation behaviour when a property is not required shouldnt be validated vs constraints if no value is provided. Also add constraints validation for length measures in list, map and string types. Issue-ID: SDC-4222 Signed-off-by: franciscovila <javier.paradela.vila@est.tech> Change-Id: I48ebb46b3de9ddac3d9dd91400ea0fad983aa94d
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java79
1 files changed, 78 insertions, 1 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java
index a9350edc18..6e9c6dd784 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java
@@ -39,6 +39,8 @@ import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -180,7 +182,7 @@ class PropertyValueConstraintValidationUtilTest {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
- propertyDefinition.setValue("{\"value_specs\":{\"key\":\"slaac\"}}");
+ propertyDefinition.setValue("{\"value_specs\":{\"key\":\"slaac\", \"key2\":\"slaac\"}}");
Either<Boolean, ResponseFormat> responseEither =
propertyValueConstraintValidationUtil.validatePropertyConstraints(
@@ -291,6 +293,81 @@ class PropertyValueConstraintValidationUtilTest {
assertEquals(schemaType, propertyDefinition.getSchemaType());
}
+ @ParameterizedTest
+ @ValueSource(strings = {"[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}, " +
+ "{\"dns_nameservers\": [\"server1\"]}]",
+ "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}, " +
+ "{\"dns_nameservers\": [\"server1\", \"server2\", \"server3\", \"server4\", \"server5\"]}]",
+ "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}, " +
+ "{\"subnetpool\": \"h\"}]",
+ "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}, " +
+ "{\"subnetpool\": \"123456\"}]",
+ "{\"value_specs\":{\"key\":\"slaac\"}}"})
+ void listOfComplexWithConstrainedFails(String value) {
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
+ final var propertyDefinition = new PropertyDefinition();
+ final String type = "list";
+ propertyDefinition.setType(type);
+ final SchemaDefinition schemaDefinition = new SchemaDefinition();
+ final PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
+ final String schemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet";
+ schemaProperty.setType(schemaType);
+ schemaDefinition.setProperty(schemaProperty);
+ propertyDefinition.setSchema(schemaDefinition);
+ propertyDefinition.setValue(value);
+ final String name = "listOfComplex";
+ propertyDefinition.setName(name);
+
+ Either<Boolean, ResponseFormat> responseEither =
+ propertyValueConstraintValidationUtil
+ .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
+
+ assertTrue(responseEither.isRight());
+ //original object values should not be changed
+ assertEquals(name, propertyDefinition.getName());
+ assertEquals(type, propertyDefinition.getType());
+ assertEquals(value, propertyDefinition.getValue());
+ assertEquals(schemaType, propertyDefinition.getSchemaType());
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}, " +
+ "{\"dns_nameservers\": [\"server1\", \"server2\", \"server3\", \"server4\"]}]",
+ "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}, " +
+ "{\"dns_nameservers\": [\"server1\", \"server1\"]}]",
+ "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}, " +
+ "{\"subnetpool\": \"123\"}]",
+ "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}, " +
+ "{\"subnetpool\": \"1234\"}]",
+ "[{\"value_specs\":{\"key1\":\"slaac\",\"key2\":\"slaac\"}}]"})
+ void listOfComplexWithConstrainedSuccess(String value) {
+ when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
+
+ final var propertyDefinition = new PropertyDefinition();
+ final String type = "list";
+ propertyDefinition.setType(type);
+ final SchemaDefinition schemaDefinition = new SchemaDefinition();
+ final PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
+ final String schemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet";
+ schemaProperty.setType(schemaType);
+ schemaDefinition.setProperty(schemaProperty);
+ propertyDefinition.setSchema(schemaDefinition);
+ propertyDefinition.setValue(value);
+ final String name = "listOfComplex";
+ propertyDefinition.setName(name);
+
+ Either<Boolean, ResponseFormat> responseEither =
+ propertyValueConstraintValidationUtil
+ .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
+
+ assertTrue(responseEither.isLeft());
+ //original object values should not be changed
+ assertEquals(name, propertyDefinition.getName());
+ assertEquals(type, propertyDefinition.getType());
+ assertEquals(value, propertyDefinition.getValue());
+ assertEquals(schemaType, propertyDefinition.getSchemaType());
+ }
+
@Test
void listOfComplexSuccessTest1() {
when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));