UITest.java
4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.dianping.cat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.unidal.helper.Urls;
import org.unidal.helper.Files;
public class UITest {
private String m_date;
private String m_local_host = "localhost:2281";
private String m_qa_host = "cat.qa.dianpingoa.com";
private List<Item> m_items = new ArrayList<Item>();
@Before
public void setUp() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.HOUR, -3);
m_date = new SimpleDateFormat("yyyyMMddHH").format(cal.getTime());
m_items.add(new Item("http://%s/cat/r/home?domain=Cat&ip=&date=%s&reportType=&op=view", "Home"));
m_items.add(new Item("http://%s/cat/r/metric?domain=Cat&ip=&date=%s&reportType=&op=view", "Metric"));
m_items.add(new Item("http://%s/cat/r/t?domain=Cat&ip=&date=%s&reportType=&op=view", "Transaction"));
m_items.add(new Item("http://%s/cat/r/e?domain=Cat&ip=&date=%s&reportType=&op=view", "Event"));
m_items.add(new Item("http://%s/cat/r/p?domain=Cat&ip=&date=%s&reportType=&op=view", "Problem"));
m_items.add(new Item("http://%s/cat/r/h?domain=Cat&ip=&date=%s&reportType=&op=view", "Heartbeat"));
m_items.add(new Item("http://%s/cat/r/cross?domain=GroupService&ip=&date=%s&reportType=&op=view", "Cross"));
m_items.add(new Item("http://%s/cat/r/cache?domain=GroupService&ip=&date=%s&reportType=&op=view", "Cache"));
m_items.add(new Item("http://%s/cat/r/sql?domain=GroupService&ip=&date=%s&reportType=&op=view", "Sql"));
m_items.add(new Item("http://%s/cat/r/matrix?domain=GroupService&ip=&date=%s&reportType=&op=view", "Matrix"));
m_items.add(new Item("http://%s/cat/r/statistics?domain=Cat&ip=&date=%s&reportType=&op=view", "Bug"));
m_items.add(new Item("http://%s/cat/r/statistics?domain=Cat&ip=&date=%s&reportType=&op=service", "Service"));
m_items.add(new Item("http://%s/cat/r/statistics?domain=Cat&ip=&date=%s&reportType=&op=utilization",
"Utilization"));
m_items.add(new Item("http://%s/cat/r/statistics?domain=Cat&ip=&date=%s&reportType=&op=heavy", "Heavy"));
m_items.add(new Item("http://%s/cat/r/state?domain=Cat&ip=&date=%s&reportType=&op=view", "State"));
m_items.add(new Item("http://%s/cat/r/state?domain=GroupService&ip=&date=%s&reportType=&op=view", "State"));
m_items.add(new Item("http://%s/cat/r/t?domain=Cat&ip=&date=%s&reportType=&op=history", "TransactionHistory"));
m_items.add(new Item("http://%s/cat/r/e?domain=Cat&ip=&date=%s&reportType=&op=history", "EventHistory"));
m_items.add(new Item("http://%s/cat/r/p?domain=Cat&ip=&date=%s&reportType=&op=history", "ProblemHistory"));
m_items.add(new Item("http://%s/cat/r/h?domain=Cat&ip=&date=%s&reportType=&op=history", "HeartbeatHistory"));
m_items.add(new Item("http://%s/cat/r/cross?domain=GroupService&ip=&date=%s&reportType=&op=history",
"CrossHistory"));
m_items.add(new Item("http://%s/cat/r/cache?domain=GroupService&ip=&date=%s&reportType=&op=history",
"CacheHistory"));
m_items.add(new Item("http://%s/cat/r/sql?domain=GroupService&ip=&date=%s&reportType=&op=history", "SqlHistory"));
m_items.add(new Item("http://%s/cat/r/matrix?domain=GroupService&ip=&date=%s&reportType=&op=history",
"MatrixHistory"));
m_items.add(new Item("http://%s/cat/r/state?domain=GroupService&ip=&date=%s&reportType=&op=history",
"StateHistory"));
m_items
.add(new Item("http://%s/cat/r/statistics?domain=Cat&ip=&date=%s&reportType=&op=historyBug", "BugHistory"));
m_items.add(new Item("http://%s/cat/r/statistics?domain=Cat&ip=&date=%s&reportType=&op=historyService",
"ServiceHistory"));
m_items.add(new Item("http://%s/cat/r/statistics?domain=Cat&ip=&date=%s&reportType=&op=historyUtilization",
"UtilizationHistory"));
m_items.add(new Item("http://%s/cat/r/statistics?domain=Cat&ip=&date=%s&reportType=&op=historyHeavy",
"HeavyHistory"));
}
@Test
public void test() {
for (Item item : m_items) {
try {
compare(item);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void compare(Item item) throws Exception {
String url = item.getUrl();
String localUrl = String.format(url, m_local_host, m_date);
String qaUrl = String.format(url, m_qa_host, m_date);
String localContent = Files.forIO().readFrom(Urls.forIO().connectTimeout(5000).openStream(localUrl), "utf-8");
String qaContent = Files.forIO().readFrom(Urls.forIO().connectTimeout(5000).openStream(qaUrl), "utf-8");
String localTrim = localContent.replaceAll("\\s*", "");
String qaTrim = qaContent.replaceAll("\\s*", "");
if (!localTrim.equals(qaTrim)) {
System.err.println(item.getTitle() + " Fail!");
}
}
public static class Item {
private String m_url;
private String m_title;
public Item(String url, String title) {
m_url = url;
m_title = title;
}
public String getUrl() {
return m_url;
}
public String getTitle() {
return m_title;
}
}
}