Search in sources :

Example 6 with Application

use of de.codecentric.boot.admin.model.Application 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 7 with Application

use of de.codecentric.boot.admin.model.Application 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 8 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class BasicAuthHttpHeaderProviderTest method test_no_header.

@Test
public void test_no_header() {
    Application app = Application.create("test").withHealthUrl("/health").build();
    assertTrue(headersProvider.getHeaders(app).isEmpty());
}
Also used : Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 9 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class BasicAuthHttpHeaderProviderTest method test_auth_header.

@Test
public void test_auth_header() {
    Application app = Application.create("test").withHealthUrl("/health").addMetadata("user.name", "test").addMetadata("user.password", "drowssap").build();
    assertThat(headersProvider.getHeaders(app).get(HttpHeaders.AUTHORIZATION).get(0), is("Basic dGVzdDpkcm93c3NhcA=="));
}
Also used : Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 10 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class ApplicationDiscoveryListenerTest method test_register_and_convert.

@Test
public void test_register_and_convert() {
    when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
    when(discovery.getInstances("service")).thenReturn(Collections.singletonList((ServiceInstance) new DefaultServiceInstance("service", "localhost", 80, false)));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));
    assertEquals(1, registry.getApplications().size());
    Application application = registry.getApplications().iterator().next();
    assertEquals("http://localhost:80/health", application.getHealthUrl());
    assertEquals("http://localhost:80", application.getManagementUrl());
    assertEquals("http://localhost:80", application.getServiceUrl());
    assertEquals("service", application.getName());
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Aggregations

Application (de.codecentric.boot.admin.model.Application)36 Test (org.junit.Test)27 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)7 ServiceInstance (org.springframework.cloud.client.ServiceInstance)7 ClientApplicationRegisteredEvent (de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent)5 ClientApplicationDeregisteredEvent (de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3 ClientApplicationEvent (de.codecentric.boot.admin.event.ClientApplicationEvent)3 StatusInfo (de.codecentric.boot.admin.model.StatusInfo)3 Collection (java.util.Collection)3 Map (java.util.Map)3 EurekaServiceInstance (org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HttpEntity (org.springframework.http.HttpEntity)2 RequestContext (com.netflix.zuul.context.RequestContext)1 ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)1