Commit 8e86ed08 by Johannes Edmeier

Move AbstractNotifier-tests to MailNotifierTests

Tests in Abstract*.class are not executed during the maven build, so I moved the tests for code in AbstractNotifierTest to MailNotifierTest
parent 1c5abd58
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.notify;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.model.StatusInfo;
public class AbstractNotifierTest {
@Test
public void test_onApplicationEvent() {
TestableNotifier notifier = new TestableNotifier();
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofDown(), StatusInfo.ofUp()));
assertTrue(notifier.hasNotified);
}
@Test
public void test_onApplicationEvent_disbaled() {
TestableNotifier notifier = new TestableNotifier();
notifier.setEnabled(false);
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofDown(), StatusInfo.ofUp()));
assertFalse(notifier.hasNotified);
}
@Test
public void test_onApplicationEvent_noSend() {
TestableNotifier notifier = new TestableNotifier();
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofUnknown(), StatusInfo.ofUp()));
assertFalse(notifier.hasNotified);
}
@Test
public void test_onApplicationEvent_noSend_wildcard() {
TestableNotifier notifier = new TestableNotifier();
notifier.setIgnoreChanges(new String[] { "*:UP" });
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofOffline(), StatusInfo.ofUp()));
assertFalse(notifier.hasNotified);
}
@Test
public void test_onApplicationEvent_throw_doesnt_propagate() {
AbstractNotifier notifier = new AbstractNotifier() {
@Override
protected void notify(ClientApplicationStatusChangedEvent event) throws Exception {
throw new RuntimeException();
}
};
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofOffline(), StatusInfo.ofUp()));
}
private static class TestableNotifier extends AbstractNotifier {
private boolean hasNotified;
@Override
protected void notify(ClientApplicationStatusChangedEvent event) throws Exception {
hasNotified = true;
}
}
}
......@@ -18,6 +18,7 @@ package de.codecentric.boot.admin.notify;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import org.junit.Before;
import org.junit.Test;
......@@ -60,4 +61,47 @@ public class MailNotifierTest {
verify(sender).send(eq(expected));
}
// The following tests are rather for AbstractNotifier
@Test
public void test_onApplicationEvent_disbaled() {
notifier.setEnabled(false);
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofDown(), StatusInfo.ofUp()));
verifyNoMoreInteractions(sender);
}
@Test
public void test_onApplicationEvent_noSend() {
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofUnknown(), StatusInfo.ofUp()));
verifyNoMoreInteractions(sender);
}
@Test
public void test_onApplicationEvent_noSend_wildcard() {
notifier.setIgnoreChanges(new String[] { "*:UP" });
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofOffline(), StatusInfo.ofUp()));
verifyNoMoreInteractions(sender);
}
@Test
public void test_onApplicationEvent_throw_doesnt_propagate() {
AbstractNotifier notifier = new AbstractNotifier() {
@Override
protected void notify(ClientApplicationStatusChangedEvent event) throws Exception {
throw new RuntimeException();
}
};
notifier.onClientApplicationStatusChanged(new ClientApplicationStatusChangedEvent(
Application.create("App").withId("-id-").withHealthUrl("http://health").build(),
StatusInfo.ofOffline(), StatusInfo.ofUp()));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment