package org.stagemonitor.alerting.alerter;

import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import org.junit.Test;
import org.slf4j.Logger;
import org.stagemonitor.alerting.check.CheckResult;
import org.stagemonitor.alerting.incident.Incident;

public class LogAlerterTest extends AbstractAlerterTest {

	private LogAlerter logAlerter;
	private Logger logger;
	private AlertSender alertSender;

	public LogAlerterTest() {
		super();
		logger = mock(Logger.class);
		logAlerter = new LogAlerter(alertingPlugin, logger);
		this.alertSender = createAlertSender(logAlerter);
	}

	@Test
	public void testLogAlert() throws Exception {
		Incident incident = alertSender.sendTestAlert(createSubscription(logAlerter), CheckResult.Status.ERROR);

		verify(logger).error(eq(String.format("Incident for check 'Test Check':\n" +
				"First failure: %s\n" +
				"Old status: OK\n" +
				"New status: ERROR\n" +
				"Failing check: 1\n" +
				"Hosts: testHost\n" +
				"Instances: testInstance\n" +
				"\n" +
				"host|instance|status|description|current value\n" +
				"----|--------|------|-----------|-------------\n" +
				"testHost | testInstance | ERROR | test | 10\n", toFreemarkerIsoLocal(incident.getFirstFailureAt()))));
	}
}

@@ -1071,165 +1071,179 @@
 %09%09%09%22
-host%7Cinstance%7Cstatus%7Cdescription%7Ccurrent value%5Cn%22 +%0A%09%09%09%09%22----%7C--------%7C------%7C-----------%7C-------------%5Cn%22 +%0A%09%09%09%09%22testHost %7C testInstance %7C ERROR %7C test %7C 10
+Details:%5Cn%22 +%0A%09%09%09%09%22Host:%5Ct%5Ct%5CttestHost%5Cn%22 +%0A%09%09%09%09%22Instance:%5Ct%5CttestInstance%5Cn%22 +%0A%09%09%09%09%22Status: %5Ct%5CtERROR%5Cn%22 +%0A%09%09%09%09%22Description:%5Cttest%5Cn%22 +%0A%09%09%09%09%22Current value:%5Ct10%5Cn%22 +%0A%09%09%09%09%22
 %5Cn%22,

Fix tests