2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Samsung. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END============================================
19 * ===================================================================
22 package org.openecomp.sdc.be.model.tosca.constraints;
24 import static org.junit.Assert.assertEquals;
26 import org.junit.Test;
27 import org.openecomp.sdc.be.model.tosca.ToscaType;
28 import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintFunctionalException;
29 import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolationException;
30 import org.openecomp.sdc.be.model.tosca.version.Version;
32 public class AbstractPropertyConstraintTest {
34 private final TestPropertyConstraint constraint = new TestPropertyConstraint();
37 public void testValidateBoolean() throws ConstraintViolationException {
39 final String value = "faLsE";
42 constraint.validate(ToscaType.BOOLEAN, value);
45 assertEquals(Boolean.valueOf(value), constraint.last);
49 public void testValidateFloat() throws ConstraintViolationException {
51 final String value = "123.456";
54 constraint.validate(ToscaType.FLOAT, value);
57 assertEquals(Float.valueOf(value), constraint.last);
61 public void testValidateVersion() throws ConstraintViolationException {
63 final String value = "12.34.1002-Release7";
66 constraint.validate(ToscaType.VERSION, value);
69 assertEquals(new Version(value), constraint.last);
73 public void testGetErrorMessageIsInstanceOf() {
75 final ConstraintFunctionalException exception = new ConstraintViolationException("exc");
78 final String message = constraint.getErrorMessage(ToscaType.SCALAR_UNIT, exception,
79 "area", "Message: %s --> %s", "prop1", "prop2");
82 assertEquals("Message: area --> [prop1, prop2]", message);
86 public void testGetErrorMessageOtherType() {
88 final ConstraintFunctionalException exception = new ConstraintFunctionalException("exc");
91 final String message = constraint.getErrorMessage(ToscaType.SCALAR_UNIT_FREQUENCY, exception,
95 assertEquals("Unsupported value provided for freq property supported value type is scalar-unit.frequency.",
100 class TestPropertyConstraint extends AbstractPropertyConstraint {
105 public void validate(Object propertyValue) {
106 last = propertyValue;
110 public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException exception, String propertyName) {