From 2da911f8ba408fbbf3d7639796208078fac28e32 Mon Sep 17 00:00:00 2001 From: vempo Date: Thu, 1 Nov 2018 20:27:39 +0200 Subject: Sorted out unit-test libraries in onboarding Fixed scope, removed junit+tesng combinations, deleted commented-out tests, did minor cleanups. Change-Id: I71d0adf5c1c95435987dbb8b4077cc43bdf09df8 Issue-ID: SDC-1886 Signed-off-by: vempo --- .../openecomp-sdc-versioning-core/pom.xml | 16 +- .../dao/impl/zusammen/ItemZusammenDaoImplTest.java | 103 ++-- .../impl/zusammen/VersionZusammenDaoImplTest.java | 55 +- .../versioning/impl/AsdcItemManagerImplTest.java | 43 +- .../sdc/versioning/impl/ItemManagerImplTest.java | 82 ++- .../versioning/impl/VersioningManagerImplTest.java | 627 ++------------------- 6 files changed, 247 insertions(+), 679 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core') 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 29b79c45cb..6684daad8d 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 @@ -33,27 +33,13 @@ org.mockito - mockito-all + mockito-core test - ${mockito.all.version} - - - org.testng - testng - test - ${testng.version} - - - snakeyaml - org.yaml - - junit junit test - ${junit.version} org.openecomp.sdc diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java index e67dc57de2..6808c958d0 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java @@ -1,20 +1,29 @@ +/* + * Copyright © 2016-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.dao.impl.zusammen; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.openecomp.sdc.versioning.dao.impl.zusammen.TestUtil.createZusammenContext; + import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.item.Info; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.openecomp.core.zusammen.api.ZusammenAdaptor; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdc.versioning.types.ItemStatus; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -24,12 +33,18 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; - -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.openecomp.sdc.versioning.dao.impl.zusammen.TestUtil.createZusammenContext; -import static org.testng.Assert.assertEquals; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdc.versioning.types.ItemStatus; public class ItemZusammenDaoImplTest { @@ -45,7 +60,7 @@ public class ItemZusammenDaoImplTest { @InjectMocks private ItemZusammenDaoImpl itemDao; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); SessionContextProviderFactory.getInstance().createInterface().create(USER, tenant); @@ -79,7 +94,7 @@ public class ItemZusammenDaoImplTest { doReturn(returnedItems).when(zusammenAdaptorMock).listItems(eq(createZusammenContext(USER))); Collection items = itemDao.list(); - Assert.assertEquals(items.size(), 3); + assertEquals(items.size(), 3); Iterator itemIterator = items.iterator(); assertItemEquals(itemIterator.next(), returnedItems.get(0)); @@ -136,17 +151,17 @@ public class ItemZusammenDaoImplTest { Item item = itemDao.create(inputItem); Info capturedInfo = capturedZusammenInfo.getValue(); - Assert.assertEquals(capturedInfo.getName(), inputItem.getName()); - Assert.assertEquals(capturedInfo.getDescription(), inputItem.getDescription()); - Assert.assertEquals(capturedInfo.getProperty(ITEM_TYPE), inputItem.getType()); - Assert.assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES), + 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()); - Assert.assertEquals(item.getId(), itemId); - Assert.assertEquals(item.getName(), inputItem.getName()); - Assert.assertEquals(item.getDescription(), inputItem.getDescription()); - Assert.assertEquals(item.getType(), inputItem.getType()); - Assert.assertEquals(item.getVersionStatusCounters(), 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 @@ -169,10 +184,10 @@ public class ItemZusammenDaoImplTest { capturedZusammenInfo.capture()); Info capturedInfo = capturedZusammenInfo.getValue(); - Assert.assertEquals(capturedInfo.getName(), item.getName()); - Assert.assertEquals(capturedInfo.getDescription(), item.getDescription()); - Assert.assertEquals(capturedInfo.getProperty(ITEM_TYPE), item.getType()); - Assert.assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES), + assertEquals(capturedInfo.getName(), item.getName()); + assertEquals(capturedInfo.getDescription(), item.getDescription()); + assertEquals(capturedInfo.getProperty(ITEM_TYPE), item.getType()); + assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES), item.getVersionStatusCounters()); } @@ -197,24 +212,24 @@ public class ItemZusammenDaoImplTest { } private void assertItemEquals(Item item, com.amdocs.zusammen.datatypes.item.Item zusammenItem) { - Assert.assertEquals(item.getId(), zusammenItem.getId().getValue()); - Assert.assertEquals(item.getName(), zusammenItem.getInfo().getName()); - Assert.assertEquals(item.getDescription(), zusammenItem.getInfo().getDescription()); - Assert.assertEquals(item.getType(), zusammenItem.getInfo().getProperty(ITEM_TYPE)); - Assert.assertEquals(item.getProperties().get(APP_PROP_1), + assertEquals(item.getId(), zusammenItem.getId().getValue()); + assertEquals(item.getName(), zusammenItem.getInfo().getName()); + assertEquals(item.getDescription(), zusammenItem.getInfo().getDescription()); + assertEquals(item.getType(), zusammenItem.getInfo().getProperty(ITEM_TYPE)); + assertEquals(item.getProperties().get(APP_PROP_1), zusammenItem.getInfo().getProperty(APP_PROP_1)); - Assert.assertEquals(item.getProperties().get(APP_PROP_2), + assertEquals(item.getProperties().get(APP_PROP_2), zusammenItem.getInfo().getProperty(APP_PROP_2)); Map zusammenStatusesMap = zusammenItem.getInfo().getProperty(ITEM_VERSIONS_STATUSES); Map statusesMap = item.getVersionStatusCounters(); - zusammenStatusesMap.entrySet().forEach(entry -> Assert - .assertEquals(statusesMap.get(VersionStatus.valueOf(entry.getKey())), entry.getValue())); + zusammenStatusesMap.entrySet() + .forEach(entry -> assertEquals(statusesMap.get(VersionStatus.valueOf(entry.getKey())), entry.getValue())); - Assert.assertEquals(item.getCreationTime(), zusammenItem.getCreationTime()); - Assert.assertEquals(item.getModificationTime(), zusammenItem.getModificationTime()); + assertEquals(item.getCreationTime(), zusammenItem.getCreationTime()); + assertEquals(item.getModificationTime(), zusammenItem.getModificationTime()); } } \ 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/dao/impl/zusammen/VersionZusammenDaoImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java index 106464811c..66157bf428 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java @@ -1,9 +1,44 @@ +/* + * Copyright © 2016-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.dao.impl.zusammen; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.openecomp.sdc.versioning.dao.impl.zusammen.TestUtil.createZusammenContext; + import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.SessionContext; -import com.amdocs.zusammen.datatypes.item.*; +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.ItemVersionStatus; +import com.amdocs.zusammen.datatypes.item.SynchronizationStatus; import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -13,22 +48,6 @@ import org.openecomp.sdc.common.session.SessionContextProviderFactory; import org.openecomp.sdc.versioning.dao.types.Revision; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.openecomp.sdc.versioning.dao.impl.zusammen.TestUtil.createZusammenContext; public class VersionZusammenDaoImplTest { @@ -39,7 +58,7 @@ public class VersionZusammenDaoImplTest { @InjectMocks private VersionZusammenDaoImpl versionDao; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); SessionContextProviderFactory.getInstance().createInterface().create(USER, tenant); diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerImplTest.java index 85a7f28d8c..0af5d5034a 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerImplTest.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerImplTest.java @@ -1,5 +1,35 @@ +/* + * Copyright © 2016-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.impl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.Before; +import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -9,17 +39,6 @@ import org.openecomp.sdc.notification.services.SubscriptionService; import org.openecomp.sdc.versioning.dao.ItemDao; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.Item; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; -import static org.testng.Assert.*; public class AsdcItemManagerImplTest { @@ -38,7 +57,7 @@ public class AsdcItemManagerImplTest { @InjectMocks private AsdcItemManagerImpl itemManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java index 8aa076728b..26f4c31111 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java @@ -1,5 +1,31 @@ +/* + * Copyright © 2016-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.impl; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verify; + +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -9,21 +35,16 @@ import org.openecomp.sdc.notification.services.SubscriptionService; import org.openecomp.sdc.versioning.dao.ItemDao; import org.openecomp.sdc.versioning.types.Item; import org.openecomp.sdc.versioning.types.ItemStatus; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import static org.mockito.Mockito.verify; -import static org.testng.Assert.assertEquals; public class ItemManagerImplTest { - private static final String USER = "user1"; + @Rule + public ExpectedException expectedException = ExpectedException.none(); + private static final String ITEM_ID = "item1"; private static final String ITEM_NAME = "item 1 name"; private static final String ITEM_TYPE_A = "A"; private static final String ITEM_TYPE_B = "B"; - private static final String tenant = "dox"; @Mock private ItemDao itemDao; @Mock @@ -33,18 +54,18 @@ public class ItemManagerImplTest { @InjectMocks private ItemManagerImpl itemManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } - @AfterMethod + @After public void tearDown(){ itemManager = null; } @Test - public void ArchiveTest(){ + public void archiveTest(){ Item item = createItem(ITEM_ID,ITEM_NAME,ITEM_TYPE_A); itemManager.archive(item); @@ -53,9 +74,11 @@ public class ItemManagerImplTest { assertEquals(item.getStatus(), ItemStatus.ARCHIVED); } - @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp = - "Archive item failed, item .* is already Archived") - public void ArchiveTestNegative(){ + @Test + public void archiveTestNegative(){ + + expectedException.expect(CoreException.class); + expectedException.expectMessage(new RegexMatcher("Archive item failed, item .* is already Archived")); Item item = createItem(ITEM_ID,ITEM_NAME,ITEM_TYPE_B); item.setStatus(ItemStatus.ARCHIVED); @@ -64,7 +87,7 @@ public class ItemManagerImplTest { } @Test - public void RestoreTest(){ + public void restoreTest(){ Item item = createItem(ITEM_ID,ITEM_NAME,ITEM_TYPE_A); item.setStatus(ItemStatus.ARCHIVED); @@ -74,17 +97,17 @@ public class ItemManagerImplTest { assertEquals(item.getStatus(), ItemStatus.ACTIVE); } - @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp = - "Restore item failed, item .* is already Active") - public void RestoreTestNegative(){ + @Test + public void restoreTestNegative(){ + + expectedException.expect(CoreException.class); + expectedException.expectMessage(new RegexMatcher("Restore item failed, item .* is already Active")); Item item = createItem(ITEM_ID,ITEM_NAME,ITEM_TYPE_B); item.setStatus(ItemStatus.ACTIVE); itemManager.restore(item); - } - private Item createItem(String id, String name, String type) { Item item = new Item(); item.setId(id); @@ -92,4 +115,23 @@ public class ItemManagerImplTest { item.setType(type); return item; } + + private static class RegexMatcher extends TypeSafeMatcher { + + private final String regex; + + private RegexMatcher(String regex) { + this.regex = regex; + } + + @Override + protected boolean matchesSafely(String s) { + return s.matches(regex); + } + + @Override + public void describeTo(Description description) { + description.appendText("Regular expression: " + regex); + } + } } diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java index a58356a1a4..bed576fee7 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java @@ -20,6 +20,28 @@ package org.openecomp.sdc.versioning.impl; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.openecomp.sdc.versioning.dao.types.SynchronizationState.OutOfSync; +import static org.openecomp.sdc.versioning.dao.types.SynchronizationState.UpToDate; +import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified; +import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -28,30 +50,20 @@ import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.versioning.ItemManager; import org.openecomp.sdc.versioning.VersionCalculator; import org.openecomp.sdc.versioning.dao.VersionDao; -import org.openecomp.sdc.versioning.dao.types.*; +import org.openecomp.sdc.versioning.dao.types.Revision; +import org.openecomp.sdc.versioning.dao.types.SynchronizationState; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionState; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.VersionCreationMethod; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; -import static org.openecomp.sdc.versioning.dao.types.SynchronizationState.OutOfSync; -import static org.openecomp.sdc.versioning.dao.types.SynchronizationState.UpToDate; -import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified; -import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft; public class VersioningManagerImplTest { private static final String ITEM_ID = "itemId"; private static final String VERSION_ID = "versionId"; + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Mock private VersionDao versionDaoMock; @Mock @@ -61,13 +73,13 @@ public class VersioningManagerImplTest { @InjectMocks private VersioningManagerImpl versioningManager; - @BeforeMethod + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } @Test - public void testListWhenNone() throws Exception { + public void testListWhenNone() { doReturn(new ArrayList<>()).when(versionDaoMock).list(ITEM_ID); List versions = versioningManager.list(ITEM_ID); @@ -76,7 +88,7 @@ public class VersioningManagerImplTest { } @Test - public void testList() throws Exception { + public void testList() { List returnedVersions = Stream.of(createVersion("1", null, null, false), createVersion("2", null, null, false), createVersion("3", null, null, false)).collect(Collectors.toList()); @@ -86,7 +98,7 @@ public class VersioningManagerImplTest { Assert.assertEquals(versions, returnedVersions); } - @Test(expectedExceptions = Exception.class) + @Test(expected = Exception.class) public void testGetNonExisting() throws Exception { Version version = new Version(VERSION_ID); @@ -97,7 +109,7 @@ public class VersioningManagerImplTest { } @Test - public void testGetNonExistingForUser() throws Exception { + public void testGetNonExistingForUser() { Version requestedVersion = new Version(VERSION_ID); Version returnedVersion = createVersion(VERSION_ID, Draft, UpToDate, false); @@ -112,7 +124,7 @@ public class VersioningManagerImplTest { } @Test - public void testGetOutOfSyncCertified() throws Exception { + public void testGetOutOfSyncCertified() { Version requestedVersion = new Version(VERSION_ID); Version returnedVersion = createVersion(VERSION_ID, Certified, UpToDate, false); @@ -128,7 +140,7 @@ public class VersioningManagerImplTest { } @Test - public void testGet() throws Exception { + public void testGet() { Version requestedVersion = new Version(VERSION_ID); Version returnedVersion = createVersion(VERSION_ID, Draft, OutOfSync, true); @@ -143,7 +155,7 @@ public class VersioningManagerImplTest { } @Test - public void testCreate() throws Exception { + public void testCreate() { Version requestedVersion = new Version(); String versionName = "versionName"; @@ -166,7 +178,7 @@ public class VersioningManagerImplTest { } @Test - public void testCreateBasedOn() throws Exception { + public void testCreateBasedOn() { Version requestedVersion = new Version(); requestedVersion.setBaseId("baseVersionId"); @@ -193,9 +205,12 @@ public class VersioningManagerImplTest { verify(versionDaoMock).publish(eq(ITEM_ID), eq(requestedVersion), eq("Create version: 4.0")); } - @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = - "Item itemId: create version failed, a version with the name 2.0 already exist") - public void testCreateWithExistingName() throws Exception { + @Test + public void testCreateWithExistingName() { + + expectedException.expect(CoreException.class); + expectedException.expectMessage("Item itemId: create version failed, a version with the name 2.0 already exist"); + Version version = new Version(); version.setBaseId("baseVersionId"); @@ -215,9 +230,12 @@ public class VersioningManagerImplTest { versioningManager.create(ITEM_ID, version, VersionCreationMethod.major); } - @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = - "Item itemId: submit version failed, version versionId is already Certified") - public void testSubmitCertified() throws Exception { + @Test + public void testSubmitCertified() { + + expectedException.expect(CoreException.class); + expectedException.expectMessage("Item itemId: submit version failed, version versionId is already Certified"); + Version version = new Version(VERSION_ID); Version returnedVersion = createVersion(VERSION_ID, Certified, UpToDate, false); @@ -227,7 +245,7 @@ public class VersioningManagerImplTest { } @Test - public void testSubmit() throws Exception { + public void testSubmit() { Version version = new Version(VERSION_ID); ArgumentCaptor versionArgumentCaptor = ArgumentCaptor.forClass(Version.class); @@ -245,7 +263,7 @@ public class VersioningManagerImplTest { } @Test - public void testPublish() throws Exception { + public void testPublish() { Version version = new Version(VERSION_ID); String publishDescription = "Publish message"; @@ -255,7 +273,7 @@ public class VersioningManagerImplTest { } @Test - public void testSync() throws Exception { + public void testSync() { Version version = new Version(VERSION_ID); versioningManager.sync(ITEM_ID, version); @@ -264,7 +282,7 @@ public class VersioningManagerImplTest { } @Test - public void testForceSync() throws Exception { + public void testForceSync() { Version version = new Version(VERSION_ID); versioningManager.forceSync(ITEM_ID, version); @@ -273,7 +291,7 @@ public class VersioningManagerImplTest { } @Test - public void testRevert() throws Exception { + public void testRevert() { Version version = new Version(VERSION_ID); String revisionId = "revisionId"; @@ -283,7 +301,7 @@ public class VersioningManagerImplTest { } @Test - public void testListRevisions() throws Exception { + public void testListRevisions() { Version version = new Version(VERSION_ID); List returnedRevisions = @@ -308,535 +326,4 @@ public class VersioningManagerImplTest { version.setState(state); return version; } - -/* - private static final String USR1 = "usr1"; - private static final String USR2 = "usr2"; - private static final String TYPE1 = "Type1"; -*/ -/* private static final String TYPE2 = "Type2";*//* - - private static final String ID1 = "Id1"; -*/ -/* private static final String ID2 = "Id2"; - private static final String ID3 = "Id3"; - private static final String TYPE1_TABLE_NAME = "vendor_license_model"; - private static final String TYPE1_ID_NAME = "vlm_id"; - private static final String TYPE1_VERSION_NAME = "version"; - private static final String TYPE2_TABLE_NAME = "feature_group"; - private static final String TYPE2_ID_NAME = "vlm_id"; - private static final String TYPE2_VERSION_NAME = "version";*//* - - private static final Version VERSION0 = new Version(0, 0); - private static final Version VERSION01 = new Version(0, 1); - private static final Version VERSION02 = new Version(0, 2); - private static final Version VERSION10 = new Version(1, 0); - private static final Version VERSION11 = new Version(1, 1); - - */ -/* private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - - private static UDTMapper versionMapper = - noSqlDb.getMappingManager().udtMapper(Version.class);*//* - - @Mock - private VersionInfoDao versionInfoDaoMock; - @Mock - private VersionInfoDeletedDao versionInfoDeletedDaoMock; - @InjectMocks - private VersioningManagerImpl versioningManager; - - @Captor - private ArgumentCaptor versionInfoEntityArg; - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - */ -/* @BeforeClass - private void init() { - versionInfoDaoMock.delete(new VersionInfoEntity(TYPE1, ID1)); - versionInfoDaoMock.delete(new VersionInfoEntity(TYPE1, ID2)); - versionInfoDaoMock.delete(new VersionInfoEntity(TYPE2, ID3)); - String deleteFromType1 = String - .format("delete from %s where %s=? and %s=?", TYPE1_TABLE_NAME, TYPE1_ID_NAME, - TYPE1_VERSION_NAME); - noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION01)); - noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION02)); - noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION11)); - - versioningManager.register(TYPE1, - new VersionableEntityMetadata(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME)); - versioningManager.register(TYPE2, - new VersionableEntityMetadata(TYPE2_TABLE_NAME, TYPE2_ID_NAME, TYPE2_VERSION_NAME)); - }*//* - - -*/ -/* @Test - public void testRegister() throws Exception { - VersionableEntityMetadata entityMetadata = - new VersionableEntityMetadata(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME); - versioningManager.register(TYPE1, entityMetadata); - - Map> versionableEntities = - versionableEntitiesCapture.capture(); - Set type1Entities = versionableEntities.get(TYPE1); - Assert.assertNotNull(type1Entities); - Assert.assertTrue(type1Entities.contains(entityMetadata)); - }*//* - - - @Test(expectedExceptions = CoreException.class) - public void testCreateAlreadyExisting() { - doReturn(new VersionInfoEntity()).when(versionInfoDaoMock).get(anyObject()); - versioningManager.create(TYPE1, ID1, USR1); - } - - @Test - public void testCreate() { - Version version = versioningManager.create(TYPE1, ID1, USR1); - Assert.assertEquals(version, VERSION01); - -*/ -/* createVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1, - version);*//* - - verify(versionInfoDaoMock).create(versionInfoEntityArg.capture()); - VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue(); - assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, new Version(0, 0), VERSION01, USR1, - VersionStatus.Locked, new HashSet<>(), null); - } - - @Test(expectedExceptions = CoreException.class) - public void testDeleteNonExisting() { - versioningManager.delete(TYPE1, ID1, USR1); - } - - @Test(expectedExceptions = CoreException.class) - public void testDeleteLocked() { - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0, - new UserCandidateVersion(USR1, VERSION01), Collections.emptySet(), null); - versioningManager.delete(TYPE1, ID1, USR1); - } - - @Test - public void testDelete() { - VersionInfoEntity versionInfoEntity = new VersionInfoEntity(); - versionInfoEntity.setStatus(VersionStatus.Draft); - doReturn(versionInfoEntity).when(versionInfoDaoMock).get(anyObject()); - - versioningManager.delete(TYPE1, ID1, USR1); - - verify(versionInfoDaoMock).delete(versionInfoEntity); - ArgumentCaptor versionInfoDeletedEntityArg = - ArgumentCaptor.forClass(VersionInfoDeletedEntity.class); - verify(versionInfoDeletedDaoMock).create(versionInfoDeletedEntityArg.capture()); - } - - @Test(expectedExceptions = CoreException.class) - public void testUndoDeleteNonExisting() { - versioningManager.undoDelete(TYPE1, ID1, USR1); - } - - @Test - public void testUndoDelete() { - VersionInfoDeletedEntity versionInfoDeletedEntity = new VersionInfoDeletedEntity(); - versionInfoDeletedEntity.setStatus(VersionStatus.Draft); - doReturn(versionInfoDeletedEntity).when(versionInfoDeletedDaoMock).get(anyObject()); - - versioningManager.undoDelete(TYPE1, ID1, USR1); - - verify(versionInfoDeletedDaoMock).delete(versionInfoDeletedEntity); - verify(versionInfoDaoMock).create(versionInfoEntityArg.capture()); -*/ -/* - VersionInfoDeletedEntity versionInfoDeletedEntity = - versionInfoDeletedDaoMock.get(new VersionInfoDeletedEntity(TYPE1, ID1)); - Assert.assertNotNull(versionInfoDeletedEntity); - - Map entitiesInfoMap = - versioningManager.listDeletedEntitiesVersionInfo(TYPE1, USR2, null); - Assert.assertEquals(entitiesInfoMap.size(), 1); - VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1)); - Assert.assertNull(versionInfoEntity); - versioningManager.undoDelete(TYPE1, ID1, USR1); - versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1)); - Assert.assertNotNull(versionInfoEntity);*//* - - } - - @Test(expectedExceptions = CoreException.class) - public void testCheckoutNonExisting() { - versioningManager.checkout(TYPE1, ID1, USR2); - } - - @Test(expectedExceptions = CoreException.class) - public void testCheckoutOnLockedSameUser() { - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0, - new UserCandidateVersion(USR1, VERSION01), Collections.emptySet(), null); - versioningManager.checkout(TYPE1, ID1, USR1); - } - - @Test(expectedExceptions = CoreException.class) - public void testCheckoutOnLockedOtherUser() { - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0, - new UserCandidateVersion(USR2, VERSION01), Collections.emptySet(), null); - versioningManager.checkout(TYPE1, ID1, USR1); - } - - @Test - public void testCheckoutOnFinalized() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION10); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions, - VERSION10); - - Version version = versioningManager.checkout(TYPE1, ID1, USR1); - Assert.assertEquals(version, VERSION11); - - VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1)); - assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION10, VERSION11, USR1, - VersionStatus.Locked, viewableVersions, VERSION10); -*/ -/* - ResultSet results = - loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1, - VERSION11); - Assert.assertTrue(results.iterator().hasNext());*//* - - } - - @Test - public void testCheckout() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions, - null); - - Version version = versioningManager.checkout(TYPE1, ID1, USR1); - Assert.assertEquals(version, VERSION02); - - verify(versionInfoDaoMock).update(versionInfoEntityArg.capture()); - VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue(); - - assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, VERSION02, USR1, - VersionStatus.Locked, viewableVersions, null); - -*/ -/* ResultSet results = - loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1, - VERSION02); - Assert.assertTrue(results.iterator().hasNext());*//* - - } - - @Test(expectedExceptions = CoreException.class) - public void testUndoCheckoutNonExisting() { - versioningManager.undoCheckout(TYPE1, ID1, USR1); - } - - @Test(expectedExceptions = CoreException.class) - public void testUndoCheckoutOnAvailable() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions, - null); - - versioningManager.undoCheckout(TYPE1, ID1, USR1); - } - - @Test(expectedExceptions = CoreException.class) - public void testUndoCheckouOnFinalized() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION10); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions, - VERSION10); - versioningManager.undoCheckout(TYPE1, ID1, USR2); - } - - @Test(expectedExceptions = CoreException.class) - public void testUndoCheckoutOnLockedOtherUser() { - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0, - new UserCandidateVersion(USR2, VERSION01), Collections.emptySet(), null); - - versioningManager.undoCheckout(TYPE1, ID1, USR1); - } - - @Test - public void testUndoCheckout() { - HashSet viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01, - new UserCandidateVersion(USR1, VERSION02), viewableVersions, null); - - Version version = versioningManager.undoCheckout(TYPE1, ID1, USR1); - Assert.assertEquals(version, VERSION01); - - VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1)); - assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null, - VersionStatus.Draft, viewableVersions, null); - -*/ -/* ResultSet results = - loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1, - VERSION02); - Assert.assertFalse(results.iterator().hasNext());*//* - - } - - @Test(expectedExceptions = CoreException.class) - public void testCheckinNonExisting() { - versioningManager.checkin(TYPE1, ID1, USR1, ""); - } - - @Test(expectedExceptions = CoreException.class) - public void testCheckinOnAvailable() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions, - null); - - versioningManager.checkin(TYPE1, ID1, USR1, "fail checkin"); - } - - - @Test(expectedExceptions = CoreException.class) - public void testCheckinOnFinalized() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION10); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions, - VERSION10); - - versioningManager.checkin(TYPE1, ID1, USR1, "failed checkin"); - } - - @Test(expectedExceptions = CoreException.class) - public void testCheckinOnLockedOtherUser() { - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0, - new UserCandidateVersion(USR2, VERSION01), Collections.emptySet(), null); - - versioningManager.checkin(TYPE1, ID1, USR1, ""); - } - - @Test - public void testCheckin() { - HashSet viewableVersions = new HashSet<>(); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0, - new UserCandidateVersion(USR1, VERSION01), viewableVersions, null); - - Version version = versioningManager.checkin(TYPE1, ID1, USR1, "checkin 0.1"); - Assert.assertEquals(version, VERSION01); - - verify(versionInfoDaoMock).update(versionInfoEntityArg.capture()); - VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue(); - - viewableVersions.add(VERSION01); - assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null, - VersionStatus.Draft, viewableVersions, null); - } - - @Test(expectedExceptions = CoreException.class) - public void testSubmitNonExisting() { - versioningManager.submit(TYPE1, ID1, USR2, "failed submit"); - } - - @Test(expectedExceptions = CoreException.class) - public void testSubmitOnLocked() { - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0, - new UserCandidateVersion(USR1, VERSION01), Collections.emptySet(), null); - versioningManager.submit(TYPE1, ID1, USR2, "failed submit"); - } - - - @Test(expectedExceptions = CoreException.class) - public void testSubmitOnFinalized() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION10); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions, - VERSION10); - versioningManager.submit(TYPE1, ID1, USR2, "failed submit"); - } - - @Test - public void testSubmit() { - Version version32 = new Version(3, 2); - Version version40 = new Version(4, 0); - - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION10); - viewableVersions.add(new Version(2, 0)); - viewableVersions.add(new Version(3, 0)); - viewableVersions.add(new Version(3, 1)); - viewableVersions.add(version32); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, version32, null, viewableVersions, - new Version(3, 0)); - - Version version = versioningManager.submit(TYPE1, ID1, USR1, "submit msg"); - Assert.assertEquals(version, version40); - viewableVersions.remove(new Version(3, 1)); - viewableVersions.remove(version32); - viewableVersions.add(version40); - - verify(versionInfoDaoMock).update(versionInfoEntityArg.capture()); - VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue(); - - assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, version40, null, null, - VersionStatus.Certified, viewableVersions, version40); - -*/ -/* ResultSet results = - loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1, - VERSION10); - Assert.assertTrue(results.iterator().hasNext());*//* - - } - - @Test(expectedExceptions = CoreException.class) - public void testGetVersionInfoOnNonExistingEntity() { - versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read); - } - - @Test - public void testGetVersionInfoForReadOnAvailable() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions, - null); - - VersionInfo versionInfo = - versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read); - assertVersionInfo(versionInfo, VERSION01, VersionStatus.Draft, null, - viewableVersions, null); - } - - @Test(expectedExceptions = CoreException.class) - public void testGetVersionInfoForWriteOnAvailable() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions, - null); - - versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write); - } - - @Test - public void testGetVersionInfoForReadOnLockedSameUser() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01, - new UserCandidateVersion(USR1, VERSION02), viewableVersions, null); - - VersionInfo versionInfo = - versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read); - viewableVersions.add(VERSION02); - assertVersionInfo(versionInfo, VERSION02, VersionStatus.Locked, USR1, viewableVersions, null); - } - - @Test - public void testGetVersionInfoForReadOnLockedOtherUser() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01, - new UserCandidateVersion(USR2, VERSION02), viewableVersions, null); - - VersionInfo versionInfo = - versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read); - Assert.assertEquals(versionInfo.getActiveVersion(), VERSION01); - assertVersionInfo(versionInfo, VERSION01, VersionStatus.Locked, USR2, viewableVersions, null); - } - - @Test(expectedExceptions = CoreException.class) - public void testGetVersionInfoForWriteOnLockedOtherUser() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01, - new UserCandidateVersion(USR2, VERSION02), viewableVersions, null); - - versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write); - } - - @Test - public void testGetVersionInfoForWriteOnLockedSameUser() { - Set viewableVersions = new HashSet<>(); - viewableVersions.add(VERSION01); - mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01, - new UserCandidateVersion(USR1, VERSION02), viewableVersions, null); - - VersionInfo versionInfo = - versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write); - viewableVersions.add(VERSION02); - assertVersionInfo(versionInfo, VERSION02, VersionStatus.Locked, USR1, viewableVersions, null); - } - -*/ -/* private void createVersionableEntityRecord(String tableName, String idName, String versionName, - String id, Version version) { - noSqlDb.execute( - String.format("insert into %s (%s,%s) values (?,?)", tableName, idName, versionName), id, - versionMapper.toUDT(version)); - } - - private ResultSet loadVersionableEntityRecord(String tableName, String idName, String versionName, - String id, Version version) { - return noSqlDb.execute( - String.format("select * from %s where %s=? and %s=?", tableName, idName, versionName), id, - versionMapper.toUDT(version)); - }*//* - - - - private static void assretVersionInfoEntity(VersionInfoEntity actual, String entityType, - String entityId, Version activeVersion, - Version candidateVersion, String candidateUser, - VersionStatus status, Set viewbleVersions, - Version latestFinalVersion) { - Assert.assertNotNull(actual); - Assert.assertEquals(actual.getEntityType(), entityType); - Assert.assertEquals(actual.getEntityId(), entityId); - Assert.assertEquals(actual.getActiveVersion(), activeVersion); - if (candidateVersion != null && candidateUser != null) { - Assert.assertEquals(actual.getCandidate().getVersion(), candidateVersion); - Assert.assertEquals(actual.getCandidate().getUser(), candidateUser); - } else { - Assert.assertNull(actual.getCandidate()); - } - Assert.assertEquals(actual.getStatus(), status); - Assert.assertEquals(actual.getViewableVersions().size(), viewbleVersions.size()); - Assert.assertEquals(actual.getViewableVersions(), viewbleVersions); - Assert.assertEquals(actual.getLatestFinalVersion(), latestFinalVersion); - } - - private static void assertVersionInfo(VersionInfo actual, Version activeVersion, - VersionStatus status, String lockingUser, - Set viewableVersions, Version latestFinalVersion) { - Assert.assertNotNull(actual); - Assert.assertEquals(actual.getActiveVersion(), activeVersion); - Assert.assertEquals(actual.getStatus(), status); - Assert.assertEquals(actual.getLockingUser(), lockingUser); - Assert.assertEquals(actual.getViewableVersions().size(), viewableVersions.size()); - Assert.assertEquals(actual.getViewableVersions(), viewableVersions); - Assert.assertEquals(actual.getLatestFinalVersion(), latestFinalVersion); - } - - private VersionInfoEntity mockVersionInfoEntity(String entityType, String entityId, - VersionStatus status, Version activeVersion, - UserCandidateVersion candidate, - Set viewableVersions, - Version latestFinalVersion) { - VersionInfoEntity mock = new VersionInfoEntity(); - mock.setEntityType(entityType); - mock.setEntityId(entityId); - mock.setStatus(status); - mock.setActiveVersion(activeVersion); - mock.setCandidate(candidate); - mock.setViewableVersions(viewableVersions); - mock.setLatestFinalVersion(latestFinalVersion); - - doReturn(mock).when(versionInfoDaoMock).get(anyObject()); - return mock; - } -*/ } -- cgit 1.2.3-korg