Search in sources :

Example 6 with Registration

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

the class EndpointDetectorTest method should_update_endpoints.

@Test
public void should_update_endpoints() {
    // given
    Registration registration = Registration.create("foo", "http://health").managementUrl("http://mgmt").build();
    Instance instance = Instance.create(InstanceId.of("onl")).register(registration).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(repository.save(instance)).expectNextCount(1).verifyComplete();
    Instance noActuator = Instance.create(InstanceId.of("noActuator")).register(Registration.create("foo", "http://health").build()).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(repository.save(noActuator)).expectNextCount(1).verifyComplete();
    Instance offline = Instance.create(InstanceId.of("off")).register(registration).withStatusInfo(StatusInfo.ofOffline());
    StepVerifier.create(repository.save(offline)).expectNextCount(1).verifyComplete();
    Instance unknown = Instance.create(InstanceId.of("unk")).register(registration).withStatusInfo(StatusInfo.ofUnknown());
    StepVerifier.create(repository.save(unknown)).expectNextCount(1).verifyComplete();
    when(strategy.detectEndpoints(any(Instance.class))).thenReturn(Mono.just(Endpoints.single("id", "url")));
    // when/then
    StepVerifier.create(Flux.from(eventStore).log("FOO", Level.SEVERE)).expectSubscription().then(() -> StepVerifier.create(detector.detectEndpoints(offline.getId())).verifyComplete()).then(() -> StepVerifier.create(detector.detectEndpoints(unknown.getId())).verifyComplete()).then(() -> StepVerifier.create(detector.detectEndpoints(noActuator.getId())).verifyComplete()).expectNoEvent(Duration.ofMillis(100L)).then(() -> StepVerifier.create(detector.detectEndpoints(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceEndpointsDetectedEvent.class)).thenCancel().verify();
    StepVerifier.create(repository.find(instance.getId())).assertNext((app) -> assertThat(app.getEndpoints()).isEqualTo(Endpoints.single("id", "url").withEndpoint("health", "http://health"))).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EndpointDetectionStrategy(de.codecentric.boot.admin.server.services.endpoints.EndpointDetectionStrategy) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) Level(java.util.logging.Level) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Flux(reactor.core.publisher.Flux) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Duration(java.time.Duration) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) ConcurrentMapEventStore(de.codecentric.boot.admin.server.eventstore.ConcurrentMapEventStore) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Mockito.mock(org.mockito.Mockito.mock) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) Test(org.junit.jupiter.api.Test)

Example 7 with Registration

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

the class BasicAuthHttpHeaderProviderTest method test_auth_header_no_separator.

@Test
public void test_auth_header_no_separator() {
    Registration registration = Registration.create("foo", "http://health").metadata("username", "test").metadata("userpassword", "drowssap").build();
    Instance instance = Instance.create(InstanceId.of("id")).register(registration);
    assertThat(this.headersProvider.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)).containsOnly("Basic dGVzdDpkcm93c3NhcA==");
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 8 with Registration

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

the class BasicAuthHttpHeaderProviderTest method test_auth_instance_enabled_use_default_creds.

@Test
public void test_auth_instance_enabled_use_default_creds() {
    Registration registration = Registration.create("foo", "http://health").name("xyz-server").build();
    Instance instance = Instance.create(InstanceId.of("id")).register(registration);
    assertThat(this.headersProviderEnableInstanceAuth.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)).containsOnly("Basic Y2xpZW50OmNsaWVudA==");
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 9 with Registration

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

the class BasicAuthHttpHeaderProviderTest method test_auth_instance_enabled_use_metadata_over_props.

@Test
public void test_auth_instance_enabled_use_metadata_over_props() {
    Registration registration = Registration.create("foo", "http://health").metadata("username", "test").metadata("userpassword", "drowssap").name("xyz-server").build();
    Instance instance = Instance.create(InstanceId.of("id")).register(registration);
    assertThat(this.headersProviderEnableInstanceAuth.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)).containsOnly("Basic dGVzdDpkcm93c3NhcA==");
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 10 with Registration

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

the class BasicAuthHttpHeaderProviderTest method test_auth_header.

@Test
public void test_auth_header() {
    Registration registration = Registration.create("foo", "http://health").metadata("user.name", "test").metadata("user.password", "drowssap").build();
    Instance instance = Instance.create(InstanceId.of("id")).register(registration);
    assertThat(this.headersProvider.getHeaders(instance).get(HttpHeaders.AUTHORIZATION)).containsOnly("Basic dGVzdDpkcm93c3NhcA==");
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) 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