Skip to content

Commit

Permalink
Add integration test for other-group duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtbc committed Sep 8, 2020
1 parent 6431d7c commit 718516c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions components/tools/OmeroJava/test/integration/DuplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import omero.model.DoubleAnnotationI;
import omero.model.Ellipse;
import omero.model.EllipseI;
import omero.model.ExperimenterGroup;
import omero.model.FileAnnotation;
import omero.model.FileAnnotationI;
import omero.model.Folder;
Expand Down Expand Up @@ -1280,6 +1281,61 @@ public void testDuplicateImageViaSkipHead() throws Exception {
Assert.assertNotEquals(originalImageId, reportedImageId);
}

/**
* Test duplication of an image that is not in the current group.
* @param isExplicitGroupContext if the group context should be set for the duplication
* @throws Exception unexpected
*/
@Test(dataProvider = "group context test cases", groups = "broken")
public void testDuplicateImageDifferentGroup(boolean isExplicitGroupContext) throws Exception {
final EventContext ec = newUserAndGroup("rwra--");
final ExperimenterGroup otherGroup = newGroupAddUser("rwra--", ec.userId);
final long otherGroupId = otherGroup.getId().getValue();
loginUser(ec);

/* save an image then put it in another group */

final Image originalImage = (Image) iUpdate.saveAndReturnObject(mmFactory.simpleImage());
final long originalImageId = originalImage.getId().getValue();
testImages.add(originalImageId);

doChange(Requests.chgrp().target(originalImage).toGroup(otherGroup).build());

/* duplicate the image even though it is not in the current group */

final long currentGroupId = iAdmin.getEventContext().groupId;
Assert.assertNotEquals(currentGroupId, otherGroupId);

final Duplicate dup = Requests.duplicate().target(originalImage).build();
final DuplicateResponse response;

if (isExplicitGroupContext) {
response = (DuplicateResponse) doChange(dup, otherGroupId);
} else {
response = (DuplicateResponse) doChange(dup);
}

/* check that the response includes duplication of the image */

final Set<Long> reportedImageIds = new HashSet<Long>(response.duplicates.get("ome.model.core.Image"));

Assert.assertEquals(reportedImageIds.size(), 1);

/* check that the reported image has a new ID */

final long reportedImageId = reportedImageIds.iterator().next();
testImages.add(reportedImageId);

Assert.assertNotEquals(originalImageId, reportedImageId);

/* check that the reported image is in the other group */

loginUser(otherGroup);
final Image reportedImage = (Image) iQuery.get("Image", reportedImageId);
final long reportedImageGroup = reportedImage.getDetails().getGroup().getId().getValue();
Assert.assertEquals(reportedImageGroup, otherGroupId);
}

/**
* Test duplication of links depending on ownership and group permissions.
* @param groupPerms the permissions on the group in which to test
Expand Down Expand Up @@ -1436,6 +1492,14 @@ public void testDuplicateWithContainerPermissions(String groupPerms, boolean myC
}
}

/**
* @return context for group context test cases
*/
@DataProvider(name = "group context test cases")
public Object[][] provideGroupContextCases() {
return new Boolean[][] { new Boolean[] {false}, new Boolean[] {true} };
}

/**
* @return group permissions for container permissions test cases
*/
Expand Down

0 comments on commit 718516c

Please sign in to comment.