summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test/java
diff options
context:
space:
mode:
authorPiotr Borelowski <p.borelowski@partner.samsung.com>2019-06-18 16:08:08 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-08-06 08:54:15 +0000
commitd7d87dc3a647e924bcf0e05e60c18f70cba3ed7b (patch)
tree8e837beffd25f3412d53fe7025b644ff1b12f8ec /catalog-model/src/test/java
parent4f088f2a33d9202238eab9fbc78b4eb7510d1438 (diff)
Added unit tests for AbstractPropertyConstraint
Improved the unit test coverage in the package org.openecomp.sdc.be.model.tosca.constraints Issue-ID: SDC-2327 Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com> Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I094ab463cc010ecd48e062a1a806b3b907223228
Diffstat (limited to 'catalog-model/src/test/java')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java113
1 files changed, 113 insertions, 0 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java
new file mode 100644
index 0000000000..82d039439a
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/constraints/AbstractPropertyConstraintTest.java
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP SDC
+ * ================================================================================
+ * Copyright (C) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ */
+
+package org.openecomp.sdc.be.model.tosca.constraints;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openecomp.sdc.be.model.tosca.ToscaType;
+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.version.Version;
+
+public class AbstractPropertyConstraintTest {
+
+ private final TestPropertyConstraint constraint = new TestPropertyConstraint();
+
+ @Test
+ public void testValidateBoolean() throws ConstraintViolationException {
+ // given
+ final String value = "faLsE";
+
+ // when
+ constraint.validate(ToscaType.BOOLEAN, value);
+
+ // then
+ assertEquals(Boolean.valueOf(value), constraint.last);
+ }
+
+ @Test
+ public void testValidateFloat() throws ConstraintViolationException {
+ // given
+ final String value = "123.456";
+
+ // when
+ constraint.validate(ToscaType.FLOAT, value);
+
+ // then
+ assertEquals(Float.valueOf(value), constraint.last);
+ }
+
+ @Test
+ public void testValidateVersion() throws ConstraintViolationException {
+ // given
+ final String value = "12.34.1002-Release7";
+
+ // when
+ constraint.validate(ToscaType.VERSION, value);
+
+ // then
+ assertEquals(new Version(value), constraint.last);
+ }
+
+ @Test
+ public void testGetErrorMessageIsInstanceOf() {
+ // given
+ final ConstraintFunctionalException exception = new ConstraintViolationException("exc");
+
+ // when
+ final String message = constraint.getErrorMessage(ToscaType.SCALAR_UNIT, exception,
+ "area", "Message: %s --> %s", "prop1", "prop2");
+
+ // then
+ assertEquals("Message: area --> [prop1, prop2]", message);
+ }
+
+ @Test
+ public void testGetErrorMessageOtherType() {
+ // given
+ final ConstraintFunctionalException exception = new ConstraintFunctionalException("exc");
+
+ // when
+ final String message = constraint.getErrorMessage(ToscaType.SCALAR_UNIT_FREQUENCY, exception,
+ "freq", null);
+
+ // then
+ assertEquals("Unsupported value provided for freq property supported value type is scalar-unit.frequency.",
+ message);
+ }
+}
+
+class TestPropertyConstraint extends AbstractPropertyConstraint {
+
+ Object last;
+
+ @Override
+ public void validate(Object propertyValue) {
+ last = propertyValue;
+ }
+
+ @Override
+ public String getErrorMessage(ToscaType toscaType, ConstraintFunctionalException exception, String propertyName) {
+ return null;
+ }
+}