Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DS-4499 Fix cleanup of test environment in earlier Integration Test #2759

Merged
merged 16 commits into from May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -92,6 +92,8 @@ public void findAllMimeTypeCheck() throws Exception {
.withMimeType("application/octet-stream")
.withDescription("Description")
.build();
context.restoreAuthSystemState();

getClient().perform(get("/api/core/bitstreamformats"))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
Expand Down
Expand Up @@ -181,12 +181,14 @@ public void retrieveFullBitstream() throws Exception {
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.build();

Bitstream bitstream = BitstreamBuilder
bitstream = BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Test bitstream")
.withDescription("This is a bitstream to test range requests")
.withMimeType("text/plain")
.build();
}
context.restoreAuthSystemState();

//** WHEN **
//We download the bitstream
Expand All @@ -213,7 +215,6 @@ public void retrieveFullBitstream() throws Exception {

//The download and head request should also be logged as a statistics record
checkNumberOfStatsRecords(bitstream, 2);
}
}

@Test
Expand All @@ -239,12 +240,14 @@ public void retrieveRangeBitstream() throws Exception {
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.build();

Bitstream bitstream = BitstreamBuilder
bitstream = BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Test bitstream")
.withDescription("This is a bitstream to test range requests")
.withMimeType("text/plain")
.build();
}
context.restoreAuthSystemState();

//** WHEN **
//We download only a specific byte range of the bitstream
Expand Down Expand Up @@ -290,7 +293,6 @@ public void retrieveRangeBitstream() throws Exception {

//Check that NO statistics record was logged for the Range requests
checkNumberOfStatsRecords(bitstream, 0);
}
}

@Test
Expand Down Expand Up @@ -322,13 +324,15 @@ public void testEmbargoedBitstream() throws Exception {
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.build();

Bitstream bitstream = BitstreamBuilder
bitstream = BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed")
.withMimeType("text/plain")
.withEmbargoPeriod("6 months")
.build();
}
context.restoreAuthSystemState();

//** WHEN **
//We download the bitstream
Expand All @@ -339,7 +343,6 @@ public void testEmbargoedBitstream() throws Exception {

//An unauthorized request should not log statistics
checkNumberOfStatsRecords(bitstream, 0);
}
}

@Test
Expand Down Expand Up @@ -397,6 +400,7 @@ public void expiredEmbargoedBitstreamTest() throws Exception {
.withName("Collection 1")
.build();


String bitstreamContent = "Embargoed!";

try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
Expand All @@ -407,7 +411,7 @@ public void expiredEmbargoedBitstreamTest() throws Exception {
.withAuthor("Smith, Donald")
.build();

Bitstream bitstream = BitstreamBuilder
bitstream = BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed")
Expand Down Expand Up @@ -546,14 +550,15 @@ public void testPrivateBitstream() throws Exception {
String bitstreamContent = "Private!";
try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {

Bitstream bitstream = BitstreamBuilder
bitstream = BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed")
.withMimeType("text/plain")
.withReaderGroup(internalGroup)
.build();

}
context.restoreAuthSystemState();
//** WHEN **
//We download the bitstream
getClient().perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content"))
Expand All @@ -564,7 +569,7 @@ public void testPrivateBitstream() throws Exception {
//An unauthorized request should not log statistics
checkNumberOfStatsRecords(bitstream, 0);

}

}

@Test
Expand Down Expand Up @@ -754,13 +759,14 @@ public void retrieveCitationCoverpageOfBitstream() throws Exception {
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.build();

Bitstream bitstream = BitstreamBuilder
bitstream = BitstreamBuilder
.createBitstream(context, publicItem1, is)
.withName("Test bitstream")
.withDescription("This is a bitstream to test the citation cover page.")
.withMimeType("application/pdf")
.build();

}
context.restoreAuthSystemState();
//** WHEN **
//We download the bitstream
byte[] content = getClient().perform(get("/api/core/bitstreams/" + bitstream.getID() + "/content"))
Expand Down Expand Up @@ -796,7 +802,6 @@ public void retrieveCitationCoverpageOfBitstream() throws Exception {

//The download and head request should also be logged as a statistics record
checkNumberOfStatsRecords(bitstream, 2);
}
}

private String extractPDFText(byte[] content) throws IOException {
Expand Down
Expand Up @@ -95,6 +95,8 @@ public void findAllTest() throws Exception {
.build();
}

context.restoreAuthSystemState();

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(get("/api/core/bitstreams/")
Expand Down Expand Up @@ -153,6 +155,8 @@ public void findAllPaginationTest() throws Exception {
.build();
}

context.restoreAuthSystemState();

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(get("/api/core/bitstreams/")
Expand Down Expand Up @@ -298,6 +302,8 @@ public void findOneBitstreamTest() throws Exception {
.build();
}

context.restoreAuthSystemState();

// When full projection is requested, response should include expected properties, links, and embeds.
getClient().perform(get("/api/core/bitstreams/" + bitstream.getID())
.param("projection", "full"))
Expand Down Expand Up @@ -363,6 +369,8 @@ public void findOneBitstreamRelsTest() throws Exception {
.build();
}

context.restoreAuthSystemState();

getClient().perform(get("/api/core/bitstreams/" + bitstream.getID() + "/format"))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
Expand Down Expand Up @@ -391,6 +399,8 @@ public void findOneLogoBitstreamTest() throws Exception {
Collection col = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection")
.withLogo("logo_collection").build();

context.restoreAuthSystemState();

getClient().perform(get("/api/core/bitstreams/" + parentCommunity.getLogo().getID()))
.andExpect(status().isOk());

Expand All @@ -413,6 +423,8 @@ public void findOneLogoBitstreamRelsTest() throws Exception {
Collection col = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection")
.withLogo("logo_collection").build();

context.restoreAuthSystemState();

getClient().perform(get("/api/core/bitstreams/" + parentCommunity.getLogo().getID() + "/content"))
.andExpect(status().isOk()).andExpect(content().string("logo_community"));

Expand All @@ -436,6 +448,8 @@ public void findOneWrongUUID() throws Exception {
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();

context.restoreAuthSystemState();

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(get("/api/core/bitstreams/" + UUID.randomUUID()))
Expand Down Expand Up @@ -480,6 +494,8 @@ public void deleteOne() throws Exception {
.build();
}

context.restoreAuthSystemState();

String token = getAuthToken(admin.getEmail(), password);

// Delete
Expand Down Expand Up @@ -527,6 +543,8 @@ public void deleteForbidden() throws Exception {
.build();
}

context.restoreAuthSystemState();

String token = getAuthToken(eperson.getEmail(), password);

// Delete using an unauthorized user
Expand Down Expand Up @@ -574,6 +592,8 @@ public void deleteUnauthorized() throws Exception {
.build();
}

context.restoreAuthSystemState();

// Delete as anonymous
getClient().perform(delete("/api/core/bitstreams/" + bitstream.getID()))
.andExpect(status().isUnauthorized());
Expand All @@ -597,6 +617,8 @@ public void deleteLogo() throws Exception {
Collection col = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection")
.withLogo("logo_collection").build();

context.restoreAuthSystemState();

String token = getAuthToken(admin.getEmail(), password);

// trying to DELETE parentCommunity logo should work
Expand Down Expand Up @@ -656,6 +678,8 @@ public void deleteDeleted() throws Exception {
.build();
}

context.restoreAuthSystemState();

String token = getAuthToken(admin.getEmail(), password);

// Delete
Expand Down Expand Up @@ -727,6 +751,8 @@ public void testHiddenMetadataForAnonymousUser() throws Exception {
.build();
}

context.restoreAuthSystemState();

// When full projection is requested, response should include expected properties, links, and embeds.
getClient().perform(get("/api/core/bitstreams/" + bitstream.getID())
.param("projection", "full"))
Expand Down Expand Up @@ -778,6 +804,8 @@ public void testHiddenMetadataForAdminUser() throws Exception {
.build();
}

context.restoreAuthSystemState();

String token = getAuthToken(admin.getEmail(), password);

// When full projection is requested, response should include expected properties, links, and embeds.
Expand Down Expand Up @@ -838,6 +866,8 @@ public void testHiddenMetadataForUserWithWriteRights() throws Exception {
.withDspaceObject(col1)
.build();

context.restoreAuthSystemState();

String token = getAuthToken(eperson.getEmail(), password);


Expand Down
Expand Up @@ -167,6 +167,8 @@ public void findBrowseBySubjectEntries() throws Exception {
.withSubject("ExtraEntry")
.build();

context.restoreAuthSystemState();

//** WHEN **
//An anonymous user browses this endpoint to find which subjects are currently in the repository
getClient().perform(get("/api/discover/browses/subject/entries")
Expand Down Expand Up @@ -251,6 +253,8 @@ public void findBrowseBySubjectItems() throws Exception {
.withSubject("AnotherTest")
.build();

context.restoreAuthSystemState();

//** WHEN **
//An anonymous user browses the items that correspond with the ExtraEntry subject query
getClient().perform(get("/api/discover/browses/subject/items")
Expand Down Expand Up @@ -508,6 +512,8 @@ public void testPaginationBrowseByDateIssuedItems() throws Exception {
.withIssueDate("2016-01-12")
.build();

context.restoreAuthSystemState();

//** WHEN **
//An anonymous user browses the items in the Browse by date issued endpoint
//sorted ascending by tile with a page size of 5
Expand Down Expand Up @@ -632,6 +638,8 @@ public void testBrowseByEntriesStartsWith() throws Exception {
.withSubject("Science Fiction")
.build();

context.restoreAuthSystemState();

// ---- BROWSES BY ENTRIES ----

//** WHEN **
Expand Down Expand Up @@ -772,6 +780,9 @@ public void testBrowseByItemsStartsWith() throws Exception {
.withIssueDate("2029")
.withSubject("Science Fiction")
.build();

context.restoreAuthSystemState();

// ---- BROWSES BY ITEM ----
//** WHEN **
//An anonymous user browses the items in the Browse by date issued endpoint
Expand Down Expand Up @@ -920,6 +931,8 @@ public void testBrowseByStartsWithAndPage() throws Exception {
.withSubject("Astronomy")
.build();

context.restoreAuthSystemState();

// ---- BROWSES BY ITEM ----

//** WHEN **
Expand Down