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

690 lines
34 KiB
Java

package de.twomartens.oparlservice.control;
import de.twomartens.oparlservice.entity.System;
import de.twomartens.oparlservice.entity.*;
import de.twomartens.oparlservice.service.OParlService;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@WebMvcTest(OParlController.class)
class OParlControllerTest {
@Autowired
private MockMvc mvc;
@MockBean
private OParlService service;
private AgendaItem testItem;
private Body testBody;
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;
@BeforeEach
void setUp() {
initializeTestValues();
}
@Test
void shouldReturnAgendaItem() throws Exception {
BDDMockito.given(service.getAgendaItem("0"))
.willReturn(Optional.of(testItem));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/agendaItem/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/AgendaItem")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnAgendaItemsInBody() throws Exception {
BDDMockito.given(service.getAgendaItemsInBody("0"))
.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();
}
@Test
void shouldReturnBody() throws Exception {
BDDMockito.given(service.getBody("0"))
.willReturn(Optional.of(testBody));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(24)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Body")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnConsultation() throws Exception {
BDDMockito.given(service.getConsultation("0"))
.willReturn(Optional.of(testConsultation));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/consultation/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasKey("paper")))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasKey("agendaItem")))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasKey("meeting")))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Consultation")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnConsultationsInBody() throws Exception {
BDDMockito.given(service.getConsultationsInBody("0"))
.willReturn(Optional.of(
ObjectList.<Consultation>builder().data(List.of(testConsultation)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/consultations")
.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/Consultation")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnErrorObject_WhenInvalidIDPassed() throws Exception {
BDDMockito.given(service.getBody("2"))
.willReturn(Optional.empty());
BDDMockito.given(service.getMembershipsInBody("2"))
.willReturn(Optional.empty());
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/2")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Error")))
.andReturn();
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/2/memberships")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is4xxClientError())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Error")))
.andReturn();
}
@Test
void shouldReturnFile() throws Exception {
BDDMockito.given(service.getFile("0"))
.willReturn(Optional.of(testFile));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/file/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(10)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasKey("accessUrl")))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/File")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnFilesInBody() throws Exception {
BDDMockito.given(service.getFilesInBody("0"))
.willReturn(Optional.of(
ObjectList.<File>builder().data(List.of(testFile)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/files")
.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(10)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.hasKey("accessUrl")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/File")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnLegislativeTerm() throws Exception {
BDDMockito.given(service.getLegislativeTerm("21"))
.willReturn(Optional.of(testTerm));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/legislativeTerm/21")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(9)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasKey("body")))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/LegislativeTerm")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnLegislativeTermsOFBody() throws Exception {
BDDMockito.given(service.getLegislativeTermsOfBody("0"))
.willReturn(Optional.of(
ObjectList.<LegislativeTerm>builder().data(List.of(testTerm)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/legislativeTerms")
.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(9)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/LegislativeTerm")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnListOfBodies() throws Exception {
BDDMockito.given(service.getBodies())
.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.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();
}
@Test
void shouldReturnLocation() throws Exception {
BDDMockito.given(service.getLocation("0"))
.willReturn(Optional.of(testLocation));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/location/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(14)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Location")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnLocationsInBody() throws Exception {
BDDMockito.given(service.getLocationsInBody("0"))
.willReturn(Optional.of(
ObjectList.<Location>builder().data(List.of(testLocation)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/locations")
.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(14)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Location")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnMeeting() throws Exception {
BDDMockito.given(service.getMeeting("0"))
.willReturn(Optional.of(testMeeting));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/meeting/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(9)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnMeetingsInBody() throws Exception {
BDDMockito.given(service.getMeetingsInBody("0"))
.willReturn(Optional.of(
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.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(Optional.of(
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.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 shouldReturnMembership() throws Exception {
BDDMockito.given(service.getMembership("0"))
.willReturn(Optional.of(testMembership));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/membership/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasKey("person")))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Membership")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnMembershipsInBody() throws Exception {
BDDMockito.given(service.getMembershipsInBody("0"))
.willReturn(Optional.of(
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.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(Optional.of(
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.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 shouldReturnOrganization() throws Exception {
BDDMockito.given(service.getOrganization("0"))
.willReturn(Optional.of(testOrganization));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/organization/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(15)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Organization")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnOrganizationsInBody() throws Exception {
BDDMockito.given(service.getOrganizationsInBody("0"))
.willReturn(Optional.of(
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.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();
}
@Test
void shouldReturnPaper() throws Exception {
BDDMockito.given(service.getPaper("0"))
.willReturn(Optional.of(testPaper));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/paper/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(10)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Paper")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnPapersInBody() throws Exception {
BDDMockito.given(service.getPapersInBody("0"))
.willReturn(Optional.of(
ObjectList.<Paper>builder().data(List.of(testPaper)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/papers")
.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(10)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].type", Matchers.equalTo("https://schema.oparl.org/1.1/Paper")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnPerson() throws Exception {
BDDMockito.given(service.getPerson("0"))
.willReturn(Optional.of(testPerson));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/person/0")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(13)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Person")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
@Test
void shouldReturnPersonsInBody() throws Exception {
BDDMockito.given(service.getPersonsInBody("0"))
.willReturn(Optional.of(
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.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();
}
@Test
void shouldReturnSystemInfo() throws Exception {
BDDMockito.given(service.getSystem())
.willReturn(testSystem);
mvc.perform(MockMvcRequestBuilders.get("/v1.1/")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(14)))
.andExpect(MockMvcResultMatchers.jsonPath("$.id", Matchers.equalTo("/v1.1/")))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/System")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn();
}
private void initializeTestValues() {
testSystem = System.builder()
.id("/v1.1/")
.type("https://schema.oparl.org/1.1/System")
.license("https://www.govdata.de/dl-de/by-2-0")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.oparlVersion("https://schema.oparl.org/1.1/")
.name("OParl interface for ALLRIS of Hamburg Eimsbüttel")
.contactEmail("github@2martens.de")
.contactName("Jim Martens")
.website("https://sitzungsdienst-eimsbuettel.hamburg.de/bi/")
.vendor("https://2martens.de")
.product("https://git.2martens.de/2martens/oparl-service")
.body("/bodies")
.deleted(false)
.build();
testTerm = LegislativeTerm.builder()
.id("/v1.1/term/21")
.type("https://schema.oparl.org/1.1/LegislativeTerm")
.body("/v1.1/body/0")
.name("21. Wahlperiode")
.startDate(LocalDate.parse("2019-05-27"))
.endDate(LocalDate.parse("2024-05-26"))
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.build();
testBody = Body.builder()
.id("/v1.1/body/0")
.type("https://schema.oparl.org/1.1/Body")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.shortName("Hamburg")
.name("Bezirk Eimsbüttel")
.system("/v1.1")
.legislativeTerm(List.of(testTerm))
.website("https://www.hamburg.de/eimsbuettel")
.ags("02000000")
.rgs("020000000000")
.equivalent(List.of("http://dbpedia.org/page/Eimsb%C3%BCttel", "http://d-nb.info/1208293575"))
.organization("/v1.1/organizations/0")
.person("/v1.1/persons/0")
.meeting("/v1.1/meetings/0")
.paper("/v1.1/papers/0")
.agendaItem("/v1.1/agendaItems/0")
.consultation("/v1.1/consultations/0")
.file("/v1.1/files/0")
.locationList("/v1.1/locations/0")
.legislativeTermList("/v1.1/terms")
.membership("/v1.1/memberships/0")
.classification("Bezirk")
.deleted(false)
.build();
testOrganization = Organization.builder()
.id("/v1.1/organization/0")
.type("https://schema.oparl.org/1.1/Organization")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.body("/v1.1/body/0")
.name("Bezirksversammlung Eimsbüttel")
.shortName("Bezirksversammlung")
.membership(Collections.emptyList())
.meeting("/v1.1/organization/0/meetings")
.consultation("/v1.1/organization/0/consultations")
.post(List.of(
"Vorsitzende/r der Bezirksversammlung",
"stellvertretende/r Vorsitzende/r der Bezirksversammlung",
"Mitglied der Bezirksversammlung"
))
.organizationType(OrganizationType.BODY)
.classification("Parlament")
.startDate(LocalDate.parse("2019-06-06"))
.deleted(false)
.build();
testPartyOrganization = Organization.builder()
.id("/v1.1/organization/1")
.type("https://schema.oparl.org/1.1/Organization")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.body("/v1.1/body/0")
.name("GRÜNE Hamburg")
.shortName("GRÜNE")
.membership(Collections.emptyList())
.meeting("/v1.1/organization/1/meetings")
.consultation("/v1.1/organization/1/consultations")
.post(Collections.emptyList())
.organizationType(OrganizationType.PARTY)
.classification("Partei")
.build();
testPerson = Person.builder()
.id("/v1.1/person/0")
.type("https://schema.oparl.org/1.1/Person")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.body("/v1.1/body/0")
.name("Erika Mustermann")
.familyName("Mustermann")
.givenName("Erika")
.formOfAddress("Frau")
.gender("female")
.status(List.of("Mitglied in der Bezirksversammlung"))
.membership(Collections.emptyList())
.deleted(false)
.build();
testMembership = Membership.builder()
.id("/v1.1/membership/0")
.type("https://schema.oparl.org/1.1/Membership")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.person("/v1.1/person/0")
.organization("/v1.1/organization/0")
.role("Mitglied der Bezirksversammlung")
.votingRight(true)
.startDate(LocalDate.parse("2019-06-06"))
.onBehalfOf("/v1.1/organization/1")
.build();
testItem = AgendaItem.builder()
.id("/v1.1/agendaItem/0")
.type("https://schema.oparl.org/1.1/AgendaItem")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.meeting("/v1.1/meeting/0")
.number("1")
.order(0)
.name("Formalia")
.isPublic(true)
.consultation("/v1.1/consultation/0")
.build();
testMeeting = Meeting.builder()
.id("/v1.1/meeting/0")
.type("https://schema.oparl.org/1.1/Meeting")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.name("Konstituierende Sitzung der Bezirksversammlung")
.meetingState(MeetingState.FINISHED)
.cancelled(false)
.agendaItem(List.of(testItem))
.build();
testPagination = Pagination.builder().build();
testLinks = Links.builder()
.next("")
.build();
testPaper = Paper.builder()
.id("/v1.1/paper/0")
.type("https://schema.oparl.org/1.1/Paper")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.body("/v1.1/body/0")
.name("OParl einführen")
.reference("21-0346")
.date(LocalDate.parse("2020-05-05"))
.paperType("Antrag")
.build();
testConsultation = Consultation.builder()
.id("/v1.1/consultation/0")
.type("https://schema.oparl.org/1.1/Consultation")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.paper("/v1.1/paper/0")
.agendaItem("/v1.1/agendaItem/0")
.meeting("/v1.1/meeting/0")
.organization(List.of("/v1.1/organization/0"))
.authoritative(false)
.role("Vorberatung")
.build();
testFile = File.builder()
.id("/v1.1/file/0")
.type("https://schema.oparl.org/1.1/File")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.name("Tagesordnung")
.fileName("Tagesordnung-0.pdf")
.mimeType("application/pdf")
.size(546)
.accessUrl("/v1.1/file/0/view")
.build();
testLocation = Location.builder()
.id("/v1.1/location/0")
.type("https://schema.oparl.org/1.1/Location")
.created(ZonedDateTime.now())
.modified(ZonedDateTime.now())
.deleted(false)
.description("Ferdinand-Streb-Saal")
.streetAddress("Grindelberg 62-66")
.postalCode("22040")
.locality("Hamburg")
.bodies(List.of(testBody.getId()))
.organizations(List.of(testOrganization.getId()))
.persons(Collections.emptyList())
.meetings(List.of(testMeeting.getId()))
.papers(Collections.emptyList())
.build();
}
}