Search in sources :

Example 1 with HttpEntity

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"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Application(de.codecentric.boot.admin.model.Application) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.Test)

Example 2 with HttpEntity

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"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Application(de.codecentric.boot.admin.model.Application) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.Test)

Example 3 with HttpEntity

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");
}
Also used : HttpEntity(org.springframework.http.HttpEntity) StatusInfo(de.codecentric.boot.admin.model.StatusInfo) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 4 with HttpEntity

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap)

Example 5 with HttpEntity

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap)

Aggregations

HttpEntity (org.springframework.http.HttpEntity)85 HttpHeaders (org.springframework.http.HttpHeaders)62 Test (org.junit.Test)46 URI (java.net.URI)15 ResponseEntity (org.springframework.http.ResponseEntity)12 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)12 ArrayList (java.util.ArrayList)11 MediaType (org.springframework.http.MediaType)11 RestTemplate (org.springframework.web.client.RestTemplate)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 MultiValueMap (org.springframework.util.MultiValueMap)9 List (java.util.List)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)7 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)7 HttpStatus (org.springframework.http.HttpStatus)6 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)6 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5