Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
87e66570
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
87e66570
编写于
4月 30, 2014
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JUnit 4.
上级
8ec605a4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
46 deletion
+51
-46
test/src/test/java/hudson/console/ConsoleAnnotatorTest.java
test/src/test/java/hudson/console/ConsoleAnnotatorTest.java
+51
-46
未找到文件。
test/src/test/java/hudson/console/ConsoleAnnotatorTest.java
浏览文件 @
87e66570
...
...
@@ -20,30 +20,35 @@ import hudson.scm.RepositoryBrowser;
import
hudson.scm.SCMDescriptor
;
import
hudson.scm.SCMRevisionState
;
import
hudson.triggers.SCMTrigger
;
import
org.jvnet.hudson.test.Bug
;
import
org.jvnet.hudson.test.HudsonTestCase
;
import
org.jvnet.hudson.test.SequenceLock
;
import
org.jvnet.hudson.test.SingleFileSCM
;
import
org.jvnet.hudson.test.TestBuilder
;
import
org.jvnet.hudson.test.TestExtension
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URL
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.Future
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.Bug
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
org.jvnet.hudson.test.SequenceLock
;
import
org.jvnet.hudson.test.SingleFileSCM
;
import
org.jvnet.hudson.test.TestBuilder
;
import
org.jvnet.hudson.test.TestExtension
;
/**
* @author Kohsuke Kawaguchi
*/
public
class
ConsoleAnnotatorTest
extends
HudsonTestCase
{
public
class
ConsoleAnnotatorTest
{
@Rule
public
JenkinsRule
r
=
new
JenkinsRule
();
/**
* Let the build complete, and see if stateless {@link ConsoleAnnotator} annotations happen as expected.
*/
@Bug
(
6031
)
public
void
testC
ompletedStatelessLogAnnotation
()
throws
Exception
{
FreeStyleProject
p
=
createFreeStyleProject
();
@Test
public
void
c
ompletedStatelessLogAnnotation
()
throws
Exception
{
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
getBuildersList
().
add
(
new
TestBuilder
()
{
public
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
listener
.
getLogger
().
println
(
"---"
);
...
...
@@ -53,14 +58,14 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
});
FreeStyleBuild
b
=
buildAndAssertSuccess
(
p
);
FreeStyleBuild
b
=
r
.
buildAndAssertSuccess
(
p
);
// make sure we see the annotation
HtmlPage
rsp
=
createWebClient
().
getPage
(
b
,
"console"
);
HtmlPage
rsp
=
r
.
createWebClient
().
getPage
(
b
,
"console"
);
assertEquals
(
1
,
rsp
.
selectNodes
(
"//B[@class='demo']"
).
size
());
// make sure raw console output doesn't include the garbage
TextPage
raw
=
(
TextPage
)
createWebClient
().
goTo
(
b
.
getUrl
()+
"consoleText"
,
"text/plain"
);
TextPage
raw
=
(
TextPage
)
r
.
createWebClient
().
goTo
(
b
.
getUrl
()+
"consoleText"
,
"text/plain"
);
System
.
out
.
println
(
raw
.
getContent
());
String
nl
=
System
.
getProperty
(
"line.separator"
);
assertTrue
(
raw
.
getContent
().
contains
(
nl
+
"---"
+
nl
+
"ooo"
+
nl
+
"ooo"
+
nl
));
...
...
@@ -73,7 +78,7 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
/**
* Only annotates the first occurrence of "ooo".
*/
@TestExtension
(
"
testC
ompletedStatelessLogAnnotation"
)
@TestExtension
(
"
c
ompletedStatelessLogAnnotation"
)
public
static
final
ConsoleAnnotatorFactory
DEMO_ANNOTATOR
=
new
ConsoleAnnotatorFactory
()
{
public
ConsoleAnnotator
newInstance
(
Object
context
)
{
return
new
DemoAnnotator
();
...
...
@@ -93,8 +98,8 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
@Bug
(
6034
)
public
void
testC
onsoleAnnotationFilterOut
()
throws
Exception
{
FreeStyleProject
p
=
createFreeStyleProject
();
@Test
public
void
c
onsoleAnnotationFilterOut
()
throws
Exception
{
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
getBuildersList
().
add
(
new
TestBuilder
()
{
public
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
listener
.
getLogger
().
print
(
"abc\n"
);
...
...
@@ -103,14 +108,14 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
});
FreeStyleBuild
b
=
buildAndAssertSuccess
(
p
);
FreeStyleBuild
b
=
r
.
buildAndAssertSuccess
(
p
);
// make sure we see the annotation
HtmlPage
rsp
=
createWebClient
().
getPage
(
b
,
"console"
);
HtmlPage
rsp
=
r
.
createWebClient
().
getPage
(
b
,
"console"
);
assertEquals
(
1
,
rsp
.
selectNodes
(
"//A[@href='http://infradna.com/']"
).
size
());
// make sure raw console output doesn't include the garbage
TextPage
raw
=
(
TextPage
)
createWebClient
().
goTo
(
b
.
getUrl
()+
"consoleText"
,
"text/plain"
);
TextPage
raw
=
(
TextPage
)
r
.
createWebClient
().
goTo
(
b
.
getUrl
()+
"consoleText"
,
"text/plain"
);
System
.
out
.
println
(
raw
.
getContent
());
assertTrue
(
raw
.
getContent
().
contains
(
"\nabc\ndef\n"
));
}
...
...
@@ -120,20 +125,20 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
class
ProgressiveLogClient
{
WebClient
wc
;
JenkinsRule
.
WebClient
wc
;
Run
run
;
String
consoleAnnotator
;
String
start
;
private
Page
p
;
ProgressiveLogClient
(
WebClient
wc
,
Run
r
)
{
ProgressiveLogClient
(
JenkinsRule
.
WebClient
wc
,
Run
r
)
{
this
.
wc
=
wc
;
this
.
run
=
r
;
}
String
next
()
throws
IOException
{
WebRequestSettings
req
=
new
WebRequestSettings
(
new
URL
(
getURL
()
+
run
.
getUrl
()
+
"/logText/progressiveHtml"
+(
start
!=
null
?
"?start="
+
start:
""
)));
WebRequestSettings
req
=
new
WebRequestSettings
(
new
URL
(
r
.
getURL
()
+
run
.
getUrl
()
+
"/logText/progressiveHtml"
+(
start
!=
null
?
"?start="
+
start:
""
)));
Map
headers
=
new
HashMap
();
if
(
consoleAnnotator
!=
null
)
headers
.
put
(
"X-ConsoleAnnotator"
,
consoleAnnotator
);
...
...
@@ -151,10 +156,10 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
* Tests the progressive output by making sure that the state of {@link ConsoleAnnotator}s are
* maintained across different progressiveLog calls.
*/
public
void
testP
rogressiveOutput
()
throws
Exception
{
@Test
public
void
p
rogressiveOutput
()
throws
Exception
{
final
SequenceLock
lock
=
new
SequenceLock
();
WebClient
wc
=
createWebClient
();
FreeStyleProject
p
=
createFreeStyleProject
();
JenkinsRule
.
WebClient
wc
=
r
.
createWebClient
();
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
getBuildersList
().
add
(
new
TestBuilder
()
{
public
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
lock
.
phase
(
0
);
...
...
@@ -186,10 +191,10 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
lock
.
done
();
// should complete successfully
assertBuildStatusSuccess
(
f
);
r
.
assertBuildStatusSuccess
(
f
);
}
@TestExtension
(
"
testP
rogressiveOutput"
)
@TestExtension
(
"
p
rogressiveOutput"
)
public
static
final
ConsoleAnnotatorFactory
STATEFUL_ANNOTATOR
=
new
ConsoleAnnotatorFactory
()
{
public
ConsoleAnnotator
newInstance
(
Object
context
)
{
return
new
StatefulAnnotator
();
...
...
@@ -210,10 +215,10 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
/**
* Place {@link ConsoleNote}s and make sure it works.
*/
public
void
testC
onsoleAnnotation
()
throws
Exception
{
@Test
public
void
c
onsoleAnnotation
()
throws
Exception
{
final
SequenceLock
lock
=
new
SequenceLock
();
WebClient
wc
=
createWebClient
();
FreeStyleProject
p
=
createFreeStyleProject
();
JenkinsRule
.
WebClient
wc
=
r
.
createWebClient
();
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
getBuildersList
().
add
(
new
TestBuilder
()
{
public
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
lock
.
phase
(
0
);
...
...
@@ -252,7 +257,7 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
lock
.
done
();
// should complete successfully
assertBuildStatusSuccess
(
f
);
r
.
assertBuildStatusSuccess
(
f
);
}
/**
...
...
@@ -276,11 +281,11 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
/**
* script.js defined in the annotator needs to be incorporated into the console page.
*/
public
void
testS
criptInclusion
()
throws
Exception
{
FreeStyleProject
p
=
createFreeStyleProject
();
FreeStyleBuild
b
=
buildAndAssertSuccess
(
p
);
@Test
public
void
s
criptInclusion
()
throws
Exception
{
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
FreeStyleBuild
b
=
r
.
buildAndAssertSuccess
(
p
);
HtmlPage
html
=
createWebClient
().
getPage
(
b
,
"console"
);
HtmlPage
html
=
r
.
createWebClient
().
getPage
(
b
,
"console"
);
// verify that there's an element inserted by the script
assertNotNull
(
html
.
getElementById
(
"inserted-by-test1"
));
assertNotNull
(
html
.
getElementById
(
"inserted-by-test2"
));
...
...
@@ -291,7 +296,7 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
return
null
;
}
@TestExtension
(
"
testS
criptInclusion"
)
@TestExtension
(
"
s
criptInclusion"
)
public
static
final
class
DescriptorImpl
extends
ConsoleAnnotationDescriptor
{
public
String
getDisplayName
()
{
return
"just to include a script"
;
...
...
@@ -299,7 +304,7 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
}
@TestExtension
(
"
testS
criptInclusion"
)
@TestExtension
(
"
s
criptInclusion"
)
public
static
final
class
JustToIncludeScriptAnnotator
extends
ConsoleAnnotatorFactory
{
public
ConsoleAnnotator
newInstance
(
Object
context
)
{
return
null
;
...
...
@@ -311,8 +316,8 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
* Makes sure '<', '&', are escaped.
*/
@Bug
(
5952
)
public
void
testE
scape
()
throws
Exception
{
FreeStyleProject
p
=
createFreeStyleProject
();
@Test
public
void
e
scape
()
throws
Exception
{
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
getBuildersList
().
add
(
new
TestBuilder
()
{
@Override
public
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
...
...
@@ -321,31 +326,31 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
});
FreeStyleBuild
b
=
buildAndAssertSuccess
(
p
);
HtmlPage
html
=
createWebClient
().
getPage
(
b
,
"console"
);
FreeStyleBuild
b
=
r
.
buildAndAssertSuccess
(
p
);
HtmlPage
html
=
r
.
createWebClient
().
getPage
(
b
,
"console"
);
String
text
=
html
.
asText
();
System
.
out
.
println
(
text
);
assertTrue
(
text
.
contains
(
"<b>&</b>"
));
assertTrue
(
b
.
getLog
(
).
contains
(
"<b>&</b>"
));
assertTrue
(
JenkinsRule
.
getLog
(
b
).
contains
(
"<b>&</b>"
));
}
/**
* Makes sure that annotations in the polling output is handled correctly.
*/
public
void
testP
ollingOutput
()
throws
Exception
{
FreeStyleProject
p
=
createFreeStyleProject
();
@Test
public
void
p
ollingOutput
()
throws
Exception
{
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
setScm
(
new
PollingSCM
());
SCMTrigger
t
=
new
SCMTrigger
(
"@daily"
);
t
.
start
(
p
,
true
);
p
.
addTrigger
(
t
);
buildAndAssertSuccess
(
p
);
r
.
buildAndAssertSuccess
(
p
);
// poll now
t
.
new
Runner
().
run
();
HtmlPage
log
=
createWebClient
().
getPage
(
p
,
"scmPollLog"
);
HtmlPage
log
=
r
.
createWebClient
().
getPage
(
p
,
"scmPollLog"
);
String
text
=
log
.
asText
();
assertTrue
(
text
,
text
.
contains
(
"$$$hello from polling"
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录