summaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorxuegao <xg353y@intl.att.com>2020-06-22 12:15:06 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-23 07:53:45 +0000
commit360884a24df3f22abc9533130c5de2d1673528f8 (patch)
tree879ab48c3e055b2869e9eb42aa4b057ec9b0584e /catalog-model
parentb29518ad6136fe628d7aff79d5fc607c5e890729 (diff)
Refactor ToscaTypeTest
Adding more tests and adding assert for old tests. Issue-ID: SDC-3143 Signed-off-by: xuegao <xg353y@intl.att.com> Change-Id: Id7cf5ec763b0d43dece9493613e336a4b3df9b72 Signed-off-by: xuegao <xg353y@intl.att.com>
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java4
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/ToscaTypeTest.java139
2 files changed, 114 insertions, 29 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java
index 87ad62195f..71abc54cb7 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaType.java
@@ -178,13 +178,13 @@ public enum ToscaType {
try {
return ConstraintUtil.parseToCollection(value, new TypeReference<List<Object>>() {});
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
- throw new IllegalArgumentException("Value must be a valid timestamp", e);
+ throw new IllegalArgumentException("Value must be a valid List", e);
}
case MAP:
try {
return ConstraintUtil.parseToCollection(value, new TypeReference<Map<String, Object>>() {});
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
- throw new IllegalArgumentException("Value must be a valid timestamp", e);
+ throw new IllegalArgumentException("Value must be a valid Map", e);
}
default:
return null;
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/ToscaTypeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/ToscaTypeTest.java
index 625cfb7424..233c44c569 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/ToscaTypeTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/ToscaTypeTest.java
@@ -20,50 +20,135 @@
package org.openecomp.sdc.be.model.tosca;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.model.tosca.version.Version;
public class ToscaTypeTest {
- private ToscaType createTestSubject() {
- return ToscaType.BOOLEAN;
+ @Test
+ public void testIsValidValueBoolean() throws Exception {
+ ToscaType toscaType = ToscaType.BOOLEAN;;
+
+ assertTrue(!toscaType.isValidValue(""));
+ assertTrue(toscaType.isValidValue("false"));
+ assertTrue(toscaType.isValidValue("FalSe"));
+ assertTrue(toscaType.isValidValue("true"));
+ assertTrue(toscaType.isValidValue("TrUe"));
}
+ @Test
+ public void testIsValidValueFloat() throws Exception {
+ ToscaType toscaType = ToscaType.FLOAT;;
+
+ assertTrue(!toscaType.isValidValue("float"));
+ assertTrue(toscaType.isValidValue("1.2534"));
+ assertTrue(toscaType.isValidValue("1.2534f"));
+ }
-
@Test
- public void testIsValidValue() throws Exception {
- ToscaType testSubject;
- String value = "";
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isValidValue(value);
+ public void testIsValidValueInteger() throws Exception {
+ ToscaType toscaType = ToscaType.INTEGER;;
+
+ assertTrue(!toscaType.isValidValue("integer"));
+ assertTrue(toscaType.isValidValue("1235"));
}
+ @Test
+ public void testIsValidValueTimestamp() throws Exception {
+ ToscaType toscaType = ToscaType.TIMESTAMP;;
+
+ assertTrue(!toscaType.isValidValue("timestamp"));
+ assertTrue(toscaType.isValidValue("Jun 30, 2009 7:03:47 AM"));
+ assertTrue(!toscaType.isValidValue("30 juin 2009 07:03:47"));
+ }
+
+ @Test
+ public void testIsValidValueVersion() throws Exception {
+ ToscaType toscaType = ToscaType.VERSION;;
+
+ assertTrue(!toscaType.isValidValue("version"));
+ assertTrue(toscaType.isValidValue("1.2"));
+ assertTrue(toscaType.isValidValue("1.2.3"));
+ assertTrue(toscaType.isValidValue("1.2-3"));
+ }
+
+ @Test
+ public void testIsValidValueList() throws Exception {
+ ToscaType toscaType = ToscaType.LIST;;
+
+ assertTrue(!toscaType.isValidValue("list"));
+ assertTrue(toscaType.isValidValue("[\"color\",\"type\"]"));
+ }
+
+ @Test
+ public void testIsValidValueMap() throws Exception {
+ ToscaType toscaType = ToscaType.MAP;;
+
+ assertTrue(!toscaType.isValidValue("map"));
+ assertTrue(toscaType.isValidValue("{\"color\":\"yellow\",\"type\":\"renault\"}"));
+ }
+
+ @Test
+ public void testGetToscaType() throws Exception {
+ ToscaType toscaType = ToscaType.MAP;;
+
+ assertEquals(ToscaType.getToscaType("map"), toscaType);
+ assertNull(ToscaType.getToscaType(null));
+ assertNull(ToscaType.getToscaType("InvalidType"));
+ }
+
+ @Test
+ public void testIsPrimitiveType() throws Exception {
+ assertTrue(!ToscaType.isPrimitiveType("map"));
+ assertTrue(!ToscaType.isPrimitiveType("list"));
+ assertTrue(!ToscaType.isPrimitiveType("String"));
+ assertTrue(ToscaType.isPrimitiveType("string"));
+ assertTrue(ToscaType.isPrimitiveType("integer"));
+ }
+
+ @Test
+ public void testIsCollectionType() throws Exception {
+ assertTrue(ToscaType.isCollectionType("map"));
+ assertTrue(ToscaType.isCollectionType("list"));
+ assertTrue(!ToscaType.isCollectionType("Map"));
+ assertTrue(!ToscaType.isCollectionType("string"));
+ assertTrue(!ToscaType.isCollectionType("integer"));
+ }
-
@Test
public void testConvert() throws Exception {
- ToscaType testSubject;
- String value = "";
- Object result;
+ ToscaType typeStr = ToscaType.STRING;
+ assertEquals(typeStr.convert("str"), "str");
+
+ ToscaType typeFloat = ToscaType.FLOAT;
+ assertTrue(typeFloat.convert("1.2357f") instanceof Float);
- // default test
- testSubject = createTestSubject();
- result = testSubject.convert(value);
+ ToscaType typeTimestamp = ToscaType.TIMESTAMP;
+ assertTrue(typeTimestamp.convert("Jun 30, 2009 7:03:47 AM") instanceof Date);
+
+ ToscaType typeVersion = ToscaType.VERSION;
+ assertTrue(typeVersion.convert("1.2.3.5.6") instanceof Version);
+
+ ToscaType typeList = ToscaType.LIST;
+ assertTrue(typeList.convert("[\"str1\",\"str2\"]") instanceof List);
+
+ ToscaType typeMap = ToscaType.MAP;
+ assertTrue(typeMap.convert("{\"color\":\"yellow\",\"type\":\"renault\"}") instanceof Map);
}
-
@Test
public void testToString() throws Exception {
- ToscaType testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.toString();
+ ToscaType testToscaType = ToscaType.SCALAR_UNIT;
+ assertEquals(testToscaType.toString(), "scalar_unit");
}
}