package com.dianping.cat.consumer.state;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import junit.framework.Assert;

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

import com.dianping.cat.Constants;
import com.dianping.cat.analysis.MessageAnalyzer;
import com.dianping.cat.consumer.state.model.entity.Machine;
import com.dianping.cat.consumer.state.model.entity.Message;
import com.dianping.cat.consumer.state.model.entity.StateReport;

public class StateAnalyzerTest extends ComponentTestCase {

	private StateAnalyzer m_analyzer;

	private String m_domain = "group";

	@Before
	public void setUp() throws Exception {
		super.setUp();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss:SS");
		Date date = sdf.parse("20120101 00:00:00:00");

		m_analyzer = (StateAnalyzer) lookup(MessageAnalyzer.class, StateAnalyzer.ID);
		
		System.out.println(date.getTime());
		
		m_analyzer.initialize(date.getTime(), Constants.HOUR, Constants.MINUTE * 5);
	}

	@Test
	public void testProcess() throws Exception {

		StateReport report = m_analyzer.getReport(m_domain);
		
		String expected = Files.forIO().readFrom(getClass().getResourceAsStream("state_analyzer.xml"), "utf-8");
		
		Assert.assertEquals(expected.replaceAll("\r", ""), report.toString().replaceAll("\r", ""));
	}
}

@@ -39,70 +39,8 @@
 e;%0A%0A
-import java.text.DateFormat;%0Aimport java.text.ParseException;%0A
 impo
@@ -91,16 +91,12 @@
 til.
-Calendar
+Date
 ;%0Aim
@@ -110,19 +110,23 @@
 va.util.
-Dat
+TimeZon
 e;%0A%0Aimpo
@@ -367,130 +367,8 @@
 er;%0A
-import com.dianping.cat.consumer.state.model.entity.Machine;%0Aimport com.dianping.cat.consumer.state.model.entity.Message;%0A
 impo
@@ -699,16 +699,74 @@
 s:SS%22);%0A
+%09%09sdf.setTimeZone(TimeZone.getTimeZone(%22Asia/Shanghai%22));%0A
 %09%09Date d

add timezone into StateAnalyzerTest