Search in sources :

Example 1 with TestNotifier

use of de.codecentric.boot.admin.server.notify.TestNotifier in project spring-boot-admin by codecentric.

the class FilteringNotifierTest method test_expired_removal.

@Test
public void test_expired_removal() {
    FilteringNotifier notifier = new FilteringNotifier(new TestNotifier(), repository);
    notifier.setCleanupInterval(Duration.ZERO);
    ApplicationNameNotificationFilter filter1 = new ApplicationNameNotificationFilter("foo", Instant.now().minus(Duration.ofSeconds(1)));
    notifier.addFilter(filter1);
    ApplicationNameNotificationFilter filter2 = new ApplicationNameNotificationFilter("bar", null);
    notifier.addFilter(filter2);
    assertThat(notifier.getNotificationFilters()).containsKey(filter1.getId()).containsKey(filter2.getId());
    StepVerifier.create(notifier.notify(event)).verifyComplete();
    assertThat(notifier.getNotificationFilters()).doesNotContainKey(filter1.getId()).containsKey(filter2.getId());
    notifier.removeFilter(filter2.getId());
    assertThat(notifier.getNotificationFilters()).doesNotContainKey(filter2.getId());
}
Also used : TestNotifier(de.codecentric.boot.admin.server.notify.TestNotifier) Test(org.junit.jupiter.api.Test)

Example 2 with TestNotifier

use of de.codecentric.boot.admin.server.notify.TestNotifier in project spring-boot-admin by codecentric.

the class FilteringNotifierTest method test_filter.

@Test
public void test_filter() {
    TestNotifier delegate = new TestNotifier();
    FilteringNotifier notifier = new FilteringNotifier(delegate, repository);
    AbstractNotificationFilter trueFilter = new AbstractNotificationFilter() {

        @Override
        public boolean filter(InstanceEvent event, Instance instance) {
            return true;
        }
    };
    notifier.addFilter(trueFilter);
    StepVerifier.create(notifier.notify(event)).verifyComplete();
    assertThat(delegate.getEvents()).doesNotContain(event);
    notifier.removeFilter(trueFilter.getId());
    StepVerifier.create(notifier.notify(event)).verifyComplete();
    assertThat(delegate.getEvents()).contains(event);
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) TestNotifier(de.codecentric.boot.admin.server.notify.TestNotifier) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) Test(org.junit.jupiter.api.Test)

Aggregations

TestNotifier (de.codecentric.boot.admin.server.notify.TestNotifier)2 Test (org.junit.jupiter.api.Test)2 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)1 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)1