Skip to content

Commit bccc19f

Browse files
authored
test-warを用いたMayaaバージョン間の比較のテストケースで例外期待の際も一致を確認 (#107)
1 parent 0eb9594 commit bccc19f

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed

doc/TESTING.md

+15
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,19 @@ innerHTML は子要素のノードが (&), (<), (>) を含む場合はそれぞ
9191
元テキスト JUnit内の記述
9292
[c&lt;l&amp;a&quot;s&gt;s] "[c&lt;l&amp;a\"s&gt;s]"
9393

94+
95+
## 過去バージョンとの比較
96+
97+
test-warを用いて過去のバージョンと最新のバージョンの実行結果の比較を行うことができる。
98+
99+
```sh
100+
export VERSION_1=1.1.34 VERSION_2=1.3.0
101+
mvn clean -Dmayaa.version=$VERSION_1 && mvn package -U -Dmayaa.version=$VERSION_1 && mvn package -U -Dmayaa.version=$VERSION_2
102+
docker compose -f docker-compose-compare.yaml up
103+
```
104+
105+
```sh
106+
mvn test -Dtest=CompareITCase -DVERSION_1=$VERSION_1 -DVERSION_2=$VERSION_2
107+
```
108+
94109
以上

test-war/src/main/webapp/java.lang.Throwable.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ <h1>Error occurred while rendering.</h1>
136136
</div>
137137
<div class="main">
138138

139-
<p class="fixed"><span m:inject="m:write" m:value="${ getMessage() }" m:escapeXml="false">error message in Exception</span></p>
139+
<p class="fixed" id="exception-message"><span m:inject="m:write" m:value="${ getMessage() }" m:escapeXml="false">error message in Exception</span></p>
140140

141141
<h2>requested path:</h2>
142142
<div class="print">

test-war/src/test/java/org/seasar/mayaa/test/compatibility/CompareITCase.java

+45-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.BufferedReader;
66
import java.io.IOException;
77
import java.io.InputStreamReader;
8+
import java.net.HttpURLConnection;
89
import java.net.MalformedURLException;
910
import java.net.URL;
1011
import java.net.URLConnection;
@@ -107,38 +108,63 @@ public void runTest() {
107108
try {
108109
final String context = "/mayaa-" + versions[i];
109110
URL url = new URL("http", "localhost", 8080, context + path);
110-
URLConnection connection = url.openConnection();
111-
112-
InputStreamReader reader = new InputStreamReader(connection.getInputStream());
113-
BufferedReader br = new BufferedReader(reader);
111+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
114112

115113
StringBuilder buf = new StringBuilder();
116-
// PathAdjusterが動作した部分を吸収
117-
br.lines()
118-
.map(e -> e.replace(context, "/MAYAA"))
119-
.forEach(e -> buf.append(e));
120114

121-
String content = buf.toString();
115+
// ステータスコードを取得
116+
int statusCode = connection.getResponseCode();
117+
118+
// ステータスコードが200以外の場合もエラーストリームを取得
119+
if (statusCode >= 200 && statusCode < 300) {
120+
try (InputStreamReader r = new InputStreamReader(connection.getInputStream());
121+
BufferedReader br = new BufferedReader(r)) {
122122

123-
// 1.1系でのXML宣言直後の連続する改行コードを1つに補正
124-
content = content.replace("?>\n\n", "?>\n");
123+
// PathAdjusterが動作した部分を吸収
124+
br.lines()
125+
.map(e -> e.replace(context, "/MAYAA"))
126+
.forEach(e -> buf.append(e));
125127

126-
// /tests/customtag/replace_injection_attribute.html のみv1.1.34にてなぜか閉じタグ</html> が </xml:html> となっているのを吸収
127-
content = content.replace("</xml:html>", "</html>");
128128

129-
results.add(Arrays.asList(content.split("\n")));
129+
String content = buf.toString();
130+
// 1.1系でのXML宣言直後の連続する改行コードを1つに補正
131+
content = content.replace("?>\n\n", "?>\n");
132+
133+
// /tests/customtag/replace_injection_attribute.html のみv1.1.34にてなぜか閉じタグ</html> が </xml:html> となっているのを吸収
134+
content = content.replace("</xml:html>", "</html>");
135+
136+
results.add(Arrays.asList(content.split("\n")));
137+
} catch (IOException e) {
138+
System.err.println("IOException:" + path);
139+
}
140+
} else {
141+
try (InputStreamReader r = new InputStreamReader(connection.getErrorStream());
142+
BufferedReader br = new BufferedReader(r)) {
130143

144+
// エラーメッセージの行だけを取得する
145+
br.lines()
146+
.filter(e -> e.contains("id=\"exception-message\""))
147+
.forEach(e -> buf.append(e));
148+
149+
String content = buf.toString();
150+
results.add(Arrays.asList(content.split("\n")));
151+
} catch (IOException e) {
152+
System.err.println("IOException:" + path);
153+
}
154+
}
155+
if (results.size() == 2) {
156+
assertArrayEquals(results.get(0).toArray(), results.get(1).toArray(), path);
157+
System.err.println("OK:" + path);
158+
}
159+
131160
} catch (MalformedURLException e) {
132-
System.err.println(path);
161+
System.err.println("MalformedURLException:" + path);
133162
} catch (IOException e) {
134-
System.err.println(path);
163+
System.err.println("IOException:" + path);
135164
} finally {
136165
//
137166
}
138167
}
139-
if (results.size() == 2) {
140-
assertArrayEquals(results.get(0).toArray(), results.get(1).toArray(), path);
141-
}
142168
}
143169
}
144170
}

0 commit comments

Comments
 (0)