From 718516c460f422b92687813489e733ced423d985 Mon Sep 17 00:00:00 2001 From: Mark Carroll Date: Tue, 8 Sep 2020 12:31:47 +0100 Subject: [PATCH] Add integration test for other-group duplication. --- .../test/integration/DuplicationTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/components/tools/OmeroJava/test/integration/DuplicationTest.java b/components/tools/OmeroJava/test/integration/DuplicationTest.java index 6d18d1febaf..ee0feadf75b 100644 --- a/components/tools/OmeroJava/test/integration/DuplicationTest.java +++ b/components/tools/OmeroJava/test/integration/DuplicationTest.java @@ -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; @@ -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 reportedImageIds = new HashSet(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 @@ -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 */