Creación de ControladorREST y ControladorRESTTEST, realizado con Álvaro Herrera

parent a46254c3
package com.carpooling.carpoolingaoraha.ControladorRESTEST;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import java.util.List;
@SpringBootTest(classes = com.carpooling.carpoolingaoraha.CarPoolingAorAhaApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ControladorRESTTEST {
@LocalServerPort
int localPort;
@Autowired
MappingJackson2HttpMessageConverter springBoot;
TestRestTemplate restTemplate;
@PostConstruct
void crearRestTemplate() {
RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder()
.rootUri("http://localhost:" + localPort + "/carpooling")
.additionalMessageConverters(List.of(springBoot));
restTemplate = new TestRestTemplate(restTemplateBuilder);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment