Browse Source

Modified controller test and related controller to cover object lists better

master
Jim Martens 10 months ago
parent
commit
2f8d73c027
  1. 14
      oparl-server/src/main/java/de/twomartens/oparlservice/control/OParlController.java
  2. 31
      oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java
  3. 87
      oparl-server/src/test/java/de/twomartens/oparlservice/control/OParlControllerTest.java

14
oparl-server/src/main/java/de/twomartens/oparlservice/control/OParlController.java

@ -32,7 +32,7 @@ public class OParlController {
@GetMapping("/bodies")
@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");
return this.service.getBodies();
}
@ -59,7 +59,7 @@ public class OParlController {
@GetMapping("/body/{id}/organizations")
@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
@Parameter(description = "body ID", example = "0")
String id) {
@ -79,7 +79,7 @@ public class OParlController {
@GetMapping("/body/{id}/persons")
@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
@Parameter(description = "body ID", example = "0")
String id) {
@ -99,7 +99,7 @@ public class OParlController {
@GetMapping("/body/{id}/memberships")
@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
@Parameter(description = "body ID", example = "0")
String id) {
@ -109,7 +109,7 @@ public class OParlController {
@GetMapping("/organization/{id}/memberships")
@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
@Parameter(description = "organization ID", example = "0")
String id) {
@ -129,7 +129,7 @@ public class OParlController {
@GetMapping("/body/{id}/meetings")
@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
@Parameter(description = "body ID", example = "0")
String id) {
@ -139,7 +139,7 @@ public class OParlController {
@GetMapping("/organization/{id}/meetings")
@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
@Parameter(description = "organization ID", example = "0")
String id) {

31
oparl-server/src/main/java/de/twomartens/oparlservice/service/OParlService.java

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

87
oparl-server/src/test/java/de/twomartens/oparlservice/control/OParlControllerTest.java

@ -34,11 +34,13 @@ class OParlControllerTest {
private Consultation testConsultation;
private File testFile;
private LegislativeTerm testTerm;
private Links testLinks;
private Location testLocation;
private Meeting testMeeting;
private Membership testMembership;
private Organization testOrganization;
private Organization testPartyOrganization;
private Pagination testPagination;
private Paper testPaper;
private Person testPerson;
private System testSystem;
@ -66,15 +68,20 @@ class OParlControllerTest {
@Test
void shouldReturnListOfBodies() throws Exception {
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")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(24)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Body")))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(24)))
.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();
}
@ -110,15 +117,16 @@ class OParlControllerTest {
@Test
void shouldReturnOrganizationsInBody() throws Exception {
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")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(15)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Organization")))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(2)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(15)))
.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();
}
@ -139,15 +147,16 @@ class OParlControllerTest {
@Test
void shouldReturnPersonsInBody() throws Exception {
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")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(13)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Person")))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(13)))
.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();
}
@ -168,30 +177,32 @@ class OParlControllerTest {
@Test
void shouldReturnMembershipsInBody() throws Exception {
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")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Membership")))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false)))
.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/Membership")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnMembershipsInOrganization() throws Exception {
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")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Membership")))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false)))
.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/Membership")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@ -213,30 +224,32 @@ class OParlControllerTest {
@Test
void shouldReturnMeetingsInBody() throws Exception {
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")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(9)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting")))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(9)))
.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();
}
@Test
void shouldReturnMeetingsInOrganization() throws Exception {
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")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0]", Matchers.aMapWithSize(9)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting")))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].deleted", Matchers.equalTo(false)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(9)))
.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();
}
@ -411,5 +424,9 @@ class OParlControllerTest {
.cancelled(false)
.agendaItem(List.of(testItem))
.build();
testPagination = Pagination.builder().build();
testLinks = Links.builder()
.next("")
.build();
}
}
Loading…
Cancel
Save