summaryrefslogtreecommitdiffstats
path: root/common/onap-tosca-datatype/src/test
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-03-28 14:39:05 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2021-03-29 07:15:14 +0000
commit4014cbcbe3a61391fa5f7de9f42ec247ca493979 (patch)
tree88435c882896b582c81b964ce98e160f00c8baf2 /common/onap-tosca-datatype/src/test
parent04c236567737c965545f64c9542a7d75ed6f9046 (diff)
Improve test coverage (common)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3428 Change-Id: I60862879fc09a81369d6e5fdf9f3c985994b163e
Diffstat (limited to 'common/onap-tosca-datatype/src/test')
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ImplementationTest.java25
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/RequirementDefinitionTest.java72
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java65
3 files changed, 125 insertions, 37 deletions
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ImplementationTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ImplementationTest.java
index 93ec20dc5a..c3d39a4ea2 100644
--- a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ImplementationTest.java
+++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ImplementationTest.java
@@ -20,26 +20,37 @@
package org.onap.sdc.tosca.datatypes.model;
-import org.junit.Test;
import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEquals;
import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCode;
import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+class ImplementationTest {
-public class ImplementationTest {
@Test
- public void shouldHaveValidGettersAndSetters() {
+ void shouldHaveValidGettersAndSetters() {
assertThat(Implementation.class, hasValidGettersAndSetters());
}
@Test
- public void shouldHaveValidEquals() {
+ void shouldHaveValidEquals() {
assertThat(Implementation.class, hasValidBeanEquals());
}
@Test
- public void shouldHaveValidHashCode() {
+ void shouldHaveValidHashCode() {
assertThat(Implementation.class, hasValidBeanHashCode());
}
-} \ No newline at end of file
+
+ @Test
+ void cloneTest() {
+ final Implementation clone = new Implementation().clone();
+ assertNotNull(clone);
+ assertTrue(clone instanceof Implementation);
+ }
+}
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/RequirementDefinitionTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/RequirementDefinitionTest.java
new file mode 100644
index 0000000000..d33f6eeabb
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/RequirementDefinitionTest.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 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=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
+
+package org.onap.sdc.tosca.datatypes.model;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.onap.sdc.tosca.services.YamlUtil;
+
+/**
+ * @author shiria
+ * @since September 07, 2016.
+ */
+public class RequirementDefinitionTest {
+
+ @Test
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(RequirementDefinition.class, hasValidGettersAndSetters());
+ }
+
+ @Test
+ public void cloneTest() {
+ RequirementDefinition reqDef1 = new RequirementDefinition();
+ reqDef1.setNode("node1");
+ reqDef1.setRelationship("my Relationship");
+ reqDef1.setCapability("capabilities");
+ reqDef1.setOccurrences(new Object[]{1, 1});
+
+ RequirementDefinition reqDef2 = reqDef1.clone();
+ NodeType nodeType = new NodeType();
+
+ List<Map<String, RequirementDefinition>> requirements = new ArrayList<>();
+ Map<String, RequirementDefinition> reqMap1 = new HashMap<>();
+ reqMap1.put("req1", reqDef1);
+ requirements.add(reqMap1);
+ Map<String, RequirementDefinition> reqMap2 = new HashMap<>();
+ reqMap2.put("req2", reqDef2);
+ requirements.add(reqMap2);
+ nodeType.setRequirements(requirements);
+
+ String yamlString = new YamlUtil().objectToYaml(nodeType);
+ Boolean passResult = !yamlString.contains("&") && !yamlString.contains("*");
+ assertEquals(true, passResult);
+ }
+
+}
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java
index 70f93649ab..b44435c9ea 100644
--- a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java
+++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java
@@ -18,58 +18,63 @@
package org.onap.sdc.tosca.datatypes.model;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
-
import java.io.InputStream;
import java.util.Map;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
-import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public class ServiceTemplateTest {
+class ServiceTemplateTest {
private static final String INTERFACE_NO_OPER = "amdocs.interfaces.interfaceNoOper";
private static final String LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard";
private static final String INTERFACE_WITH_OPER = "amdocs.interfaces.interfaceWithOper";
- public static final String NORMALIZE_INTERFACE_TYPE = "/mock/serviceTemplate/normalizeInterfaceType.yaml";
- public static final String NEW_OPER_1 = "newOper1";
- public static final String NEW_OPER_2 = "newOper2";
+ private static final String NORMALIZE_INTERFACE_TYPE = "/mock/serviceTemplate/normalizeInterfaceType.yaml";
+ private static final String NEW_OPER_1 = "newOper1";
+ private static final String NEW_OPER_2 = "newOper2";
@Test
- public void getNormalizeInterfaceTypesTest() throws IOException {
- ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- try (InputStream yamlFile = toscaExtensionYamlUtil
- .loadYamlFileIs(NORMALIZE_INTERFACE_TYPE)) {
+ void getNormalizeInterfaceTypesTest() throws IOException {
+ final ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (final InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(NORMALIZE_INTERFACE_TYPE)) {
- ServiceTemplate serviceTemplateFromYaml =
- toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+ ServiceTemplate serviceTemplateFromYaml = toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
Map<String, InterfaceType> normalizeInterfaceTypes = serviceTemplateFromYaml.getNormalizeInterfaceTypes();
- Assert.assertNotNull(normalizeInterfaceTypes);
+ assertNotNull(normalizeInterfaceTypes);
InterfaceType interfaceNoOper = normalizeInterfaceTypes.get(INTERFACE_NO_OPER);
- Assert.assertNotNull(interfaceNoOper);
- Assert.assertEquals(LIFECYCLE_STANDARD, interfaceNoOper.getDerived_from());
- Assert.assertNull(interfaceNoOper.getOperations());
+ assertNotNull(interfaceNoOper);
+ assertEquals(LIFECYCLE_STANDARD, interfaceNoOper.getDerived_from());
+ assertNull(interfaceNoOper.getOperations());
InterfaceType interfaceWithOper = normalizeInterfaceTypes.get(INTERFACE_WITH_OPER);
- Assert.assertNotNull(interfaceWithOper);
- Assert.assertEquals(LIFECYCLE_STANDARD, interfaceWithOper.getDerived_from());
- Assert.assertNotNull(interfaceWithOper.getOperations());
- Assert.assertEquals(2, interfaceWithOper.getOperations().size());
- Assert.assertNull(interfaceWithOper.getOperations().get(NEW_OPER_1));
- Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2));
- Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2).getDescription());
+ assertNotNull(interfaceWithOper);
+ assertEquals(LIFECYCLE_STANDARD, interfaceWithOper.getDerived_from());
+ assertNotNull(interfaceWithOper.getOperations());
+ assertEquals(2, interfaceWithOper.getOperations().size());
+ assertNull(interfaceWithOper.getOperations().get(NEW_OPER_1));
+ assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2));
+ assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2).getDescription());
}
+ }
+ @Test
+ void shouldHaveValidGettersAndSetters() {
+ assertThat(ServiceTemplate.class, hasValidGettersAndSettersExcluding("imports", "normalizeInterfaceTypes"));
}
@Test
- public void shouldHaveValidGettersAndSetters() {
- assertThat(ServiceTemplate.class,
- hasValidGettersAndSettersExcluding("imports", "normalizeInterfaceTypes"));
+ void addInterfaceTypeTest() {
+ final ServiceTemplate serviceTemplateFromYaml = new ServiceTemplate();
+ serviceTemplateFromYaml.addInterfaceType("mock", new InterfaceType());
+ assertEquals(1, serviceTemplateFromYaml.getInterface_types().size());
+ serviceTemplateFromYaml.addInterfaceType("mock", new InterfaceType());
+ assertEquals(1, serviceTemplateFromYaml.getInterface_types().size());
}
}