Skip to content

Commit

Permalink
Merge pull request #34 from abes-esr/CDE-293-appel-best-ppn-prod-ko-q…
Browse files Browse the repository at this point in the history
…uand-caracteres-accentues-dans-luri

Cde 293 appel best ppn prod ko quand caracteres accentues dans luri
  • Loading branch information
pierre-maraval authored Nov 21, 2023
2 parents e7de626 + ebf50e7 commit fc3b939
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public BestPpnController(BestPpnService service) {
@GetMapping(value = "/bestPpn")
public String bestPpn(@RequestParam(name = "provider") String provider, @RequestParam(name = "publication_title", required = false) String publicationTitle,
@RequestParam(name = "publication_type") String publicationType, @RequestParam(name = "online_identifier", required = false) String onlineIdentifier,
@RequestParam(name = "print_identifier", required = false) String printIdentifier, @RequestParam(name = "doi", required = false) String doi,
@RequestParam(name = "print_identifier", required = false) String printIdentifier, @RequestParam(name = "titleUrl", required = false) String titleUrl,
@RequestParam(name = "date_monograph_published_online", required = false) String dateMonographPublishedOnline, @RequestParam(name = "date_monograph_published_print", required = false) String dateMonographPublishedPrint,
@RequestParam(name = "first_author", required = false) String firstAuthor, @RequestParam(name = "force", required = false) Boolean force) throws IOException, IllegalPpnException {
try {
Expand All @@ -48,14 +48,14 @@ public String bestPpn(@RequestParam(name = "provider") String provider, @Request
ligneKbartDto.setPublicationTitle((publicationTitle != null) ? publicationTitle : "");
ligneKbartDto.setOnlineIdentifier((onlineIdentifier != null) ? onlineIdentifier : "");
ligneKbartDto.setPrintIdentifier((printIdentifier != null) ? printIdentifier : "");
ligneKbartDto.setTitleUrl((doi != null) ? doi : "");
ligneKbartDto.setTitleUrl((titleUrl != null) ? titleUrl : "");
ligneKbartDto.setDateMonographPublishedPrint((dateMonographPublishedPrint != null) ? dateMonographPublishedPrint : "");
ligneKbartDto.setDateMonographPublishedOnline((dateMonographPublishedOnline != null) ? dateMonographPublishedOnline : "");
ligneKbartDto.setFirstAuthor((firstAuthor != null) ? firstAuthor : "");
boolean injectKafka = (force != null) ? force : false;
return service.getBestPpn(ligneKbartDto, provider, injectKafka).getPpn();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Une url dans le champ doi du kbart n'est pas correcte");
throw new IllegalArgumentException("Une url dans le champ title_url du kbart n'est pas correcte");
} catch (BestPpnException | RestClientException | IllegalArgumentException e) {
return e.getMessage();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ kafkaconvergence.openapi.url=
springdoc.swagger-ui.path=/convergence-documentation
springdoc.api-docs.path=/convergence-api-docs

springdoc.packages-to-scan=fr.abes.kafkaconvergence.controller
springdoc.packages-to-scan=fr.abes.bestppn.controller
springdoc.swagger-ui.try-it-out-enabled=true
springdoc.swagger-ui.operations-sorter=method
springdoc.swagger-ui.tags-sorter=alpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ void testBestPpnControllerWrongNumberOfParameters() throws Exception {
@DisplayName("test controller with wrong URL format")
void testBestPpnControllerBadUrlFormat() throws Exception {
Mockito.when(service.getBestPpn(Mockito.any(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new URISyntaxException("test", "Format d'URL incorrect"));
this.mockMvc.perform(get("/api/v1/bestPpn?provider=cairn&publication_type=monograph&print_identifier=9781111111111&doi=test").characterEncoding(StandardCharsets.UTF_8))
this.mockMvc.perform(get("/api/v1/bestPpn?provider=cairn&publication_type=monograph&print_identifier=9781111111111&title_url=test").characterEncoding(StandardCharsets.UTF_8))
.andExpect(status().isBadRequest())
.andExpect(result -> Assertions.assertTrue((result.getResolvedException() instanceof IllegalArgumentException)))
.andExpect(result -> Assertions.assertTrue(result.getResponse().getContentAsString(StandardCharsets.UTF_8).contains("Une url dans le champ doi du kbart n'est pas correcte")));
.andExpect(result -> Assertions.assertTrue(result.getResponse().getContentAsString(StandardCharsets.UTF_8).contains("Une url dans le champ title_url du kbart n'est pas correcte")));
}

@Test
@DisplayName("test controller with BestPpnException")
void testBestPpnControllerBestPpnException() throws Exception {
Mockito.when(service.getBestPpn(Mockito.any(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new BestPpnException("Plusieurs ppn imprimés"));
this.mockMvc.perform(get("/api/v1/bestPpn?provider=cairn&publication_type=monograph&print_identifier=9781111111111&doi=test").characterEncoding(StandardCharsets.UTF_8))
this.mockMvc.perform(get("/api/v1/bestPpn?provider=cairn&publication_type=monograph&print_identifier=9781111111111&title_url=test").characterEncoding(StandardCharsets.UTF_8))
.andExpect(status().isOk())
.andExpect(result -> Assertions.assertTrue(result.getResponse().getContentAsString(StandardCharsets.UTF_8).contains("Plusieurs ppn imprimés")));
}
Expand All @@ -94,7 +94,7 @@ void testBestPpnControllerBestPpnException() throws Exception {
@DisplayName("test controller Ok")
void testBestPpnControllerOk() throws Exception {
Mockito.when(service.getBestPpn(Mockito.any(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(new PpnWithDestinationDto("1111111111", DESTINATION_TOPIC.BEST_PPN_BACON));
this.mockMvc.perform(get("/api/v1/bestPpn?provider=cairn&publication_type=monograph&print_identifier=9781111111111&doi=test").characterEncoding(StandardCharsets.UTF_8))
this.mockMvc.perform(get("/api/v1/bestPpn?provider=cairn&publication_type=monograph&print_identifier=9781111111111&title_url=test").characterEncoding(StandardCharsets.UTF_8))
.andExpect(status().isOk())
.andExpect(result -> Assertions.assertTrue(result.getResponse().getContentAsString(StandardCharsets.UTF_8).contains("111111111")));
}
Expand Down

0 comments on commit fc3b939

Please sign in to comment.