return handleToscaTemplate(javaBean, property, propertyValue, customTag);
}
if (javaBean instanceof ToscaPropertyConstraintValidValues) {
- return handleToscaPropertyConstraintValidValues(javaBean, property, propertyValue, customTag);
+ return handleToscaPropertyConstraintValidValues((ToscaPropertyConstraintValidValues)javaBean, property, propertyValue, customTag);
}
if (javaBean instanceof ToscaProperty) {
return handleToscaProperty(javaBean, property, propertyValue, customTag);
return nodeTuple;
}
- private NodeTuple handleToscaPropertyConstraintValidValues(final Object javaBean, final Property property, final Object propertyValue,
+ private NodeTuple handleToscaPropertyConstraintValidValues(final ToscaPropertyConstraintValidValues javaBean, final Property property, final Object propertyValue,
final Tag customTag) {
final NodeTuple nodeTuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
if ("validValues".equals(property.getName())) {
- final String validValuesEntryName = ToscaPropertyConstraintValidValues.getEntryToscaName("validValues");
+ final String validValuesEntryName = javaBean.getEntryToscaName("validValues");
return new NodeTuple(representData(validValuesEntryName), nodeTuple.getValueNode());
}
return nodeTuple;
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;
final Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
for (final Object constraintJson : propertyFieldConstraints) {
final PropertyConstraint propertyConstraint = validateAndGetPropertyConstraint(propertyType, constraintType, gson, constraintJson);
- constraintList.add(propertyConstraint);
+ if (propertyConstraint != null) {
+ constraintList.add(propertyConstraint);
+ }
}
return constraintList;
}
private void evaluateConstraintsOnProperty(PropertyDefinition propertyDefinition) {
ToscaType toscaType = ToscaType.isValidType(propertyDefinition.getType());
- if (isPropertyNotMappedAsInput(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())
- && isValidValueConstraintPresent(propertyDefinition.getConstraints())) {
+ if (isPropertyNotMappedAsInput(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) {
for (PropertyConstraint propertyConstraint : propertyDefinition.getConstraints()) {
try {
propertyConstraint.initialize(toscaType);
*/
package org.openecomp.sdc.be.impl;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
module.addDeserializer(ToscaFunction.class, new ToscaFunctionJsonDeserializer());
mapper.registerModule(module);
+ mapper.setSerializationInclusion(Include.NON_NULL);
component = mapper.readValue(data, clazz);
if (component == null) {
BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
*/
package org.openecomp.sdc.be.servlets;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
SimpleModule module = new SimpleModule("customDeserializationModule");
module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
mapper.registerModule(module);
+ mapper.setSerializationInclusion(Include.NON_NULL);
object = mapper.readValue(json, clazz);
if (object != null) {
return object;
import com.google.gson.stream.JsonReader;
import fj.data.Either;
import java.io.StringReader;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
import org.openecomp.sdc.be.model.Component;
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.ValidValuesConstraint;
import org.openecomp.sdc.be.model.tosca.converters.DataTypePropertyConverter;
import org.openecomp.sdc.be.model.tosca.converters.ToscaMapValueConverter;
import org.openecomp.sdc.be.model.tosca.converters.ToscaValueBaseConverter;
import org.openecomp.sdc.be.model.tosca.converters.ToscaValueConverter;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraint;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintEqual;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintGreaterOrEqual;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintGreaterThan;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintInRange;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLength;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLessOrEqual;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLessThan;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintMaxLength;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintMinLength;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintValidValues;
import org.openecomp.sdc.be.tosca.model.ToscaSchemaDefinition;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.Yaml;
+
@Service
public class PropertyConvertor {
prop.setStatus(property.getStatus());
}
prop.setMetadata(property.getMetadata());
+
+ List<ToscaPropertyConstraint> constraints = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(property.getConstraints())) {
+ constraints = convertConstraints(property.getConstraints());
+ prop.setConstraints(constraints);
+ }
return prop;
}
+
+ private List<ToscaPropertyConstraint> convertConstraints(List<PropertyConstraint> constraints) {
+ List<ToscaPropertyConstraint> convertedConstraints = new ArrayList<>();
+ for (PropertyConstraint constraint: constraints){
+ if (constraint instanceof EqualConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintEqual(((EqualConstraint) constraint).getEqual()));
+ }
+ if (constraint instanceof GreaterThanConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintGreaterThan(((GreaterThanConstraint) constraint).getGreaterThan()));
+ }
+ if (constraint instanceof GreaterOrEqualConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintGreaterOrEqual(((GreaterOrEqualConstraint) constraint).getGreaterOrEqual()));
+ }
+ if (constraint instanceof LessThanConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintLessThan(((LessThanConstraint) constraint).getLessThan()));
+ }
+ if (constraint instanceof LessOrEqualConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintLessOrEqual(((LessOrEqualConstraint) constraint).getLessOrEqual()));
+ }
+ if (constraint instanceof InRangeConstraint) {
+ InRangeConstraint inRangeConstraint = (InRangeConstraint) constraint;
+ List<String> range = new ArrayList<>();
+ range.add(inRangeConstraint.getRangeMinValue());
+ range.add(inRangeConstraint.getRangeMaxValue());
+ convertedConstraints.add(new ToscaPropertyConstraintInRange(range));
+ }
+ if (constraint instanceof ValidValuesConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintValidValues(((ValidValuesConstraint) constraint).getValidValues()));
+ }
+ if (constraint instanceof LengthConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintLength(((LengthConstraint) constraint).getLength().toString()));
+ }
+ if (constraint instanceof MinLengthConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintMinLength(((MinLengthConstraint) constraint).getMinLength()));
+ }
+ if (constraint instanceof MaxLengthConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintMaxLength(((MaxLengthConstraint) constraint).getMaxLength()));
+ }
+ }
+ return convertedConstraints;
+ }
public Object convertToToscaObject(PropertyDataDefinition property, String value, Map<String, DataTypeDefinition> dataTypes,
boolean preserveEmptyValue) {
import org.openecomp.sdc.be.tosca.model.ToscaPolicyTemplate;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import org.openecomp.sdc.be.tosca.model.ToscaPropertyAssignment;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraint;
import org.openecomp.sdc.be.tosca.model.ToscaRelationshipTemplate;
import org.openecomp.sdc.be.tosca.model.ToscaRequirement;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
options.setCanonical(false);
representer.addClassTag(toscaTemplate.getClass(), Tag.MAP);
representer.setPropertyUtils(new UnsortedPropertyUtils());
+
+
Yaml yaml = new Yaml(representer, options);
String yamlAsString = yaml.dumpAsMap(toscaTemplate);
StringBuilder sb = new StringBuilder();
if (javaBean instanceof ToscaRelationshipTemplate && "name".equals(property.getName())) {
return null;
}
+ if (javaBean instanceof ToscaPropertyConstraint) {
+ return handleToscaPropertyConstraint((ToscaPropertyConstraint)javaBean, property, propertyValue, customTag);
+ }
removeDefaultP(propertyValue);
NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
if (javaBean instanceof ToscaTopolgyTemplate && "relationshipTemplates".equals(property.getName())) {
}
return "_defaultp_".equals(property.getName()) ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
}
+
+ private NodeTuple handleToscaPropertyConstraint(final ToscaPropertyConstraint javaBean, final Property property, final Object propertyValue,
+ final Tag customTag) {
+ final NodeTuple nodeTuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
+ final String entryToscaName = javaBean.getEntryToscaName(property.getName());
+ return new NodeTuple(representData(entryToscaName), nodeTuple.getValueNode());
+ }
private void removeDefaultP(final Object propertyValue) {
if (propertyValue instanceof Map) {
public interface ToscaPropertyConstraint {
ConstraintType getConstraintType();
+
+ /**
+ * Get the TOSCA entry name of an attribute in this class.
+ *
+ * @param attributeName the class attribute name
+ * @return the TOSCA entry represented by the attribute
+ */
+ String getEntryToscaName(final String attributeName);
}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA equal constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintEqual implements ToscaPropertyConstraint {
+
+ private String equal;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.EQUAL;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("equal".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA greater_or_equal constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintGreaterOrEqual implements ToscaPropertyConstraint {
+
+ private String greaterOrEqual;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.GREATER_OR_EQUAL;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("greaterOrEqual".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA greater_than constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintGreaterThan implements ToscaPropertyConstraint {
+
+ private String greaterThan;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.GREATER_THAN;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("greaterThan".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import java.util.List;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA in_range constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintInRange implements ToscaPropertyConstraint {
+
+ private List<String> inRange;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.IN_RANGE;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("inRange".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA length constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintLength implements ToscaPropertyConstraint {
+
+ private String length;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LENGTH;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("length".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA less_or_equal constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintLessOrEqual implements ToscaPropertyConstraint {
+
+ private String lessOrEqual;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LESS_OR_EQUAL;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("lessOrEqual".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA less_than constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintLessThan implements ToscaPropertyConstraint {
+
+ private String lessThan;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LESS_THAN;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("lessThan".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA max_length constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintMaxLength implements ToscaPropertyConstraint {
+
+ private Integer maxLength;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.MAX_LENGTH;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("maxLength".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA min_length constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintMinLength implements ToscaPropertyConstraint {
+
+ private Integer minLength;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("minLength".equals(attributeName)) {
+ return ConstraintType.MIN_LENGTH.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return ConstraintType.MIN_LENGTH;
+ }
+}
private List<String> validValues;
- /**
- * Get the TOSCA entry name of an attribute in this class.
- *
- * @param attributeName the class attribute name
- * @return the TOSCA entry represented by the attribute
- */
- public static String getEntryToscaName(final String attributeName) {
+ @Override
+ public String getEntryToscaName(final String attributeName) {
if ("validValues".equals(attributeName)) {
return "valid_values";
}
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;
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;
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;
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() {
*/
package org.openecomp.sdc.be.model;
+import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;
}
public List<PropertyConstraint> safeGetConstraints() {
- return CollectionUtils.safeGetList(constraints);
+ return new ArrayList<PropertyConstraint>(CollectionUtils.safeGetList(constraints));
}
}
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.Maps;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonSerializer;
import fj.data.Either;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.StringJoiner;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+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.ValidValuesConstraint;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
log.warn("ConstraintType was not found for constraint name:{}", key);
} else {
switch (constraintType) {
+ case EQUAL:
+ if (value != null) {
+ String asString = value.getAsString();
+ log.debug("Before adding value to EqualConstraint object. value = {}", asString);
+ propertyConstraint = new EqualConstraint(asString);
+ break;
+ } else {
+ log.warn("The value of equal constraint is null");
+ }
+ break;
case IN_RANGE:
if (value != null) {
if (value instanceof JsonArray) {
}
}
break;
+ case LENGTH:
+ if (value != null) {
+ 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");
+ }
+ break;
case MIN_LENGTH:
if (value != null) {
int asInt = value.getAsInt();
log.warn("The value of MinLengthConstraint is null");
}
break;
+ case MAX_LENGTH:
+ if (value != null) {
+ 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");
+ }
+ break;
default:
log.warn("Key {} is not supported. Ignored.", key);
}
public PropertyConstraint deserialize(com.fasterxml.jackson.core.JsonParser json, DeserializationContext context) throws IOException {
ObjectCodec oc = json.getCodec();
JsonNode node = oc.readTree(json);
+ PropertyConstraint propertyConstraint = null;
+
+ Iterator<Entry<String, JsonNode>> fieldsIterator = node.fields();
+ while (fieldsIterator.hasNext()) {
+ Entry<String, JsonNode> field = fieldsIterator.next();
+ ConstraintType constraintType = ConstraintType.findByType(field.getKey()).orElse(null);
+ JsonNode value = field.getValue();
+
+ if (constraintType == null) {
+ log.warn("ConstraintType was not found for constraint name:{}", field.getKey());
+ } else {
+ if (value == null) {
+ log.warn("The value of " + constraintType + " constraint is null");
+ }
+ switch (constraintType) {
+ case EQUAL:
+ propertyConstraint = deserializeConstraintWithStringOperand(value, EqualConstraint.class);
+ break;
+ case IN_RANGE:
+ propertyConstraint = deserializeInRangeConstraintConstraint(value);
+ break;
+ case GREATER_THAN:
+ propertyConstraint = deserializeConstraintWithStringOperand(value, GreaterThanConstraint.class);
+ break;
+ case LESS_THAN:
+ propertyConstraint = deserializeConstraintWithStringOperand(value, LessThanConstraint.class);
+ break;
+ case GREATER_OR_EQUAL:
+ propertyConstraint = deserializeConstraintWithStringOperand(value, GreaterOrEqualConstraint.class);
+ break;
+ case LESS_OR_EQUAL:
+ propertyConstraint = deserializeConstraintWithStringOperand(value, LessOrEqualConstraint.class);
+ break;
+ case VALID_VALUES:
+ propertyConstraint = deserializeValidValuesConstraint(value);
+ break;
+ case LENGTH:
+ propertyConstraint = deserializeConstraintWithIntegerOperand(value, LengthConstraint.class);
+ break;
+ case MIN_LENGTH:
+ propertyConstraint = deserializeConstraintWithIntegerOperand(value, MinLengthConstraint.class);
+ break;
+ case MAX_LENGTH:
+ propertyConstraint = deserializeConstraintWithIntegerOperand(value, MaxLengthConstraint.class);
+ break;
+ default:
+ log.warn("Key {} is not supported. Ignored.", field.getKey());
+ }
+ }
+ }
+
+ return propertyConstraint;
+ }
+
+ private PropertyConstraint deserializeConstraintWithStringOperand(JsonNode value, Class<? extends PropertyConstraint> constraintClass) {
+ String asString = value.asText();
+ log.debug("Before adding value to {} object. value = {}", constraintClass, asString);
+ try {
+ return constraintClass.getConstructor(String.class).newInstance(asString);
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
+ | SecurityException exception) {
+ log.error("Error deserializing constraint", exception);
+ return null;
+ }
+ }
+
+ private PropertyConstraint deserializeConstraintWithIntegerOperand(JsonNode value, Class<? extends PropertyConstraint> constraintClass) {
+ Integer asInt = value.asInt();
+ log.debug("Before adding value to {} object. value = {}", constraintClass, asInt);
+ try {
+ return constraintClass.getConstructor(Integer.class).newInstance(asInt);
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
+ | SecurityException exception) {
+ log.error("Error deserializing constraint", exception);
+ return null;
+ }
+ }
+
+ private PropertyConstraint deserializeInRangeConstraintConstraint(JsonNode value) {
+ if (value instanceof ArrayNode) {
+ ArrayNode rangeArray = (ArrayNode) value;
+ 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);
+ return rangeConstraint;
+ }
+ }
return null;
}
+
+ private PropertyConstraint deserializeValidValuesConstraint(JsonNode value) {
+ ArrayNode rangeArray = (ArrayNode) value;
+ if (rangeArray.size() == 0) {
+ log.error("The valid values constraint content is invalid. value = {}", value);
+ } else {
+ ValidValuesConstraint vvConstraint = new ValidValuesConstraint();
+ List<String> validValues = new ArrayList<>();
+ for (JsonNode jsonElement : rangeArray) {
+ String item = jsonElement.asText();
+ validValues.add(item);
+ }
+ vvConstraint.setValidValues(validValues);
+ return vvConstraint;
+ }
+ return null;
+ }
+
+
}
}
public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName, String errorMessage,
String... propertyValue) {
if (e instanceof ConstraintViolationException) {
- return String.format(errorMessage, propertyName, Arrays.toString(propertyValue));
+ return String.format(errorMessage, propertyName, propertyValue.length == 1 ? propertyValue[0] : Arrays.toString(propertyValue));
}
return String.format(INVALID_VALUE_ERROR_MESSAGE, propertyName, toscaType.getType());
}
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolationException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraintException;
+import lombok.Getter;
@SuppressWarnings("serial")
public class EqualConstraint extends AbstractPropertyConstraint implements Serializable {
@NotNull
- private String constraintValue;
+ @Getter
+ private String equal;
private Object typed;
- public EqualConstraint(String constraintValue) {
+ public EqualConstraint(String equal) {
super();
- this.constraintValue = constraintValue;
- }
-
- public String getConstraintValue() {
- return constraintValue;
+ this.equal = equal;
}
@Override
public void initialize(ToscaType propertyType) throws ConstraintValueDoNotMatchPropertyTypeException {
- if (propertyType.isValidValue(constraintValue)) {
- typed = propertyType.convert(constraintValue);
+ if (propertyType.isValidValue(equal)) {
+ typed = propertyType.convert(equal);
} else {
throw new ConstraintValueDoNotMatchPropertyTypeException(
- "constraintValue constraint has invalid value <" + constraintValue + "> property type is <" + propertyType.toString() + ">");
+ "constraintValue constraint has invalid value <" + equal + "> property type is <" + propertyType.toString() + ">");
}
}
}
} else if (typed == null) {
fail(propertyValue);
- } else if (typed instanceof Comparable && typed != propertyValue) {
- fail(propertyValue);
} else if (!typed.equals(propertyValue)) {
fail(propertyValue);
}
private void fail(Object propertyValue) throws ConstraintViolationException {
throw new ConstraintViolationException(
- "Equal constraint violation, the reference is <" + constraintValue + "> but the value to compare is <" + propertyValue + ">");
+ "Equal constraint violation, the reference is <" + equal + "> but the value to compare is <" + propertyValue + ">");
}
@Override
public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
- return getErrorMessage(toscaType, e, propertyName, "%s property value must be %s", constraintValue);
+ return getErrorMessage(toscaType, e, propertyName, "%s property value must be %s", equal);
}
}
@Override
public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
- return getErrorMessage(toscaType, e, propertyName, "%f property value must be >= %f", greaterOrEqual);
+ return getErrorMessage(toscaType, e, propertyName, "%s property value must be greater than or equal to %s", greaterOrEqual);
}
}
@Override
public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
- return getErrorMessage(toscaType, e, propertyName, "%f property value must be > %f", greaterThan);
+ return getErrorMessage(toscaType, e, propertyName, "%s property value must be greater than %s", greaterThan);
}
}
@Override
public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
- return getErrorMessage(toscaType, e, propertyName, "%f property value must be between >= [%s] and <= [%s]", String.valueOf(min),
+ return getErrorMessage(toscaType, e, propertyName, "%s property value must be between >= [%s] and <= [%s]", String.valueOf(min),
String.valueOf(max));
}
}
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolationException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraintException;
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
+@AllArgsConstructor
+@NoArgsConstructor
public class LengthConstraint extends AbstractPropertyConstraint {
@NotNull
@Override
public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
- return getErrorMessage(toscaType, e, propertyName, "%s property value must be <= %s", lessOrEqual);
+ return getErrorMessage(toscaType, e, propertyName, "%s property value must be less than or equal to %s", lessOrEqual);
}
}
import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolationException;
import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraintException;
+@Getter
@AllArgsConstructor
public class LessThanConstraint extends AbstractComparablePropertyConstraint {
@Override
public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException e, String propertyName) {
- return getErrorMessage(toscaType, e, propertyName, "%s value must be < %s", lessThan);
+ return getErrorMessage(toscaType, e, propertyName, "%s value must be less than %s", lessThan);
}
}
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;
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.DataTypeData;
import org.openecomp.sdc.be.resources.data.PropertyData;
import org.openecomp.sdc.be.resources.data.PropertyValueData;
private List<PropertyConstraint> buildConstraints() {
List<PropertyConstraint> constraints = new ArrayList<>();
- GreaterThanConstraint propertyConstraint1 = new GreaterThanConstraint("0");
- LessOrEqualConstraint propertyConstraint2 = new LessOrEqualConstraint("10");
- List<String> range = new ArrayList<>();
- range.add("0");
- range.add("100");
- InRangeConstraint propertyConstraint3 = new InRangeConstraint(range);
+ EqualConstraint propertyConstraint1 = new EqualConstraint("0");
+ GreaterThanConstraint propertyConstraint2 = new GreaterThanConstraint("1");
+ GreaterOrEqualConstraint propertyConstraint3 = new GreaterOrEqualConstraint("3");
+ LessThanConstraint propertyConstraint4 = new LessThanConstraint("5");
+ LessOrEqualConstraint propertyConstraint5 = new LessOrEqualConstraint("7");
+ InRangeConstraint propertyConstraint6 = buildInRangeConstraint();
+ ValidValuesConstraint propertyConstraint7 = buildValidValuesConstraint();
+ LengthConstraint propertyConstraint8 = new LengthConstraint(9);
+ MinLengthConstraint propertyConstraint9 = new MinLengthConstraint(11);
+ MaxLengthConstraint propertyConstraint10 = new MaxLengthConstraint(13);
constraints.add(propertyConstraint1);
constraints.add(propertyConstraint2);
constraints.add(propertyConstraint3);
+ constraints.add(propertyConstraint4);
+ constraints.add(propertyConstraint5);
+ constraints.add(propertyConstraint6);
+ constraints.add(propertyConstraint7);
+ constraints.add(propertyConstraint8);
+ constraints.add(propertyConstraint9);
+ constraints.add(propertyConstraint10);
return constraints;
}
+
+ private InRangeConstraint buildInRangeConstraint() {
+ List<String> range = new ArrayList<>();
+ range.add("23");
+ range.add("67");
+ InRangeConstraint inRangeConstraint = new InRangeConstraint(range);
+ return inRangeConstraint;
+ }
+
+ private ValidValuesConstraint buildValidValuesConstraint() {
+ List<String> validValues = new ArrayList<>();
+ validValues.add("abc");
+ validValues.add("def");
+ validValues.add("fhi");
+ ValidValuesConstraint validValuesConstraint = new ValidValuesConstraint(validValues);
+ return validValuesConstraint;
+ }
@Test
public void findPropertyValueBestMatch1() {