package com.dianping.cat.system.notify;

import junit.framework.Assert;

import org.junit.Test;
import org.unidal.helper.Files;
import org.unidal.lookup.ComponentTestCase;

import com.dianping.cat.consumer.event.model.entity.EventReport;
import com.dianping.cat.consumer.problem.model.entity.ProblemReport;
import com.dianping.cat.consumer.transaction.model.entity.TransactionReport;
import com.dianping.cat.consumer.transaction.model.transform.DefaultSaxParser;

public class RenderTest extends ComponentTestCase {
	
	@Test
	public void testTransaction() throws Exception {
		ReportRender render = lookup(ReportRender.class);
		String excepted = Files.forIO().readFrom(getClass().getResourceAsStream("TransactionRender.txt"), "utf-8");
		String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("Transaction.xml"), "utf-8");
		TransactionReport report = DefaultSaxParser.parse(oldXml);

		String result = render.renderReport(report);
		Assert.assertEquals(excepted.replaceAll("\r", ""), result.replaceAll("\r", ""));
	}

	@Test
	public void testEvent() throws Exception {
		ReportRender render = lookup(ReportRender.class);
		String excepted = Files.forIO().readFrom(getClass().getResourceAsStream("EventRender.txt"), "utf-8");
		String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("Event.xml"), "utf-8");
		EventReport report = com.dianping.cat.consumer.event.model.transform.DefaultSaxParser.parse(oldXml);

		String result = render.renderReport(report);
		Assert.assertEquals(excepted.replaceAll("\r", ""), result.replaceAll("\r", ""));
	}
	
	@Test
	public void testProblem() throws Exception {
		ReportRender render = lookup(ReportRender.class);
		String excepted = Files.forIO().readFrom(getClass().getResourceAsStream("ProblemRender.txt"), "utf-8");
		String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("Problem.xml"), "utf-8");
		ProblemReport report = com.dianping.cat.consumer.problem.model.transform.DefaultSaxParser.parse(oldXml);

		String result = render.renderReport(report);
		Assert.assertEquals(excepted.replaceAll("\r", ""), result.replaceAll("\r", ""));
	}
	
}

@@ -933,32 +933,62 @@
 Report(report);%0A
+%09%09System.out.println(result);%0A
 %09%09Assert.assertE
@@ -1054,16 +1054,51 @@
 , %22%22));%0A
+%09%09System.out.println(%22---------%22);%0A
 %09%7D%0A%0A%09@Te
@@ -1539,32 +1539,62 @@
 Report(report);%0A
+%09%09System.out.println(result);%0A
 %09%09Assert.assertE
@@ -1656,24 +1656,58 @@
 %22%5Cr%22, %22%22));%0A
+%09%09System.out.println(%22--------%22);%0A
 %09%7D%0A%09%0A%09@Test%0A
@@ -2159,24 +2159,54 @@
 rt(report);%0A
+%09%09System.out.println(result);%0A
 %09%09Assert.ass
@@ -2276,15 +2276,50 @@
 , %22%22));%0A
+%09%09System.out.println(%22---------%22);%0A
 %09%7D%0A%09%0A%7D%0A

add debug log