Search in sources :

Example 16 with InstanceStatusChangedEvent

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

the class MailNotifierTest method should_send_mail_using_default_template.

@Test
public void should_send_mail_using_default_template() throws IOException, MessagingException {
    Map<String, Object> details = new HashMap<>();
    details.put("Simple Value", 1234);
    details.put("Complex Value", singletonMap("Nested Simple Value", "99!"));
    StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofDown(details)))).verifyComplete();
    ArgumentCaptor<MimeMessage> mailCaptor = ArgumentCaptor.forClass(MimeMessage.class);
    verify(sender).send(mailCaptor.capture());
    MimeMessage mail = mailCaptor.getValue();
    assertThat(mail.getSubject()).isEqualTo("application-name (cafebabe) is DOWN");
    assertThat(mail.getRecipients(Message.RecipientType.TO)).containsExactly(new InternetAddress("foo@bar.com"));
    assertThat(mail.getRecipients(Message.RecipientType.CC)).containsExactly(new InternetAddress("bar@foo.com"));
    assertThat(mail.getFrom()).containsExactly(new InternetAddress("SBA <no-reply@example.com>"));
    assertThat(mail.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
    String body = extractBody(mail.getDataHandler());
    assertThat(body).isEqualTo(loadExpectedBody("expected-default-mail"));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 17 with InstanceStatusChangedEvent

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

the class EndpointDetectionTriggerTest method should_detect_on_status_changed.

@Test
public void should_detect_on_status_changed() {
    // when status-change event is emitted
    this.events.next(new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown()));
    // then should update
    verify(this.detector, times(1)).detectEndpoints(this.instance.getId());
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 18 with InstanceStatusChangedEvent

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

the class HazelcastNotificationTriggerTest method should_trigger_notifications.

@Test
void should_trigger_notifications() {
    // given then notifier has subscribed to the events and no notification was sent
    // before
    this.sentNotifications.clear();
    this.trigger.start();
    await().until(this.events::wasSubscribed);
    // when registered event is emitted
    InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown());
    this.events.next(event);
    // then should notify
    verify(this.notifier, times(1)).notify(event);
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 19 with InstanceStatusChangedEvent

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

the class MailNotifierTest method should_not_propagate_error.

@Test
public void should_not_propagate_error() {
    Notifier notifier = new AbstractStatusChangeNotifier(repository) {

        @Override
        protected Mono<Void> doNotify(InstanceEvent event, Instance application) {
            return Mono.error(new IllegalStateException("test"));
        }
    };
    StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 20 with InstanceStatusChangedEvent

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

the class MailNotifierTest method should_not_send_when_unknown_to_up.

@Test
public void should_not_send_when_unknown_to_up() {
    StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))).verifyComplete();
    verifyNoMoreInteractions(sender);
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)51 Test (org.junit.jupiter.api.Test)47 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)9 HttpEntity (org.springframework.http.HttpEntity)6 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)5 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)5 URI (java.net.URI)5 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)4 HashMap (java.util.HashMap)4 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)3 Message (de.codecentric.boot.admin.server.notify.MicrosoftTeamsNotifier.Message)3 Instant (java.time.Instant)3 JSONObject (org.json.JSONObject)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 Registration (de.codecentric.boot.admin.server.domain.values.Registration)2 MimeMessage (javax.mail.internet.MimeMessage)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)1 WireMock.ok (com.github.tomakehurst.wiremock.client.WireMock.ok)1