Search in sources :

Example 1 with Registration

use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverterTest method convert_secure_healthUrl.

@Test
public void convert_secure_healthUrl() {
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("https://localhost:80/health");
    EurekaServiceInstance service = mock(EurekaServiceInstance.class);
    when(service.getInstanceInfo()).thenReturn(instanceInfo);
    when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
    when(service.getServiceId()).thenReturn("test");
    Registration registration = new EurekaServiceInstanceConverter().convert(service);
    assertThat(registration.getHealthUrl()).isEqualTo("https://localhost:80/health");
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaServiceInstance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.jupiter.api.Test)

Example 2 with Registration

use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverterTest method convert_missing_mgmtpath.

@Test
public void convert_missing_mgmtpath() {
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
    EurekaServiceInstance service = mock(EurekaServiceInstance.class);
    when(service.getInstanceInfo()).thenReturn(instanceInfo);
    when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
    when(service.getServiceId()).thenReturn("test");
    Registration registration = new EurekaServiceInstanceConverter().convert(service);
    assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/actuator");
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaServiceInstance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.jupiter.api.Test)

Example 3 with Registration

use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.

the class KubernetesServiceInstanceConverterTest method convert_using_port_mgmt.

@Test
public void convert_using_port_mgmt() {
    ServiceInstance service = mock(ServiceInstance.class);
    when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
    when(service.getServiceId()).thenReturn("test");
    when(service.getMetadata()).thenReturn(Collections.singletonMap("port.management", "9080"));
    Registration registration = new KubernetesServiceInstanceConverter().convert(service);
    assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:9080/actuator");
    assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:9080/actuator/health");
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.jupiter.api.Test)

Example 4 with Registration

use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.

the class InfoUpdaterTest method should_update_info_for_online_with_info_endpoint_only.

@Test
public void should_update_info_for_online_with_info_endpoint_only() {
    // given
    Registration registration = Registration.create("foo", this.wireMock.url("/health")).build();
    Instance instance = Instance.create(InstanceId.of("onl")).register(registration).withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();
    String body = "{ \"foo\": \"bar\" }";
    this.wireMock.stubFor(get("/info").willReturn(okJson(body).withHeader("Content-Length", Integer.toString(body.length()))));
    Instance noInfo = Instance.create(InstanceId.of("noinfo")).register(registration).withEndpoints(Endpoints.single("beans", this.wireMock.url("/beans"))).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(this.repository.save(noInfo)).expectNextCount(1).verifyComplete();
    Instance offline = Instance.create(InstanceId.of("off")).register(registration).withStatusInfo(StatusInfo.ofOffline());
    StepVerifier.create(this.repository.save(offline)).expectNextCount(1).verifyComplete();
    Instance unknown = Instance.create(InstanceId.of("unk")).register(registration).withStatusInfo(StatusInfo.ofUnknown());
    StepVerifier.create(this.repository.save(unknown)).expectNextCount(1).verifyComplete();
    // when
    StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateInfo(offline.getId())).verifyComplete()).then(() -> StepVerifier.create(this.updater.updateInfo(unknown.getId())).verifyComplete()).then(() -> StepVerifier.create(this.updater.updateInfo(noInfo.getId())).verifyComplete()).expectNoEvent(Duration.ofMillis(100L)).then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel().verify();
    StepVerifier.create(this.repository.find(instance.getId())).assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.from(singletonMap("foo", "bar")))).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) InstanceExchangeFilterFunctions.timeout(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.timeout) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Endpoint(de.codecentric.boot.admin.server.domain.values.Endpoint) WireMock.okJson(com.github.tomakehurst.wiremock.client.WireMock.okJson) Info(de.codecentric.boot.admin.server.domain.values.Info) InstanceExchangeFilterFunctions.rewriteEndpointUrl(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.rewriteEndpointUrl) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) AfterAll(org.junit.jupiter.api.AfterAll) InstanceExchangeFilterFunctions.retry(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.retry) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) WireMock.serverError(com.github.tomakehurst.wiremock.client.WireMock.serverError) Collections.singletonMap(java.util.Collections.singletonMap) InstanceWebClient(de.codecentric.boot.admin.server.web.client.InstanceWebClient) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Registration(de.codecentric.boot.admin.server.domain.values.Registration) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) Collections.emptyMap(java.util.Collections.emptyMap) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) Options(com.github.tomakehurst.wiremock.core.Options) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) AfterEach(org.junit.jupiter.api.AfterEach) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 5 with Registration

use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.

the class CloudFoundryInstanceIdGeneratorTest method test_cloud_foundry_instance_id.

@Test
public void test_cloud_foundry_instance_id() {
    Registration registration = Registration.create("foo", "http://health").metadata("applicationId", "549e64cf-a478-423d-9d6d-02d803a028a8").metadata("instanceId", "0").build();
    assertThat(instance.generateId(registration)).isEqualTo(InstanceId.of("549e64cf-a478-423d-9d6d-02d803a028a8:0"));
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Aggregations

Registration (de.codecentric.boot.admin.server.domain.values.Registration)53 Test (org.junit.jupiter.api.Test)46 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)15 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)12 ServiceInstance (org.springframework.cloud.client.ServiceInstance)9 JSONObject (org.json.JSONObject)8 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)8 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)7 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)6 Info (de.codecentric.boot.admin.server.domain.values.Info)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 StepVerifier (reactor.test.StepVerifier)6 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)5 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)5 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)5 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)5 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Collections.singletonMap (java.util.Collections.singletonMap)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3