내 스프링 부트 프로젝트를 1.3.x에서 1.5.2로 업데이트했습니다. 테스트 프레임 워크가 "변경"되어 코드를 마이그레이션하려고합니다. RestTemplate의 응답 상태 코드는 401이어야하지만 새로운 "구조"로 코드를 변경하면 404가 발견되지 않습니다. 어떤 아이디어가 누락되었을 수 있습니까?봄 부팅 테스트, 1.3에서 1.5로 마이그레이션
오래된 코드 :
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ApiAuthServerApplication.class)
@WebAppConfiguration
@IntegrationTest("{server.port:0, server.address:localhost}")
public class ApiEndpointTests {
@Value("${local.server.port}")
private int port;
private RestTemplate template = new TestRestTemplate();
@Test
public void clientsEndpointProtected() {
ResponseEntity<String> response = template.getForEntity("http://localhost:"
+ port + "/uaa/api/v1/oauth/clients", String.class);
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}
}
새로운 코드는 내가 노력 :
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ApiAuthServerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ApiEndpointTests {
@LocalServerPort
private int port;
private TestRestTemplate template = new TestRestTemplate();
@Test
public void clientsEndpointProtected() {
ResponseEntity<String> response = template.getForEntity("http://localhost:"
+ port + "/uaa/api/v1/oauth/clients", String.class);
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}
}
는 또한 TestRestTemplate
@Autowire
에 노력하고 요청에 호스트 이름과 포트를 생략합니다.
당신은'Autowire'은'TestRestTemplate' 대신 새로운 인스턴스를 생성 @, 봄 부팅 후 제대로 URL을 수정해야 할 필요가해야 당신은/UAA/API'호출 할 수 있습니다/v1/oauth/clients'에 있습니다. –
이전에 시도한 결과와 동일한 결과가 나타납니다. – Filip