Search in sources :

Example 31 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class QueryIndexEndpointStrategyTest method should_return_empty_when_mgmt_equals_service_url.

@Test
public void should_return_empty_when_mgmt_equals_service_url() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/app/health")).managementUrl(this.wireMock.url("/app")).serviceUrl(this.wireMock.url("/app")).build());
    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
    // when/then
    StepVerifier.create(strategy.detectEndpoints(instance)).verifyComplete();
    this.wireMock.verify(0, anyRequestedFor(urlPathEqualTo("/app")));
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 32 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class QueryIndexEndpointStrategyTest method should_return_empty_on_not_found.

@Test
public void should_return_empty_on_not_found() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
    this.wireMock.stubFor(get("/mgmt").willReturn(notFound()));
    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
    // when
    StepVerifier.create(strategy.detectEndpoints(instance)).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 33 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class QueryIndexEndpointStrategyTest method should_return_endpoints_with_aligned_scheme.

@Test
public void should_return_endpoints_with_aligned_scheme() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
    String host = "http://localhost:" + this.wireMock.httpsPort();
    String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"" + host + "/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"" + host + "/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"" + host + "/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"" + host + "/mgmt/info\"}}}";
    this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));
    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
    // when
    String secureHost = "https://localhost:" + this.wireMock.httpsPort();
    StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(Endpoints.single("metrics", secureHost + "/mgmt/stats").withEndpoint("info", // 
    secureHost + "/mgmt/info")).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 34 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class QueryIndexEndpointStrategyTest method should_return_empty_on_wrong_content_type.

@Test
public void should_return_empty_on_wrong_content_type() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
    String body = "HELLOW WORLD";
    this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", MediaType.TEXT_PLAIN_VALUE)));
    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
    // when
    StepVerifier.create(strategy.detectEndpoints(instance)).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Example 35 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class QueryIndexEndpointStrategyTest method should_return_empty_on_empty_endpoints.

@Test
public void should_return_empty_on_empty_endpoints() {
    // given
    Instance instance = Instance.create(InstanceId.of("id")).register(Registration.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
    String body = "{\"_links\":{}}";
    this.wireMock.stubFor(get("/mgmt").willReturn(okJson(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));
    QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
    // when
    StepVerifier.create(strategy.detectEndpoints(instance)).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Test(org.junit.jupiter.api.Test)

Aggregations

Instance (de.codecentric.boot.admin.server.domain.entities.Instance)44 Test (org.junit.jupiter.api.Test)42 Registration (de.codecentric.boot.admin.server.domain.values.Registration)23 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 StepVerifier (reactor.test.StepVerifier)14 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 Mono (reactor.core.publisher.Mono)10 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)9 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)8 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)8 Flux (reactor.core.publisher.Flux)8 ArrayList (java.util.ArrayList)7 Collections.singletonMap (java.util.Collections.singletonMap)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Application (de.codecentric.boot.admin.server.domain.entities.Application)6 Info (de.codecentric.boot.admin.server.domain.values.Info)6 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)6 Mockito.mock (org.mockito.Mockito.mock)6