Add test for browse entries pagination

(cherry picked from commit a7bc82084e)
This commit is contained in:
Toni Prieto
2025-03-23 23:53:58 +01:00
committed by github-actions[bot]
parent d6ff41d9f5
commit b2f44f57f9

View File

@@ -259,6 +259,185 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe
)));
}
@Test
public void findBrowseBySubjectEntriesPagination() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
//2. Three public items that are readable by Anonymous with different subjects
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
Item publicItem2 = ItemBuilder.createItem(context, col2)
.withTitle("Public item 2")
.withIssueDate("2016-02-13")
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
.withSubject("TestingForMore").withSubject("ExtraEntry")
.build();
Item publicItem3 = ItemBuilder.createItem(context, col2)
.withTitle("Public item 2")
.withIssueDate("2016-02-13")
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
.withSubject("AnotherTest").withSubject("TestingForMore")
.withSubject("ExtraEntry")
.build();
Item withdrawnItem1 = ItemBuilder.createItem(context, col2)
.withTitle("Withdrawn item 1")
.withIssueDate("2016-02-13")
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
.withSubject("AnotherTest").withSubject("TestingForMore")
.withSubject("ExtraEntry").withSubject("WithdrawnEntry")
.withdrawn()
.build();
Item privateItem1 = ItemBuilder.createItem(context, col2)
.withTitle("Private item 1")
.withIssueDate("2016-02-13")
.withAuthor("Smith, Maria").withAuthor("Doe, Jane")
.withSubject("AnotherTest").withSubject("TestingForMore")
.withSubject("ExtraEntry").withSubject("PrivateEntry")
.makeUnDiscoverable()
.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")
.param("projection", "full")
.param("size", "1"))
//** THEN **
//The status has to be 200
.andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.number", is(0)))
//Check that there are indeed 3 different subjects
.andExpect(jsonPath("$.page.totalElements", is(3)))
//Check that the subject matches as expected
.andExpect(jsonPath("$._embedded.entries",
contains(BrowseEntryResourceMatcher.matchBrowseEntry("AnotherTest", 1)
)));
getClient().perform(get("/api/discover/browses/subject/entries")
.param("projection", "full")
.param("size", "1")
.param("page","1"))
//** THEN **
//The status has to be 200
.andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.number", is(1)))
//Check that there are indeed 3 different subjects
.andExpect(jsonPath("$.page.totalElements", is(3)))
//Check that the subject matches as expected
.andExpect(jsonPath("$._embedded.entries",
contains(BrowseEntryResourceMatcher.matchBrowseEntry("ExtraEntry", 3)
)));
getClient().perform(get("/api/discover/browses/subject/entries")
.param("projection", "full")
.param("size", "1")
.param("page","2"))
//** THEN **
//The status has to be 200
.andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.number", is(2)))
//Check that there are indeed 3 different subjects
.andExpect(jsonPath("$.page.totalElements", is(3)))
//Check that the subject matches as expected
.andExpect(jsonPath("$._embedded.entries",
contains(BrowseEntryResourceMatcher.matchBrowseEntry("TestingForMore", 2)
)));
getClient().perform(get("/api/discover/browses/subject/entries")
.param("sort", "value,desc")
.param("size", "1"))
//** THEN **
//The status has to be 200
.andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.number", is(0)))
//Check that there are indeed 3 different subjects
.andExpect(jsonPath("$.page.totalElements", is(3)))
//Check that the subject matches as expected
.andExpect(jsonPath("$._embedded.entries",
contains(BrowseEntryResourceMatcher.matchBrowseEntry("TestingForMore", 2)
)));
getClient().perform(get("/api/discover/browses/subject/entries")
.param("sort", "value,desc")
.param("size", "1")
.param("page","1"))
//** THEN **
//The status has to be 200
.andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.number", is(1)))
//Check that there are indeed 3 different subjects
.andExpect(jsonPath("$.page.totalElements", is(3)))
//Check that the subject matches as expected
.andExpect(jsonPath("$._embedded.entries",
contains(BrowseEntryResourceMatcher.matchBrowseEntry("ExtraEntry", 3)
)));
getClient().perform(get("/api/discover/browses/subject/entries")
.param("sort", "value,desc")
.param("size", "1")
.param("page","2"))
//** THEN **
//The status has to be 200
.andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.number", is(2)))
//Check that there are indeed 3 different subjects
.andExpect(jsonPath("$.page.totalElements", is(3)))
//Check that the subject matches as expected
.andExpect(jsonPath("$._embedded.entries",
contains(BrowseEntryResourceMatcher.matchBrowseEntry("AnotherTest", 1)
)));
}
@Test
public void findBrowseBySubjectEntriesWithAuthority() throws Exception {
configurationService.setProperty("choices.plugin.dc.subject",