diff options
14 files changed, 130 insertions, 37 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()); } } diff --git a/zusammen-lib/pom.xml b/zusammen-lib/pom.xml index fbba028..20c4afc 100644 --- a/zusammen-lib/pom.xml +++ b/zusammen-lib/pom.xml @@ -30,7 +30,7 @@ </parent> <properties> - <zusammen.version>1.0.1</zusammen.version> + <zusammen.version>1.0.2</zusammen.version> <zusammen-state-store.version>1.0.3</zusammen-state-store.version> <zusammen-collaboration-store.version>1.0.3</zusammen-collaboration-store.version> <zusammen-index-store.version>1.0.0</zusammen-index-store.version> diff --git a/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/persistence/ZusammenConnector.java b/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/persistence/ZusammenConnector.java index 88edfaf..3379efe 100644 --- a/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/persistence/ZusammenConnector.java +++ b/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/persistence/ZusammenConnector.java @@ -46,6 +46,8 @@ public interface ZusammenConnector { Id createItem(SessionContext context, Info info); + Id createItem(SessionContext context, Id itemId, Info info); + void deleteItem(SessionContext context, Id itemId); void updateItem(SessionContext context, Id itemId, Info info); @@ -57,6 +59,8 @@ public interface ZusammenConnector { Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData); + Id createVersion(SessionContext context, Id itemId, Id versionId, Id baseVersionId, ItemVersionData itemVersionData); + void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData); ItemVersion getVersion(SessionContext context, Id itemId, Id versionId); diff --git a/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/persistence/impl/ZusammenConnectorImpl.java b/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/persistence/impl/ZusammenConnectorImpl.java index 55446bb..ce30114 100644 --- a/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/persistence/impl/ZusammenConnectorImpl.java +++ b/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/persistence/impl/ZusammenConnectorImpl.java @@ -88,7 +88,6 @@ public class ZusammenConnectorImpl implements ZusammenConnector { return getResponseValue(response, String.format("get item %s", itemId)); } - @Override public Id createItem(SessionContext context, Info info) { Response<Id> response = itemAdaptorFactory.createInterface(context).create(context, info); @@ -96,6 +95,12 @@ public class ZusammenConnectorImpl implements ZusammenConnector { } @Override + public Id createItem(SessionContext context, Id itemId, Info info) { + Response<Id> response = itemAdaptorFactory.createInterface(context).create(context, itemId, info); + return getResponseValue(response, String.format("create item with id %s", itemId)); + } + + @Override public void deleteItem(SessionContext context, Id itemId) { Response<Void> response = itemAdaptorFactory.createInterface(context).delete(context, itemId); getResponseValue(response, String.format("get item %s", itemId)); @@ -130,6 +135,14 @@ public class ZusammenConnectorImpl implements ZusammenConnector { } @Override + public Id createVersion(SessionContext context, Id itemId, Id versionId, Id baseVersionId, ItemVersionData itemVersionData) { + Response<Id> response = + versionAdaptorFactory.createInterface(context).create(context, itemId, versionId, baseVersionId, itemVersionData); + return getResponseValue(response, + String.format("create version with id %s for item %s based on version %s", versionId, itemId, baseVersionId)); + } + + @Override public void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData) { Response<Void> response = versionAdaptorFactory.createInterface(context).update(context, itemId, versionId, itemVersionData); diff --git a/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/services/ZusammenAdaptor.java b/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/services/ZusammenAdaptor.java index c0f701f..5aa9e1e 100644 --- a/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/services/ZusammenAdaptor.java +++ b/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/services/ZusammenAdaptor.java @@ -46,6 +46,8 @@ public interface ZusammenAdaptor { Id createItem(SessionContext context, Info info); + Id createItem(SessionContext context, Id itemId, Info info); + void updateItem(SessionContext context, Id itemId, Info info); Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId); @@ -54,6 +56,8 @@ public interface ZusammenAdaptor { Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData); + Id createVersion(SessionContext context, Id itemId, Id versionId, Id baseVersionId, ItemVersionData itemVersionData); + void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData); ItemVersion getVersion(SessionContext context, Id itemId, Id versionId); diff --git a/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImpl.java b/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImpl.java index 4fcd022..8b33256 100644 --- a/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImpl.java +++ b/zusammen-lib/src/main/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImpl.java @@ -186,6 +186,11 @@ public class ZusammenAdaptorImpl implements ZusammenAdaptor { } @Override + public Id createItem(SessionContext context, Id itemId, Info info) { + return connector.createItem(context, itemId, info); + } + + @Override public void deleteItem(SessionContext context, Id itemId) { connector.deleteItem(context, itemId); } @@ -226,6 +231,11 @@ public class ZusammenAdaptorImpl implements ZusammenAdaptor { } @Override + public Id createVersion(SessionContext context, Id itemId, Id versionId, Id baseVersionId, ItemVersionData itemVersionData) { + return connector.createVersion(context, itemId, versionId, baseVersionId, itemVersionData); + } + + @Override public void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData) { connector.updateVersion(context, itemId, versionId, itemVersionData); } |