use of org.springframework.http.HttpEntity in project spring-boot-admin by codecentric.
the class ApplicationOperationsTest method test_getHealth.
@Test
@SuppressWarnings("rawtypes")
public void test_getHealth() {
Application app = Application.create("test").withHealthUrl("http://health").withManagementUrl("http://mgmt").build();
ArgumentCaptor<HttpEntity> requestEntity = ArgumentCaptor.forClass(HttpEntity.class);
HttpHeaders headers = new HttpHeaders();
headers.add("auth", "foo:bar");
when(headersProvider.getHeaders(eq(app))).thenReturn(headers);
when(restTemplate.exchange(eq(URI.create("http://health")), eq(HttpMethod.GET), requestEntity.capture(), eq(Map.class))).thenReturn(ResponseEntity.ok().body((Map) singletonMap("foo", "bar")));
ResponseEntity<Map<String, Serializable>> response = ops.getHealth(app);
assertThat(response.getBody()).containsEntry("foo", "bar");
assertThat(requestEntity.getValue().getHeaders()).containsEntry("auth", asList("foo:bar"));
}
use of org.springframework.http.HttpEntity in project spring-boot-admin by codecentric.
the class ApplicationOperationsTest method test_getInfo.
@Test
@SuppressWarnings("rawtypes")
public void test_getInfo() {
Application app = Application.create("test").withHealthUrl("http://health").withManagementUrl("http://mgmt").build();
ArgumentCaptor<HttpEntity> requestEntity = ArgumentCaptor.forClass(HttpEntity.class);
HttpHeaders headers = new HttpHeaders();
headers.add("auth", "foo:bar");
when(headersProvider.getHeaders(eq(app))).thenReturn(headers);
when(restTemplate.exchange(eq(URI.create("http://mgmt/info")), eq(HttpMethod.GET), requestEntity.capture(), eq(Map.class))).thenReturn(ResponseEntity.ok().body((Map) singletonMap("foo", "bar")));
ResponseEntity<Map<String, Serializable>> response = ops.getInfo(app);
assertThat(response.getBody()).containsEntry("foo", "bar");
assertThat(requestEntity.getValue().getHeaders()).containsEntry("auth", asList("foo:bar"));
}
use of org.springframework.http.HttpEntity in project spring-boot-admin by codecentric.
the class HipchatNotifierTest method test_onApplicationEvent_trigger.
@Test
public void test_onApplicationEvent_trigger() {
StatusInfo infoDown = StatusInfo.ofDown();
StatusInfo infoUp = StatusInfo.ofUp();
@SuppressWarnings("unchecked") ArgumentCaptor<HttpEntity<Map<String, Object>>> httpRequest = ArgumentCaptor.forClass((Class<HttpEntity<Map<String, Object>>>) (Class<?>) HttpEntity.class);
when(restTemplate.postForEntity(isA(String.class), httpRequest.capture(), eq(Void.class))).thenReturn(ResponseEntity.ok((Void) null));
notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), infoUp, infoDown));
assertThat(httpRequest.getValue().getHeaders()).containsEntry("Content-Type", asList("application/json"));
Map<String, Object> body = httpRequest.getValue().getBody();
assertThat(body).containsEntry("color", "red");
assertThat(body).containsEntry("message", "<strong>App</strong>/-id- is <strong>DOWN</strong>");
assertThat(body).containsEntry("notify", Boolean.TRUE);
assertThat(body).containsEntry("message_format", "html");
}
use of org.springframework.http.HttpEntity in project spring-boot-admin by codecentric.
the class LetsChatNotifierTest method expectedMessage.
private HttpEntity<?> expectedMessage(String message) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
String auth = Base64Utils.encodeToString(String.format("%s:%s", token, user).getBytes());
httpHeaders.add(HttpHeaders.AUTHORIZATION, String.format("Basic %s", auth));
Map<String, Object> messageJson = new HashMap<>();
messageJson.put("text", message);
return new HttpEntity<>(messageJson, httpHeaders);
}
use of org.springframework.http.HttpEntity in project spring-boot-admin by codecentric.
the class HipchatNotifier method createHipChatNotification.
protected HttpEntity<Map<String, Object>> createHipChatNotification(ClientApplicationEvent event) {
Map<String, Object> body = new HashMap<>();
body.put("color", getColor(event));
body.put("message", getMessage(event));
body.put("notify", getNotify());
body.put("message_format", "html");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return new HttpEntity<>(body, headers);
}
Aggregations