aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Puzikov <d.puzikov2@partner.samsung.com>2020-04-02 19:03:21 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-04-07 14:44:56 +0000
commite69b87493fb84ef585d02b03d02ec8cc1f819381 (patch)
tree078316c8ec6f33e7632848ffbab75f785e7329c3
parentd1b56d9b7382b8ca53a4006e93c6f35aaae611c0 (diff)
More unit tests added
Unused constant removed. Error logging added. Change-Id: I91dca825e54ffd8f11a69344d6bb00b4e70dbea1 Issue-ID: SDC-2869 Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml6
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java18
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImplTest.java453
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImplTest.java82
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImplTest.java91
5 files changed, 637 insertions, 13 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml
index dace713fa0..aec40f4d33 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml
@@ -37,6 +37,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.jmockit</groupId>
+ <artifactId>jmockit</artifactId>
+ <version>${jmockit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java
index 410b7d2f8f..5fe48ff7ca 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.versioning.impl;
import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.versioning.VersionCalculator;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
@@ -29,20 +31,12 @@ import java.util.HashSet;
import java.util.Set;
public class VersionCalculatorImpl implements VersionCalculator {
+ private static final Logger LOGGER = LoggerFactory.getLogger(VersionCalculatorImpl.class);
private static final String INITIAL_VERSION = "1.0";
private static final String VERSION_STRING_VIOLATION_MSG =
"Version string must be in the format of: {integer}.{integer}";
- private static final String PARENT_LEVEL_VERSION_CANNOT_BE_CREATED_FROM_TOP_LEVEL =
- "Creation of parent level version on top level version is invalid.";
- private static final String SUB_LEVEL_VERSION_CANNOT_BE_CREATED_FROM_LOWEST_LEVEL =
- "Creation of parent level version on top level version is invalid.";
-
- private static final String VERSION_CALCULATION_ERROR_MSG =
- "Version calculation error.";
-
- private static final String INVALID_CREATION_METHOD_MSG = "Invalid creation method-";
-
+ private static final String INVALID_CREATION_METHOD_MSG = "Invalid creation method";
@Override
public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
@@ -85,12 +79,10 @@ public class VersionCalculatorImpl implements VersionCalculator {
optionalCreationMethods.add(versionCreationMethod);
}
} catch (IllegalArgumentException iae) {
- //not a valid creation method.
+ LOGGER.error("{}:{}", INVALID_CREATION_METHOD_MSG, versionCreationMethod.name(), iae);
}
}
}
version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods);
-
}
-
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImplTest.java
new file mode 100644
index 0000000000..18a6081b6c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImplTest.java
@@ -0,0 +1,453 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Samsung 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.versioning.impl;
+
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.isA;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import mockit.Deencapsulation;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.versioning.ActionVersioningManager;
+import org.openecomp.sdc.versioning.AsdcItemManager;
+import org.openecomp.sdc.versioning.VersionCalculator;
+import org.openecomp.sdc.versioning.dao.VersionDao;
+import org.openecomp.sdc.versioning.dao.VersionInfoDao;
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
+import org.openecomp.sdc.versioning.dao.types.UserCandidateVersion;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+import org.openecomp.sdc.versioning.types.VersionInfo;
+import org.openecomp.sdc.versioning.types.VersionableEntityAction;
+import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ActionVersioningManagerImplTest {
+ @Mock
+ private VersionInfoDao versionInfoDao;
+ @Mock
+ private VersionInfoDeletedDao versionInfoDeletedDao;
+ @Mock
+ private VersionDao versionDao;
+ @Mock
+ private VersionCalculator versionCalculator;
+ @Mock
+ private AsdcItemManager asdcItemManager;
+
+ private ActionVersioningManager actionVersioningManager;
+ private VersionInfoEntity versionInfoEntity;
+
+ @Before
+ public void setUp(){
+ actionVersioningManager = createSUT();
+
+ versionInfoEntity = new VersionInfoEntity();
+ versionInfoEntity.setActiveVersion(new Version());
+ versionInfoEntity.setStatus(VersionStatus.Draft);
+ versionInfoEntity.setCandidate(new UserCandidateVersion("mock-user", new Version()));
+ }
+
+ private ActionVersioningManager createSUT() {
+ return new ActionVersioningManagerImpl(
+ versionInfoDao,
+ versionInfoDeletedDao,
+ versionDao,
+ versionCalculator,
+ asdcItemManager
+ );
+ }
+
+ @Test
+ public void testCtor() {
+ assertThat(actionVersioningManager, isA(ActionVersioningManager.class));
+ }
+
+ @Test
+ public void testlistDeletedEntitiesVersionInfo() {
+ when(versionInfoDeletedDao.list(any(VersionInfoDeletedEntity.class))).thenReturn(new ArrayList<>());
+
+ Map<String, VersionInfo> result = actionVersioningManager.listDeletedEntitiesVersionInfo(
+ "mock-type",
+ "mock-user",
+ VersionableEntityAction.Read
+ );
+
+ assertThat(result, notNullValue());
+ }
+
+ @Test
+ public void testList() {
+ when(versionDao.list(anyString())).thenReturn(new ArrayList<>());
+
+ List<Version> result = actionVersioningManager.list("mock-id");
+
+ assertThat(result, notNullValue());
+ }
+
+ @Test
+ public void testGet() {
+ when(versionDao.get(anyString(), any(Version.class))).thenReturn(Optional.of(new Version()));
+
+ Version result = actionVersioningManager.get("mock-id", new Version());
+
+ assertThat(result, isA(Version.class));
+ }
+
+ @Test
+ public void testListEntitiesVersionInfo() {
+ when(versionInfoDao.list(any(VersionInfoEntity.class))).thenReturn(new ArrayList<>());
+
+ Map<String, VersionInfo> result = actionVersioningManager.listEntitiesVersionInfo(
+ "mock-type",
+ "mock-user",
+ VersionableEntityAction.Read
+ );
+
+ assertThat(result, notNullValue());
+ }
+
+ @Test
+ public void testGetEntityVersionInfo() {
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ VersionInfo result = actionVersioningManager.getEntityVersionInfo(
+ "mock-type",
+ "mock-id",
+ "mock-user",
+ VersionableEntityAction.Read
+ );
+
+ assertThat(result, notNullValue());
+ }
+
+ @Test
+ public void testCreate() {
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(null);
+
+ Version result = actionVersioningManager.create(
+ "mock-type",
+ "mock-id",
+ "mock-user"
+ );
+
+ assertThat(result, notNullValue());
+ }
+
+ @Test(expected = CoreException.class)
+ public void testCreateFailed() {
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(new VersionInfoEntity());
+
+ actionVersioningManager.create(
+ "mock-type",
+ "mock-id",
+ "mock-user"
+ );
+
+ fail("Should throw CoreException");
+ }
+
+ @Test
+ public void testCreateAlt() {
+ Version result = actionVersioningManager.create(
+ "mock-type",
+ new Version(),
+ VersionCreationMethod.minor
+ );
+
+ assertThat(result, notNullValue());
+ }
+
+ @Test
+ public void testRegister() {
+ actionVersioningManager.register(
+ "mock-type",
+ new VersionableEntityMetadata(
+ "mock-name",
+ "mock-id-name",
+ "mock-ver-id-name"
+ )
+ );
+ Map<String, Set<VersionableEntityMetadata>> entities = Deencapsulation.getField(actionVersioningManager, "VERSIONABLE_ENTITIES");
+ assertThat(entities, notNullValue());
+ assertThat(entities.size(), is(1));
+ }
+
+ @Test
+ public void testDelete() {
+ versionInfoEntity.setStatus(VersionStatus.Certified);
+
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ actionVersioningManager.delete(
+ "moct-type",
+ "mock-id",
+ "mock-user"
+ );
+
+ verify(versionInfoDeletedDao).create(any(VersionInfoDeletedEntity.class));
+ verify(versionInfoDao).delete(any(VersionInfoEntity.class));
+ }
+
+ @Test(expected = CoreException.class)
+ public void testDeleteLocked() {
+ versionInfoEntity.setStatus(VersionStatus.Locked);
+ UserCandidateVersion userCandidateVersion = new UserCandidateVersion("mock-user", new Version());
+ versionInfoEntity.setCandidate(userCandidateVersion);
+
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ actionVersioningManager.delete(
+ "moct-type",
+ "mock-id",
+ "mock-user"
+ );
+ fail("Should throw CoreException");
+ }
+
+ @Test
+ public void testUndoDelete() {
+ when(versionInfoDeletedDao.get(any(VersionInfoDeletedEntity.class))).thenReturn(new VersionInfoDeletedEntity());
+
+ actionVersioningManager.undoDelete(
+ "mock-type",
+ "mock-id",
+ "mock-user"
+ );
+
+ verify(versionInfoDao).create(any(VersionInfoEntity.class));
+ verify(versionInfoDeletedDao).delete(any(VersionInfoDeletedEntity.class));
+ }
+
+ @Test(expected = CoreException.class)
+ public void testUndoDeleteFail() {
+ when(versionInfoDeletedDao.get(any(VersionInfoDeletedEntity.class))).thenReturn(null);
+
+ actionVersioningManager.undoDelete(
+ "mock-type",
+ "mock-id",
+ "mock-user"
+ );
+
+ fail("Should throw CoreException");
+ }
+
+ @Test
+ public void testCheckout() {
+ versionInfoEntity.setStatus(VersionStatus.Certified);
+
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ Version result = actionVersioningManager.checkout(
+ "moct-type",
+ "mock-id",
+ "mock-user"
+ );
+
+ assertThat(result, notNullValue());
+ assertThat(result.getStatus(), is(VersionStatus.Draft));
+ }
+
+ @Test(expected = CoreException.class)
+ public void testCheckoutFailNotFound() {
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(null);
+
+ actionVersioningManager.checkout(
+ "moct-type",
+ "mock-id",
+ "mock-user"
+ );
+
+ fail("Should throw CoreException");
+ }
+
+ @Test(expected = CoreException.class)
+ public void testCheckoutLockedFail() {
+ versionInfoEntity.setStatus(VersionStatus.Locked);
+
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ actionVersioningManager.checkout(
+ "mock-type",
+ "mock-id",
+ "mock-user"
+ );
+
+ fail("Should throw CoreException");
+ }
+
+ @Test
+ public void testUndoCheckout() {
+ versionInfoEntity.setStatus(VersionStatus.Locked);
+
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ Version result = actionVersioningManager.undoCheckout(
+ "mock-type",
+ "mock-id",
+ "mock-user"
+ );
+ assertThat(result, notNullValue(Version.class));
+ }
+
+ @Test
+ public void testCheckin() {
+ versionInfoEntity.setStatus(VersionStatus.Locked);
+
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ Version result = actionVersioningManager.checkin(
+ "mock-type",
+ "mock-id",
+ "mock-user",
+ "mock-desc"
+ );
+ assertThat(result, notNullValue(Version.class));
+ }
+
+ @Test(expected = CoreException.class)
+ public void testCheckinDraft() {
+ versionInfoEntity.setStatus(VersionStatus.Draft);
+
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ Version result = actionVersioningManager.checkin(
+ "mock-type",
+ "mock-id",
+ "mock-user",
+ "mock-desc"
+ );
+ assertThat(result, notNullValue(Version.class));
+ }
+
+ @Test
+ public void testForceSync() {
+ actionVersioningManager.forceSync("mock-id", new Version());
+ }
+
+ @Test
+ public void testSubmit() {
+ when(versionDao.get(anyString(), any(Version.class))).thenReturn(Optional.of(new Version()));
+
+ actionVersioningManager.submit(
+ "mock-type",
+ new Version(),
+ "mock-desc"
+ );
+ verify(versionDao).update(anyString(), any(Version.class));
+ verify(asdcItemManager).updateVersionStatus(anyString(), any(VersionStatus.class), any(VersionStatus.class));
+ }
+
+ @Test
+ public void testSubmitAlt() {
+ versionInfoEntity.setStatus(VersionStatus.Draft);
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ Version result = actionVersioningManager.submit(
+ "mock-type",
+ "mock-id",
+ "mock-user",
+ "mock-desc"
+ );
+ assertThat(result, notNullValue(Version.class));
+ }
+
+ @Test(expected = CoreException.class)
+ public void testSubmitAltFailNotFound() {
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(null);
+
+ actionVersioningManager.submit(
+ "mock-type",
+ "mock-id",
+ "mock-user",
+ "mock-desc"
+ );
+
+ fail("Should throw CoreException");
+ }
+
+ @Test(expected = CoreException.class)
+ public void testSubmitAltFailCertified() {
+ versionInfoEntity.setStatus(VersionStatus.Certified);
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ actionVersioningManager.submit(
+ "mock-type",
+ "mock-id",
+ "mock-user",
+ "mock-desc"
+ );
+
+ fail("Should throw CoreException");
+ }
+
+ @Test(expected = CoreException.class)
+ public void testSubmitAltFailLocked() {
+ versionInfoEntity.setStatus(VersionStatus.Locked);
+ when(versionInfoDao.get(any(VersionInfoEntity.class))).thenReturn(versionInfoEntity);
+
+ actionVersioningManager.submit(
+ "mock-type",
+ "mock-id",
+ "mock-user",
+ "mock-desc"
+ );
+
+ fail("Should throw CoreException");
+ }
+
+ @Test
+ public void testSync() {
+ actionVersioningManager.sync("mock-id", new Version());
+ verify(versionDao).sync(anyString(), any(Version.class));
+ }
+
+ @Test
+ public void testRevert() {
+ actionVersioningManager.revert("mock-id", new Version(), "mock-rev-id");
+ verify(versionDao).revert(anyString(), any(Version.class), anyString());
+ }
+
+ @Test
+ public void testListRevisions() {
+ actionVersioningManager.listRevisions("mock-id", new Version());
+ verify(versionDao).listRevisions(anyString(), any(Version.class));
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImplTest.java
new file mode 100644
index 0000000000..bb6420a3aa
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImplTest.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Samsung 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.versioning.impl;
+
+import static junit.framework.TestCase.fail;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+
+public class MajorVersionCalculatorImplTest {
+ private MajorVersionCalculatorImpl majorVersionCalculator;
+
+ @Before
+ public void setUp() {
+ majorVersionCalculator = new MajorVersionCalculatorImpl();
+ }
+
+ @Test
+ public void testCalculateNullBaseVer() {
+ String result = majorVersionCalculator.calculate(null, VersionCreationMethod.major);
+
+ assertThat(result, is("1.0"));
+ }
+
+ @Test
+ public void testCalculateNotNullBaseVer() {
+ String result = majorVersionCalculator.calculate("2.0", VersionCreationMethod.major);
+
+ assertThat(result, is("3.0"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCalculateFail() {
+ majorVersionCalculator.calculate("1", VersionCreationMethod.major);
+
+ fail("Should throw IllegalArgumentException");
+ }
+
+ @Test
+ public void testInjectAdditionalInfo() {
+ Version version = new Version();
+ version.setAdditionalInfo(new HashMap<>());
+ version.setStatus(VersionStatus.Certified);
+
+ Set<String> versions = new HashSet<>();
+ versions.add("3.0");
+
+ majorVersionCalculator.injectAdditionalInfo(version, versions);
+
+ assertThat(version.getAdditionalInfo(), notNullValue());
+ assertThat(version.getAdditionalInfo().size(), is(1));
+ assertThat(version.getAdditionalInfo().get("OptionalCreationMethods"), is(Collections.singleton(VersionCreationMethod.major)));
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImplTest.java
new file mode 100644
index 0000000000..fe06d47533
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImplTest.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Samsung 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.versioning.impl;
+
+import static junit.framework.TestCase.fail;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+
+public class VersionCalculatorImplTest {
+
+ private VersionCalculatorImpl versionCalculator;
+
+ @Before
+ public void setUp() {
+ versionCalculator = new VersionCalculatorImpl();
+ }
+
+ @Test
+ public void testCalculateNullBaseVer() {
+ String result = versionCalculator.calculate(null, VersionCreationMethod.major);
+
+ assertThat(result, is("1.0"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCalculateFail() {
+ versionCalculator.calculate("2", VersionCreationMethod.major);
+
+ fail("Should throw IllegalArgumentException");
+ }
+
+ @Test
+ public void testCalculateNotNullBaseVerMajor() {
+ String result = versionCalculator.calculate("2.1", VersionCreationMethod.major);
+
+ assertThat(result, is("3.0"));
+ }
+
+ @Test
+ public void testCalculateNotNullBaseVerMinor() {
+ String result = versionCalculator.calculate("2.1", VersionCreationMethod.minor);
+
+ assertThat(result, is("2.2"));
+ }
+
+ @Test
+ public void testInjectAdditionalInfo() {
+ Version version = new Version();
+ version.setAdditionalInfo(new HashMap<>());
+ version.setStatus(VersionStatus.Certified);
+
+ Set<String> versions = new HashSet<>();
+ versions.add("3.0");
+
+ versionCalculator.injectAdditionalInfo(version, versions);
+
+ assertThat(version.getAdditionalInfo(), notNullValue());
+ assertThat(version.getAdditionalInfo().size(), is(1));
+ assertThat(version.getAdditionalInfo().get("OptionalCreationMethods"),
+ is(ImmutableSet.of(VersionCreationMethod.major, VersionCreationMethod.minor)));
+ }
+} \ No newline at end of file