private static final String TARGET = "Target";
private static final String INPUT_NOT_FOUND_LOG = "Input '{}' not found in parent component '{}', unique id '{}'";
private static final Set<String> TYPES_WITH_SCHEMA = Set.of(ToscaPropertyType.MAP.getType(), ToscaPropertyType.LIST.getType());
- private static final Set<String> COMPARABLE_TYPES = Set
- .of(ToscaPropertyType.STRING.getType(), ToscaPropertyType.INTEGER.getType(), ToscaPropertyType.FLOAT.getType());
+ private static final Set<String> COMPARABLE_TYPES = Set.of(
+ ToscaPropertyType.SCALAR_UNIT_SIZE.getType(),
+ ToscaPropertyType.SCALAR_UNIT_TIME.getType(),
+ ToscaPropertyType.SCALAR_UNIT_BITRATE.getType(),
+ ToscaPropertyType.SCALAR_UNIT_FREQUENCY.getType(),
+ ToscaPropertyType.BOOLEAN.getType(),
+ ToscaPropertyType.STRING.getType(),
+ ToscaPropertyType.INTEGER.getType(),
+ ToscaPropertyType.FLOAT.getType());
private final ComponentsUtils componentsUtils;
private final ApplicationDataTypeCache applicationDataTypeCache;
private final FilterConstraintValidator filterConstraintValidator;
}
return Either.left(true);
}
+
public Either<Boolean, ResponseFormat> validateFilter(final Component parentComponent, final String componentInstanceId,
final FilterConstraintDto filterConstraint) {
validateFilterConstraint(filterConstraint);
}
return findSubProperty(propertyPath.subList(1, propertyPath.size()), propertyDefinition.getType(), modelDataTypes);
}
-
+
private Optional<ComponentInstanceProperty> getInstanceProperties(final Component parentComponent, final String componentInstanceId,
final String capabilityName, final String propertyName) {
if (StringUtils.isEmpty(capabilityName)) {
return parentComponent.getComponentInstancesProperties().get(componentInstanceId).stream()
- .filter(property -> propertyName.equals(property.getName())).findFirst();
+ .filter(property -> propertyName.equals(property.getName())).findFirst();
} else {
final Optional<ComponentInstance> componentInstanceOptional = parentComponent.getComponentInstances().stream()
- .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)).findAny();
+ .filter(componentInstance -> componentInstance.getUniqueId().equals(componentInstanceId)).findAny();
if (componentInstanceOptional.isPresent()) {
for (final List<CapabilityDefinition> listOfCaps : componentInstanceOptional.get().getCapabilities().values()) {
final Optional<CapabilityDefinition> capDef = listOfCaps.stream().filter(cap -> cap.getName().equals(capabilityName)).findAny();
if (componentInstanceProperty == null) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName()));
}
- if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) {
+ if (filterConstraint.getOperator().isComparable() && !TYPES_WITH_SCHEMA.contains(componentInstanceProperty.getType())
+ && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(),
filterConstraint.getOperator().getType()));
}
if (componentProperty == null) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName()));
}
- if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentProperty.getType())) {
+ if (filterConstraint.getOperator().isComparable() && !TYPES_WITH_SCHEMA.contains(componentProperty.getType())
+ && !COMPARABLE_TYPES.contains(componentProperty.getType())) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(),
filterConstraint.getOperator().getType()));
}
if (componentInstanceProperty == null) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.SELECTED_PROPERTY_NOT_PRESENT, filterConstraint.getPropertyName()));
}
- if (filterConstraint.getOperator().isComparable() && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) {
+ if (filterConstraint.getOperator().isComparable() && !TYPES_WITH_SCHEMA.contains(componentInstanceProperty.getType())
+ && !COMPARABLE_TYPES.contains(componentInstanceProperty.getType())) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraint.getPropertyName(),
filterConstraint.getOperator().getType()));
}
return isValidValueCheck(componentInstanceProperty.getType(), componentInstanceProperty.getSchemaType(), parentComponent.getModel(),
filterConstraint.getValue(), filterConstraint.getPropertyName());
}
-
- private Optional<ComponentInstanceProperty> getComponentInstanceProperty(CapabilityDefinition capabilityDefinition, final String propertyName){
- return capabilityDefinition.getProperties().stream().filter(property -> property.getName().equals(propertyName)).findAny();
+
+ private Optional<ComponentInstanceProperty> getComponentInstanceProperty(CapabilityDefinition capabilityDefinition, final String propertyName) {
+ return capabilityDefinition.getProperties().stream().filter(property -> property.getName().equals(propertyName)).findAny();
}
private Either<Boolean, ResponseFormat> isValidValueCheck(final String type, final String schemaType, final String model,
valueAsJsonString = new Gson().toJson(value);
} catch (final Exception e) {
LOGGER.debug("Unsupported property filter value", e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, String.valueOf(value)));
+ return Either.right(
+ componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, String.valueOf(value)));
}
if (toscaPropertyType != null) {
if (toscaPropertyType.getValidator().isValid(valueAsJsonString, schemaType, modelDataTypesMap)) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, type, propertyName, valueAsJsonString));
}
- public Either<Boolean, ResponseFormat> validateSubstitutionFilter(final Component component, final List<FilterConstraintDto> filterConstraintList) {
+ public Either<Boolean, ResponseFormat> validateSubstitutionFilter(final Component component,
+ final List<FilterConstraintDto> filterConstraintList) {
if (CollectionUtils.isEmpty(filterConstraintList)) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.CONSTRAINT_FORMAT_INCORRECT));
}
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.Yaml;
-
@Service
public class PropertyConvertor {
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
private static final String INNER_SERVICE = "innerService";
private static final String PROPERTY_NAME = "Prop1";
private static final String COMPONENT1_ID = "component1";
- private static final String PARENTSERVICE_ID = "parentservice";
+ private static final String PARENT_SERVICE_ID = "parentservice";
private static final String COMPONENT2_ID = "component2";
private ComponentsUtils componentsUtils;
@Mock
- ApplicationDataTypeCache applicationDataTypeCache;
+ private ApplicationDataTypeCache applicationDataTypeCache;
@Mock
private FilterConstraintValidator filterConstraintValidator;
@InjectMocks
final ResponseFormat expectedResponse = new ResponseFormat();
when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, "?", INNER_SERVICE)).thenReturn(expectedResponse);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
+ nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
assertTrue(either.isRight());
assertEquals(expectedResponse, either.right().value());
final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(PROPERTY_NAME, FilterValueType.STATIC, ConstraintType.EQUAL,
PropertyFilterTargetType.PROPERTY, "true");
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
assertTrue(either.isRight());
filterConstraintDto.setTargetType(PropertyFilterTargetType.CAPABILITY);
either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
createToscaGetFunction("test", PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of("test2"))
);
Either<Boolean, ResponseFormat> actualValidationResult =
- nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
+ nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
assertTrue(actualValidationResult.isRight());
final var filterConstraint2 = buildFilterConstraintDto(
FilterValueType.GET_PROPERTY,
ConstraintType.EQUAL,
PropertyFilterTargetType.PROPERTY,
- createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of("Prop1"))
+ createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of("Prop1"))
);
actualValidationResult =
- nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint2));
+ nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint2));
assertTrue(actualValidationResult.isLeft());
final var staticFilter1 = buildFilterConstraintDto(
"true"
);
final ResponseFormat expectedResponse = new ResponseFormat();
- when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraintDto.getPropertyName(),
- filterConstraintDto.getOperator().getType())
+ when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.BOOLEAN.getType(),
+ filterConstraintDto.getPropertyName(), "\"true\"")
).thenReturn(expectedResponse);
final Either<Boolean, ResponseFormat> validationResult =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(filterConstraintDto));
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(filterConstraintDto));
assertTrue(validationResult.isRight());
assertEquals(expectedResponse, validationResult.right().value());
}
baseFilterConstraintDto.setValue("trues");
final ResponseFormat responseFormat = new ResponseFormat();
- when(componentsUtils
- .getResponseFormat(eq(ActionStatus.UNSUPPORTED_VALUE_PROVIDED), eq(ToscaPropertyType.BOOLEAN.getType()), eq(PROPERTY_NAME), any())
+ when(componentsUtils.getResponseFormat
+ (ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.BOOLEAN.getType(), PROPERTY_NAME, "\"trues\"")
).thenReturn(responseFormat);
final Either<Boolean, ResponseFormat> validationResult =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
assertTrue(validationResult.isRight());
assertEquals(responseFormat, validationResult.right().value());
baseFilterConstraintDto.setValue("true");
baseFilterConstraintDto.setOperator(ConstraintType.GREATER_THAN);
Either<Boolean, ResponseFormat> either =
- nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
+ nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
assertTrue(either.isLeft());
}
void testValidatePropertyConstraintParentSuccess() {
final var service = createService(ToscaPropertyType.STRING.getType());
final ToscaGetFunctionDataDefinition toscaGetFunction =
- createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
final var filterConstraintDto = buildFilterConstraintDto(
PROPERTY_NAME,
FilterValueType.GET_PROPERTY,
final Service service = createService(ToscaPropertyType.STRING.getType());
service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
final ToscaGetFunctionDataDefinition toscaGetFunction =
- createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
final var filterConstraintDto = buildFilterConstraintDto(
PROPERTY_NAME,
FilterValueType.GET_PROPERTY,
.thenReturn(expectedResponse);
final ToscaGetFunctionDataDefinition toscaGetFunction =
- createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
final var filterConstraintDto = buildFilterConstraintDto(
PROPERTY_NAME,
FilterValueType.GET_PROPERTY,
Service service = createService(ToscaPropertyType.STRING.getType());
service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
final ToscaGetFunctionDataDefinition toscaGetFunction =
- createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
final var filterConstraintDto = buildFilterConstraintDto(
PROPERTY_NAME,
FilterValueType.GET_PROPERTY,
service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setSchema(schemaDefinition);
final ToscaGetFunctionDataDefinition toscaGetFunction =
- createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
+ createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
final var filterConstraintDto = buildFilterConstraintDto(
PROPERTY_NAME,
FilterValueType.GET_PROPERTY,
private Service createService(String type, String schemaType) {
Service service = new Service();
- service.setName(PARENTSERVICE_ID);
+ service.setName(PARENT_SERVICE_ID);
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setName(PROPERTY_NAME);
propertyDefinition.setType(type);
- if (schemaType != null){
+ if (schemaType != null) {
SchemaDefinition schemaDefinition = new SchemaDefinition();
PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
schemaProperty.setType(schemaType);
service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
- ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+ ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
componentInstanceProperty.setName(PROPERTY_NAME);
componentInstanceProperty.setType(type);
- ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
+ ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
componentInstanceProperty2.setName(PROPERTY_NAME);
componentInstanceProperty2.setType(type);
Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
componentInstancePropertyMap.put(componentInstance.getUniqueId(),
- Collections.singletonList(componentInstanceProperty));
+ Collections.singletonList(componentInstanceProperty));
componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
- Collections.singletonList(componentInstanceProperty2));
+ Collections.singletonList(componentInstanceProperty2));
componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));
service.setComponentInstancesProperties(componentInstancePropertyMap);
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import fj.data.Either;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+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;
+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.PatternConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
+import org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraint;
class PropertyConvertorTest {
private PropertyConvertor propertyConvertor;
@BeforeEach
- public void setUp(){
+ public void setUp() {
MockitoAnnotations.openMocks(this);
property = new PropertyDefinition();
property.setName("myProperty");
@Test
void testConvertProperty() {
- SchemaDefinition schema = new SchemaDefinition();
- schema.setProperty(property);
-
- property.setSchema(schema);
-
- propertyConvertor.convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY);
+ SchemaDefinition schema = new SchemaDefinition();
+ schema.setProperty(property);
+ property.setSchema(schema);
+
+ assertNotNull(propertyConvertor.convertProperty(dataTypes, property, PropertyType.PROPERTY));
+ }
+
+ @Test
+ void testConvertPropertyWithEqualConstraint() {
+ assertTrue(testConstraints(new EqualConstraint(123), ConstraintType.EQUAL, true));
+ }
+
+ @Test
+ void testConvertPropertyWithGreaterOrEqualConstraint() {
+ assertTrue(testConstraints(new GreaterOrEqualConstraint<>(123), ConstraintType.GREATER_OR_EQUAL, true));
+ }
+
+ @Test
+ void testConvertPropertyWithGreaterThanConstraint() {
+ assertTrue(testConstraints(new GreaterThanConstraint<>(123), ConstraintType.GREATER_THAN, true));
+ }
+
+ @Test
+ void testConvertPropertyWithLessOrEqualConstraint() {
+ assertTrue(testConstraints(new LessOrEqualConstraint<>(123), ConstraintType.LESS_OR_EQUAL, true));
+ }
+
+ @Test
+ void testConvertPropertyWithLessThanConstraint() {
+ assertTrue(testConstraints(new LessThanConstraint<>(123), ConstraintType.LESS_THAN, true));
+ }
+
+ @Test
+ void testConvertPropertyWithInRangeConstraint() {
+ assertTrue(testConstraints(new InRangeConstraint(Arrays.asList(123, 345)), ConstraintType.IN_RANGE, false));
+ }
+
+ @Test
+ void testConvertPropertyWithValidValuesConstraint() {
+ assertTrue(testConstraints(new ValidValuesConstraint(Arrays.asList(123, 345)), ConstraintType.VALID_VALUES, false));
+ }
+
+ @Test
+ void testConvertPropertyWithLengthConstraint() {
+ assertTrue(testConstraints(new LengthConstraint(), ConstraintType.LENGTH, false));
+ }
+
+ @Test
+ void testConvertPropertyWithMaxLengthConstraint() {
+ assertTrue(testConstraints(new MaxLengthConstraint(12), ConstraintType.MAX_LENGTH, false));
+ }
+
+ @Test
+ void testConvertPropertyWithMinLengthConstraint() {
+ assertTrue(testConstraints(new MinLengthConstraint(1), ConstraintType.MIN_LENGTH, false));
+ }
+
+ @Test
+ void testConvertPropertyWithPatternConstraint() {
+ assertTrue(testConstraints(new PatternConstraint("[a-z]"), ConstraintType.PATTERN, false));
}
@Test
assertNotNull(result);
assertEquals(Integer.valueOf(def), result.getDefaultp());
}
-
+
@Test
void convertPropertyWithMetadata() {
Map<String, String> metadata = new HashMap<>();
for (ToscaProperty prop : result.left().value().getProperties().values()) {
assertNull(prop.getDefaultp());
}
- }
+ }
@Test
void convertPropertyWhichStartsWithSemiColon() {
propertyConvertor.convertProperty(Collections.emptyMap(), property, PropertyConvertor.PropertyType.PROPERTY);
assertEquals("/", toscaProperty.getDefaultp());
}
-
+
@Test
void convertPropertyWithYamlValue() {
final PropertyDefinition property = new PropertyDataDefinitionBuilder()
final ToscaProperty toscaProperty =
propertyConvertor.convertProperty(Collections.emptyMap(), property, PropertyConvertor.PropertyType.PROPERTY);
assertTrue(toscaProperty.getDefaultp() instanceof Map);
- assertTrue(((Map)toscaProperty.getDefaultp()).get("concat") instanceof List);
- assertEquals(3, ((List)((Map)toscaProperty.getDefaultp()).get("concat")).size());
+ assertTrue(((Map) toscaProperty.getDefaultp()).get("concat") instanceof List);
+ assertEquals(3, ((List) ((Map) toscaProperty.getDefaultp()).get("concat")).size());
+ }
+
+ private boolean testConstraints(PropertyConstraint propertyConstraint, ConstraintType constraintType, boolean checkComparable) {
+ property.setConstraints(Collections.singletonList(propertyConstraint));
+
+ ToscaProperty toscaProperty = propertyConvertor.convertProperty(dataTypes, property, PropertyType.PROPERTY);
+ assertNotNull(toscaProperty);
+ List<ToscaPropertyConstraint> constraints = toscaProperty.getConstraints();
+ assertNotNull(constraints);
+ ToscaPropertyConstraint constraint = constraints.get(0);
+ assertNotNull(constraint);
+ ConstraintType actualConstraintType = constraint.getConstraintType();
+ assertEquals(constraintType, actualConstraintType);
+ if (checkComparable) {
+ assertTrue(actualConstraintType.isComparable());
+ }
+ return true;
}
}
@Setter
@AllArgsConstructor
@EqualsAndHashCode
-public class GreaterOrEqualConstraint extends AbstractComparablePropertyConstraint {
+public class GreaterOrEqualConstraint<T> extends AbstractComparablePropertyConstraint {
@NotNull
- private Object greaterOrEqual;
+ private T greaterOrEqual;
@Override
public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
public void changeConstraintValueTypeTo(String propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
ToscaType toscaType = ToscaType.getToscaType(propertyType);
try {
- greaterOrEqual = toscaType.convert(String.valueOf(greaterOrEqual));
+ greaterOrEqual = (T) toscaType.convert(String.valueOf(greaterOrEqual));
} catch (Exception e) {
throw new ConstraintValueDoNotMatchPropertyTypeException(
"greaterOrEqual constraint has invalid values <" + greaterOrEqual.toString() + "> property type is <" + propertyType + ">");
@Setter
@AllArgsConstructor
@EqualsAndHashCode
-public class LessThanConstraint extends AbstractComparablePropertyConstraint {
+public class LessThanConstraint<T> extends AbstractComparablePropertyConstraint {
@NotNull
- private Object lessThan;
+ private T lessThan;
@Override
public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
public void changeConstraintValueTypeTo(String propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
ToscaType toscaType = ToscaType.getToscaType(propertyType);
try {
- lessThan = toscaType.convert(String.valueOf(lessThan));
+ lessThan = (T) toscaType.convert(String.valueOf(lessThan));
} catch (Exception e) {
throw new ConstraintValueDoNotMatchPropertyTypeException(
"lessThan constraint has invalid values <" + lessThan.toString() + "> property type is <" + propertyType + ">");
PATTERN("pattern"),
SCHEMA("schema");
- private static final Set<ConstraintType> comparableConstraints = Set.of(ConstraintType.GREATER_THAN, ConstraintType.LESS_THAN);
+ private static final Set<ConstraintType> comparableConstraints = Set.of(
+ ConstraintType.EQUAL,
+ ConstraintType.GREATER_THAN,
+ ConstraintType.GREATER_OR_EQUAL,
+ ConstraintType.LESS_OR_EQUAL,
+ ConstraintType.LESS_THAN);
private final String type;
private final List<String> typeAlias;