diff options
author | 2017-12-20 14:30:43 +0200 | |
---|---|---|
committer | 2017-12-21 11:12:33 +0000 | |
commit | 8e9c0653dd6c6862123c9609ae34e1206d86456e (patch) | |
tree | 5eeef00ec0677133baa439ca8d7ffd7aca4804b6 /openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core | |
parent | 785ebcc95de3e064e843bec04ba7a209d854fc7c (diff) |
Add collaboration feature
Issue-ID: SDC-767
Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core')
3 files changed, 468 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/TestUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/TestUtils.java new file mode 100644 index 0000000000..79e918c808 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/TestUtils.java @@ -0,0 +1,64 @@ +/* + * Copyright © 2016-2017 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.core.zusammen.plugin.collaboration; + +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.UserInfo; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.datatypes.item.ItemVersionData; +import com.amdocs.zusammen.datatypes.item.Relation; + +import java.util.Arrays; + +public class TestUtils { + + public static SessionContext createSessionContext(UserInfo user, String tenant) { + SessionContext context = new SessionContext(); + context.setUser(user); + context.setTenant(tenant); + return context; + } + + public static ElementContext createElementContext(Id itemId, Id versionId) { + ElementContext elementContext = new ElementContext(); + elementContext.setItemId(itemId); + elementContext.setVersionId(versionId); + return elementContext; + } + + public static Info createInfo(String value) { + Info info = new Info(); + info.setName(value); + info.addProperty("Name", "name_" + value); + info.addProperty("Desc", "desc_" + value); + return info; + } + + public static ItemVersion createItemVersion(Id id, Id baseId, String name, boolean dirty) { + ItemVersion version = new ItemVersion(); + version.setId(id); + version.setBaseId(baseId); + ItemVersionData data = new ItemVersionData(); + data.setInfo(TestUtils.createInfo(name)); + data.setRelations(Arrays.asList(new Relation(), new Relation())); + version.setData(data); + return version; + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/VersionCollaborationStoreTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/VersionCollaborationStoreTest.java new file mode 100644 index 0000000000..4c4621e98b --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/VersionCollaborationStoreTest.java @@ -0,0 +1,237 @@ +package org.openecomp.core.zusammen.plugin.collaboration; + +public class VersionCollaborationStoreTest {/* + private static final String TENANT = "test"; + private static final String USER = "ItemStateStoreTest_user"; + private static final SessionContext context = + TestUtils.createSessionContext(new UserInfo(USER), TENANT); + + @Mock + private VersionDao versionDaoMock; + @Mock + private ElementStore elementCollaborationStore; + @Spy + @InjectMocks + private VersionStore versionCollaborationStore; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(versionCollaborationStore.getVersionDao(anyObject())).thenReturn(versionDaoMock); + } +*//* + @Test + public void testListPrivateItemVersions() throws Exception { + testListItemVersions(Space.PRIVATE, USER); + } + + @Test + public void testListPublicItemVersions() throws Exception { + testListItemVersions(Space.PUBLIC, ZusammenPluginConstants.PUBLIC_SPACE); + } + + @Test + public void testIsPrivateItemVersionExist() throws Exception { + testIsItemVersionExist(Space.PRIVATE, USER); + } + + @Test + public void testIsPublicItemVersionExist() throws Exception { + testIsItemVersionExist(Space.PUBLIC, ZusammenPluginConstants.PUBLIC_SPACE); + } + + @Test + public void testIsItemVersionExistWhenNot() throws Exception { + Id itemId = new Id(); + Id versionId = new Id(); + doReturn(Optional.empty()).when(versionDaoMock).get(context, USER, itemId, versionId); + + boolean itemExist = + versionCollaborationStore.isItemVersionExist(context, Space.PRIVATE, itemId, versionId); + Assert.assertFalse(itemExist); + } + + @Test + public void testGetPrivateItemVersion() throws Exception { + testGetItemVersion(Space.PRIVATE, USER); + } + + @Test + public void testGetPublicItemVersion() throws Exception { + testGetItemVersion(Space.PUBLIC, ZusammenPluginConstants.PUBLIC_SPACE); + } + + + @Test + public void testGetNonExistingItemVersion() throws Exception { + Id itemId = new Id(); + Id versionId = new Id(); + doReturn(Optional.empty()).when(versionDaoMock).get(context, USER, itemId, versionId); + + ItemVersion itemVersion = + versionCollaborationStore.getItemVersion(context, Space.PRIVATE, itemId, versionId); + Assert.assertNull(itemVersion); + }*//* + + @Test + public void testCreatePrivateItemVersion() throws Exception { + testCreateItemVersion(Space.PRIVATE, USER, null); + } + + @Test + public void testCreatePrivateItemVersionBasedOn() throws Exception { + testCreateItemVersion(Space.PRIVATE, USER, new Id()); + } + + @Test + public void testCreatePublicItemVersion() throws Exception { + testCreateItemVersion(Space.PUBLIC, ZusammenPluginConstants.PUBLIC_SPACE, null); + } + + @Test + public void testCreatePublicItemVersionBasedOn() throws Exception { + testCreateItemVersion(Space.PUBLIC, ZusammenPluginConstants.PUBLIC_SPACE, new Id()); + } + + @Test + public void testUpdatePrivateItemVersion() throws Exception { + testUpdateItemVersion(Space.PRIVATE, USER); + } + + @Test + public void testUpdatePublicItemVersion() throws Exception { + testUpdateItemVersion(Space.PUBLIC, ZusammenPluginConstants.PUBLIC_SPACE); + } + + @Test + public void testDeletePrivateItemVersion() throws Exception { + testDeleteItemVersion(Space.PRIVATE, USER); + } + + @Test + public void testDeletePublicItemVersion() throws Exception { + testDeleteItemVersion(Space.PUBLIC, ZusammenPluginConstants.PUBLIC_SPACE); + } + + @Test + public void testPublishItemVersionWhenNotDirty() throws Exception { + Id itemId = new Id(); + ItemVersion version = TestUtils.createItemVersion(new Id(), null, "v1", false); + doReturn(Optional.of(version)).when(versionDaoMock).get(context, USER, itemId, version.getId()); + + versionCollaborationStore.publishItemVersion(context, itemId, version.getId(), "message"); + + } +*//* + private void testIsItemVersionExist(Space space, String spaceName) { + Id itemId = new Id(); + ItemVersion retrievedVersion = TestUtils.createItemVersion(new Id(), null, "v1"); + doReturn(Optional.of(retrievedVersion)).when(versionDaoMock) + .get(context, spaceName, itemId, retrievedVersion.getId()); + + boolean itemExist = + versionCollaborationStore + .isItemVersionExist(context, space, itemId, retrievedVersion.getId()); + Assert.assertTrue(itemExist); + } + + private void testGetItemVersion(Space space, String spaceName) throws Exception { + Id itemId = new Id(); + ItemVersion retrievedVersion = TestUtils.createItemVersion(new Id(), null, "v1"); + doReturn(Optional.of(retrievedVersion)).when(versionDaoMock) + .get(context, spaceName, itemId, retrievedVersion.getId()); + + ItemVersion itemVersion = + versionCollaborationStore.getItemVersion(context, space, itemId, retrievedVersion.getId()); + Assert.assertEquals(itemVersion, retrievedVersion); + } + + private void testListItemVersions(Space space, String spaceName) { + Id itemId = new Id(); + ItemVersion v1 = TestUtils.createItemVersion(new Id(), null, "v1"); + ItemVersion v2 = TestUtils.createItemVersion(new Id(), v1.getId(), "v2"); + ItemVersion v3 = TestUtils.createItemVersion(new Id(), v2.getId(), "v3"); + List<ItemVersion> retrievedVersions = Arrays.asList(v1, v2, v3); + doReturn(retrievedVersions).when(versionDaoMock).list(context, spaceName, itemId); + + Collection<ItemVersion> itemVersions = + versionCollaborationStore.listItemVersions(context, space, itemId); + Assert.assertEquals(itemVersions, retrievedVersions); + }*//* + + private void testCreateItemVersion(Space space, String spaceName, Id baseId) { + Id itemId = new Id(); + ItemVersion v1 = TestUtils.createItemVersion(new Id(), baseId, "v1", false); + List<ElementEntity> baseVersionElements = mockVersionElements(spaceName, itemId, baseId); + + ArgumentCaptor<ItemVersion> versionCaptor = ArgumentCaptor.forClass(ItemVersion.class); + + Date creationTime = new Date(); + versionCollaborationStore + .createItemVersion(context, space, itemId, baseId, v1.getId(), v1.getData(), creationTime); + + verify(versionDaoMock).create(eq(context), eq(spaceName), eq(itemId), versionCaptor.capture()); + //baseId, v1.getId(),v1.getData(), creationTime); + + ItemVersion capturedVersion = versionCaptor.getValue(); + Assert.assertEquals(baseId, capturedVersion.getBaseId()); + Assert.assertEquals(v1.getId(), capturedVersion.getId()); + Assert.assertEquals(v1.getData(), capturedVersion.getData()); + Assert.assertEquals(creationTime, capturedVersion.getCreationTime()); +*//* verify(versionDaoMock) + .create(anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), anyObject(), + anyObject());*//* + +*//* if (baseId != null) { + baseVersionElements.forEach(element -> + verify(elementCollaborationStore).create(eq(context), + eq(new ElementEntityContext(spaceName, itemId, v1.getId())), + eq(element))); + } else { + verifyZeroInteractions(elementCollaborationStore); + }*//* + } + + private void testUpdateItemVersion(Space space, String spaceName) { + Id itemId = new Id(); + ItemVersion retrievedVersion = TestUtils.createItemVersion(new Id(), null, "v1", false); + doReturn(Optional.of(retrievedVersion)).when(versionDaoMock) + .get(context, spaceName, itemId, retrievedVersion.getId()); + + ItemVersionData updatedData = new ItemVersionData(); + updatedData.setInfo(TestUtils.createInfo("v1 updated")); + updatedData.setRelations( + Arrays.asList(new Relation(), new Relation(), new Relation(), new Relation())); + versionCollaborationStore.updateItemVersion( + context, space, itemId, retrievedVersion.getId(), updatedData, new Date()); + + *//*verify(versionDaoMock) + .update(context, spaceName, itemId, retrievedVersion.getId(), updatedData, modificationTime);*//* + verify(versionDaoMock) + .update(anyObject(), anyObject(), anyObject(), anyObject()); + + } + + private void testDeleteItemVersion(Space space, String spaceName) { + Id itemId = new Id(); + Id versionId = new Id(); + + List<ElementEntity> versionElements = mockVersionElements(spaceName, itemId, versionId); + versionCollaborationStore.deleteItemVersion(context, space, itemId, versionId); + +*//* versionElements.forEach(element -> + verify(elementCollaborationStore).delete(eq(context), + eq(new ElementEntityContext(spaceName, itemId, versionId)), + eq(element)));*//* + verify(versionDaoMock).delete(context, spaceName, itemId, versionId); + } + + private List<ElementEntity> mockVersionElements(String spaceName, Id itemId, Id versionId) { + ElementEntity elm1 = new ElementEntity(new Id()); + ElementEntity elm2 = new ElementEntity(new Id()); + List<ElementEntity> baseVersionElements = Arrays.asList(elm1, elm2); +*//* doReturn(baseVersionElements).when(elementCollaborationStore) + .list(eq(context), eq(new ElementEntityContext(spaceName, itemId, versionId)));*//* + return baseVersionElements; + }*/ +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/impl/ElementStageStoreImplTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/impl/ElementStageStoreImplTest.java new file mode 100644 index 0000000000..7f137b01b0 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/impl/ElementStageStoreImplTest.java @@ -0,0 +1,167 @@ +package org.openecomp.core.zusammen.plugin.collaboration.impl; + +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.UserInfo; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Resolution; +import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.core.zusammen.plugin.collaboration.TestUtils; +import org.openecomp.core.zusammen.plugin.dao.ElementStageRepository; +import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity; +import org.openecomp.core.zusammen.plugin.dao.types.StageEntity; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.Date; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.same; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ElementStageStoreImplTest { + private static final UserInfo USER = new UserInfo("user"); + private static final SessionContext context = TestUtils.createSessionContext(USER, "test"); + private static final ElementContext elementContext = + TestUtils.createElementContext(new Id(), new Id()); + + @Mock + private ElementStageRepository elementStageRepositoryMock; + @Spy + private ElementStageStoreImpl elementStageStore; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(elementStageStore.getElementStageRepository(anyObject())) + .thenReturn(elementStageRepositoryMock); + } + + @Test + public void testListIds() throws Exception { + + } + + @Test + public void testGet() throws Exception { + + } + + @Test + public void testGetConflicted() throws Exception { + + } + + @Test + public void testHasConflicts() throws Exception { + + } + + @Test + public void testListConflictedDescriptors() throws Exception { + + } + + @Test + public void testCreate() throws Exception { + + } + + @Test + public void testDelete() throws Exception { + + } + + @Test + public void testResolveConflictWhenNotStaged() throws Exception { + doReturn(Optional.empty()) + .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject()); + elementStageStore + .resolveConflict(context, elementContext, new ElementEntity(new Id()), Resolution.YOURS); + } + + @Test + public void testResolveConflictWhenNotConflicted() throws Exception { + Id elementId = new Id(); + StageEntity<ElementEntity> stagedElement = + new StageEntity<>(new ElementEntity(elementId), new Date()); + doReturn(Optional.of(stagedElement)) + .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject()); + elementStageStore + .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS); + } + + @Test + public void testResolveConflictByYours() throws Exception { + Id elementId = new Id(); + StageEntity<ElementEntity> stagedElement = + new StageEntity<>(new ElementEntity(elementId), new Date()); + stagedElement.setAction(Action.UPDATE); + stagedElement.setConflicted(true); + + doReturn(Optional.of(stagedElement)) + .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject()); + + elementStageStore + .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS); + + verify(elementStageRepositoryMock).markAsNotConflicted(same(context), + eq(new ElementEntityContext(USER.getUserName(), elementContext)), + same(stagedElement.getEntity()), same(Action.IGNORE)); + } + + @Test + public void testResolveConflictByYoursWithRelated() throws Exception { + Id elementId = new Id(); + StageEntity<ElementEntity> stagedElement = + new StageEntity<>(new ElementEntity(elementId), new Date()); + stagedElement.setAction(Action.UPDATE); + stagedElement.setConflicted(true); + ElementEntity relatedElement1 = new ElementEntity(new Id()); + ElementEntity relatedElement2 = new ElementEntity(new Id()); + ElementEntity relatedElement3 = new ElementEntity(new Id()); + Set<ElementEntity> relatedElements = new HashSet<>(); + relatedElements.add(relatedElement1); + relatedElements.add(relatedElement2); + relatedElements.add(relatedElement3); + stagedElement.setConflictDependents(relatedElements); + + doReturn(Optional.of(stagedElement)) + .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject()); + + elementStageStore + .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS); + + ElementEntityContext elementEntityContext = + new ElementEntityContext(USER.getUserName(), elementContext); + verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext), + same(stagedElement.getEntity()), same(Action.IGNORE)); + verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext), + same(relatedElement1), same(Action.IGNORE)); + verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext), + same(relatedElement2), same(Action.IGNORE)); + verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext), + same(relatedElement3), same(Action.IGNORE)); + } + + @Test + public void testResolveConflictByTheirs() throws Exception { + + } + + @Test + public void testResolveConflictByTheirsWithRelated() throws Exception { + + } + +}
\ No newline at end of file |