aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorxuegao <xue.gao@intl.att.com>2021-03-22 11:22:47 +0100
committerxuegao <xue.gao@intl.att.com>2021-03-24 08:25:00 +0100
commit134ca5667da901a703ecb0c78d96873712a9d0d3 (patch)
tree38738cddb2798a54d1f81c22d005b9ff1e0c79f0 /catalog-model
parenteb57d1efc197968a4073b331b2dc8f40d8109847 (diff)
Improve test coverage
Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I9e00af2824366ae45d47d2dcecf322fd3e9a6fea Signed-off-by: xuegao <xue.gao@intl.att.com>
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java43
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidatorTest.java40
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/ListValidatorTest.java52
3 files changed, 111 insertions, 24 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java
index b58949d4c2..6b3b766afa 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java
@@ -22,42 +22,37 @@ package org.openecomp.sdc.be.model.tosca.converters;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class MapConverterTest {
- private MapConverter createTestSubject() {
- return new MapConverter();
- }
-
-
@Test
public void testGetInstance() throws Exception {
- MapConverter result;
-
- // default test
- result = MapConverter.getInstance();
+ assertNotNull(MapConverter.getInstance());
}
@Test
public void testConvert() throws Exception {
- MapConverter testSubject;
- String value = "";
- String innerType = "";
+ MapConverter testSubject = new MapConverter();
Map<String, DataTypeDefinition> dataTypes = null;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.convert(value, innerType, dataTypes);
+ assertTrue(testSubject.convert("", null, dataTypes).isEmpty());
+ assertTrue(testSubject.convert("", "string", dataTypes).isEmpty());
+ assertNull(testSubject.convert("{\"key\":}", "integer", dataTypes));
+
+ assertEquals("{\"key\":\"value\"}", testSubject.convert("{\"key\":\"value\"}", "list", dataTypes));
+ assertEquals("{\"key\":\"value\"}", testSubject.convert("{\"key\":\"value\"}", "string", dataTypes));
+ assertEquals("{\"key\":2}", testSubject.convert("{\"key\":2}", "integer", dataTypes));
+ assertEquals("{\"key\":null}", testSubject.convert("{\"key\":null}", "integer", dataTypes));
+ assertEquals("{\"key\":0.2}", testSubject.convert("{\"key\":0.2}", "float", dataTypes));
+ assertEquals("{\"key\":null}", testSubject.convert("{\"key\":null}", "float", dataTypes));
+ assertEquals("{\"key\":true}", testSubject.convert("{\"key\":true}", "boolean", dataTypes));
+ assertEquals("{\"key\":null}", testSubject.convert("{\"key\":null}", "boolean", dataTypes));
}
-
-
-
-
-
-
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidatorTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidatorTest.java
new file mode 100644
index 0000000000..1a07314b8d
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidatorTest.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. 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.validators;
+
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class KeyValidatorTest {
+
+ @Test
+ public void isValidTest() {
+ assertFalse(KeyValidator.getInstance().isValid(null, "string"));
+
+ String veryLongString = "veryverylonglonglonglonglonglongstringveryverylonglonglonglonglonglongstringveryverylonglonglonglonglonglongstring";
+ assertFalse(KeyValidator.getInstance().isValid(veryLongString, "string"));
+
+ assertTrue(KeyValidator.getInstance().isValid("test", "string"));
+ }
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/ListValidatorTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/ListValidatorTest.java
new file mode 100644
index 0000000000..528ac7a7c9
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/ListValidatorTest.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. 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.validators;
+
+
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ListValidatorTest {
+
+ @Test
+ public void isValidTest() {
+ Map<String, DataTypeDefinition> map = new HashMap();
+ ListValidator validator = new ListValidator();
+ assertTrue(validator.isValid("", "", map));
+ assertFalse(validator.isValid("test", null, map));
+
+ assertTrue(validator.isValid("[2,3]", "integer", map));
+ assertTrue(validator.isValid("[0.2]", "float", map));
+ assertTrue(validator.isValid("[true]", "boolean", map));
+ assertTrue(validator.isValid("[test]", "string", map));
+ assertTrue(validator.isValid("[{\"key\":1};{\"key2\":2}]", "json", map));
+
+ assertFalse(validator.isValid("[[1,2],[3]]", "list", map));
+ assertFalse(validator.isValid("[2,true]", "integer", map));
+ assertFalse(validator.isValid("test", "wrong", map));
+ }
+}