Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FIY695
jenkins
提交
a930d31f
J
jenkins
项目概览
FIY695
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
a930d31f
编写于
8月 23, 2015
作者:
T
tfennelly
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HelpLinkTest fixes
上级
7ba1798a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
14 deletion
+80
-14
test/src/main/java/com/gargoylesoftware/htmlunit/WebResponseListener.java
...va/com/gargoylesoftware/htmlunit/WebResponseListener.java
+40
-0
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
+19
-3
test/src/test/java/hudson/model/HelpLinkTest.java
test/src/test/java/hudson/model/HelpLinkTest.java
+21
-11
未找到文件。
test/src/main/java/com/gargoylesoftware/htmlunit/WebResponseListener.java
0 → 100644
浏览文件 @
a930d31f
package
com.gargoylesoftware.htmlunit
;
import
org.junit.Assert
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.concurrent.CopyOnWriteArrayList
;
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public
interface
WebResponseListener
{
void
onLoadWebResponse
(
WebRequest
webRequest
,
WebResponse
webResponse
)
throws
IOException
;
public
final
class
StatusListener
implements
WebResponseListener
{
private
final
int
statusCode
;
private
final
List
<
WebResponse
>
responses
=
new
CopyOnWriteArrayList
<>();
public
StatusListener
(
final
int
statusCode
)
{
this
.
statusCode
=
statusCode
;
}
@Override
public
void
onLoadWebResponse
(
WebRequest
webRequest
,
WebResponse
webResponse
)
throws
IOException
{
if
(
webResponse
.
getStatusCode
()
==
statusCode
)
{
responses
.
add
(
webResponse
);
}
}
public
void
assertHasResponses
()
{
Assert
.
assertTrue
(!
responses
.
isEmpty
());
}
public
List
<
WebResponse
>
getResponses
()
{
return
responses
;
}
}
}
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
浏览文件 @
a930d31f
...
...
@@ -32,7 +32,7 @@ import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import
com.gargoylesoftware.htmlunit.Page
;
import
com.gargoylesoftware.htmlunit.WebRequest
;
import
com.gargoylesoftware.htmlunit.WebResponse
;
import
com.gargoylesoftware.htmlunit.Web
Window
;
import
com.gargoylesoftware.htmlunit.Web
ResponseListener
;
import
com.gargoylesoftware.htmlunit.html.DomNode
;
import
com.gargoylesoftware.htmlunit.html.HtmlButton
;
import
com.gargoylesoftware.htmlunit.html.HtmlElement
;
...
...
@@ -148,7 +148,6 @@ import java.util.TimerTask;
import
java.util.TreeSet
;
import
java.util.UUID
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.LinkedBlockingQueue
;
...
...
@@ -161,7 +160,6 @@ import java.util.logging.Level;
import
java.util.logging.LogRecord
;
import
java.util.logging.Logger
;
import
javax.annotation.CheckForNull
;
import
javax.annotation.Nonnull
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContextEvent
;
...
...
@@ -1859,6 +1857,8 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
public
class
WebClient
extends
com
.
gargoylesoftware
.
htmlunit
.
WebClient
{
private
static
final
long
serialVersionUID
=
5808915989048338267L
;
private
List
<
WebResponseListener
>
webResponseListeners
=
new
ArrayList
<>();
public
WebClient
()
{
// default is IE6, but this causes 'n.doScroll('left')' to fail in event-debug.js:1907 as HtmlUnit doesn't implement such a method,
// so trying something else, until we discover another problem.
...
...
@@ -1918,6 +1918,22 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
//setTimeout(60*1000);
}
public
void
addWebResponseListener
(
WebResponseListener
listener
)
{
webResponseListeners
.
add
(
listener
);
}
@Override
public
WebResponse
loadWebResponse
(
final
WebRequest
webRequest
)
throws
IOException
{
WebResponse
webResponse
=
super
.
loadWebResponse
(
webRequest
);
if
(!
webResponseListeners
.
isEmpty
())
{
for
(
WebResponseListener
listener
:
webResponseListeners
)
{
listener
.
onLoadWebResponse
(
webRequest
,
webResponse
);
}
}
return
webResponse
;
}
/**
* Logs in to Jenkins.
*/
...
...
test/src/test/java/hudson/model/HelpLinkTest.java
浏览文件 @
a930d31f
package
hudson.model
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
com.gargoylesoftware.htmlunit.WebResponseListener
;
import
com.gargoylesoftware.htmlunit.html.DomNodeUtil
;
import
com.gargoylesoftware.htmlunit.html.HtmlElementUtil
;
import
hudson.tasks.BuildStepMonitor
;
import
org.junit.Assert
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
com.gargoylesoftware.htmlunit.html.HtmlPage
;
...
...
@@ -49,7 +51,12 @@ public class HelpLinkTest {
private
void
clickAllHelpLinks
(
AbstractProject
p
)
throws
Exception
{
// TODO: how do we add all the builders and publishers so that we can test this meaningfully?
clickAllHelpLinks
(
j
.
createWebClient
().
getPage
(
p
,
"configure"
));
clickAllHelpLinks
(
j
.
createWebClient
(),
p
);
}
private
void
clickAllHelpLinks
(
JenkinsRule
.
WebClient
webClient
,
AbstractProject
p
)
throws
Exception
{
// TODO: how do we add all the builders and publishers so that we can test this meaningfully?
clickAllHelpLinks
(
webClient
.
getPage
(
p
,
"configure"
));
}
private
void
clickAllHelpLinks
(
HtmlPage
p
)
throws
Exception
{
...
...
@@ -57,8 +64,9 @@ public class HelpLinkTest {
assertTrue
(
helpLinks
.
size
()>
0
);
System
.
out
.
println
(
"Clicking "
+
helpLinks
.
size
()+
" help links"
);
for
(
HtmlAnchor
helpLink
:
(
List
<
HtmlAnchor
>)
helpLinks
)
helpLink
.
click
();
for
(
HtmlAnchor
helpLink
:
(
List
<
HtmlAnchor
>)
helpLinks
)
{
HtmlElementUtil
.
click
(
helpLink
);
}
}
public
static
class
HelpNotFoundBuilder
extends
Publisher
{
...
...
@@ -93,13 +101,15 @@ public class HelpLinkTest {
try
{
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
p
.
getPublishersList
().
add
(
new
HelpNotFoundBuilder
());
clickAllHelpLinks
(
p
);
fail
(
"should detect a failure"
);
}
catch
(
AssertionError
e
)
{
if
(
e
.
getMessage
().
contains
(
d
.
getHelpFile
()))
;
// expected
else
throw
e
;
JenkinsRule
.
WebClient
webclient
=
j
.
createWebClient
();
WebResponseListener
.
StatusListener
statusListener
=
new
WebResponseListener
.
StatusListener
(
404
);
webclient
.
addWebResponseListener
(
statusListener
);
clickAllHelpLinks
(
webclient
,
p
);
statusListener
.
assertHasResponses
();
String
contentAsString
=
statusListener
.
getResponses
().
get
(
0
).
getContentAsString
();
Assert
.
assertTrue
(
contentAsString
.
contains
(
d
.
getHelpFile
()));
}
finally
{
Publisher
.
all
().
remove
(
d
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录