diff options
author | talig <talig@amdocs.com> | 2020-03-30 21:07:49 +0300 |
---|---|---|
committer | talig <talig@amdocs.com> | 2020-03-30 21:07:49 +0300 |
commit | 7b17d6daf1414fc25edcd113d0d4eec5b24abc64 (patch) | |
tree | 55835b4d50d007ec52c89dae16b8e00c587ed584 /versioning-lib | |
parent | 154541d238a390cd25c21fab0c2f585b92011135 (diff) |
Add ability to set item/version Id upon creation
Issue-ID: SDC-2860
Signed-off-by: talig <talig@amdocs.com>
Change-Id: If09337e55cce99462fa05617b8691ce34eabf5b1
Diffstat (limited to 'versioning-lib')
9 files changed, 97 insertions, 35 deletions
diff --git a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/types/InternalItem.java b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/types/InternalItem.java index 2751bfc..4b435fa 100644 --- a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/types/InternalItem.java +++ b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/types/InternalItem.java @@ -29,10 +29,6 @@ import org.onap.sdc.common.versioning.services.types.VersionStatus; @Getter public class InternalItem extends Item { - public void setId(String id) { - this.id = id; - } - public void setCreationTime(Date creationTime) { this.creationTime = creationTime; } @@ -67,6 +63,7 @@ public class InternalItem extends Item { } public void populateExternalFields(Item item) { + setId(item.getId()); setType(item.getType()); setName(item.getName()); setOwner(item.getOwner()); diff --git a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/types/InternalVersion.java b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/types/InternalVersion.java index 91b0c1e..ac49d6f 100644 --- a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/types/InternalVersion.java +++ b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/types/InternalVersion.java @@ -23,10 +23,6 @@ import org.onap.sdc.common.versioning.services.types.VersionStatus; public class InternalVersion extends Version { - public void setId(String id) { - this.id = id; - } - public void setBaseId(String baseId) { this.baseId = baseId; } @@ -52,6 +48,7 @@ public class InternalVersion extends Version { } public void populateExternalFields(Version version) { + setId(version.getId()); setDescription(version.getDescription()); version.getProperties().forEach(this::addProperty); } diff --git a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/zusammen/ItemZusammenDao.java b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/zusammen/ItemZusammenDao.java index d2c755b..33abe1f 100644 --- a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/zusammen/ItemZusammenDao.java +++ b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/zusammen/ItemZusammenDao.java @@ -56,8 +56,12 @@ public class ItemZusammenDao implements ItemDao { @Override public InternalItem create(InternalItem item) { - Id itemId = zusammenAdaptor.createItem(contextCreator.create(), mapToZusammenItemInfo(item)); - item.setId(itemId.getValue()); + if (item.getId() == null) { + Id itemId = zusammenAdaptor.createItem(contextCreator.create(), mapToZusammenItemInfo(item)); + item.setId(itemId.getValue()); + } else { + zusammenAdaptor.createItem(contextCreator.create(), new Id(item.getId()), mapToZusammenItemInfo(item)); + } return item; } diff --git a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/zusammen/VersionZusammenDao.java b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/zusammen/VersionZusammenDao.java index c4118e2..55f1ba5 100644 --- a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/zusammen/VersionZusammenDao.java +++ b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/persistence/zusammen/VersionZusammenDao.java @@ -62,10 +62,16 @@ public class VersionZusammenDao implements VersionDao { @Override public InternalVersion create(String itemId, InternalVersion version) { - Id versionId = zusammenAdaptor.createVersion(contextCreator.create(), new Id(itemId), - version.getBaseId() == null ? null : new Id(version.getBaseId()), mapToZusammenVersion(version)); - - version.setId(versionId.getValue()); + Id baseVersionId = version.getBaseId() == null ? null : new Id(version.getBaseId()); + if (version.getId() == null) { + Id versionId = zusammenAdaptor.createVersion(contextCreator.create(), new Id(itemId), baseVersionId, + mapToZusammenVersion(version)); + version.setId(versionId.getValue()); + } else { + zusammenAdaptor + .createVersion(contextCreator.create(), new Id(itemId), new Id(version.getId()), baseVersionId, + mapToZusammenVersion(version)); + } return version; } diff --git a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/services/types/Item.java b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/services/types/Item.java index 853d30d..3d53d90 100644 --- a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/services/types/Item.java +++ b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/services/types/Item.java @@ -26,8 +26,8 @@ import lombok.Setter; @Getter public class Item { - - protected String id; + @Setter + private String id; protected Date creationTime; protected Date modificationTime; protected ItemStatus status = ItemStatus.ACTIVE; diff --git a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/services/types/Version.java b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/services/types/Version.java index 5cb0b69..ad5fd1f 100644 --- a/versioning-lib/src/main/java/org/onap/sdc/common/versioning/services/types/Version.java +++ b/versioning-lib/src/main/java/org/onap/sdc/common/versioning/services/types/Version.java @@ -30,8 +30,8 @@ import lombok.Setter; @Getter @NoArgsConstructor public class Version { - - protected String id; + @Setter + private String id; protected String baseId; protected String name; protected VersionStatus status = VersionStatus.Draft; diff --git a/versioning-lib/src/test/java/org/onap/sdc/common/versioning/persistence/zusammen/ItemZusammenDaoTest.java b/versioning-lib/src/test/java/org/onap/sdc/common/versioning/persistence/zusammen/ItemZusammenDaoTest.java index 3b5ab87..b4fe655 100644 --- a/versioning-lib/src/test/java/org/onap/sdc/common/versioning/persistence/zusammen/ItemZusammenDaoTest.java +++ b/versioning-lib/src/test/java/org/onap/sdc/common/versioning/persistence/zusammen/ItemZusammenDaoTest.java @@ -169,6 +169,37 @@ public class ItemZusammenDaoTest { assertEquals(item.getVersionStatusCounters(), inputItem.getVersionStatusCounters()); } + + @Test + public void testCreateWithId() { + String itemId = "itemId"; + + InternalItem inputItem = new InternalItem(); + inputItem.setId(itemId); + inputItem.setName("vsp1"); + inputItem.setDescription("VSP 1"); + inputItem.setType("vsp"); + + ArgumentCaptor<Info> capturedZusammenInfo = ArgumentCaptor.forClass(Info.class); + + doReturn(new Id(itemId)).when(zusammenAdaptorMock) + .createItem(eq(SESSION_CONTEXT), eq(new Id(inputItem.getId())),capturedZusammenInfo.capture()); + + InternalItem item = itemDao.create(inputItem); + + Info capturedInfo = capturedZusammenInfo.getValue(); + assertEquals(capturedInfo.getName(), inputItem.getName()); + assertEquals(capturedInfo.getDescription(), inputItem.getDescription()); + assertEquals(capturedInfo.getProperty(ITEM_TYPE), inputItem.getType()); + assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES), inputItem.getVersionStatusCounters()); + + assertEquals(item.getId(), itemId); + assertEquals(item.getName(), inputItem.getName()); + assertEquals(item.getDescription(), inputItem.getDescription()); + assertEquals(item.getType(), inputItem.getType()); + assertEquals(item.getVersionStatusCounters(), inputItem.getVersionStatusCounters()); + } + @Test public void testUpdate() { InternalItem item = new InternalItem(); diff --git a/versioning-lib/src/test/java/org/onap/sdc/common/versioning/persistence/zusammen/VersionZusammenDaoTest.java b/versioning-lib/src/test/java/org/onap/sdc/common/versioning/persistence/zusammen/VersionZusammenDaoTest.java index bb96472..ee6ca86 100644 --- a/versioning-lib/src/test/java/org/onap/sdc/common/versioning/persistence/zusammen/VersionZusammenDaoTest.java +++ b/versioning-lib/src/test/java/org/onap/sdc/common/versioning/persistence/zusammen/VersionZusammenDaoTest.java @@ -156,6 +156,32 @@ public class VersionZusammenDaoTest { } @Test + public void testCreateWithId() { + String itemId = "itemId"; + String versionId = "versionId"; + InternalVersion version = new InternalVersion(); + version.setId(versionId); + version.setName("1.0"); + version.setDescription("version description"); + version.setStatus(VersionStatus.Draft); + + ArgumentCaptor<ItemVersionData> capturedZusammenVersion = ArgumentCaptor.forClass(ItemVersionData.class); + + doReturn(new Id(versionId)).when(zusammenAdaptorMock) + .createVersion(eq(SESSION_CONTEXT), eq(new Id(itemId)), eq(new Id(version.getId())), isNull(), + capturedZusammenVersion.capture()); + + versionDao.create(itemId, version); + + Assert.assertEquals(version.getId(), versionId); + + Info capturedInfo = capturedZusammenVersion.getValue().getInfo(); + Assert.assertEquals(capturedInfo.getName(), version.getName()); + Assert.assertEquals(capturedInfo.getDescription(), version.getDescription()); + Assert.assertEquals(VersionStatus.valueOf(capturedInfo.getProperty(STATUS_PROPERTY)), version.getStatus()); + } + + @Test public void testUpdate() { String itemId = "itemId"; InternalVersion version = new InternalVersion(); diff --git a/versioning-lib/src/test/java/org/onap/sdc/common/versioning/services/impl/VersioningManagerImplTest.java b/versioning-lib/src/test/java/org/onap/sdc/common/versioning/services/impl/VersioningManagerImplTest.java index 9901266..29b8220 100644 --- a/versioning-lib/src/test/java/org/onap/sdc/common/versioning/services/impl/VersioningManagerImplTest.java +++ b/versioning-lib/src/test/java/org/onap/sdc/common/versioning/services/impl/VersioningManagerImplTest.java @@ -16,14 +16,17 @@ package org.onap.sdc.common.versioning.services.impl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Optional; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdc.common.versioning.persistence.ItemDao; @@ -32,8 +35,6 @@ import org.onap.sdc.common.versioning.persistence.types.InternalVersion; import org.onap.sdc.common.versioning.services.VersioningManager; import org.onap.sdc.common.versioning.services.types.Version; -import static org.junit.Assert.*; - @RunWith(MockitoJUnitRunner.class) public class VersioningManagerImplTest { @@ -43,13 +44,8 @@ public class VersioningManagerImplTest { private VersionDao versionDao; @Mock private VersionCalculator versionCalculator; - - private VersioningManager versioningManager; - - @Before - public void initVersioningManager() { - versioningManager = new VersioningManagerImpl(versionDao, versionCalculator, itemDao); - } + @InjectMocks + private VersioningManagerImpl versioningManager; @Test public void testList() { @@ -83,15 +79,20 @@ public class VersioningManagerImplTest { @Test public void testUpdate() { - String blaBla = "blaBla"; + String itemId = "itemId"; + String versionId = "versionId"; InternalVersion internalVersion = new InternalVersion(); - internalVersion.setId(blaBla); - when(versionDao.get(blaBla, blaBla)).thenReturn(Optional.of(internalVersion)); + internalVersion.setId(versionId); + + when(versionDao.get(itemId, versionId)).thenReturn(Optional.of(internalVersion)); + Version version = new Version(); - version.setDescription(blaBla); - Version updatedVersion = versioningManager.update(blaBla, blaBla, version); + version.setId(versionId); + version.setDescription("version desc"); + Version updatedVersion = versioningManager.update(itemId, versionId, version); + assertNotNull(updatedVersion); - assertEquals(blaBla, updatedVersion.getId()); - assertEquals(blaBla, updatedVersion.getDescription()); + assertEquals(versionId, updatedVersion.getId()); + assertEquals(version.getDescription(), updatedVersion.getDescription()); } } |