Modified controller test and related controller to cover object lists better

This commit is contained in:
Jim Martens 2020-07-11 19:58:13 +02:00
parent e2f896338f
commit 2f8d73c027
3 changed files with 74 additions and 58 deletions

View File

@ -32,7 +32,7 @@ public class OParlController {
@GetMapping("/bodies") @GetMapping("/bodies")
@Operation(summary = "List of available bodies", description = "returns a list of available bodies in this OParl system") @Operation(summary = "List of available bodies", description = "returns a list of available bodies in this OParl system")
public List<Body> bodies() { public ObjectList<Body> bodies() {
log.info("method invoked /v1.1/bodies"); log.info("method invoked /v1.1/bodies");
return this.service.getBodies(); return this.service.getBodies();
} }
@ -59,7 +59,7 @@ public class OParlController {
@GetMapping("/body/{id}/organizations") @GetMapping("/body/{id}/organizations")
@Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in requested body") @Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in requested body")
public List<Organization> organizationsInBody( public ObjectList<Organization> organizationsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id) {
@ -79,7 +79,7 @@ public class OParlController {
@GetMapping("/body/{id}/persons") @GetMapping("/body/{id}/persons")
@Operation(summary = "List of all persons in body", description = "returns a list of all persons in requested body") @Operation(summary = "List of all persons in body", description = "returns a list of all persons in requested body")
public List<Person> persons( public ObjectList<Person> persons(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id) {
@ -99,7 +99,7 @@ public class OParlController {
@GetMapping("/body/{id}/memberships") @GetMapping("/body/{id}/memberships")
@Operation(summary = "List of all memberships in body", description = "returns a list of all memberships in requested body") @Operation(summary = "List of all memberships in body", description = "returns a list of all memberships in requested body")
public List<Membership> membershipsInBody( public ObjectList<Membership> membershipsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id) {
@ -109,7 +109,7 @@ public class OParlController {
@GetMapping("/organization/{id}/memberships") @GetMapping("/organization/{id}/memberships")
@Operation(summary = "List of all memberships in organization", description = "returns a list of all memberships in requested organization") @Operation(summary = "List of all memberships in organization", description = "returns a list of all memberships in requested organization")
public List<Membership> membershipsInOrganization( public ObjectList<Membership> membershipsInOrganization(
@PathVariable @PathVariable
@Parameter(description = "organization ID", example = "0") @Parameter(description = "organization ID", example = "0")
String id) { String id) {
@ -129,7 +129,7 @@ public class OParlController {
@GetMapping("/body/{id}/meetings") @GetMapping("/body/{id}/meetings")
@Operation(summary = "List of all meetings in body", description = "returns a list of all meetings in requested body") @Operation(summary = "List of all meetings in body", description = "returns a list of all meetings in requested body")
public List<Meeting> meetingsInBody( public ObjectList<Meeting> meetingsInBody(
@PathVariable @PathVariable
@Parameter(description = "body ID", example = "0") @Parameter(description = "body ID", example = "0")
String id) { String id) {
@ -139,7 +139,7 @@ public class OParlController {
@GetMapping("/organization/{id}/meetings") @GetMapping("/organization/{id}/meetings")
@Operation(summary = "List of all meetings in organization", description = "returns a list of all meetings in requested organization") @Operation(summary = "List of all meetings in organization", description = "returns a list of all meetings in requested organization")
public List<Meeting> meetingsInOrganization( public ObjectList<Meeting> meetingsInOrganization(
@PathVariable @PathVariable
@Parameter(description = "organization ID", example = "0") @Parameter(description = "organization ID", example = "0")
String id) { String id) {

View File

@ -1,13 +1,12 @@
package de.twomartens.oparlservice.service; package de.twomartens.oparlservice.service;
import de.twomartens.oparlservice.configs.OParlServiceProperties; import de.twomartens.oparlservice.configs.OParlServiceProperties;
import de.twomartens.oparlservice.entity.*;
import de.twomartens.oparlservice.entity.System; import de.twomartens.oparlservice.entity.System;
import de.twomartens.oparlservice.entity.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List; import java.util.List;
@Service @Service
@ -77,8 +76,8 @@ public class OParlService {
return null; return null;
} }
public List<Body> getBodies() { public ObjectList<Body> getBodies() {
return List.of(exampleBody); return null;
} }
public Body getBody(String id) { public Body getBody(String id) {
@ -93,36 +92,36 @@ public class OParlService {
return null; return null;
} }
public List<Meeting> getMeetingsInBody(String bodyID) { public ObjectList<Meeting> getMeetingsInBody(String bodyID) {
return Collections.emptyList(); return null;
} }
public List<Meeting> getMeetingsInOrganization(String organizationID) { public ObjectList<Meeting> getMeetingsInOrganization(String organizationID) {
return Collections.emptyList(); return null;
} }
public Membership getMembership(String id) { public Membership getMembership(String id) {
return null; return null;
} }
public List<Membership> getMembershipsInBody(String bodyID) { public ObjectList<Membership> getMembershipsInBody(String bodyID) {
return Collections.emptyList(); return null;
} }
public List<Membership> getMembershipsInOrganization(String organizationID) { public ObjectList<Membership> getMembershipsInOrganization(String organizationID) {
return Collections.emptyList(); return null;
} }
public List<Organization> getOrganizationsInBody(String bodyID) { public ObjectList<Organization> getOrganizationsInBody(String bodyID) {
return Collections.emptyList(); return null;
} }
public Organization getOrganization(String id) { public Organization getOrganization(String id) {
return null; return null;
} }
public List<Person> getPersonsInBody(String bodyID) { public ObjectList<Person> getPersonsInBody(String bodyID) {
return Collections.emptyList(); return null;
} }
public Person getPerson(String id) { public Person getPerson(String id) {

View File

@ -34,11 +34,13 @@ class OParlControllerTest {
private Consultation testConsultation; private Consultation testConsultation;
private File testFile; private File testFile;
private LegislativeTerm testTerm; private LegislativeTerm testTerm;
private Links testLinks;
private Location testLocation; private Location testLocation;
private Meeting testMeeting; private Meeting testMeeting;
private Membership testMembership; private Membership testMembership;
private Organization testOrganization; private Organization testOrganization;
private Organization testPartyOrganization; private Organization testPartyOrganization;
private Pagination testPagination;
private Paper testPaper; private Paper testPaper;
private Person testPerson; private Person testPerson;
private System testSystem; private System testSystem;
@ -66,15 +68,20 @@ class OParlControllerTest {
@Test @Test
void shouldReturnListOfBodies() throws Exception { void shouldReturnListOfBodies() throws Exception {
BDDMockito.given(service.getBodies()) BDDMockito.given(service.getBodies())
.willReturn(List.of(testBody)); .willReturn(ObjectList.<Body>builder()
.data(List.of(testBody))
.pagination(testPagination)
.links(testLinks)
.build());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/bodies") mvc.perform(MockMvcRequestBuilders.get("/v1.1/bodies")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(24))) .andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Body"))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(24)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Body")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@ -110,15 +117,16 @@ class OParlControllerTest {
@Test @Test
void shouldReturnOrganizationsInBody() throws Exception { void shouldReturnOrganizationsInBody() throws Exception {
BDDMockito.given(service.getOrganizationsInBody("0")) BDDMockito.given(service.getOrganizationsInBody("0"))
.willReturn(List.of(testOrganization, testPartyOrganization)); .willReturn(ObjectList.<Organization>builder().data(List.of(testOrganization, testPartyOrganization)).pagination(testPagination).links(testLinks).build());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/organizations") mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/organizations")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(15))) .andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(2)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Organization"))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(15)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Organization")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@ -139,15 +147,16 @@ class OParlControllerTest {
@Test @Test
void shouldReturnPersonsInBody() throws Exception { void shouldReturnPersonsInBody() throws Exception {
BDDMockito.given(service.getPersonsInBody("0")) BDDMockito.given(service.getPersonsInBody("0"))
.willReturn(List.of(testPerson)); .willReturn(ObjectList.<Person>builder().data(List.of(testPerson)).pagination(testPagination).links(testLinks).build());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/persons") mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/persons")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(13))) .andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Person"))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(13)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Person")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@ -168,30 +177,32 @@ class OParlControllerTest {
@Test @Test
void shouldReturnMembershipsInBody() throws Exception { void shouldReturnMembershipsInBody() throws Exception {
BDDMockito.given(service.getMembershipsInBody("0")) BDDMockito.given(service.getMembershipsInBody("0"))
.willReturn(List.of(testMembership)); .willReturn(ObjectList.<Membership>builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/memberships") mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/memberships")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(11))) .andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Membership"))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Membership")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@Test @Test
void shouldReturnMembershipsInOrganization() throws Exception { void shouldReturnMembershipsInOrganization() throws Exception {
BDDMockito.given(service.getMembershipsInOrganization("0")) BDDMockito.given(service.getMembershipsInOrganization("0"))
.willReturn(List.of(testMembership)); .willReturn(ObjectList.<Membership>builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/organization/0/memberships") mvc.perform(MockMvcRequestBuilders.get("/v1.1/organization/0/memberships")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(11))) .andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Membership"))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Membership")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@ -213,30 +224,32 @@ class OParlControllerTest {
@Test @Test
void shouldReturnMeetingsInBody() throws Exception { void shouldReturnMeetingsInBody() throws Exception {
BDDMockito.given(service.getMeetingsInBody("0")) BDDMockito.given(service.getMeetingsInBody("0"))
.willReturn(List.of(testMeeting)); .willReturn(ObjectList.<Meeting>builder().data(List.of(testMeeting)).pagination(testPagination).links(testLinks).build());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/meetings") mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/meetings")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(9))) .andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting"))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(9)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@Test @Test
void shouldReturnMeetingsInOrganization() throws Exception { void shouldReturnMeetingsInOrganization() throws Exception {
BDDMockito.given(service.getMeetingsInOrganization("0")) BDDMockito.given(service.getMeetingsInOrganization("0"))
.willReturn(List.of(testMeeting)); .willReturn(ObjectList.<Meeting>builder().data(List.of(testMeeting)).pagination(testPagination).links(testLinks).build());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/organization/0/meetings") mvc.perform(MockMvcRequestBuilders.get("/v1.1/organization/0/meetings")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(9))) .andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting"))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(9)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@ -411,5 +424,9 @@ class OParlControllerTest {
.cancelled(false) .cancelled(false)
.agendaItem(List.of(testItem)) .agendaItem(List.of(testItem))
.build(); .build();
testPagination = Pagination.builder().build();
testLinks = Links.builder()
.next("")
.build();
} }
} }