aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org
diff options
context:
space:
mode:
authormojahidi <mojahidul.islam@amdocs.com>2018-10-10 10:58:39 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-10-10 09:24:45 +0000
commit1eda33de6c88b9c1d6259e74b50c55ab1bb9357a (patch)
tree13ba8ee7905d3eca067fef9616afa2e2ce77b92f /openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org
parent30bcbe8f02ea5fec868d0986c0b5185f8af7a5c7 (diff)
Increased UT coverage -versioning-api-types
Increased UT coverage openecomp-sdc-versioning-api-types Change-Id: I28098e79848315076e75777e957a5dfe6f1eb481 Issue-ID: SDC-1673 Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org')
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionInfoDaoImplStub.java51
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionableEntityImplStub.java53
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersioningUtilTest.java159
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/types/ItemTest.java56
4 files changed, 319 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionInfoDaoImplStub.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionInfoDaoImplStub.java
new file mode 100644
index 0000000000..d5799b11fe
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionInfoDaoImplStub.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * Copyright © 2017-2018 European Support Limited
+ *
+ * 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.
+ *
+ */
+
+package org.openecomp.sdc.versioning;
+
+import org.openecomp.core.dao.BaseDao;
+
+import java.util.Collection;
+
+public class VersionInfoDaoImplStub implements BaseDao<VersionableEntityImplStub> {
+
+ @Override
+ public Collection<VersionableEntityImplStub> list(VersionableEntityImplStub entity) {
+ return null;
+ }
+
+ @Override
+ public void create(VersionableEntityImplStub entity) {
+
+ }
+
+ @Override
+ public void update(VersionableEntityImplStub entity) {
+
+ }
+
+ @Override
+ public VersionableEntityImplStub get(VersionableEntityImplStub entity) {
+ return null;
+ }
+
+ @Override
+ public void delete(VersionableEntityImplStub entity) {
+
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionableEntityImplStub.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionableEntityImplStub.java
new file mode 100644
index 0000000000..4c429be1b2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersionableEntityImplStub.java
@@ -0,0 +1,53 @@
+/*
+ *
+ * Copyright © 2017-2018 European Support Limited
+ *
+ * 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.
+ *
+ */
+
+package org.openecomp.sdc.versioning;
+
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
+
+public class VersionableEntityImplStub implements VersionableEntity {
+ @Override
+ public String getEntityType() {
+ return "entityType";
+ }
+
+ @Override
+ public String getFirstClassCitizenId() {
+ return "firstClassCitizenId";
+ }
+
+ @Override
+ public String getId() {
+ return "id";
+ }
+
+ @Override
+ public void setId(String id) {
+ }
+
+ @Override
+ public Version getVersion() {
+ return new Version();
+ }
+
+ @Override
+ public void setVersion(Version version) {
+
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersioningUtilTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersioningUtilTest.java
new file mode 100644
index 0000000000..7448100792
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/VersioningUtilTest.java
@@ -0,0 +1,159 @@
+
+/*
+ *
+ * Copyright © 2017-2018 European Support Limited
+ *
+ * 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.
+ *
+ */
+
+package org.openecomp.sdc.versioning;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.VersionInfo;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class VersioningUtilTest {
+
+ @Test
+ public void testResolveVersion() {
+ Version version = new Version();
+ version.setMajor(1);
+ version.setMinor(1);
+
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setActiveVersion(version);
+ versionInfo.setViewableVersions(Arrays.asList(version));
+ versionInfo.setLockingUser("user");
+ Version resolveVersion = VersioningUtil.resolveVersion(version, versionInfo, "user");
+ Assert.assertNotNull(resolveVersion);
+ Assert.assertEquals(1,resolveVersion.getMajor());
+ Assert.assertEquals(1,resolveVersion.getMinor());
+
+ }
+
+ @Test(expected = CoreException.class)
+ public void testResolveVersionNegative() {
+ Version version = new Version();
+ version.setMajor(1);
+ version.setMinor(1);
+
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setActiveVersion(version);
+ versionInfo.setViewableVersions(Arrays.asList(new Version()));
+ versionInfo.setLockingUser("user");
+ VersioningUtil.resolveVersion(null, versionInfo, "user");
+
+ }
+
+ @Test
+ public void testResolveVersionFinalOnly() {
+ Version version = new Version();
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setActiveVersion(version);
+ versionInfo.setViewableVersions(Arrays.asList(version));
+ versionInfo.setLatestFinalVersion(version);
+ Assert.assertNotNull(VersioningUtil.resolveVersion(null, versionInfo, true));
+
+ }
+
+ @Test(expected = CoreException.class)
+ public void testResolveVersionWithNonFinalVersions() {
+ Version version = new Version();
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setActiveVersion(version);
+ versionInfo.setViewableVersions(Arrays.asList(new Version()));
+ versionInfo.setLatestFinalVersion(version);
+ VersioningUtil.resolveVersion(version, versionInfo,true);
+ }
+
+ @Test
+ public void testResolveVersionWithoutFinal() {
+ Version version = new Version();
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setActiveVersion(version);
+ versionInfo.setViewableVersions(Arrays.asList(version));
+ Assert.assertNotNull(VersioningUtil.resolveVersion(null, versionInfo, false));
+
+ }
+
+ @Test(expected = CoreException.class)
+ public void testResolveVersionWithoutFinalVersion() {
+ Version version = new Version();
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setActiveVersion(version);
+ versionInfo.setViewableVersions(Arrays.asList(version));
+ VersioningUtil.resolveVersion(null, versionInfo, true);
+
+ }
+
+ @Test(expected = CoreException.class)
+ public void testResolveVersionFinalOnlyNegative() {
+ Version version = new Version();
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setActiveVersion(version);
+ versionInfo.setViewableVersions(Arrays.asList(version));
+ versionInfo.setLatestFinalVersion(version);
+ VersioningUtil.resolveVersion(version, versionInfo, true);
+
+ }
+
+ @Test(expected = CoreException.class)
+ public void testValidateEntityExistence() {
+ VersioningUtil.validateEntityExistence(null, new VersionableEntityImplStub(), "firstClassCitizenType");
+ }
+
+ @Test(expected = CoreException.class)
+ public void testValidateEntitiesExistence() {
+ Set<String> entityIds = new HashSet<>();
+ entityIds.add("id1");
+ entityIds.add("id2");
+ VersioningUtil.validateEntitiesExistence(entityIds, new VersionableEntityImplStub(),
+ new VersionInfoDaoImplStub(),"firstClassCitizenType");
+ }
+
+ @Test(expected = CoreException.class)
+ public void testValidateEntitiesExistenceSizeOne() {
+ Set<String> entityIds = new HashSet<>();
+ entityIds.add("id1");
+ VersioningUtil.validateEntitiesExistence(entityIds, new VersionableEntityImplStub(),
+ new VersionInfoDaoImplStub(),"firstClassCitizenType");
+ }
+
+ @Test(expected = CoreException.class)
+ public void testValidateContainedEntitiesExistence() {
+ Set<String> inputContainedEntityIds = new HashSet<>();
+ inputContainedEntityIds.add("id1");
+ inputContainedEntityIds.add("id2");
+ Set<String> retrievedContainedEntityIds = new HashSet<>();
+ VersioningUtil.validateContainedEntitiesExistence("containedEntityType",
+ inputContainedEntityIds, new VersionableEntityImplStub(), retrievedContainedEntityIds);
+ }
+
+ @Test(expected = CoreException.class)
+ public void testValidateContainedEntitiesExistenceWithIdOne() {
+ Set<String> inputContainedEntityIds = new HashSet<>();
+ inputContainedEntityIds.add("id1");
+ inputContainedEntityIds.add("id2");
+ Set<String> retrievedContainedEntityIds = new HashSet<>();
+ retrievedContainedEntityIds.add("id1");
+ VersioningUtil.validateContainedEntitiesExistence("containedEntityType",
+ inputContainedEntityIds, new VersionableEntityImplStub(), retrievedContainedEntityIds);
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/types/ItemTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/types/ItemTest.java
new file mode 100644
index 0000000000..f69cfcce59
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/test/java/org/openecomp/sdc/versioning/types/ItemTest.java
@@ -0,0 +1,56 @@
+/*
+ *
+ * Copyright © 2017-2018 European Support Limited
+ *
+ * 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.
+ *
+ */
+
+package org.openecomp.sdc.versioning.types;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ItemTest {
+
+ @Test
+ public void testAddVersionStatus() {
+ Item item = new Item();
+ item.addVersionStatus(VersionStatus.Draft);
+ Assert.assertEquals(1, item.getVersionStatusCounters().size());
+ }
+
+ @Test
+ public void testAddProperty() {
+ Item item = new Item();
+ item.setProperties(new HashMap<>());
+ item.addProperty("item1", new Object());
+ Assert.assertEquals(1, item.getProperties().size());
+ }
+ @Test
+ public void testRemoveVersionStatus() {
+ Item item = new Item();
+ Map<VersionStatus, Integer> versionStatusCounters = new EnumMap<>(VersionStatus.class);
+ versionStatusCounters.put(VersionStatus.Draft, 1);
+ item.setVersionStatusCounters(versionStatusCounters);
+ item.removeVersionStatus(VersionStatus.Draft);
+ Assert.assertEquals(0, item.getVersionStatusCounters().size());
+ }
+
+} \ No newline at end of file