Added remaining operations and corresponding tests

This commit is contained in:
Jim Martens 2020-07-11 22:09:26 +02:00
parent d2b8ae5b6d
commit 9a88ef34b2
3 changed files with 657 additions and 260 deletions

View File

@ -23,15 +23,39 @@ public class OParlController {
this.service = service; this.service = service;
} }
@GetMapping("/") @GetMapping("/agendaItem/{id}")
@Operation(summary = "System information", description = "returns information about the OParl system", responses = { @Operation(summary = "information about agenda item", description = "returns the requested agenda item", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", content = @Content( @ApiResponse(description = "Successful Operation", responseCode = "200",
mediaType = "application/json", schema = @Schema(implementation = System.class) content = @Content(mediaType = "application/json", schema = @Schema(implementation = Body.class))),
)) @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
}) })
public System system() { public AgendaItem agendaItem(
log.info("method invoked /v1.1"); @PathVariable
return service.getSystem(); @Parameter(description = "agendaItem ID", example = "0")
String id) {
log.info("invoked method /v1.1/agendaItem/{}", id);
return service.getAgendaItem(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Kein Tagesordnungspunkt mit angefragter ID existiert");
});
}
@GetMapping("/body/{id}/agendaItems")
@Operation(summary = "List of all agenda items in body",
description = "returns a list of all agenda items in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<AgendaItem> agendaItemsInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("invoked method /v1.1/body/{}/agendaItems", id);
return service.getAgendaItemsInBody(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
});
} }
@GetMapping("/bodies") @GetMapping("/bodies")
@ -62,6 +86,76 @@ public class OParlController {
}); });
} }
@GetMapping("/consultation/{id}")
@Operation(summary = "information about consultation", description = "returns the requested consultation", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Consultation.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Consultation consultation(
@PathVariable
@Parameter(description = "consultation ID", example = "0")
String id) {
log.info("invoked method /v1.1/consultation/{}", id);
return service.getConsultation(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Beratung mit angefragter ID existiert");
});
}
@GetMapping("/body/{id}/consultations")
@Operation(summary = "List of all consultations in body",
description = "returns a list of all consultations in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Consultation> consultationsInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("invoked method /v1.1/body/{}/consultations", id);
return service.getConsultationsInBody(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
});
}
@GetMapping("/file/{id}")
@Operation(summary = "information about file", description = "returns the requested file", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = File.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public File file(
@PathVariable
@Parameter(description = "file ID", example = "0")
String id) {
log.info("invoked method /v1.1/file/{}", id);
return service.getFile(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Datei mit angefragter ID existiert");
});
}
@GetMapping("/body/{id}/files")
@Operation(summary = "List of all files in body",
description = "returns a list of all files in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<File> filesInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("invoked method /v1.1/body/{}/files", id);
return service.getFilesInBody(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
});
}
@GetMapping("/term/{id}") @GetMapping("/term/{id}")
@Operation(summary = "information about legislative term", description = "returns information about the requested legislative term", responses = { @Operation(summary = "information about legislative term", description = "returns information about the requested legislative term", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
@ -79,123 +173,72 @@ public class OParlController {
}); });
} }
@GetMapping("/body/{id}/organizations") @GetMapping("/body/{id}/legislativeTerms")
@Operation(summary = "List of all organizations in body", description = "returns a list of all organizations in 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.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class))) schema = @Schema(implementation = ErrorObject.class)))
}) })
public ObjectList<Organization> organizationsInBody( public ObjectList<LegislativeTerm> legislativeTermsOfBody(
@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/{}/organizations", id); log.info("invoked method /v1.1/body/{}/legislativeTerms", id);
return service.getOrganizationsInBody(id).orElseThrow(() -> { return service.getLegislativeTermsOfBody(id).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}") @GetMapping("/location/{id}")
@Operation(summary = "information about organization", description = "returns the requested organization", responses = { @Operation(summary = "information about location", description = "returns the requested location", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Organization.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = Location.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class))) schema = @Schema(implementation = ErrorObject.class)))
}) })
public Organization organization( public Location location(
@PathVariable @PathVariable
@Parameter(description = "organization ID", example = "0") @Parameter(description = "location ID", example = "0")
String id) { String id) {
log.info("invoked method /v1.1/organization/{}", id); log.info("invoked method /v1.1/location/{}", id);
return service.getOrganization(id).orElseThrow(() -> { return service.getLocation(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Kein Ort mit angefragter ID existiert");
}); });
} }
@GetMapping("/body/{id}/persons") @GetMapping("/body/{id}/locations")
@Operation(summary = "List of all persons in body", description = "returns a list of all persons in requested body", responses = { @Operation(summary = "List of all locations in body",
description = "returns a list of all locations 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.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class))) schema = @Schema(implementation = ErrorObject.class)))
}) })
public ObjectList<Person> persons( public ObjectList<Location> locationsInBody(
@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/{}/persons", id); log.info("invoked method /v1.1/body/{}/locations", id);
return service.getPersonsInBody(id).orElseThrow(() -> { return service.getLocationsInBody(id).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("/person/{id}") @GetMapping("/meeting/{id}")
@Operation(summary = "information about person", description = "returns the requested person", responses = { @Operation(summary = "information about meeting", description = "returns the requested meeting", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Person.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = Meeting.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class))) schema = @Schema(implementation = ErrorObject.class)))
}) })
public Person person( public Meeting meeting(
@PathVariable @PathVariable
@Parameter(description = "person ID", example = "0") @Parameter(description = "meeting ID", example = "0")
String id) { String id) {
log.info("invoked method /v1.1/person/{}", id); log.info("invoked method /v1.1/meeting/{}", id);
return service.getPerson(id).orElseThrow(() -> { return service.getMeeting(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Person mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Sitzung mit angefragter ID existiert");
});
}
@GetMapping("/body/{id}/memberships")
@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",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Membership> membershipsInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("invoked method /v1.1/body/{}/memberships", id);
return service.getMembershipsInBody(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
});
}
@GetMapping("/organization/{id}/memberships")
@Operation(summary = "List of all memberships in organization",
description = "returns a list of all memberships in requested organization", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Membership> membershipsInOrganization(
@PathVariable
@Parameter(description = "organization ID", example = "0")
String id) {
log.info("invoked method /v1.1/organization/{}/memberships", id);
return service.getMembershipsInOrganization(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert");
});
}
@GetMapping("/membership/{id}")
@Operation(summary = "information about membership", description = "returns the requested membership", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Membership.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Membership membership(
@PathVariable
@Parameter(description = "membership ID", example = "0")
String id) {
log.info("invoked method /v1.1/membership/{}", id);
return service.getMembership(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Mitgliedschaft mit angefragter ID existiert");
}); });
} }
@ -235,55 +278,55 @@ public class OParlController {
}); });
} }
@GetMapping("/meeting/{id}") @GetMapping("/membership/{id}")
@Operation(summary = "information about meeting", description = "returns the requested meeting", responses = { @Operation(summary = "information about membership", description = "returns the requested membership", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Meeting.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = Membership.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class))) schema = @Schema(implementation = ErrorObject.class)))
}) })
public Meeting meeting( public Membership membership(
@PathVariable @PathVariable
@Parameter(description = "meeting ID", example = "0") @Parameter(description = "membership ID", example = "0")
String id) { String id) {
log.info("invoked method /v1.1/meeting/{}", id); log.info("invoked method /v1.1/membership/{}", id);
return service.getMeeting(id).orElseThrow(() -> { return service.getMembership(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Sitzung mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Mitgliedschaft mit angefragter ID existiert");
}); });
} }
@GetMapping("/body/{id}/agendaItems") @GetMapping("/body/{id}/memberships")
@Operation(summary = "List of all agenda items in body", @Operation(summary = "List of all memberships in body", description = "returns a list of all memberships 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",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class))) schema = @Schema(implementation = ErrorObject.class)))
}) })
public ObjectList<AgendaItem> agendaItemsInBody( public ObjectList<Membership> membershipsInBody(
@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); log.info("invoked method /v1.1/body/{}/memberships", id);
return service.getAgendaItemsInBody(id).orElseThrow(() -> { return service.getMembershipsInBody(id).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("/agendaItem/{id}") @GetMapping("/organization/{id}/memberships")
@Operation(summary = "information about agenda item", description = "returns the requested agenda item", responses = { @Operation(summary = "List of all memberships in organization",
description = "returns a list of all memberships in requested organization", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", @ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Body.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json", @ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class))) schema = @Schema(implementation = ErrorObject.class)))
}) })
public AgendaItem agendaItem( public ObjectList<Membership> membershipsInOrganization(
@PathVariable @PathVariable
@Parameter(description = "agendaItem ID", example = "0") @Parameter(description = "organization ID", example = "0")
String id) { String id) {
log.info("invoked method /v1.1/agendaItem/{}", id); log.info("invoked method /v1.1/organization/{}/memberships", id);
return service.getAgendaItem(id).orElseThrow(() -> { return service.getMembershipsInOrganization(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Kein Tagesordnungspunkt mit angefragter ID existiert"); throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert");
}); });
} }
@ -295,4 +338,118 @@ public class OParlController {
.debug(exception.getLocalizedMessage()) .debug(exception.getLocalizedMessage())
.build(); .build();
} }
@GetMapping("/organization/{id}")
@Operation(summary = "information about organization", description = "returns the requested organization", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Organization.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Organization organization(
@PathVariable
@Parameter(description = "organization ID", example = "0")
String id) {
log.info("invoked method /v1.1/organization/{}", id);
return service.getOrganization(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Organisation mit angefragter ID existiert");
});
}
@GetMapping("/body/{id}/organizations")
@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",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Organization> organizationsInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("invoked method /v1.1/body/{}/organizations", id);
return service.getOrganizationsInBody(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
});
}
@GetMapping("/paper/{id}")
@Operation(summary = "information about paper", description = "returns the requested paper", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Paper.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Paper paper(
@PathVariable
@Parameter(description = "paper ID", example = "0")
String id) {
log.info("invoked method /v1.1/paper/{}", id);
return service.getPaper(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Drucksache mit angefragter ID existiert");
});
}
@GetMapping("/body/{id}/papers")
@Operation(summary = "List of all papers in body",
description = "returns a list of all papers in requested body", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Paper> papersInBody(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("invoked method /v1.1/body/{}/papers", id);
return service.getPapersInBody(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
});
}
@GetMapping("/person/{id}")
@Operation(summary = "information about person", description = "returns the requested person", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Person.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public Person person(
@PathVariable
@Parameter(description = "person ID", example = "0")
String id) {
log.info("invoked method /v1.1/person/{}", id);
return service.getPerson(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Person mit angefragter ID existiert");
});
}
@GetMapping("/body/{id}/persons")
@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",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ObjectList.class))),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ErrorObject.class)))
})
public ObjectList<Person> persons(
@PathVariable
@Parameter(description = "body ID", example = "0")
String id) {
log.info("invoked method /v1.1/body/{}/persons", id);
return service.getPersonsInBody(id).orElseThrow(() -> {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Keine Körperschaft mit angefragter ID existiert");
});
}
@GetMapping("/")
@Operation(summary = "System information", description = "returns information about the OParl system", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200", content = @Content(
mediaType = "application/json", schema = @Schema(implementation = System.class)
))
})
public System system() {
log.info("method invoked /v1.1");
return service.getSystem();
}
} }

View File

@ -32,10 +32,38 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Consultation>> getConsultationsInBody(String bodyID) {
return Optional.empty();
}
public Optional<Consultation> getConsultation(String id) {
return Optional.empty();
}
public Optional<ObjectList<File>> getFilesInBody(String bodyID) {
return Optional.empty();
}
public Optional<File> getFile(String id) {
return Optional.empty();
}
public Optional<ObjectList<LegislativeTerm>> getLegislativeTermsOfBody(String bodyID) {
return Optional.empty();
}
public Optional<LegislativeTerm> getLegislativeTerm(String id) { public Optional<LegislativeTerm> getLegislativeTerm(String id) {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Location>> getLocationsInBody(String bodyID) {
return Optional.empty();
}
public Optional<Location> getLocation(String id) {
return Optional.empty();
}
public Optional<Meeting> getMeeting(String id) { public Optional<Meeting> getMeeting(String id) {
return Optional.empty(); return Optional.empty();
} }
@ -68,6 +96,14 @@ public class OParlService {
return Optional.empty(); return Optional.empty();
} }
public Optional<ObjectList<Paper>> getPapersInBody(String bodyID) {
return Optional.empty();
}
public Optional<Paper> getPaper(String id) {
return Optional.empty();
}
public Optional<ObjectList<Person>> getPersonsInBody(String bodyID) { public Optional<ObjectList<Person>> getPersonsInBody(String bodyID) {
return Optional.empty(); return Optional.empty();
} }

View File

@ -51,6 +51,87 @@ class OParlControllerTest {
initializeTestValues(); 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 @Test
void shouldReturnErrorObject_WhenInvalidIDPassed() throws Exception { void shouldReturnErrorObject_WhenInvalidIDPassed() throws Exception {
BDDMockito.given(service.getBody("2")) BDDMockito.given(service.getBody("2"))
@ -75,20 +156,72 @@ class OParlControllerTest {
} }
@Test @Test
void shouldReturnSystemInfo() throws Exception { void shouldReturnFile() throws Exception {
BDDMockito.given(service.getSystem()) BDDMockito.given(service.getFile("0"))
.willReturn(testSystem); .willReturn(Optional.of(testFile));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/") mvc.perform(MockMvcRequestBuilders.get("/v1.1/file/0")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(14))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(10)))
.andExpect(MockMvcResultMatchers.jsonPath("$.id", Matchers.equalTo("/v1.1/"))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasKey("accessUrl")))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/System"))) .andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/File")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn(); .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/term/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 @Test
void shouldReturnListOfBodies() throws Exception { void shouldReturnListOfBodies() throws Exception {
BDDMockito.given(service.getBodies()) BDDMockito.given(service.getBodies())
@ -110,145 +243,47 @@ class OParlControllerTest {
} }
@Test @Test
void shouldReturnBody() throws Exception { void shouldReturnLocation() throws Exception {
BDDMockito.given(service.getBody("0")) BDDMockito.given(service.getLocation("0"))
.willReturn(Optional.of(testBody)); .willReturn(Optional.of(testLocation));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0") mvc.perform(MockMvcRequestBuilders.get("/v1.1/location/0")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(24))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(14)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Body"))) .andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Location")))
.andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@Test @Test
void shouldReturnLegislativeTerm() throws Exception { void shouldReturnLocationsInBody() throws Exception {
BDDMockito.given(service.getLegislativeTerm("21")) BDDMockito.given(service.getLocationsInBody("0"))
.willReturn(Optional.of(testTerm)); .willReturn(Optional.of(
ObjectList.<Location>builder().data(List.of(testLocation)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/term/21") 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)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(9))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(9)))
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasKey("body"))) .andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting")))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/LegislativeTerm")))
.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 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 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 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 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 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))) .andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@ -290,52 +325,168 @@ class OParlControllerTest {
} }
@Test @Test
void shouldReturnMeeting() throws Exception { void shouldReturnMembership() throws Exception {
BDDMockito.given(service.getMeeting("0")) BDDMockito.given(service.getMembership("0"))
.willReturn(Optional.of(testMeeting)); .willReturn(Optional.of(testMembership));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/meeting/0") mvc.perform(MockMvcRequestBuilders.get("/v1.1/membership/0")
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(9))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(11)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/Meeting"))) .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))) .andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@Test @Test
void shouldReturnAgendaItemsInBody() throws Exception { void shouldReturnMembershipsInBody() throws Exception {
BDDMockito.given(service.getAgendaItemsInBody("0")) BDDMockito.given(service.getMembershipsInBody("0"))
.willReturn(Optional.of( .willReturn(Optional.of(
ObjectList.<AgendaItem>builder().data(List.of(testItem)).pagination(testPagination).links(testLinks).build() ObjectList.<Membership>builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build()
)); ));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/body/0/agendaItems") 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.aMapWithSize(3))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$.data", Matchers.hasSize(1)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]", Matchers.aMapWithSize(11))) .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].type", Matchers.equalTo("https://schema.oparl.org/1.1/Membership")))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false))) .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
@Test @Test
void shouldReturnAgendaItem() throws Exception { void shouldReturnMembershipsInOrganization() throws Exception {
BDDMockito.given(service.getAgendaItem("0")) BDDMockito.given(service.getMembershipsInOrganization("0"))
.willReturn(Optional.of(testItem)); .willReturn(Optional.of(
ObjectList.<Membership>builder().data(List.of(testMembership)).pagination(testPagination).links(testLinks).build()
));
mvc.perform(MockMvcRequestBuilders.get("/v1.1/agendaItem/0") 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.aMapWithSize(11))) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.aMapWithSize(3)))
.andExpect(MockMvcResultMatchers.jsonPath("$.type", Matchers.equalTo("https://schema.oparl.org/1.1/AgendaItem"))) .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))) .andExpect(MockMvcResultMatchers.jsonPath("$.deleted", Matchers.equalTo(false)))
.andReturn(); .andReturn();
} }
void initializeTestValues() { @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() testSystem = System.builder()
.id("/v1.1/") .id("/v1.1/")
.type("https://schema.oparl.org/1.1/System") .type("https://schema.oparl.org/1.1/System")
@ -482,5 +633,58 @@ class OParlControllerTest {
testLinks = Links.builder() testLinks = Links.builder()
.next("") .next("")
.build(); .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();
} }
} }