From cbaad2e71403169089560490b8d58dd5e8576e4f Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Mon, 13 Aug 2018 16:52:04 -0500 Subject: [PATCH 01/10] Implemented method for Browser Entries --- .../app/rest/repository/BrowseEntryLinkRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/BrowseEntryLinkRepository.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/BrowseEntryLinkRepository.java index 52fe6a894b..998c5eb8bd 100644 --- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/BrowseEntryLinkRepository.java +++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/BrowseEntryLinkRepository.java @@ -61,8 +61,11 @@ public class BrowseEntryLinkRepository extends AbstractDSpaceRestRepository // FIXME this should be bind automatically and available as method // argument String scope = null; + String startsWith = null; + if (request != null) { scope = request.getParameter("scope"); + startsWith = request.getParameter("startsWith"); } @@ -103,7 +106,7 @@ public class BrowseEntryLinkRepository extends AbstractDSpaceRestRepository // bs.setJumpToItem(focus); // bs.setJumpToValue(valueFocus); // bs.setJumpToValueLang(valueFocusLang); - // bs.setStartsWith(startsWith); + bs.setStartsWith(startsWith); if (pageable != null) { bs.setOffset(pageable.getOffset()); bs.setResultsPerPage(pageable.getPageSize()); From e25a732e6b362f87e1802ca454febfbb0c237616 Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Thu, 16 Aug 2018 00:35:19 -0500 Subject: [PATCH 02/10] Implemented startsWith for Items --- .../dspace/app/rest/repository/BrowseItemLinkRepository.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/BrowseItemLinkRepository.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/BrowseItemLinkRepository.java index 348e24152d..243100983e 100644 --- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/BrowseItemLinkRepository.java +++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/BrowseItemLinkRepository.java @@ -61,11 +61,13 @@ public class BrowseItemLinkRepository extends AbstractDSpaceRestRepository String scope = null; String filterValue = null; String filterAuthority = null; + String startsWith = null; if (request != null) { scope = request.getParameter("scope"); filterValue = request.getParameter("filterValue"); filterAuthority = request.getParameter("filterAuthority"); + startsWith = request.getParameter("startsWith"); } Context context = obtainContext(); BrowseEngine be = new BrowseEngine(context); @@ -128,7 +130,7 @@ public class BrowseItemLinkRepository extends AbstractDSpaceRestRepository // bs.setJumpToItem(focus); // bs.setJumpToValue(valueFocus); // bs.setJumpToValueLang(valueFocusLang); - // bs.setStartsWith(startsWith); + bs.setStartsWith(startsWith); if (pageable != null) { bs.setOffset(pageable.getOffset()); bs.setResultsPerPage(pageable.getPageSize()); From c02a5aa7782566a03e5e98f5252068a5bd234efa Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Thu, 16 Aug 2018 18:55:50 -0500 Subject: [PATCH 03/10] Wrote Integration Tests --- .../app/rest/BrowsesResourceControllerIT.java | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java index ceb32ce419..52008b0244 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java @@ -7,6 +7,7 @@ */ package org.dspace.app.rest; +import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasItem; @@ -498,4 +499,169 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe "Item 7", "2016-01-12") ))); } + + + @Test + public void testBrowseByStartsWith() 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. 7 public items that are readable by Anonymous + Item item1 = ItemBuilder.createItem(context, col1) + .withTitle("Alan Turing") + .withAuthor("Alan Mathison Turing") + .withIssueDate("1912-06-23") + .withSubject("Computing") + .build(); + + Item item2 = ItemBuilder.createItem(context, col1) + .withTitle("Blade Runner") + .withAuthor("Ridley Scott") + .withIssueDate("1982-06-25") + .withSubject("Science Fiction") + .build(); + + Item item5 = ItemBuilder.createItem(context, col1) + .withTitle("Python") + .withAuthor("Guido van Rossum") + .withIssueDate("1990") + .withSubject("Computing") + .build(); + + Item item4 = ItemBuilder.createItem(context, col1) + .withTitle("Java") + .withAuthor("James Gosling") + .withIssueDate("1995-05-23") + .withSubject("Computing") + .build(); + + Item item6 = ItemBuilder.createItem(context, col2) + .withTitle("Zeta Reticuli") + .withAuthor("Universe") + .withIssueDate("2018-01-01") + .withSubject("Astronomy") + .build(); + + Item item7 = ItemBuilder.createItem(context, col2) + .withTitle("Moon") + .withAuthor("Universe") + .withIssueDate("2018-01-02") + .withSubject("Astronomy") + .build(); + + Item item3 = ItemBuilder.createItem(context, col1) + .withTitle("T-800") + .withAuthor("James Cameron") + .withIssueDate("2029") + .withSubject("Science Fiction") + .build(); + + // ---- BROWSES BY ITEM ---- + + //** WHEN ** + //An anonymous user browses the items in the Browse by date issued endpoint + //with startsWith set to 1990 + getClient().perform(get("/api/discover/browses/dateissued/items") + .param("startsWith", "1990")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect only the "remaining" five items to be present + .andExpect(jsonPath("$.page.totalElements", is(5))) + .andExpect(jsonPath("$.page.number", is(0))) + + //Verify that the index jumps to the "Python" item. + .andExpect(jsonPath("$._embedded.items", + contains(ItemMatcher.matchItemWithTitleAndDateIssued(item5, + "Python", "1990"), + ItemMatcher.matchItemWithTitleAndDateIssued(item4, + "Java", "1995-05-23"), + ItemMatcher.matchItemWithTitleAndDateIssued(item6, + "Zeta Reticuli", "2018-01-01"), + ItemMatcher.matchItemWithTitleAndDateIssued(item7, + "Moon", "2018-01-02"), + ItemMatcher.matchItemWithTitleAndDateIssued(item3, + "T-800", "2029") + ))); + //** WHEN ** + //An anonymous user browses the items in the Browse by Title endpoint + //with startsWith set to Blade + getClient().perform(get("/api/discover/browses/title/items") + .param("startsWith", "T")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect only the "T-800" and "Zeta Reticuli" items to be present + .andExpect(jsonPath("$.page.totalElements", is(2))) + .andExpect(jsonPath("$.page.number", is(0))) + + //Verify that the index jumps to the "T-800" item. + .andExpect(jsonPath("$._embedded.items", + contains(ItemMatcher.matchItemWithTitleAndDateIssued(item3, + "T-800", "2029"), + ItemMatcher.matchItemWithTitleAndDateIssued(item6, + "Zeta Reticuli", "2018-01-01") + ))); + // ---- BROWSES BY ENTRIES ---- + + //** WHEN ** + //An anonymous user browses the entries in the Browse by Author endpoint + //with startsWith set to J + getClient().perform(get("/api/discover/browses/author/entries") + .param("startsWith", "J")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect only the entries "James Cameron" and "James Gosling" to be present + .andExpect(jsonPath("$.page.totalElements", is(2))) + .andExpect(jsonPath("$.page.number", is(0))) + + //Verify that the index filters to the "James'" items. + .andExpect(jsonPath("$._embedded.browseEntries", + contains(BrowseEntryResourceMatcher.matchBrowseEntry("James Cameron", 1), + BrowseEntryResourceMatcher.matchBrowseEntry("James Gosling", 1) + ))); + //** WHEN ** + //An anonymous user browses the entries in the Browse by Subject endpoint + //with startsWith set to C + getClient().perform(get("/api/discover/browses/subject/entries") + .param("startsWith", "C")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect only the entry "Computing" to be present + .andExpect(jsonPath("$.page.totalElements", is(1))) + .andExpect(jsonPath("$.page.number", is(0))) + + //Verify that the index filters to the "Computing'" items. + .andExpect(jsonPath("$._embedded.browseEntries", + contains(BrowseEntryResourceMatcher.matchBrowseEntry("Computing", 3) + ))); + } } \ No newline at end of file From cd94bbd0eefb893b6c3a56c3a90f13d1966d0581 Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Fri, 17 Aug 2018 12:15:42 -0500 Subject: [PATCH 04/10] Checkstyle errors fixed Added ITs for startsWith + Scope --- .../app/rest/BrowsesResourceControllerIT.java | 106 +++++++++++++----- 1 file changed, 77 insertions(+), 29 deletions(-) diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java index 52008b0244..d024de5f7a 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java @@ -7,7 +7,6 @@ */ package org.dspace.app.rest; -import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasItem; @@ -519,49 +518,49 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //2. 7 public items that are readable by Anonymous Item item1 = ItemBuilder.createItem(context, col1) .withTitle("Alan Turing") - .withAuthor("Alan Mathison Turing") + .withAuthor("Turing, Alan Mathison") .withIssueDate("1912-06-23") .withSubject("Computing") .build(); Item item2 = ItemBuilder.createItem(context, col1) .withTitle("Blade Runner") - .withAuthor("Ridley Scott") + .withAuthor("Scott, Ridley") .withIssueDate("1982-06-25") .withSubject("Science Fiction") .build(); - Item item5 = ItemBuilder.createItem(context, col1) + Item item3 = ItemBuilder.createItem(context, col1) .withTitle("Python") - .withAuthor("Guido van Rossum") + .withAuthor("Van Rossum, Guido") .withIssueDate("1990") .withSubject("Computing") .build(); - Item item4 = ItemBuilder.createItem(context, col1) + Item item4 = ItemBuilder.createItem(context, col2) .withTitle("Java") - .withAuthor("James Gosling") + .withAuthor("Gosling, James") .withIssueDate("1995-05-23") .withSubject("Computing") .build(); - - Item item6 = ItemBuilder.createItem(context, col2) + + Item item5 = ItemBuilder.createItem(context, col2) .withTitle("Zeta Reticuli") .withAuthor("Universe") .withIssueDate("2018-01-01") .withSubject("Astronomy") .build(); - Item item7 = ItemBuilder.createItem(context, col2) + Item item6 = ItemBuilder.createItem(context, col2) .withTitle("Moon") .withAuthor("Universe") .withIssueDate("2018-01-02") .withSubject("Astronomy") .build(); - Item item3 = ItemBuilder.createItem(context, col1) + Item item7 = ItemBuilder.createItem(context, col2) .withTitle("T-800") - .withAuthor("James Cameron") + .withAuthor("Cameron, James") .withIssueDate("2029") .withSubject("Science Fiction") .build(); @@ -586,20 +585,21 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //Verify that the index jumps to the "Python" item. .andExpect(jsonPath("$._embedded.items", - contains(ItemMatcher.matchItemWithTitleAndDateIssued(item5, + contains(ItemMatcher.matchItemWithTitleAndDateIssued(item3, "Python", "1990"), ItemMatcher.matchItemWithTitleAndDateIssued(item4, "Java", "1995-05-23"), + ItemMatcher.matchItemWithTitleAndDateIssued(item5, + "Zeta Reticuli", + "2018-01-01"), ItemMatcher.matchItemWithTitleAndDateIssued(item6, - "Zeta Reticuli", "2018-01-01"), - ItemMatcher.matchItemWithTitleAndDateIssued(item7, "Moon", "2018-01-02"), - ItemMatcher.matchItemWithTitleAndDateIssued(item3, + ItemMatcher.matchItemWithTitleAndDateIssued(item7, "T-800", "2029") ))); //** WHEN ** //An anonymous user browses the items in the Browse by Title endpoint - //with startsWith set to Blade + //with startsWith set to T getClient().perform(get("/api/discover/browses/title/items") .param("startsWith", "T")) @@ -615,18 +615,18 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //Verify that the index jumps to the "T-800" item. .andExpect(jsonPath("$._embedded.items", - contains(ItemMatcher.matchItemWithTitleAndDateIssued(item3, + contains(ItemMatcher.matchItemWithTitleAndDateIssued(item7, "T-800", "2029"), - ItemMatcher.matchItemWithTitleAndDateIssued(item6, - "Zeta Reticuli", "2018-01-01") + ItemMatcher.matchItemWithTitleAndDateIssued(item5, + "Zeta Reticuli", + "2018-01-01") ))); - // ---- BROWSES BY ENTRIES ---- - //** WHEN ** - //An anonymous user browses the entries in the Browse by Author endpoint - //with startsWith set to J - getClient().perform(get("/api/discover/browses/author/entries") - .param("startsWith", "J")) + //An anonymous user browses the items in the Browse by Title endpoint + //with startsWith set to Blade and scope set to Col 1 + getClient().perform(get("/api/discover/browses/title/items") + .param("startsWith", "Blade") + .param("scope", col1.getID().toString())) //** THEN ** //The status has to be 200 OK @@ -634,15 +634,63 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(content().contentType(contentType)) - //We expect only the entries "James Cameron" and "James Gosling" to be present + //We expect only the "Blade Runner" and "Python" items to be present .andExpect(jsonPath("$.page.totalElements", is(2))) .andExpect(jsonPath("$.page.number", is(0))) + //Verify that the index jumps to the "Blade Runner" item. + .andExpect(jsonPath("$._embedded.items", + contains(ItemMatcher.matchItemWithTitleAndDateIssued(item2, + "Blade Runner", + "1982-06-25"), + ItemMatcher.matchItemWithTitleAndDateIssued(item3, + "Python", "1990") + ))); + + // ---- BROWSES BY ENTRIES ---- + + //** WHEN ** + //An anonymous user browses the entries in the Browse by Author endpoint + //with startsWith set to U + getClient().perform(get("/api/discover/browses/author/entries") + .param("startsWith", "U")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect only the "Universe" entry to be present + .andExpect(jsonPath("$.page.totalElements", is(1))) + .andExpect(jsonPath("$.page.number", is(0))) + + //Verify that the index filters to the "Universe" entries and Counts 2 Items. + .andExpect(jsonPath("$._embedded.browseEntries", + contains(BrowseEntryResourceMatcher.matchBrowseEntry("Universe", 2) + ))); + //** WHEN ** + //An anonymous user browses the entries in the Browse by Author endpoint + //with startsWith set to T and scope set to Col 1 + getClient().perform(get("/api/discover/browses/author/entries") + .param("startsWith", "T") + .param("scope", col1.getID().toString())) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect only the entry "Turing, Alan Mathison" to be present + .andExpect(jsonPath("$.page.totalElements", is(1))) + .andExpect(jsonPath("$.page.number", is(0))) + //Verify that the index filters to the "James'" items. .andExpect(jsonPath("$._embedded.browseEntries", - contains(BrowseEntryResourceMatcher.matchBrowseEntry("James Cameron", 1), - BrowseEntryResourceMatcher.matchBrowseEntry("James Gosling", 1) + contains(BrowseEntryResourceMatcher.matchBrowseEntry("Turing, Alan Mathison", 1) ))); + //** WHEN ** //An anonymous user browses the entries in the Browse by Subject endpoint //with startsWith set to C From c0f31e889fd1c8eb180159bef354950ae217ace4 Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Fri, 17 Aug 2018 16:01:49 -0500 Subject: [PATCH 05/10] CheckStyle Fixes --- .../org/dspace/app/rest/BrowsesResourceControllerIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java index d024de5f7a..02f9b31bc0 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java @@ -590,7 +590,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe ItemMatcher.matchItemWithTitleAndDateIssued(item4, "Java", "1995-05-23"), ItemMatcher.matchItemWithTitleAndDateIssued(item5, - "Zeta Reticuli", + "Zeta Reticuli", "2018-01-01"), ItemMatcher.matchItemWithTitleAndDateIssued(item6, "Moon", "2018-01-02"), @@ -618,7 +618,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe contains(ItemMatcher.matchItemWithTitleAndDateIssued(item7, "T-800", "2029"), ItemMatcher.matchItemWithTitleAndDateIssued(item5, - "Zeta Reticuli", + "Zeta Reticuli", "2018-01-01") ))); //** WHEN ** @@ -641,7 +641,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //Verify that the index jumps to the "Blade Runner" item. .andExpect(jsonPath("$._embedded.items", contains(ItemMatcher.matchItemWithTitleAndDateIssued(item2, - "Blade Runner", + "Blade Runner", "1982-06-25"), ItemMatcher.matchItemWithTitleAndDateIssued(item3, "Python", "1990") From 40ca9f6150213d55eaa33db6ca8f422bb74720e7 Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Fri, 5 Oct 2018 00:21:49 -0500 Subject: [PATCH 06/10] Added URL parameter parsing for Browse Endpoint --- .../app/rest/RestResourceController.java | 7 +++++-- .../app/rest/BrowsesResourceControllerIT.java | 18 +++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java index bfd5296e22..0685705efd 100644 --- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java +++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java @@ -678,8 +678,11 @@ public class RestResourceController implements InitializingBean { if (Page.class.isAssignableFrom(linkMethod.getReturnType())) { Page pageResult = (Page) linkMethod .invoke(linkRepository, request, uuid, page, projection); - Link link = linkTo(this.getClass(), apiCategory, model).slash(uuid).slash(subpath) - .withSelfRel(); + + //TODO we need to strip any existing paging information from the query string + //Even if the paging info is not removed, the params don't get duplicated. + Link link = linkTo(this.getClass(), apiCategory, model).slash(uuid) + .slash(subpath + '?' + request.getQueryString()).withSelfRel(); Page halResources = pageResult.map(linkRepository::wrapResource); halResources.forEach(linkService::addLinks); diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java index 3527175b5f..63c48efb25 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java @@ -571,7 +571,8 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //An anonymous user browses the items in the Browse by date issued endpoint //with startsWith set to 1990 getClient().perform(get("/api/discover/browses/dateissued/items") - .param("startsWith", "1990")) + .param("startsWith", "1990") + .param("size", "2")) //** THEN ** //The status has to be 200 OK @@ -580,22 +581,17 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe .andExpect(content().contentType(contentType)) //We expect only the "remaining" five items to be present - .andExpect(jsonPath("$.page.totalElements", is(5))) - .andExpect(jsonPath("$.page.number", is(0))) + .andExpect(jsonPath("$.page.totalElements", is(7))) + .andExpect(jsonPath("$.page.number", is(1))) + .andExpect(jsonPath("$.page.size", is(2))) + .andExpect(jsonPath("$._links.first.href", contains("startsWith=1990"))) //Verify that the index jumps to the "Python" item. .andExpect(jsonPath("$._embedded.items", contains(ItemMatcher.matchItemWithTitleAndDateIssued(item3, "Python", "1990"), ItemMatcher.matchItemWithTitleAndDateIssued(item4, - "Java", "1995-05-23"), - ItemMatcher.matchItemWithTitleAndDateIssued(item5, - "Zeta Reticuli", - "2018-01-01"), - ItemMatcher.matchItemWithTitleAndDateIssued(item6, - "Moon", "2018-01-02"), - ItemMatcher.matchItemWithTitleAndDateIssued(item7, - "T-800", "2029") + "Java", "1995-05-23") ))); //** WHEN ** //An anonymous user browses the items in the Browse by Title endpoint From 819a42b69e35b0e214a619041c67da9abb609fb8 Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Wed, 17 Oct 2018 23:32:39 -0500 Subject: [PATCH 07/10] Fixed Integration Tests --- .../app/rest/BrowsesResourceControllerIT.java | 181 ++++++++++-------- 1 file changed, 97 insertions(+), 84 deletions(-) diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java index 63c48efb25..a64c56b901 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java @@ -9,6 +9,7 @@ package org.dspace.app.rest; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -499,7 +500,6 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe ))); } - @Test public void testBrowseByStartsWith() throws Exception { context.turnOffAuthorisationSystem(); @@ -565,13 +565,12 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe .withSubject("Science Fiction") .build(); - // ---- BROWSES BY ITEM ---- + // ---- BROWSES BY ENTRIES ---- //** WHEN ** - //An anonymous user browses the items in the Browse by date issued endpoint - //with startsWith set to 1990 - getClient().perform(get("/api/discover/browses/dateissued/items") - .param("startsWith", "1990") + //An anonymous user browses the entries in the Browse by Author endpoint + //with startsWith set to U + getClient().perform(get("/api/discover/browses/author/entries?startsWith=U") .param("size", "2")) //** THEN ** @@ -580,11 +579,85 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(content().contentType(contentType)) - //We expect only the "remaining" five items to be present + //We expect only the "Universe" entry to be present + .andExpect(jsonPath("$.page.totalElements", is(1))) + //As entry browsing works as a filter, we expect to be on page 0 + .andExpect(jsonPath("$.page.number", is(0))) + + //Verify that the index filters to the "Universe" entries and Counts 2 Items. + .andExpect(jsonPath("$._embedded.browseEntries", + contains(BrowseEntryResourceMatcher.matchBrowseEntry("Universe", 2) + ))) + //Verify startsWith parameter is included in the links + .andExpect(jsonPath("$._links.self.href", containsString("?startsWith=U"))); + + //** WHEN ** + //An anonymous user browses the entries in the Browse by Author endpoint + //with startsWith set to T and scope set to Col 1 + getClient().perform(get("/api/discover/browses/author/entries?startsWith=T") + .param("scope", col1.getID().toString())) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect only the entry "Turing, Alan Mathison" to be present + .andExpect(jsonPath("$.page.totalElements", is(1))) + //As entry browsing works as a filter, we expect to be on page 0 + .andExpect(jsonPath("$.page.number", is(0))) + + //Verify that the index filters to the "Turing, Alan'" items. + .andExpect(jsonPath("$._embedded.browseEntries", + contains(BrowseEntryResourceMatcher.matchBrowseEntry("Turing, Alan Mathison", 1) + ))) + //Verify that the startsWith paramater is included in the links + .andExpect(jsonPath("$._links.self.href", containsString("?startsWith=T"))); + + //** WHEN ** + //An anonymous user browses the entries in the Browse by Subject endpoint + //with startsWith set to C + getClient().perform(get("/api/discover/browses/subject/entries?startsWith=C")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect only the entry "Computing" to be present + .andExpect(jsonPath("$.page.totalElements", is(1))) + //As entry browsing works as a filter, we expect to be on page 0 + .andExpect(jsonPath("$.page.number", is(0))) + + //Verify that the index filters to the "Computing'" items. + .andExpect(jsonPath("$._embedded.browseEntries", + contains(BrowseEntryResourceMatcher.matchBrowseEntry("Computing", 3) + ))) + //Verify that the startsWith paramater is included in the links + .andExpect(jsonPath("$._links.self.href", containsString("?startsWith=C"))); + + // ---- BROWSES BY ITEM ---- + + //** WHEN ** + //An anonymous user browses the items in the Browse by date issued endpoint + //with startsWith set to 1990 + getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=1990") + .param("size", "2")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect the totalElements to be the 7 items present in the repository .andExpect(jsonPath("$.page.totalElements", is(7))) + //We expect to jump to page 1 of the index .andExpect(jsonPath("$.page.number", is(1))) .andExpect(jsonPath("$.page.size", is(2))) - .andExpect(jsonPath("$._links.first.href", contains("startsWith=1990"))) + .andExpect(jsonPath("$._links.first.href", containsString("startsWith=1990"))) //Verify that the index jumps to the "Python" item. .andExpect(jsonPath("$._embedded.items", @@ -596,8 +669,8 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //** WHEN ** //An anonymous user browses the items in the Browse by Title endpoint //with startsWith set to T - getClient().perform(get("/api/discover/browses/title/items") - .param("startsWith", "T")) + getClient().perform(get("/api/discover/browses/title/items?startsWith=T") + .param("size", "2")) //** THEN ** //The status has to be 200 OK @@ -605,9 +678,11 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(content().contentType(contentType)) - //We expect only the "T-800" and "Zeta Reticuli" items to be present - .andExpect(jsonPath("$.page.totalElements", is(2))) - .andExpect(jsonPath("$.page.number", is(0))) + //We expect the totalElements to be the 7 items present in the repository + .andExpect(jsonPath("$.page.totalElements", is(7))) + //We expect to jump to page 2 in the index + .andExpect(jsonPath("$.page.number", is(2))) + .andExpect(jsonPath("$._links.first.href", containsString("startsWith=T"))) //Verify that the index jumps to the "T-800" item. .andExpect(jsonPath("$._embedded.items", @@ -617,12 +692,13 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe "Zeta Reticuli", "2018-01-01") ))); + //** WHEN ** //An anonymous user browses the items in the Browse by Title endpoint //with startsWith set to Blade and scope set to Col 1 - getClient().perform(get("/api/discover/browses/title/items") - .param("startsWith", "Blade") - .param("scope", col1.getID().toString())) + getClient().perform(get("/api/discover/browses/title/items?startsWith=Blade") + .param("scope", col1.getID().toString()) + .param("size", "2")) //** THEN ** //The status has to be 200 OK @@ -630,82 +706,19 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(content().contentType(contentType)) - //We expect only the "Blade Runner" and "Python" items to be present - .andExpect(jsonPath("$.page.totalElements", is(2))) + //We expect the totalElements to be the 3 items present in the collection + .andExpect(jsonPath("$.page.totalElements", is(3))) + //As this is is a small collection, we expect to go-to page 0 .andExpect(jsonPath("$.page.number", is(0))) + .andExpect(jsonPath("$._links.first.href", containsString("startsWith=Blade"))) //Verify that the index jumps to the "Blade Runner" item. .andExpect(jsonPath("$._embedded.items", - contains(ItemMatcher.matchItemWithTitleAndDateIssued(item2, + contains(ItemMatcher.matchItemWithTitleAndDateIssued(item2, "Blade Runner", "1982-06-25"), ItemMatcher.matchItemWithTitleAndDateIssued(item3, "Python", "1990") ))); - - // ---- BROWSES BY ENTRIES ---- - - //** WHEN ** - //An anonymous user browses the entries in the Browse by Author endpoint - //with startsWith set to U - getClient().perform(get("/api/discover/browses/author/entries") - .param("startsWith", "U")) - - //** THEN ** - //The status has to be 200 OK - .andExpect(status().isOk()) - //We expect the content type to be "application/hal+json;charset=UTF-8" - .andExpect(content().contentType(contentType)) - - //We expect only the "Universe" entry to be present - .andExpect(jsonPath("$.page.totalElements", is(1))) - .andExpect(jsonPath("$.page.number", is(0))) - - //Verify that the index filters to the "Universe" entries and Counts 2 Items. - .andExpect(jsonPath("$._embedded.browseEntries", - contains(BrowseEntryResourceMatcher.matchBrowseEntry("Universe", 2) - ))); - //** WHEN ** - //An anonymous user browses the entries in the Browse by Author endpoint - //with startsWith set to T and scope set to Col 1 - getClient().perform(get("/api/discover/browses/author/entries") - .param("startsWith", "T") - .param("scope", col1.getID().toString())) - - //** THEN ** - //The status has to be 200 OK - .andExpect(status().isOk()) - //We expect the content type to be "application/hal+json;charset=UTF-8" - .andExpect(content().contentType(contentType)) - - //We expect only the entry "Turing, Alan Mathison" to be present - .andExpect(jsonPath("$.page.totalElements", is(1))) - .andExpect(jsonPath("$.page.number", is(0))) - - //Verify that the index filters to the "James'" items. - .andExpect(jsonPath("$._embedded.browseEntries", - contains(BrowseEntryResourceMatcher.matchBrowseEntry("Turing, Alan Mathison", 1) - ))); - - //** WHEN ** - //An anonymous user browses the entries in the Browse by Subject endpoint - //with startsWith set to C - getClient().perform(get("/api/discover/browses/subject/entries") - .param("startsWith", "C")) - - //** THEN ** - //The status has to be 200 OK - .andExpect(status().isOk()) - //We expect the content type to be "application/hal+json;charset=UTF-8" - .andExpect(content().contentType(contentType)) - - //We expect only the entry "Computing" to be present - .andExpect(jsonPath("$.page.totalElements", is(1))) - .andExpect(jsonPath("$.page.number", is(0))) - - //Verify that the index filters to the "Computing'" items. - .andExpect(jsonPath("$._embedded.browseEntries", - contains(BrowseEntryResourceMatcher.matchBrowseEntry("Computing", 3) - ))); } } \ No newline at end of file From 7d5e12a7932d43317bc3a3ef727159ea47097a4f Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Tue, 13 Nov 2018 18:40:28 -0600 Subject: [PATCH 08/10] Added QueryString null handling. --- .../org/dspace/app/rest/RestResourceController.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java index 0685705efd..6541cc7235 100644 --- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java +++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java @@ -679,10 +679,15 @@ public class RestResourceController implements InitializingBean { Page pageResult = (Page) linkMethod .invoke(linkRepository, request, uuid, page, projection); - //TODO we need to strip any existing paging information from the query string - //Even if the paging info is not removed, the params don't get duplicated. - Link link = linkTo(this.getClass(), apiCategory, model).slash(uuid) - .slash(subpath + '?' + request.getQueryString()).withSelfRel(); + Link link = null; + String querystring = request.getQueryString(); + if (querystring != null) { + link = linkTo(this.getClass(), apiCategory, model).slash(uuid) + .slash(subpath + '?' + querystring).withSelfRel(); + } else { + link = linkTo(this.getClass(), apiCategory, model).slash(uuid).withSelfRel(); + } + Page halResources = pageResult.map(linkRepository::wrapResource); halResources.forEach(linkService::addLinks); From 8ebb6a1a41adbe524a6a0e6e53c4a01facd6e63f Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Wed, 21 Nov 2018 18:58:09 -0600 Subject: [PATCH 09/10] Added handling of empty querystring. Added startsWithandPage test. --- .../app/rest/RestResourceController.java | 2 +- .../app/rest/BrowsesResourceControllerIT.java | 259 +++++++++++++++++- 2 files changed, 259 insertions(+), 2 deletions(-) diff --git a/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java b/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java index 6541cc7235..808a7fdc30 100644 --- a/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java +++ b/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java @@ -681,7 +681,7 @@ public class RestResourceController implements InitializingBean { Link link = null; String querystring = request.getQueryString(); - if (querystring != null) { + if (querystring != null && querystring.length() > 0) { link = linkTo(this.getClass(), apiCategory, model).slash(uuid) .slash(subpath + '?' + querystring).withSelfRel(); } else { diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java index a64c56b901..90c790eaed 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java @@ -501,7 +501,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe } @Test - public void testBrowseByStartsWith() throws Exception { + public void testBrowseByEntriesStartsWith() throws Exception { context.turnOffAuthorisationSystem(); //** GIVEN ** @@ -638,6 +638,72 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //Verify that the startsWith paramater is included in the links .andExpect(jsonPath("$._links.self.href", containsString("?startsWith=C"))); + }; + + @Test + public void testBrowseByItemsStartsWith() 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. 7 public items that are readable by Anonymous + Item item1 = ItemBuilder.createItem(context, col1) + .withTitle("Alan Turing") + .withAuthor("Turing, Alan Mathison") + .withIssueDate("1912-06-23") + .withSubject("Computing") + .build(); + + Item item2 = ItemBuilder.createItem(context, col1) + .withTitle("Blade Runner") + .withAuthor("Scott, Ridley") + .withIssueDate("1982-06-25") + .withSubject("Science Fiction") + .build(); + + Item item3 = ItemBuilder.createItem(context, col1) + .withTitle("Python") + .withAuthor("Van Rossum, Guido") + .withIssueDate("1990") + .withSubject("Computing") + .build(); + + Item item4 = ItemBuilder.createItem(context, col2) + .withTitle("Java") + .withAuthor("Gosling, James") + .withIssueDate("1995-05-23") + .withSubject("Computing") + .build(); + + Item item5 = ItemBuilder.createItem(context, col2) + .withTitle("Zeta Reticuli") + .withAuthor("Universe") + .withIssueDate("2018-01-01") + .withSubject("Astronomy") + .build(); + + Item item6 = ItemBuilder.createItem(context, col2) + .withTitle("Moon") + .withAuthor("Universe") + .withIssueDate("2018-01-02") + .withSubject("Astronomy") + .build(); + + Item item7 = ItemBuilder.createItem(context, col2) + .withTitle("T-800") + .withAuthor("Cameron, James") + .withIssueDate("2029") + .withSubject("Science Fiction") + .build(); // ---- BROWSES BY ITEM ---- //** WHEN ** @@ -721,4 +787,195 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe "Python", "1990") ))); } + + @Test + public void testBrowseByStartsWithAndPage() 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. 7 public items that are readable by Anonymous + Item item1 = ItemBuilder.createItem(context, col1) + .withTitle("Alan Turing") + .withAuthor("Turing, Alan Mathison") + .withIssueDate("1912-06-23") + .withSubject("Computing") + .build(); + + Item item2 = ItemBuilder.createItem(context, col1) + .withTitle("Blade Runner") + .withAuthor("Scott, Ridley") + .withIssueDate("1982-06-25") + .withSubject("Science Fiction") + .build(); + + Item item3 = ItemBuilder.createItem(context, col2) + .withTitle("Java") + .withAuthor("Gosling, James") + .withIssueDate("1995-05-23") + .withSubject("Computing") + .build(); + + Item item4 = ItemBuilder.createItem(context, col2) + .withTitle("Moon") + .withAuthor("Universe") + .withIssueDate("2018-01-02") + .withSubject("Astronomy") + .build(); + + Item item5 = ItemBuilder.createItem(context, col1) + .withTitle("Python") + .withAuthor("Van Rossum, Guido") + .withIssueDate("1990") + .withSubject("Computing") + .build(); + + Item item6 = ItemBuilder.createItem(context, col2) + .withTitle("T-800") + .withAuthor("Cameron, James") + .withIssueDate("2029") + .withSubject("Science Fiction") + .build(); + + Item item7 = ItemBuilder.createItem(context, col2) + .withTitle("Zeta Reticuli") + .withAuthor("Universe") + .withIssueDate("2018-01-01") + .withSubject("Astronomy") + .build(); + + // ---- BROWSES BY ITEM ---- + + //** WHEN ** + //An anonymous user browses the items in the Browse by date issued endpoint + //with startsWith set to 1990 and Page to 3 + getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=1990") + .param("size", "2").param("page", "2")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect the totalElements to be the 7 items present in the repository + .andExpect(jsonPath("$.page.totalElements", is(7))) + //We expect to jump to page 1 of the index + .andExpect(jsonPath("$.page.number", is(2))) + .andExpect(jsonPath("$.page.size", is(2))) + .andExpect(jsonPath("$._links.first.href", containsString("startsWith=1990"))) + + //Verify that the index jumps to the "Zeta Reticuli" item. + .andExpect(jsonPath("$._embedded.items", + contains(ItemMatcher.matchItemWithTitleAndDateIssued(item7, + "Zeta Reticuli", "2018-01-01"), + ItemMatcher.matchItemWithTitleAndDateIssued(item4, + "Moon", "2018-01-02") + ))); + } + + @Test + public void testBrowseByStartsWithAndPageGreaterThanTotalPages() throws Exception { + // This test an scenario where a nonexisting page is requested (The page number is greater than + // the total number of pages ) + 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. 7 public items that are readable by Anonymous + Item item1 = ItemBuilder.createItem(context, col1) + .withTitle("Alan Turing") + .withAuthor("Turing, Alan Mathison") + .withIssueDate("1912-06-23") + .withSubject("Computing") + .build(); + + Item item2 = ItemBuilder.createItem(context, col1) + .withTitle("Blade Runner") + .withAuthor("Scott, Ridley") + .withIssueDate("1982-06-25") + .withSubject("Science Fiction") + .build(); + + Item item3 = ItemBuilder.createItem(context, col1) + .withTitle("Python") + .withAuthor("Van Rossum, Guido") + .withIssueDate("1990") + .withSubject("Computing") + .build(); + + Item item4 = ItemBuilder.createItem(context, col2) + .withTitle("Java") + .withAuthor("Gosling, James") + .withIssueDate("1995-05-23") + .withSubject("Computing") + .build(); + + Item item5 = ItemBuilder.createItem(context, col2) + .withTitle("Zeta Reticuli") + .withAuthor("Universe") + .withIssueDate("2018-01-01") + .withSubject("Astronomy") + .build(); + + Item item6 = ItemBuilder.createItem(context, col2) + .withTitle("Moon") + .withAuthor("Universe") + .withIssueDate("2018-01-02") + .withSubject("Astronomy") + .build(); + + Item item7 = ItemBuilder.createItem(context, col2) + .withTitle("T-800") + .withAuthor("Cameron, James") + .withIssueDate("2029") + .withSubject("Science Fiction") + .build(); + // ---- BROWSES BY ITEM ---- + + //** WHEN ** + //An anonymous user browses the items in the Browse by date issued endpoint + //with startsWith set to 1990 and Page to 300 + getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=1990") + .param("size", "2").param("page", "300")) + + //** THEN ** + //The status has to be 200 OK + .andExpect(status().isOk()) + //We expect the content type to be "application/hal+json;charset=UTF-8" + .andExpect(content().contentType(contentType)) + + //We expect the totalElements to be the 7 items present in the repository + .andExpect(jsonPath("$.page.totalElements", is(7))) + //We expect to jump to the LAST page of the index + .andExpect(jsonPath("$.page.number", is(3))) + .andExpect(jsonPath("$.page.size", is(2))) + .andExpect(jsonPath("$._links.first.href", containsString("startsWith=1990"))) + + //Verify that the index jumps to the "Python" item. + .andExpect(jsonPath("$._embedded.items", + contains(ItemMatcher.matchItemWithTitleAndDateIssued(item3, + "Python", "1990"), + ItemMatcher.matchItemWithTitleAndDateIssued(item4, + "Java", "1995-05-23") + ))); + } } \ No newline at end of file From 6600839fa42c3a646a6ed71f5f6f3240fb5723a4 Mon Sep 17 00:00:00 2001 From: Pablo Prieto Date: Wed, 21 Nov 2018 21:23:00 -0600 Subject: [PATCH 10/10] Fixed ITs --- .../app/rest/BrowsesResourceControllerIT.java | 105 +----------------- 1 file changed, 5 insertions(+), 100 deletions(-) diff --git a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java index 90c790eaed..beacc1b838 100644 --- a/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java +++ b/dspace-spring-rest/src/test/java/org/dspace/app/rest/BrowsesResourceControllerIT.java @@ -639,7 +639,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe .andExpect(jsonPath("$._links.self.href", containsString("?startsWith=C"))); }; - + @Test public void testBrowseByItemsStartsWith() throws Exception { context.turnOffAuthorisationSystem(); @@ -787,7 +787,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe "Python", "1990") ))); } - + @Test public void testBrowseByStartsWithAndPage() throws Exception { context.turnOffAuthorisationSystem(); @@ -852,7 +852,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe .withIssueDate("2018-01-01") .withSubject("Astronomy") .build(); - + // ---- BROWSES BY ITEM ---- //** WHEN ** @@ -877,105 +877,10 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe //Verify that the index jumps to the "Zeta Reticuli" item. .andExpect(jsonPath("$._embedded.items", contains(ItemMatcher.matchItemWithTitleAndDateIssued(item7, - "Zeta Reticuli", "2018-01-01"), + "Zeta Reticuli", "2018-01-01"), ItemMatcher.matchItemWithTitleAndDateIssued(item4, - "Moon", "2018-01-02") + "Moon", "2018-01-02") ))); } - @Test - public void testBrowseByStartsWithAndPageGreaterThanTotalPages() throws Exception { - // This test an scenario where a nonexisting page is requested (The page number is greater than - // the total number of pages ) - 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. 7 public items that are readable by Anonymous - Item item1 = ItemBuilder.createItem(context, col1) - .withTitle("Alan Turing") - .withAuthor("Turing, Alan Mathison") - .withIssueDate("1912-06-23") - .withSubject("Computing") - .build(); - - Item item2 = ItemBuilder.createItem(context, col1) - .withTitle("Blade Runner") - .withAuthor("Scott, Ridley") - .withIssueDate("1982-06-25") - .withSubject("Science Fiction") - .build(); - - Item item3 = ItemBuilder.createItem(context, col1) - .withTitle("Python") - .withAuthor("Van Rossum, Guido") - .withIssueDate("1990") - .withSubject("Computing") - .build(); - - Item item4 = ItemBuilder.createItem(context, col2) - .withTitle("Java") - .withAuthor("Gosling, James") - .withIssueDate("1995-05-23") - .withSubject("Computing") - .build(); - - Item item5 = ItemBuilder.createItem(context, col2) - .withTitle("Zeta Reticuli") - .withAuthor("Universe") - .withIssueDate("2018-01-01") - .withSubject("Astronomy") - .build(); - - Item item6 = ItemBuilder.createItem(context, col2) - .withTitle("Moon") - .withAuthor("Universe") - .withIssueDate("2018-01-02") - .withSubject("Astronomy") - .build(); - - Item item7 = ItemBuilder.createItem(context, col2) - .withTitle("T-800") - .withAuthor("Cameron, James") - .withIssueDate("2029") - .withSubject("Science Fiction") - .build(); - // ---- BROWSES BY ITEM ---- - - //** WHEN ** - //An anonymous user browses the items in the Browse by date issued endpoint - //with startsWith set to 1990 and Page to 300 - getClient().perform(get("/api/discover/browses/dateissued/items?startsWith=1990") - .param("size", "2").param("page", "300")) - - //** THEN ** - //The status has to be 200 OK - .andExpect(status().isOk()) - //We expect the content type to be "application/hal+json;charset=UTF-8" - .andExpect(content().contentType(contentType)) - - //We expect the totalElements to be the 7 items present in the repository - .andExpect(jsonPath("$.page.totalElements", is(7))) - //We expect to jump to the LAST page of the index - .andExpect(jsonPath("$.page.number", is(3))) - .andExpect(jsonPath("$.page.size", is(2))) - .andExpect(jsonPath("$._links.first.href", containsString("startsWith=1990"))) - - //Verify that the index jumps to the "Python" item. - .andExpect(jsonPath("$._embedded.items", - contains(ItemMatcher.matchItemWithTitleAndDateIssued(item3, - "Python", "1990"), - ItemMatcher.matchItemWithTitleAndDateIssued(item4, - "Java", "1995-05-23") - ))); - } } \ No newline at end of file