Search in sources :

Example 1 with InstanceRegisteredEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.

the class InfoUpdateTriggerTest method should_not_update_when_stopped.

@Test
public void should_not_update_when_stopped() {
    // when registered event is emitted but the trigger has been stopped
    this.trigger.stop();
    clearInvocations(this.updater);
    this.events.next(new InstanceRegisteredEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration()));
    // then should not update
    verify(this.updater, never()).updateInfo(this.instance.getId());
}
Also used : InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Test(org.junit.jupiter.api.Test)

Example 2 with InstanceRegisteredEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.

the class MicrosoftTeamsNotifierTest method test_onApplicationRegisteredEvent_resolve.

@Test
@SuppressWarnings("unchecked")
void test_onApplicationRegisteredEvent_resolve() {
    InstanceRegisteredEvent event = new InstanceRegisteredEvent(instance.getId(), 1L, instance.getRegistration());
    StepVerifier.create(notifier.doNotify(event, instance)).verifyComplete();
    ArgumentCaptor<HttpEntity<Message>> entity = ArgumentCaptor.forClass(HttpEntity.class);
    verify(mockRestTemplate).postForEntity(eq(URI.create("http://example.com")), entity.capture(), eq(Void.class));
    assertThat(entity.getValue().getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
    assertMessage(entity.getValue().getBody(), notifier.getRegisteredTitle(), notifier.getMessageSummary(), "Test App with id TestAppId has registered with Spring Boot Admin", BLUE);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Test(org.junit.jupiter.api.Test)

Example 3 with InstanceRegisteredEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.

the class InstanceRegisteredEventMixinTest method verifyDeserializeWithoutRegistration.

@Test
public void verifyDeserializeWithoutRegistration() throws JSONException, JsonProcessingException {
    String json = new JSONObject().put("instance", "test123").put("version", 12345678L).put("timestamp", 1587751031.000000000).put("type", "REGISTERED").toString();
    InstanceRegisteredEvent event = objectMapper.readValue(json, InstanceRegisteredEvent.class);
    assertThat(event).isNotNull();
    assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
    assertThat(event.getVersion()).isEqualTo(12345678L);
    assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));
    assertThat(event.getRegistration()).isNull();
}
Also used : JSONObject(org.json.JSONObject) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Test(org.junit.jupiter.api.Test)

Example 4 with InstanceRegisteredEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.

the class InstanceRegisteredEventMixinTest method verifySerializeWithoutRegistration.

@Test
public void verifySerializeWithoutRegistration() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    InstanceRegisteredEvent event = new InstanceRegisteredEvent(id, 12345678L, timestamp, null);
    JsonContent<InstanceRegisteredEvent> jsonContent = jsonTester.write(event);
    assertThat(jsonContent).extractingJsonPathStringValue("$.instance").isEqualTo("test123");
    assertThat(jsonContent).extractingJsonPathNumberValue("$.version").isEqualTo(12345678);
    assertThat(jsonContent).extractingJsonPathNumberValue("$.timestamp").isEqualTo(1587751031.000000000);
    assertThat(jsonContent).extractingJsonPathStringValue("$.type").isEqualTo("REGISTERED");
    assertThat(jsonContent).extractingJsonPathValue("$.registration").isNull();
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 5 with InstanceRegisteredEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent in project spring-boot-admin by codecentric.

the class InstanceRegisteredEventMixinTest method verifyDeserialize.

@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
    String json = new JSONObject().put("instance", "test123").put("version", 12345678L).put("timestamp", 1587751031.000000000).put("type", "REGISTERED").put("registration", new JSONObject().put("name", "test").put("managementUrl", "http://localhost:9080/").put("healthUrl", "http://localhost:9080/heath").put("serviceUrl", "http://localhost:8080/").put("source", "http-api").put("metadata", new JSONObject().put("PASSWORD", "******").put("user", "humptydumpty"))).toString();
    InstanceRegisteredEvent event = objectMapper.readValue(json, InstanceRegisteredEvent.class);
    assertThat(event).isNotNull();
    assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
    assertThat(event.getVersion()).isEqualTo(12345678L);
    assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));
    Registration registration = event.getRegistration();
    assertThat(registration).isNotNull();
    assertThat(registration.getName()).isEqualTo("test");
    assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:9080/");
    assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:9080/heath");
    assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:8080/");
    assertThat(registration.getSource()).isEqualTo("http-api");
    assertThat(registration.getMetadata()).containsOnly(entry("PASSWORD", "******"), entry("user", "humptydumpty"));
}
Also used : JSONObject(org.json.JSONObject) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)22 Test (org.junit.jupiter.api.Test)20 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)5 Registration (de.codecentric.boot.admin.server.domain.values.Registration)5 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)4 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)4 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)4 Instant (java.time.Instant)4 JSONObject (org.json.JSONObject)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 HttpEntity (org.springframework.http.HttpEntity)2 InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)1 InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)1 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)1 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)1 Info (de.codecentric.boot.admin.server.domain.values.Info)1 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)1 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1 HttpHeaders (org.springframework.http.HttpHeaders)1