Skip to content
Permalink
Browse files

#1104 Update/Fix test classes due to changes made for ticket 1122 (II)

-> The local test User objects have to be retrieved after creating a
collection (because the side effect that the user objects (with
user-grants) passed to the method get updated is removed!)
-> So that new test classes are being executed they have to be added to
the corresponding suite classes for now.

- Updated & Fixed test classes: CollectionServiceTest, ItemServiceTest
- Re-add CollectionServiceTest and ItemServiceTest to ServiceTestSuite
  • Loading branch information...
helkv committed Jul 8, 2019
1 parent 7f7591d commit 450c2a26fac86c0f9b26c88ee793cee6a799b257
@@ -4,20 +4,19 @@
import org.junit.runners.Suite;

import de.mpg.imeji.testimpl.logic.service.CollectionServiceCreateTest;
import de.mpg.imeji.testimpl.logic.service.CollectionServiceTest;
import de.mpg.imeji.testimpl.logic.service.ContentServiceTest;
import de.mpg.imeji.testimpl.logic.service.ItemServiceTest;
import de.mpg.imeji.testimpl.logic.service.ShareServiceTest;
import de.mpg.imeji.testimpl.logic.service.StatementServiceTest;
import de.mpg.imeji.testimpl.logic.service.StatementServiceUpdateTest;
import de.mpg.imeji.testimpl.logic.service.UserServiceTest;
import de.mpg.imeji.testimpl.logic.service.UsergroupServiceTest;

@RunWith(Suite.class)
@Suite.SuiteClasses({
//CollectionServiceTest.class,
ShareServiceTest.class, StatementServiceTest.class, UsergroupServiceTest.class, UserServiceTest.class, ContentServiceTest.class,
CollectionServiceCreateTest.class, StatementServiceUpdateTest.class
//ItemServiceTest.class
})
@Suite.SuiteClasses({CollectionServiceTest.class, ShareServiceTest.class, StatementServiceTest.class, UsergroupServiceTest.class,
UserServiceTest.class, ContentServiceTest.class, CollectionServiceCreateTest.class, StatementServiceUpdateTest.class,
ItemServiceTest.class})

public class ServiceTestSuite {

@@ -62,12 +62,14 @@
private static CollectionImeji collectionPrivate;
private static CollectionImeji collectionReleased;

private static UserService userService;

//TODO: Create separate test classes to test the CollectionService CRUD methods and link them here
//Like: CollectionServiceCreateTest

@BeforeClass
public static void specificSetup() {
UserService userService = new UserService();
userService = new UserService();
try {
sysadmin = ImejiFactory.newUser().setEmail("admin3@test.org").setPerson("admin3", "admin3", "org").setPassword("password")
.setQuota(Long.MAX_VALUE).build();
@@ -95,9 +97,11 @@ public static void specificSetup() {

collectionService.create(collectionPrivate, defaultUser);
collectionService.create(collectionReleased, defaultUser);
defaultUser = userService.retrieve(defaultUser.getId(), sysadmin);
Item releasedItem = ImejiFactory.newItem(collectionReleased);
(new ItemService()).create(releasedItem, collectionReleased, defaultUser);
collectionService.releaseWithDefaultLicense(collectionReleased, defaultUser);
collectionReleased = collectionService.retrieve(collectionReleased.getId(), sysadmin);

userReadGrant.getGrants().add(new Grant(GrantType.READ, collectionPrivate.getId().toString()).toGrantString());
userEditGrant.getGrants().add(new Grant(GrantType.EDIT, collectionPrivate.getId().toString()).toGrantString());
@@ -120,6 +124,7 @@ private void create_Test(String msg, CollectionImeji col, User user, Class excep
try {
try {
service.create(col, user);
user = userService.retrieve(user.getId(), sysadmin);
} catch (ImejiException e) {
if (!e.getClass().equals(exception)) {
Assert.fail(msg + ": " + e.getMessage());
@@ -273,6 +278,7 @@ public void delete() {
CollectionImeji collectionToDelete = ImejiFactory.newCollection().setTitle("Delete").setPerson("p", "p", "o").build();
try {
collectionService.create(collectionToDelete, defaultUser);
defaultUser = userService.retrieve(defaultUser.getId(), sysadmin);
Item itemToDelete = ImejiFactory.newItem(collectionToDelete);
itemService.create(itemToDelete, collectionToDelete, defaultUser);
delete_Test("private Collection, edit grant user", collectionToDelete, userEditGrant, NotAllowedError.class);
@@ -337,14 +343,15 @@ private void delete_Test(String msg, CollectionImeji col, User user, Class excep

@Test
public void release() {
CollectionService service = new CollectionService();
CollectionService collectionService = new CollectionService();
CollectionImeji collectionToRelease = ImejiFactory.newCollection().setTitle("To Release").setPerson("m", "p", "g").build();
try {
service.create(collectionToRelease, defaultUser);
collectionService.create(collectionToRelease, defaultUser);
defaultUser = userService.retrieve(defaultUser.getId(), sysadmin);

release_Test("Empty collection", collectionToRelease, null, defaultUser, getDefaultLicense(), getDefaultLicense(),
UnprocessableError.class);
collectionToRelease = service.retrieve(collectionToRelease.getId(), sysadmin);
collectionToRelease = collectionService.retrieve(collectionToRelease.getId(), sysadmin);

Item itemToRelease = ImejiFactory.newItem(collectionToRelease);
itemToRelease.getLicenses().add(getDefaultLicense());
@@ -354,18 +361,18 @@ public void release() {

release_Test("Unauthorized user", collectionToRelease, itemToRelease, userEditGrant, getDefaultLicense(), getDefaultLicense(),
NotAllowedError.class);
collectionToRelease = service.retrieve(collectionToRelease.getId(), sysadmin);
collectionToRelease = collectionService.retrieve(collectionToRelease.getId(), sysadmin);

Lock lock = new Lock(itemToRelease.getId().toString(), null);
Locks.lock(lock);
release_Test("Locked item", collectionToRelease, itemToRelease, defaultUser, getDefaultLicense(), getDefaultLicense(),
UnprocessableError.class);
Locks.unLock(lock);
collectionToRelease = service.retrieve(collectionToRelease.getId(), sysadmin);
collectionToRelease = collectionService.retrieve(collectionToRelease.getId(), sysadmin);

release_Test("pending collection, collection admin", collectionToRelease, itemToRelease, defaultUser, getDefaultLicense(),
getDefaultLicense(), null);
collectionToRelease = service.retrieve(collectionToRelease.getId(), sysadmin);
collectionToRelease = collectionService.retrieve(collectionToRelease.getId(), sysadmin);
itemToRelease = (new ItemService()).retrieve(itemToRelease.getId().toString(), sysadmin);

release_Test("Already released collection", collectionToRelease, itemToRelease, defaultUser, getDefaultLicense(), getDefaultLicense(),
@@ -422,16 +429,17 @@ private void release_Test(String msg, CollectionImeji col, Item item, User user,

@Test
public void withdraw() {
CollectionService service = new CollectionService();
CollectionService collectionService = new CollectionService();
CollectionImeji collectionToWithdraw = ImejiFactory.newCollection().setTitle("To Withdraw").setPerson("m", "p", "g").build();
collectionToWithdraw.setDiscardComment("discard test");
try {
service.create(collectionToWithdraw, defaultUser);
collectionService.create(collectionToWithdraw, defaultUser);
defaultUser = userService.retrieve(defaultUser.getId(), sysadmin);
Item itemToWithdraw = ImejiFactory.newItem(collectionToWithdraw);
new ItemService().create(itemToWithdraw, collectionToWithdraw, defaultUser);
withdraw_Test("collection pending", collectionToWithdraw, defaultUser, WorkflowException.class);
service.release(collectionToWithdraw, defaultUser, getDefaultLicense());
collectionToWithdraw = service.retrieve(collectionToWithdraw.getId(), sysadmin);
collectionService.release(collectionToWithdraw, defaultUser, getDefaultLicense());
collectionToWithdraw = collectionService.retrieve(collectionToWithdraw.getId(), sysadmin);
userEditGrant.getGrants().add(new Grant(GrantType.EDIT, collectionToWithdraw.getId().toString()).toGrantString());
new UserService().update(userEditGrant, sysadmin);
// withdraw_Test("user edit grant", collectionToWithdraw, userEditGrant,
@@ -441,7 +449,7 @@ public void withdraw() {
withdraw_Test("No discard comment", collectionToWithdraw, defaultUser, UnprocessableError.class);
collectionToWithdraw.setDiscardComment("discard test");
withdraw_Test("released collection, collection admin user", collectionToWithdraw, defaultUser, null);
collectionToWithdraw = service.retrieve(collectionToWithdraw.getId(), defaultUser);
collectionToWithdraw = collectionService.retrieve(collectionToWithdraw.getId(), defaultUser);
withdraw_Test("collection already withdrawn", collectionToWithdraw, defaultUser, WorkflowException.class);

} catch (ImejiException e) {
@@ -10,8 +10,8 @@
import java.util.Collection;
import java.util.List;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -628,6 +628,8 @@ public void release() {

release_Test("Admin grant user, not yet released item, no licence", Arrays.asList(itemToRelease, itemToRelease2), userAdmin,
getDefaultLicense(), getDefaultLicense(), null);
itemToRelease = service.retrieve(itemToRelease.getId(), userAdmin);
itemToRelease2 = service.retrieve(itemToRelease2.getId(), userAdmin);
service.withdraw(Arrays.asList(itemToRelease), "standart comment", userAdmin);
service.withdraw(Arrays.asList(itemToRelease2), "standart comment", userAdmin);

@@ -638,6 +640,7 @@ public void release() {
service.create(itemToRelease, collectionPrivate, userAdmin);
release_Test("Edit grant user, not yet released item, item already has license", Arrays.asList(itemToRelease), userAdmin,
getDefaultLicense(), lic, null);
itemToRelease = service.retrieve(itemToRelease.getId(), userAdmin);
service.withdraw(Arrays.asList(itemToRelease), "standart comment", userAdmin);

} catch (ImejiException e) {
@@ -679,11 +682,12 @@ public void withdraw() {
service.createWithFile(withdrawReleased, ImejiTestResources.getTest2Jpg(), "Test2.jpg", collectionPrivate, userAdmin);
service.releaseWithDefaultLicense(Arrays.asList(withdrawReleased), userAdmin);
withdrawReleased = service.retrieve(withdrawReleased.getId(), userAdmin);
withdraw_Test("released item, edit user", withdrawReleased, userEditGrant, null);
withdraw_Test("released item, edit user", withdrawReleased, userEditGrant, NotAllowedError.class);

withdrawReleased = ImejiFactory.newItem(collectionPrivate);
service.createWithFile(withdrawReleased, ImejiTestResources.getTest7Jpg(), "Test7.jpg", collectionPrivate, userAdmin);
service.releaseWithDefaultLicense(Arrays.asList(withdrawReleased), userAdmin);
withdrawReleased = service.retrieve(withdrawReleased.getId(), userAdmin);
withdraw_Test("released item, admin user", withdrawReleased, userAdmin, null);
} catch (ImejiException e) {
Assert.fail(e.getMessage());

0 comments on commit 450c2a2

Please sign in to comment.
You can’t perform that action at this time.