Added pagination support to object list requests

This commit is contained in:
Jim Martens 2020-07-18 13:41:13 +02:00
parent e6501cba83
commit 4022711f1a
3 changed files with 330 additions and 230 deletions

View File

@ -1,7 +1,7 @@
package de.twomartens.oparlservice.control; package de.twomartens.oparlservice.control;
import de.twomartens.oparlservice.entity.dto.*;
import de.twomartens.oparlservice.entity.dto.System; import de.twomartens.oparlservice.entity.dto.System;
import de.twomartens.oparlservice.entity.dto.*;
import de.twomartens.oparlservice.service.OParlService; import de.twomartens.oparlservice.service.OParlService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
@ -40,7 +40,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/agendaItems") @GetMapping(value = {"/body/{id}/agendaItems", "/body/{id}/agendaItems/{pageNumber}"})
@Operation(summary = "List of all agenda items in body", @Operation(summary = "List of all agenda items in body",
description = "returns a list of all agenda items in requested body", responses = { description = "returns a list of all agenda items in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -51,9 +51,15 @@ public class OParlController {
public ObjectList<AgendaItem> agendaItemsInBody( public ObjectList<AgendaItem> agendaItemsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
log.info("invoked method /v1.1/body/{}/agendaItems", id); @PathVariable(required = false)
return service.getAgendaItemsInBody(id).orElseThrow(() -> { @Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/agendaItems/{}", id, pageNumber);
if (pageNumber == null) {
pageNumber = 1;
}
return service.getAgendaItemsInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@ -103,7 +109,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/consultations") @GetMapping(value = {"/body/{id}/consultations", "/body/{id}/consultations/{pageNumber}"})
@Operation(summary = "List of all consultations in body", @Operation(summary = "List of all consultations in body",
description = "returns a list of all consultations in requested body", responses = { description = "returns a list of all consultations in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -114,9 +120,15 @@ public class OParlController {
public ObjectList<Consultation> consultationsInBody( public ObjectList<Consultation> consultationsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/consultations", id); log.info("invoked method /v1.1/body/{}/consultations", id);
return service.getConsultationsInBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getConsultationsInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@ -138,7 +150,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/files") @GetMapping(value = {"/body/{id}/files", "/body/{id}/files/{pageNumber}"})
@Operation(summary = "List of all files in body", @Operation(summary = "List of all files in body",
description = "returns a list of all files in requested body", responses = { description = "returns a list of all files in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -149,9 +161,15 @@ public class OParlController {
public ObjectList<File> filesInBody( public ObjectList<File> filesInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/files", id); log.info("invoked method /v1.1/body/{}/files", id);
return service.getFilesInBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getFilesInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@ -173,7 +191,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/legislativeTerms") @GetMapping(value = {"/body/{id}/legislativeTerms", "/body/{id}/legislativeTerms/{pageNumber}"})
@Operation(summary = "List of all legislative terms of a body", description = "returns a list of all legislative terms of requested body", responses = { @Operation(summary = "List of all legislative terms of a body", description = "returns a list of all legislative terms of requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListLegislativeTerm.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListLegislativeTerm.class))),
@ -183,9 +201,15 @@ public class OParlController {
public ObjectList<LegislativeTerm> legislativeTermsOfBody( public ObjectList<LegislativeTerm> legislativeTermsOfBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/legislativeTerms", id); log.info("invoked method /v1.1/body/{}/legislativeTerms", id);
return service.getLegislativeTermsOfBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getLegislativeTermsOfBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@ -207,7 +231,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/locations") @GetMapping(value = {"/body/{id}/locations", "/body/{id}/locations/{pageNumber}"})
@Operation(summary = "List of all locations in body", @Operation(summary = "List of all locations in body",
description = "returns a list of all locations in requested body", responses = { description = "returns a list of all locations in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -218,9 +242,15 @@ public class OParlController {
public ObjectList<Location> locationsInBody( public ObjectList<Location> locationsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/locations", id); log.info("invoked method /v1.1/body/{}/locations", id);
return service.getLocationsInBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getLocationsInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@ -242,7 +272,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/meetings") @GetMapping(value = {"/body/{id}/meetings", "/body/{id}/meetings/{pageNumber}"})
@Operation(summary = "List of all meetings in body", @Operation(summary = "List of all meetings in body",
description = "returns a list of all meetings in requested body", responses = { description = "returns a list of all meetings in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -253,14 +283,20 @@ public class OParlController {
public ObjectList<Meeting> meetingsInBody( public ObjectList<Meeting> meetingsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/meetings", id); log.info("invoked method /v1.1/body/{}/meetings", id);
return service.getMeetingsInBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getMeetingsInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@GetMapping("/organization/{id}/meetings") @GetMapping(value = {"/organization/{id}/meetings", "/organization/{id}/meetings/{pageNumber}"})
@Operation(summary = "List of all meetings in organization", @Operation(summary = "List of all meetings in organization",
description = "returns a list of all meetings in requested organization", responses = { description = "returns a list of all meetings in requested organization", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -271,9 +307,15 @@ public class OParlController {
public ObjectList<Meeting> meetingsInOrganization( public ObjectList<Meeting> meetingsInOrganization(
@PathVariable @PathVariable
@Parameter(description = "organization ID", example = "0") @Parameter(description = "organization ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/organization/{}/meetings", id); log.info("invoked method /v1.1/organization/{}/meetings", id);
return service.getMeetingsInOrganization(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getMeetingsInOrganization(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert");
}); });
} }
@ -295,7 +337,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/memberships") @GetMapping(value = {"/body/{id}/memberships", "/body/{id}/memberships/{pageNumber}"})
@Operation(summary = "List of all memberships in body", description = "returns a list of all memberships in requested body", responses = { @Operation(summary = "List of all memberships in body", description = "returns a list of all memberships in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMembership.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListMembership.class))),
@ -305,14 +347,20 @@ public class OParlController {
public ObjectList<Membership> membershipsInBody( public ObjectList<Membership> membershipsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/memberships", id); log.info("invoked method /v1.1/body/{}/memberships", id);
return service.getMembershipsInBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getMembershipsInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@GetMapping("/organization/{id}/memberships") @GetMapping(value = {"/organization/{id}/memberships", "/organization/{id}/memberships/{pageNumber}"})
@Operation(summary = "List of all memberships in organization", @Operation(summary = "List of all memberships in organization",
description = "returns a list of all memberships in requested organization", responses = { description = "returns a list of all memberships in requested organization", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -323,9 +371,15 @@ public class OParlController {
public ObjectList<Membership> membershipsInOrganization( public ObjectList<Membership> membershipsInOrganization(
@PathVariable @PathVariable
@Parameter(description = "organization ID", example = "0") @Parameter(description = "organization ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/organization/{}/memberships", id); log.info("invoked method /v1.1/organization/{}/memberships", id);
return service.getMembershipsInOrganization(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getMembershipsInOrganization(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert");
}); });
} }
@ -356,7 +410,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/organizations") @GetMapping(value = {"/body/{id}/organizations", "/body/{id}/organizations/{pageNumber}"})
@Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in requested body", responses = { @Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListOrganization.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListOrganization.class))),
@ -366,9 +420,15 @@ public class OParlController {
public ObjectList<Organization> organizationsInBody( public ObjectList<Organization> organizationsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/organizations", id); log.info("invoked method /v1.1/body/{}/organizations", id);
return service.getOrganizationsInBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getOrganizationsInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@ -390,7 +450,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/papers") @GetMapping(value = {"/body/{id}/papers", "/body/{id}/papers/{pageNumber}"})
@Operation(summary = "List of all papers in body", @Operation(summary = "List of all papers in body",
description = "returns a list of all papers in requested body", responses = { description = "returns a list of all papers in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -401,9 +461,15 @@ public class OParlController {
public ObjectList<Paper> papersInBody( public ObjectList<Paper> papersInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/papers", id); log.info("invoked method /v1.1/body/{}/papers", id);
return service.getPapersInBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getPapersInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }
@ -425,7 +491,7 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/persons") @GetMapping(value = {"/body/{id}/persons", "/body/{id}/persons/{pageNumber}"})
@Operation(summary = "List of all persons in body", description = "returns a list of all persons in requested body", responses = { @Operation(summary = "List of all persons in body", description = "returns a list of all persons in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListPerson.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.ObjectListPerson.class))),
@ -435,9 +501,15 @@ public class OParlController {
public ObjectList<Person> persons( public ObjectList<Person> persons(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id,
@PathVariable(required = false)
@Parameter(description = "page number", example = "1")
Integer pageNumber) {
log.info("invoked method /v1.1/body/{}/persons", id); log.info("invoked method /v1.1/body/{}/persons", id);
return service.getPersonsInBody(id).orElseThrow(() -> { if (pageNumber == null) {
pageNumber = 1;
}
return service.getPersonsInBody(id, pageNumber).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
}); });
} }

View File

@ -16,7 +16,7 @@ public class OParlService {
this.properties = properties; this.properties = properties;
} }
public Optional<ObjectList<AgendaItem>> getAgendaItemsInBody(String bodyID) { public Optional<ObjectList<AgendaItem>> getAgendaItemsInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
@ -32,7 +32,7 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Consultation>> getConsultationsInBody(String bodyID) { public Optional<ObjectList<Consultation>> getConsultationsInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
@ -40,7 +40,7 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<File>> getFilesInBody(String bodyID) { public Optional<ObjectList<File>> getFilesInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
@ -48,7 +48,7 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<LegislativeTerm>> getLegislativeTermsOfBody(String bodyID) { public Optional<ObjectList<LegislativeTerm>> getLegislativeTermsOfBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
@ -56,7 +56,7 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Location>> getLocationsInBody(String bodyID) { public Optional<ObjectList<Location>> getLocationsInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
@ -68,11 +68,11 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Meeting>> getMeetingsInBody(String bodyID) { public Optional<ObjectList<Meeting>> getMeetingsInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Meeting>> getMeetingsInOrganization(String organizationID) { public Optional<ObjectList<Meeting>> getMeetingsInOrganization(String organizationID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
@ -80,15 +80,15 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Membership>> getMembershipsInBody(String bodyID) { public Optional<ObjectList<Membership>> getMembershipsInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Membership>> getMembershipsInOrganization(String organizationID) { public Optional<ObjectList<Membership>> getMembershipsInOrganization(String organizationID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Organization>> getOrganizationsInBody(String bodyID) { public Optional<ObjectList<Organization>> getOrganizationsInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
@ -96,7 +96,7 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Paper>> getPapersInBody(String bodyID) { public Optional<ObjectList<Paper>> getPapersInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }
@ -104,7 +104,7 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Person>> getPersonsInBody(String bodyID) { public Optional<ObjectList<Person>> getPersonsInBody(String bodyID, int pageNumber) {
return Optional.empty(); return Optional.empty();
} }

View File

@ -67,7 +67,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnAgendaItemsInBody() throws Exception { void shouldReturnAgendaItemsInBody() throws Exception {
BDDMockito.given(service.getAgendaItemsInBody("0")) BDDMockito.given(service.getAgendaItemsInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<AgendaItem>builder().data(List.of(testItem)).pagination(testPagination).links(testLinks).build() ObjectList.<AgendaItem>builder().data(List.of(testItem)).pagination(testPagination).links(testLinks).build()
)); ));
@ -83,6 +83,34 @@ class OParlControllerTest {
.andReturn(); .andReturn();
} }
@Test
void shouldAssumeFirstPage_WhenNoPageNumberGiven() throws Exception {
BDDMockito.given(service.getAgendaItemsInBody("0", 1))
.willReturn(Optional.of(
ObjectList.<AgendaItem>builder().data(List.of(testItem)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/agendaItems")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/AgendaItem")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/agendaItems/1")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/AgendaItem")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test @Test
void shouldReturnBody() throws Exception { void shouldReturnBody() throws Exception {
BDDMockito.given(service.getBody("0")) BDDMockito.given(service.getBody("0"))
@ -116,7 +144,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnConsultationsInBody() throws Exception { void shouldReturnConsultationsInBody() throws Exception {
BDDMockito.given(service.getConsultationsInBody("0")) BDDMockito.given(service.getConsultationsInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Consultation>builder().data(List.of(testConsultation)).pagination(testPagination).links(testLinks).build() ObjectList.<Consultation>builder().data(List.of(testConsultation)).pagination(testPagination).links(testLinks).build()
)); ));
@ -137,7 +165,7 @@ class OParlControllerTest {
BDDMockito.given(service.getBody("2")) BDDMockito.given(service.getBody("2"))
.willReturn(Optional.empty()); .willReturn(Optional.empty());
BDDMockito.given(service.getMembershipsInBody("2")) BDDMockito.given(service.getMembershipsInBody("2", 1))
.willReturn(Optional.empty()); .willReturn(Optional.empty());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/2") mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/2")
@ -172,7 +200,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnFilesInBody() throws Exception { void shouldReturnFilesInBody() throws Exception {
BDDMockito.given(service.getFilesInBody("0")) BDDMockito.given(service.getFilesInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<File>builder().data(List.of(testFile)).pagination(testPagination).links(testLinks).build() ObjectList.<File>builder().data(List.of(testFile)).pagination(testPagination).links(testLinks).build()
)); ));
@ -205,8 +233,8 @@ class OParlControllerTest {
} }
@Test @Test
void shouldReturnLegislativeTermsOFBody() throws Exception { void shouldReturnLegislativeTermsOfBody() throws Exception {
BDDMockito.given(service.getLegislativeTermsOfBody("0")) BDDMockito.given(service.getLegislativeTermsOfBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<LegislativeTerm>builder().data(List.of(testTerm)).pagination(testPagination).links(testLinks).build() ObjectList.<LegislativeTerm>builder().data(List.of(testTerm)).pagination(testPagination).links(testLinks).build()
)); ));
@ -258,7 +286,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnLocationsInBody() throws Exception { void shouldReturnLocationsInBody() throws Exception {
BDDMockito.given(service.getLocationsInBody("0")) BDDMockito.given(service.getLocationsInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Location>builder().data(List.of(testLocation)).pagination(testPagination).links(testLinks).build() ObjectList.<Location>builder().data(List.of(testLocation)).pagination(testPagination).links(testLinks).build()
)); ));
@ -290,7 +318,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnMeetingsInBody() throws Exception { void shouldReturnMeetingsInBody() throws Exception {
BDDMockito.given(service.getMeetingsInBody("0")) BDDMockito.given(service.getMeetingsInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Meeting>builder().data(List.of(testMeeting)).pagination(testPagination).links(testLinks).build() ObjectList.<Meeting>builder().data(List.of(testMeeting)).pagination(testPagination).links(testLinks).build()
)); ));
@ -308,7 +336,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnMeetingsInOrganization() throws Exception { void shouldReturnMeetingsInOrganization() throws Exception {
BDDMockito.given(service.getMeetingsInOrganization("0")) BDDMockito.given(service.getMeetingsInOrganization("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Meeting>builder().data(List.of(testMeeting)).pagination(testPagination).links(testLinks).build() ObjectList.<Meeting>builder().data(List.of(testMeeting)).pagination(testPagination).links(testLinks).build()
)); ));
@ -341,7 +369,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnMembershipsInBody() throws Exception { void shouldReturnMembershipsInBody() throws Exception {
BDDMockito.given(service.getMembershipsInBody("0")) BDDMockito.given(service.getMembershipsInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Membership>builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build() ObjectList.<Membership>builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build()
)); ));
@ -359,7 +387,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnMembershipsInOrganization() throws Exception { void shouldReturnMembershipsInOrganization() throws Exception {
BDDMockito.given(service.getMembershipsInOrganization("0")) BDDMockito.given(service.getMembershipsInOrganization("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Membership>builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build() ObjectList.<Membership>builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build()
)); ));
@ -391,7 +419,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnOrganizationsInBody() throws Exception { void shouldReturnOrganizationsInBody() throws Exception {
BDDMockito.given(service.getOrganizationsInBody("0")) BDDMockito.given(service.getOrganizationsInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Organization>builder().data(List.of(testOrganization, testPartyOrganization)).pagination(testPagination).links(testLinks).build() ObjectList.<Organization>builder().data(List.of(testOrganization, testPartyOrganization)).pagination(testPagination).links(testLinks).build()
)); ));
@ -423,7 +451,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnPapersInBody() throws Exception { void shouldReturnPapersInBody() throws Exception {
BDDMockito.given(service.getPapersInBody("0")) BDDMockito.given(service.getPapersInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Paper>builder().data(List.of(testPaper)).pagination(testPagination).links(testLinks).build() ObjectList.<Paper>builder().data(List.of(testPaper)).pagination(testPagination).links(testLinks).build()
)); ));
@ -455,7 +483,7 @@ class OParlControllerTest {
@Test @Test
void shouldReturnPersonsInBody() throws Exception { void shouldReturnPersonsInBody() throws Exception {
BDDMockito.given(service.getPersonsInBody("0")) BDDMockito.given(service.getPersonsInBody("0", 1))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<Person>builder().data(List.of(testPerson)).pagination(testPagination).links(testLinks).build() ObjectList.<Person>builder().data(List.of(testPerson)).pagination(testPagination).links(testLinks).build()
)); ));