0

Buenas tardes estoy desarrollando una funcionalidad en java 8 webflux, intento generar 1 test a nivel de Controller sin embargo cuando intento ejecutar me sale el siguiente error:

'
org.springframework.core.codec.CodecException: No suitable writer found for part: file
    
at org.springframework.http.codec.multipart.MultipartHttpMessageWriter.encodePart(MultipartHttpMessageWriter.java:260) ~[spring-web-5.3.6.jar:5.3.6]
.
.
.
'

Adjunto codigo de test:

        MultipartBodyBuilder multipartBodyBuilder = new MultipartBodyBuilder();
        multipartBodyBuilder.part("file", new ClassPathResource("ejemplo.csv"))
                .contentType(MediaType.MULTIPART_FORM_DATA);
        
        Mockito.when(salespointService.importData(any(FilePart.class))).thenReturn(Flux.just(""));

        webClient.post()
                .uri("/upload")
                .header("x", "x")
                .contentType(MediaType.MULTIPART_FORM_DATA)
                .body(BodyInserters.fromMultipartData(multipartBodyBuilder.build()))
                .exchange()
                .expectStatus().isOk();

Adjunto codigo de Controller:

    @PostMapping("/upload")
    @ResponseStatus(HttpStatus.OK)
    public Mono<List<String>> importData(@RequestPart("file") FilePart filePartMono) {
        .
        .
        .
    }    
2
  • tal parece que tu multipartBodyBuilder no tiene contenido, es decir podrias tratar de crearlo con algo tipo bodyBuilder.asyncPart("file", file.content(), DataBuffer.class) el 23 dic. 2022 a las 4:29
  • Muchas gracias si se trato de eso. Ya lo pude resolver :) el 23 dic. 2022 a las 4:37

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.