use of org.springframework.web.client.RestTemplate in project spring-cloud-sleuth by spring-cloud.
the class TraceFilterWebIntegrationTests method should_not_create_a_span_for_error_controller.
@Test
public void should_not_create_a_span_for_error_controller() {
try {
new RestTemplate().getForObject("http://localhost:" + port() + "/", String.class);
BDDAssertions.fail("should fail due to runtime exception");
} catch (Exception e) {
}
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.accumulator.getSpans()).hasSize(1);
Span fromFirstTraceFilterFlow = this.accumulator.getSpans().get(0);
then(fromFirstTraceFilterFlow.tags()).containsEntry("http.status_code", "500").containsEntry("http.method", "GET").containsEntry("mvc.controller.class", "ExceptionThrowingController").containsEntry("error", "Request processing failed; nested exception is java.lang.RuntimeException: Throwing exception");
// issue#714
String hex = fromFirstTraceFilterFlow.traceId();
String[] split = capture.toString().split("\n");
List<String> list = Arrays.stream(split).filter(s -> s.contains("Uncaught exception thrown")).filter(s -> s.contains(hex + "," + hex + ",true]")).collect(Collectors.toList());
then(list).isNotEmpty();
}
use of org.springframework.web.client.RestTemplate in project spring-cloud-sleuth by spring-cloud.
the class TraceUserInfoRestTemplateCustomizer method postProcessAfterInitialization.
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof RestTemplate) {
RestTemplate rt = (RestTemplate) bean;
new RestTemplateInterceptorInjector(interceptor()).inject(rt);
}
return bean;
}
use of org.springframework.web.client.RestTemplate in project crnk-framework by crnk-project.
the class BasicSpringBootTest method testRelationshipInclusion.
@Test
public void testRelationshipInclusion() {
Project project = new Project();
ProjectRepository projectRepository = new ProjectRepository();
projectRepository.save(project);
Task task = new Task();
task.setProject(project);
TaskRepository taskRepository = new TaskRepository();
taskRepository.save(task);
RestTemplate testRestTemplate = new RestTemplate();
ResponseEntity<String> response = testRestTemplate.getForEntity("http://localhost:" + this.port + "/api/tasks?include[tasks]=schedule%2Cproject", String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
JsonFluentAssert included = assertThatJson(response.getBody()).node("included");
included.isArray().ofLength(1);
}
use of org.springframework.web.client.RestTemplate in project crnk-framework by crnk-project.
the class BasicSpringBootTest method testTestEndpointWithQueryParams.
@Test
public void testTestEndpointWithQueryParams() {
RestTemplate testRestTemplate = new RestTemplate();
ResponseEntity<String> response = testRestTemplate.getForEntity("http://localhost:" + this.port + "/api/tasks?filter[tasks][name]=John", String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertThatJson(response.getBody()).node("data").isPresent();
}
use of org.springframework.web.client.RestTemplate in project crnk-framework by crnk-project.
the class BasicSpringBootTest method testErrorsSerializedAsJsonApi.
@Test
public void testErrorsSerializedAsJsonApi() throws IOException {
RestTemplate testRestTemplate = new RestTemplate();
try {
testRestTemplate.getForEntity("http://localhost:" + this.port + "/doesNotExist", String.class);
Assert.fail();
} catch (HttpClientErrorException e) {
assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
String body = e.getResponseBodyAsString();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(JacksonModule.createJacksonModule());
Document document = mapper.readerFor(Document.class).readValue(body);
Assert.assertEquals(1, document.getErrors().size());
ErrorData errorData = document.getErrors().get(0);
Assert.assertEquals("404", errorData.getStatus());
Assert.assertEquals("Not Found", errorData.getTitle());
Assert.assertEquals("No message available", errorData.getDetail());
}
}
Aggregations