package br.com.alura.DaysOfCodeSpring; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; 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.http.HttpStatus; import org.springframework.http.ResponseEntity; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class ApplicationTests { @LocalServerPort private int port; @Autowired private TestRestTemplate restTemplate; @Test void deveRetornarTop250FilmesIMDB() { String url = "http://localhost:" + port + "/api"; ResponseEntity response = restTemplate.getForEntity(url, String.class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); } }