提交 cf54f0c9 编写于 作者: A ainilife

add unit test for top report merger

上级 24ce16ce
package com.dianping.cat.consumer.top;
import org.junit.Assert;
import org.junit.Test;
import org.unidal.webres.helper.Files;
import com.dianping.cat.consumer.top.model.entity.TopReport;
import com.dianping.cat.consumer.top.model.transform.DefaultSaxParser;
public class TopReportMergerTest {
@Test
public void testTopReportMerge() throws Exception {
String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("top_analyzer.xml"), "utf-8");
String newXml = Files.forIO().readFrom(getClass().getResourceAsStream("top_analyzer.xml"), "utf-8");
TopReport reportOld = DefaultSaxParser.parse(oldXml);
TopReport reportNew = DefaultSaxParser.parse(newXml);
String expected = Files.forIO().readFrom(getClass().getResourceAsStream("top_analyzer_merger.xml"), "utf-8");
TopReportMerger merger = new TopReportMerger(new TopReport(reportOld.getDomain()));
reportOld.accept(merger);
reportNew.accept(merger);
Assert.assertEquals("Check the merge result!", expected.replace("\r", ""), merger.getTopReport().toString()
.replace("\r", ""));
Assert.assertEquals("Source report is changed!", newXml.replace("\r", ""), reportNew.toString().replace("\r", ""));
}
}
<?xml version="1.0" encoding="utf-8"?>
<top-report domain="Cat" startTime="2012-01-01 00:00:00" endTime="2012-01-01 00:59:59">
<domain name="Cat">
<segment id="2" error="0" url="16" url-duration="10.00" service="60" service-duration="10.00" sql="38" sql-duration="10.00" call="54" call-duration="10.00" cache="0" cache-duration="0.00" url-error="4" url-sum="160.00" service-error="8" service-sum="600.00" sql-error="4" sql-sum="380.00" call-error="8" call-sum="540.00" cache-error="0" cache-sum="0.00">
</segment>
</domain>
</top-report>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册