summaryrefslogtreecommitdiffstats
path: root/common/onap-tosca-datatype
diff options
context:
space:
mode:
authorJulienBe <julien.bertozzi@intl.att.com>2020-06-17 14:22:53 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-18 05:41:22 +0000
commitccdff9dd945d15b537f922999a569deb9b08a2d6 (patch)
tree711d6747b7c1410e1ab076a17ccd95ab8cde4278 /common/onap-tosca-datatype
parent135e9ebdc84ebe58d3ff338d439631d45eb5f01e (diff)
create tests for ScalarUnitValidator.java
Issue-ID: SDC-3123 Change-Id: Iaa60ce2df46ee7a4d9138a56cf4d4c115a059240 Signed-off-by: JulienBe <julien.bertozzi@intl.att.com>
Diffstat (limited to 'common/onap-tosca-datatype')
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidator.java6
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidatorTest.java60
2 files changed, 64 insertions, 2 deletions
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidator.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidator.java
index d7e538e0a7..5e2e2e5ee7 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidator.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidator.java
@@ -28,10 +28,12 @@ import org.apache.commons.lang3.StringUtils;
*/
public class ScalarUnitValidator {
- private static ScalarUnitValidator scalarUnitValidator = new ScalarUnitValidator();
+ private static final ScalarUnitValidator scalarUnitValidator = new ScalarUnitValidator();
/**
* Tosca Scalar Unit Types structure.
+ *
+ * At least positive integers, no single white space, 1 to 3 chars
*/
private final Pattern pattern = Pattern.compile("\\d+\\s*[a-zA-Z]{1,3}");
@@ -71,4 +73,4 @@ public class ScalarUnitValidator {
.anyMatch(scalarUnit ->
scalarUnit.name().equalsIgnoreCase(strValue) || strValue.endsWith(scalarUnit.name())));
}
-}
+} \ No newline at end of file
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidatorTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidatorTest.java
new file mode 100644
index 0000000000..bee5f7ae2f
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ScalarUnitValidatorTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T. 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.onap.sdc.tosca.datatypes.model;
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+public class ScalarUnitValidatorTest {
+
+ @Test
+ public void shouldGetAnInstance() {
+ assertNotNull(ScalarUnitValidator.getInstance());
+ }
+
+ @Test
+ public void testScalarUnit() {
+ ScalarUnitValidator validator = ScalarUnitValidator.getInstance();
+ assertTrue(validator.isScalarUnit(null));
+ assertTrue(validator.isScalarUnit("1y"));
+ assertTrue(validator.isScalarUnit("2ye"));
+ assertTrue(validator.isScalarUnit("3yes"));
+
+ assertFalse(validator.isScalarUnit("no"));
+ assertFalse(validator.isScalarUnit("1nooo"));
+ }
+
+ @Test
+ public void testValueScalarUnit() {
+ ScalarUnitValidator validator = ScalarUnitValidator.getInstance();
+ assertTrue(validator.isValueScalarUnit("2B", TestEnum.class));
+
+ assertFalse(validator.isValueScalarUnit("1val", TestEnum.class));
+ assertFalse(validator.isValueScalarUnit("null", null));
+ assertFalse(validator.isValueScalarUnit(null, null));
+ }
+}
+
+enum TestEnum {
+ B, KB
+} \ No newline at end of file