From 1fc1c92c7559b706eba72ee799779b2eb0a678db Mon Sep 17 00:00:00 2001 From: "julian.schallenmueller" Date: Mon, 25 Mar 2019 16:23:13 +0100 Subject: [PATCH] TSK-816: Deleted duplicated tests and moved functionality tests into acceptance --- .../java/pro/taskana/impl/WorkbasketImpl.java | 8 + .../taskana/impl/WorkbasketSummaryImpl.java | 36 ++ .../workbasket/CreateWorkbasketAccTest.java | 22 ++ .../workbasket/GetWorkbasketAccTest.java | 24 +- .../impl/WorkbasketServiceImplTest.java | 361 ------------------ 5 files changed, 89 insertions(+), 362 deletions(-) diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketImpl.java index 9047d93b8..92fa76338 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketImpl.java @@ -217,6 +217,10 @@ public class WorkbasketImpl implements Workbasket { result.setOwner(this.getOwner()); result.setDomain(this.getDomain()); result.setType(this.getType()); + result.setCustom1(this.getCustom1()); + result.setCustom2(this.getCustom2()); + result.setCustom3(this.getCustom3()); + result.setCustom4(this.getCustom4()); result.setOrgLevel1(this.getOrgLevel1()); result.setOrgLevel2(this.getOrgLevel2()); result.setOrgLevel3(this.getOrgLevel3()); @@ -238,6 +242,7 @@ public class WorkbasketImpl implements Workbasket { result = prime * result + ((domain == null) ? 0 : domain.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + (markedForDeletion ? 1231 : 1237); result = prime * result + ((modified == null) ? 0 : modified.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((orgLevel1 == null) ? 0 : orgLevel1.hashCode()); @@ -324,6 +329,9 @@ public class WorkbasketImpl implements Workbasket { } else if (!key.equals(other.key)) { return false; } + if (markedForDeletion != other.markedForDeletion) { + return false; + } if (modified == null) { if (other.modified != null) { return false; diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketSummaryImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketSummaryImpl.java index 35d12592c..ef6515e8d 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketSummaryImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketSummaryImpl.java @@ -236,10 +236,15 @@ public class WorkbasketSummaryImpl implements WorkbasketSummary { public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((custom1 == null) ? 0 : custom1.hashCode()); + result = prime * result + ((custom2 == null) ? 0 : custom2.hashCode()); + result = prime * result + ((custom3 == null) ? 0 : custom3.hashCode()); + result = prime * result + ((custom4 == null) ? 0 : custom4.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((domain == null) ? 0 : domain.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + (markedForDeletion ? 1231 : 1237); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((orgLevel1 == null) ? 0 : orgLevel1.hashCode()); result = prime * result + ((orgLevel2 == null) ? 0 : orgLevel2.hashCode()); @@ -262,6 +267,34 @@ public class WorkbasketSummaryImpl implements WorkbasketSummary { return false; } WorkbasketSummaryImpl other = (WorkbasketSummaryImpl) obj; + if (custom1 == null) { + if (other.custom1 != null) { + return false; + } + } else if (!custom1.equals(other.custom1)) { + return false; + } + if (custom2 == null) { + if (other.custom2 != null) { + return false; + } + } else if (!custom2.equals(other.custom2)) { + return false; + } + if (custom3 == null) { + if (other.custom3 != null) { + return false; + } + } else if (!custom3.equals(other.custom3)) { + return false; + } + if (custom4 == null) { + if (other.custom4 != null) { + return false; + } + } else if (!custom4.equals(other.custom4)) { + return false; + } if (description == null) { if (other.description != null) { return false; @@ -290,6 +323,9 @@ public class WorkbasketSummaryImpl implements WorkbasketSummary { } else if (!key.equals(other.key)) { return false; } + if (markedForDeletion != other.markedForDeletion) { + return false; + } if (name == null) { if (other.name != null) { return false; diff --git a/lib/taskana-core/src/test/java/acceptance/workbasket/CreateWorkbasketAccTest.java b/lib/taskana-core/src/test/java/acceptance/workbasket/CreateWorkbasketAccTest.java index f2617bee4..c0c8d97f1 100644 --- a/lib/taskana-core/src/test/java/acceptance/workbasket/CreateWorkbasketAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/workbasket/CreateWorkbasketAccTest.java @@ -2,6 +2,7 @@ package acceptance.workbasket; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.List; @@ -57,6 +58,7 @@ public class CreateWorkbasketAccTest extends AbstractAccTest { Workbasket createdWorkbasket = workbasketService.getWorkbasket("NT1234", "DOMAIN_A"); assertNotNull(createdWorkbasket); assertNotNull(createdWorkbasket.getId()); + assertTrue(createdWorkbasket.getId().startsWith("WBI")); assertEquals(workbasket, createdWorkbasket); Workbasket createdWorkbasket2 = workbasketService.getWorkbasket(createdWorkbasket.getId()); assertNotNull(createdWorkbasket); @@ -144,6 +146,26 @@ public class CreateWorkbasketAccTest extends AbstractAccTest { fail("InvalidWorkbasketException was expected"); } catch (InvalidWorkbasketException e) { } + + workbasket = workbasketService.newWorkbasket("", "novatec"); + workbasket.setName("Megabasket"); + workbasket.setType(WorkbasketType.GROUP); + workbasket.setOrgLevel1("company"); + try { // empty key + workbasketService.createWorkbasket(workbasket); + fail("InvalidWorkbasketException was expected"); + } catch (InvalidWorkbasketException e) { + } + + workbasket = workbasketService.newWorkbasket("key", "novatec"); + workbasket.setName(""); + workbasket.setType(WorkbasketType.GROUP); + workbasket.setOrgLevel1("company"); + try { // empty name + workbasketService.createWorkbasket(workbasket); + fail("InvalidWorkbasketException was expected"); + } catch (InvalidWorkbasketException e) { + } } @WithAccessId( diff --git a/lib/taskana-core/src/test/java/acceptance/workbasket/GetWorkbasketAccTest.java b/lib/taskana-core/src/test/java/acceptance/workbasket/GetWorkbasketAccTest.java index e3de10234..1b0517556 100644 --- a/lib/taskana-core/src/test/java/acceptance/workbasket/GetWorkbasketAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/workbasket/GetWorkbasketAccTest.java @@ -129,6 +129,11 @@ public class GetWorkbasketAccTest extends AbstractAccTest { assertEquals("abteilung", workbasketSummary.getOrgLevel2()); assertEquals("projekt", workbasketSummary.getOrgLevel3()); assertEquals("team", workbasketSummary.getOrgLevel4()); + assertEquals("custom1", workbasketSummary.getCustom1()); + assertEquals("custom2", workbasketSummary.getCustom2()); + assertEquals("custom3", workbasketSummary.getCustom3()); + assertEquals("custom4", workbasketSummary.getCustom4()); + assertEquals(false, workbasketSummary.isMarkedForDeletion()); } @Test(expected = WorkbasketNotFoundException.class) @@ -146,10 +151,27 @@ public class GetWorkbasketAccTest extends AbstractAccTest { } @Test(expected = NotAuthorizedException.class) - public void testThrowsExceptionIfNotAuthorized() + public void testGetByIdNotAuthorized() throws NotAuthorizedException, WorkbasketNotFoundException { WorkbasketService workbasketService = taskanaEngine.getWorkbasketService(); workbasketService.getWorkbasket("WBI:100000000000000000000000000000000001"); } + @Test(expected = NotAuthorizedException.class) + public void testGetByKeyDomainNotAuthorized() + throws NotAuthorizedException, WorkbasketNotFoundException { + WorkbasketService workbasketService = taskanaEngine.getWorkbasketService(); + workbasketService.getWorkbasket("GPK_KSC", "DOMAIN_A"); + } + + @WithAccessId( + userName = "user_1_1", + groupNames = {"group_1"}) + @Test(expected = WorkbasketNotFoundException.class) + public void testGetWorkbasketByIdNotExisting() + throws NotAuthorizedException, WorkbasketNotFoundException { + WorkbasketService workbasketService = taskanaEngine.getWorkbasketService(); + workbasketService.getWorkbasket("NOT EXISTING ID"); + } + } diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java index 0b53ecc8a..8c0889c3d 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.StringStartsWith.startsWith; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -32,7 +31,6 @@ import pro.taskana.TaskQuery; import pro.taskana.TaskService; import pro.taskana.TaskSummary; import pro.taskana.Workbasket; -import pro.taskana.WorkbasketPermission; import pro.taskana.WorkbasketType; import pro.taskana.configuration.TaskanaEngineConfiguration; import pro.taskana.exceptions.DomainNotFoundException; @@ -91,291 +89,6 @@ public class WorkbasketServiceImplTest { MockitoAnnotations.initMocks(this); } - @Test(expected = NotAuthorizedException.class) - public void testGetWorkbasketById_NonAuthorizedUser() - throws WorkbasketNotFoundException, NotAuthorizedException { - String wbId = "ID-1"; - Workbasket wb = createTestWorkbasket(wbId, "Key-1"); - WorkbasketPermission authorization = WorkbasketPermission.READ; - doReturn(wb).when(workbasketMapperMock).findById(wbId); - doThrow(NotAuthorizedException.class).when(cutSpy).checkAuthorization(wb.getId(), - authorization); - - try { - cutSpy.getWorkbasket(wbId); - } catch (NotAuthorizedException ex) { - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(workbasketMapperMock, times(1)).findById(wbId); - verify(cutSpy, times(1)).checkAuthorization(wb.getId(), authorization); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verify(taskanaEngineImplMock, times(1)).isUserInRole(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - throw ex; - } - } - - @Test(expected = WorkbasketNotFoundException.class) - public void testGetWorkbasketById_AuthenticatedWithoutResult() - throws NotAuthorizedException, WorkbasketNotFoundException { - String wbId = "ID-1"; - doReturn(null).when(workbasketMapperMock).findById(wbId); - - try { - cutSpy.getWorkbasket(wbId); - } catch (WorkbasketNotFoundException ex) { - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(workbasketMapperMock, times(1)).findById(wbId); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - throw ex; - } - } - - @Test - public void testGetWorkbasketById() throws NotAuthorizedException, WorkbasketNotFoundException { - String wbId = "ID-1"; - Workbasket wb = createTestWorkbasket(wbId, "key-1"); - WorkbasketPermission authorization = WorkbasketPermission.READ; - doReturn(wb).when(workbasketMapperMock).findById(wbId); - doNothing().when(cutSpy).checkAuthorization(wb.getId(), authorization); - - Workbasket actualWb = cutSpy.getWorkbasket(wbId); - - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(workbasketMapperMock, times(1)).findById(wbId); - verify(cutSpy, times(1)).checkAuthorization(wb.getId(), authorization); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verify(taskanaEngineImplMock, times(1)).isUserInRole(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(actualWb, equalTo(wb)); - } - - @Test(expected = NotAuthorizedException.class) - public void testGetWorkbasketByKey_NonAuthorizedUser() - throws WorkbasketNotFoundException, NotAuthorizedException { - String wbKey = "Key-1"; - Workbasket wb = createTestWorkbasket("ID", wbKey); - WorkbasketPermission authorization = WorkbasketPermission.READ; - doReturn(wb).when(workbasketMapperMock).findByKeyAndDomain(wbKey, "domain"); - doThrow(NotAuthorizedException.class).when(cutSpy).checkAuthorization(wbKey, "domain", authorization); - - try { - cutSpy.getWorkbasket(wbKey, "domain"); - } catch (NotAuthorizedException ex) { - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(workbasketMapperMock, times(1)).findByKeyAndDomain(wbKey, "domain"); - verify(cutSpy, times(1)).checkAuthorization(wbKey, "domain", authorization); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verify(taskanaEngineImplMock, times(1)).isUserInRole(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - throw ex; - } - - } - - @Test(expected = WorkbasketNotFoundException.class) - public void testGetWorkbasketByKey_AuthenticatedWithoutResult() - throws NotAuthorizedException, WorkbasketNotFoundException { - String wbKey = "Key-1"; - doReturn(null).when(workbasketMapperMock).findByKeyAndDomain(wbKey, "dummy"); - - try { - cutSpy.getWorkbasket(wbKey, "dummy"); - } catch (WorkbasketNotFoundException ex) { - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(workbasketMapperMock, times(1)).findByKeyAndDomain(wbKey, "dummy"); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - throw ex; - } - } - - @Test - public void testGetWorkbasketByKey() throws NotAuthorizedException, WorkbasketNotFoundException { - String wbKey = "Key-1"; - Workbasket wb = createTestWorkbasket("ID-1", wbKey); - WorkbasketPermission authorization = WorkbasketPermission.READ; - doNothing().when(cutSpy).checkAuthorization(wbKey, "test", authorization); - doReturn(wb).when(workbasketMapperMock).findByKeyAndDomain(wbKey, "test"); - - Workbasket actualWb = cutSpy.getWorkbasket(wbKey, "test"); - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(cutSpy, times(1)).checkAuthorization(wbKey, "test", authorization); - verify(workbasketMapperMock, times(1)).findByKeyAndDomain(wbKey, "test"); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verify(taskanaEngineImplMock, times(1)).isUserInRole(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(actualWb, equalTo(wb)); - } - - @Test - public void testCreateWorkbasket_InvalidWorkbasketCases() - throws NotAuthorizedException, WorkbasketAlreadyExistException, - DomainNotFoundException { - WorkbasketImpl wb = new WorkbasketImpl(); - int serviceCalls = 1; - - // KEY NULL - try { - wb.setId(null); - wb.setKey(null); - doReturn(null).when(workbasketMapperMock).findByKeyAndDomain(any(), any()); - cutSpy.createWorkbasket(wb); - } catch (InvalidWorkbasketException ex) { - verify(taskanaEngineImplMock, times(serviceCalls)).openConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any()); - verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(wb.getId(), not(equalTo(null))); - assertThat(wb.getCreated(), not(equalTo(null))); - assertThat(wb.getModified(), not(equalTo(null))); - } - - // KEY EMPTY - serviceCalls++; - try { - wb.setKey(""); - cutSpy.createWorkbasket(wb); - } catch (InvalidWorkbasketException ex) { - verify(taskanaEngineImplMock, times(serviceCalls)).openConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any()); - verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(wb.getId(), not(equalTo(null))); - assertThat(wb.getCreated(), not(equalTo(null))); - assertThat(wb.getModified(), not(equalTo(null))); - } - - // NAME NULL - serviceCalls++; - try { - wb.setKey("KEY"); - wb.setName(null); - cutSpy.createWorkbasket(wb); - } catch (InvalidWorkbasketException ex) { - verify(taskanaEngineImplMock, times(serviceCalls)).openConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any()); - verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(wb.getId(), not(equalTo(null))); - assertThat(wb.getCreated(), not(equalTo(null))); - assertThat(wb.getModified(), not(equalTo(null))); - } - - // NAME EMPTY - serviceCalls++; - try { - wb.setName(""); - cutSpy.createWorkbasket(wb); - } catch (InvalidWorkbasketException ex) { - verify(taskanaEngineImplMock, times(serviceCalls)).openConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any()); - verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(wb.getId(), not(equalTo(null))); - assertThat(wb.getCreated(), not(equalTo(null))); - assertThat(wb.getModified(), not(equalTo(null))); - } - - // DOMAIN NULL - serviceCalls++; - try { - wb.setName("Name"); - wb.setDomain(null); - cutSpy.createWorkbasket(wb); - } catch (InvalidWorkbasketException ex) { - verify(taskanaEngineImplMock, times(serviceCalls)).openConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any()); - verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(wb.getId(), not(equalTo(null))); - assertThat(wb.getCreated(), not(equalTo(null))); - assertThat(wb.getModified(), not(equalTo(null))); - } - - // TYPE NULL - serviceCalls++; - try { - wb.setDomain("Domain"); - wb.setType(null); - cutSpy.createWorkbasket(wb); - } catch (InvalidWorkbasketException ex) { - verify(taskanaEngineImplMock, times(serviceCalls)).openConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).returnConnection(); - verify(taskanaEngineImplMock, times(serviceCalls)).checkRoleMembership(any()); - verify(workbasketMapperMock, times(serviceCalls)).findByKeyAndDomain(any(), any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(wb.getId(), not(equalTo(null))); - assertThat(wb.getCreated(), not(equalTo(null))); - assertThat(wb.getModified(), not(equalTo(null))); - } - - } - - @Test - public void testCreateWorkbasket_WithoutDistibutionTargets() - throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException, - WorkbasketAlreadyExistException, DomainNotFoundException { - WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1"); - doNothing().when(workbasketMapperMock).insert(expectedWb); - doReturn(expectedWb).when(workbasketMapperMock).findById(any()); - doReturn(taskanaEngineConfigurationMock).when(taskanaEngineImplMock).getConfiguration(); - doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled(); - doReturn(true).when(taskanaEngineImplMock).domainExists(any()); - - Workbasket actualWb = cutSpy.createWorkbasket(expectedWb); - cutSpy.setDistributionTargets(expectedWb.getId(), null); - - verify(taskanaEngineImplMock, times(4)).openConnection(); - verify(taskanaEngineImplMock, times(1)).getConfiguration(); - verify(taskanaEngineConfigurationMock, times(1)).isSecurityEnabled(); - verify(workbasketMapperMock, times(1)).insert(expectedWb); - verify(workbasketMapperMock, times(1)).findByKeyAndDomain(any(), any()); - verify(workbasketMapperMock, times(2)).findById(expectedWb.getId()); - verify(workbasketMapperMock, times(1)).update(any()); - verify(taskanaEngineImplMock, times(4)).returnConnection(); - verify(taskanaEngineImplMock, times(2)).checkRoleMembership(any()); - verify(taskanaEngineImplMock, times(1)).isUserInRole(any()); - verify(taskanaEngineImplMock, times(1)).domainExists(any()); - verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - assertThat(actualWb.getId(), not(equalTo(null))); - assertThat(actualWb.getId(), startsWith("WBI")); - assertThat(actualWb.getCreated(), not(equalTo(null))); - assertThat(actualWb.getModified(), not(equalTo(null))); - } - @Test public void testCreateWorkbasket_WithDistibutionTargets() throws WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException, @@ -462,55 +175,6 @@ public class WorkbasketServiceImplTest { } } - @Test - public void testDeleteWorkbasketWithNullOrEmptyParam() - throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException { - // null param - try { - cutSpy.deleteWorkbasket(null); - fail("delete() should have thrown an InvalidArgumentException, when the param ID is null."); - } catch (InvalidArgumentException e) { - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - } - - // null param - try { - cutSpy.deleteWorkbasket(""); - fail("delete() should have thrown an InvalidArgumentException, when the param ID is EMPTY-String."); - } catch (InvalidArgumentException e) { - verify(taskanaEngineImplMock, times(2)).openConnection(); - verify(taskanaEngineImplMock, times(2)).returnConnection(); - verify(taskanaEngineImplMock, times(2)).checkRoleMembership(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - } - } - - @Test(expected = WorkbasketNotFoundException.class) - public void testDeleteWorkbasketNotExisting() - throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException { - String workbasketId = "WBI:0"; - doThrow(WorkbasketNotFoundException.class).when(cutSpy).getWorkbasket(workbasketId); - try { - cutSpy.deleteWorkbasket(workbasketId); - } catch (WorkbasketNotFoundException e) { - verify(taskanaEngineImplMock, times(1)).openConnection(); - verify(cutSpy, times(1)).getWorkbasket(workbasketId); - verify(taskanaEngineImplMock, times(1)).returnConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketMapperMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - throw e; - } - } - @Test(expected = WorkbasketNotFoundException.class) public void testDeleteWorkbasketIsUsed() throws NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException, WorkbasketNotFoundException { @@ -533,31 +197,6 @@ public class WorkbasketServiceImplTest { } } - @Test - public void testDeleteWorkbasket() - throws NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException, WorkbasketNotFoundException { - Workbasket wb = createTestWorkbasket("WBI:0", "wb-key"); - - try { - // WB deleted - cutSpy.deleteWorkbasket(wb.getId()); - } catch (WorkbasketNotFoundException e) { - // Workbasket is deleted - } - - verify(taskanaEngineImplMock, times(2)).openConnection(); - verify(cutSpy, times(1)).getWorkbasket(wb.getId()); - verify(taskanaEngineImplMock, times(0)).getSqlSession(); - verify(sqlSessionMock, times(0)).getMapper(TaskMapper.class); - - verify(workbasketMapperMock, times(1)).findById(wb.getId()); - verify(taskanaEngineImplMock, times(2)).returnConnection(); - verify(taskanaEngineImplMock, times(1)).checkRoleMembership(any()); - verifyNoMoreInteractions(taskQueryMock, taskServiceMock, workbasketAccessMapperMock, - distributionTargetMapperMock, - taskanaEngineImplMock, taskanaEngineConfigurationMock); - } - private WorkbasketImpl createTestWorkbasket(String id, String key) { WorkbasketImpl workbasket = new WorkbasketImpl(); workbasket.setId(id);