Source:
public void restrictedGroupBitstreamForbiddenTest() throws Exception { context.turnOffAuthorisationSystem(); EPerson eperson2 = EPersonBuilder.createEPerson(context) .withEmail("eperson2@mail.com") .withPassword("qwerty02") .build(); parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity) .withName("Collection 1") .build(); Group restrictedGroup = GroupBuilder.createGroup(context) .withName("Restricted Group") .addMember(eperson) .build(); String bitstreamContent = "Private!"; try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) { Item item = ItemBuilder.createItem(context, col1) .withTitle("item 1") .withIssueDate("2013-01-17") .withAuthor("Doe, John") .build(); Bitstream bitstream = BitstreamBuilder .createBitstream(context, item, is) .withName("Test Embargoed Bitstream") .withDescription("This bitstream is embargoed") .withMimeType("text/plain") .withReaderGroup(restrictedGroup) .build(); String authToken = getAuthToken(eperson.getEmail(), password); getClient(authToken).perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content")) .andExpect(status().isOk()); checkNumberOfStatsRecords(bitstream, 1); String tokenEPerson2 = getAuthToken(eperson2.getEmail(), "qwerty02"); getClient(tokenEPerson2).perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content")) .andExpect(status().isForbidden()); getClient().perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content")) .andExpect(status().isUnauthorized()); checkNumberOfStatsRecords(bitstream, 1); } }

Target:
public void restrictedGroupBitstreamForbiddenTest() throws Exception { context.turnOffAuthorisationSystem(); EPerson eperson2 = EPersonBuilder.createEPerson(context) .withEmail("eperson2@mail.com") .withPassword("qwerty02") .build(); parentCommunity = CommunityBuilder.createCommunity(context) .withName("Parent Community") .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity) .withName("Collection 1") .build(); Group restrictedGroup = GroupBuilder.createGroup(context) .withName("Restricted Group") .addMember(eperson) .build(); String bitstreamContent = "Private!"; try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) { Item item = ItemBuilder.createItem(context, col1) .withTitle("item 1") .withIssueDate("2013-01-17") .withAuthor("Doe, John") .build(); bitstream = BitstreamBuilder .createBitstream(context, item, is) .withName("Test Embargoed Bitstream") .withDescription("This bitstream is embargoed") .withMimeType("text/plain") .withReaderGroup(restrictedGroup) .build(); } context.restoreAuthSystemState(); String authToken = getAuthToken(eperson.getEmail(), password); getClient(authToken).perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content")) .andExpect(status().isOk()); checkNumberOfStatsRecords(bitstream, 1); String tokenEPerson2 = getAuthToken(eperson2.getEmail(), "qwerty02"); getClient(tokenEPerson2).perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content")) .andExpect(status().isForbidden()); getClient().perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content")) .andExpect(status().isUnauthorized()); checkNumberOfStatsRecords(bitstream, 1); }