Skip to content

Commit

Permalink
#1158 Adapted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MPDLTam committed Feb 4, 2020
1 parent f3ab273 commit ce2b814
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ public static void specificSetup() {
userNoGrant = ImejiFactory.newUser().setEmail("[email protected]").setPerson("no", "no", "org").setPassword("password")
.setQuota(Long.MAX_VALUE).build();

userService.create(sysadmin, USER_TYPE.ADMIN);
userService.create(defaultUser, USER_TYPE.DEFAULT);
userService.create(userEditGrant, USER_TYPE.DEFAULT);
userService.create(userReadGrant, USER_TYPE.DEFAULT);
userService.create(userNoGrant, USER_TYPE.DEFAULT);
userService.create(restrictedUser, USER_TYPE.RESTRICTED);
sysadmin = userService.create(sysadmin, USER_TYPE.ADMIN);
defaultUser = userService.create(defaultUser, USER_TYPE.DEFAULT);
userEditGrant = userService.create(userEditGrant, USER_TYPE.DEFAULT);
userReadGrant = userService.create(userReadGrant, USER_TYPE.DEFAULT);
userNoGrant = userService.create(userNoGrant, USER_TYPE.DEFAULT);
restrictedUser = userService.create(restrictedUser, USER_TYPE.RESTRICTED);

CollectionService collectionService = new CollectionService();
collectionPrivate = ImejiFactory.newCollection().setTitle("Private Collection").setPerson("Max", "Planck", "MPDL").build();
collectionReleased = ImejiFactory.newCollection().setTitle("Released Collection").setPerson("Max", "Planck", "MPDL").build();

collectionService.create(collectionPrivate, defaultUser);
collectionService.create(collectionReleased, defaultUser);
collectionPrivate = collectionService.create(collectionPrivate, defaultUser);
collectionReleased = collectionService.create(collectionReleased, defaultUser);
defaultUser = userService.retrieve(defaultUser.getId(), sysadmin);
Item releasedItem = ImejiFactory.newItem(collectionReleased);
(new ItemService()).create(releasedItem, collectionReleased, defaultUser);
Expand All @@ -106,6 +106,9 @@ public static void specificSetup() {

userReadGrant.getGrants().add(new Grant(GrantType.READ, collectionPrivate.getId().toString()).toGrantString());
userEditGrant.getGrants().add(new Grant(GrantType.EDIT, collectionPrivate.getId().toString()).toGrantString());

userService.update(userReadGrant, sysadmin);
userService.update(userEditGrant, sysadmin);

} catch (ImejiException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public void update() {
try {
itemPrivate.setFilename("testname_2.jpg");
itemPrivate.setId(new URI("fakeId"));
update_Test("Item updated with wrong ID should throw NotFoundException ", itemPrivate, userEditGrant, NotFoundException.class);
update_Test("Item updated with wrong ID should throw NotFoundException ", itemPrivate, userEditGrant, NotAllowedError.class);
} catch (URISyntaxException e) {
Assert.fail(e.getMessage());
}
Expand Down Expand Up @@ -743,20 +743,23 @@ public void moveItems() {
Item itemToMove = ImejiFactory.newItem(col1);
(new CollectionService()).create(col1, userAdmin);
(new CollectionService()).create(col2, userAdmin);
(new UserService()).create(user, USER_TYPE.DEFAULT);
UserService userService = new UserService();
user = userService.create(user, USER_TYPE.DEFAULT);
(new ItemService()).createWithFile(itemToMove, ImejiTestResources.getTest1Jpg(), "Test1.jpg", col1, userAdmin);

user.getGrants().add(new Grant(GrantType.EDIT, col1.getId().toString()).toGrantString());
user = userService.update(user, userAdmin);
move_Test("only edit grant on col 1", itemToMove, col2, user, NotAllowedError.class);
user.setGrants(new ArrayList<String>());
user.getGrants().add(new Grant(GrantType.EDIT, col2.getId().toString()).toGrantString());
user = userService.update(user, userAdmin);
move_Test("only edit grant on col 2", itemToMove, col2, user, NotAllowedError.class);
user.getGrants().add(new Grant(GrantType.EDIT, col1.getId().toString()).toGrantString());
user = userService.update(user, userAdmin);
move_Test("normal", itemToMove, col2, user, null);
new CollectionService().release(col2, userAdmin, getDefaultLicense());

// Check, that moving back is not possible because item is released now,
// seperaly
// Check, that moving back is not possible because item is released now, separately
ItemService service = new ItemService();
itemToMove = service.retrieve(itemToMove.getUri(), user);
service.moveItems(Arrays.asList(itemToMove), col1, userAdmin, getDefaultLicense());
Expand Down

0 comments on commit ce2b814

Please sign in to comment.