Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
9062a944
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
9062a944
编写于
5月 20, 2014
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JUnit 4.
上级
e0d0490a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
54 deletion
+61
-54
test/src/test/java/hudson/PluginManagerTest.java
test/src/test/java/hudson/PluginManagerTest.java
+61
-54
未找到文件。
test/src/test/java/hudson/PluginManagerTest.java
浏览文件 @
9062a944
...
...
@@ -42,8 +42,12 @@ import java.util.List;
import
java.util.concurrent.Future
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.tools.ant.filters.StringInputStream
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
import
org.jvnet.hudson.test.Bug
;
import
org.jvnet.hudson.test.
HudsonTestCas
e
;
import
org.jvnet.hudson.test.
JenkinsRul
e
;
import
org.jvnet.hudson.test.Url
;
import
org.jvnet.hudson.test.recipes.WithPlugin
;
import
org.jvnet.hudson.test.recipes.WithPluginManager
;
...
...
@@ -51,67 +55,70 @@ import org.jvnet.hudson.test.recipes.WithPluginManager;
/**
* @author Kohsuke Kawaguchi
*/
public
class
PluginManagerTest
extends
HudsonTestCase
{
@Override
protected
void
setUp
()
throws
Exception
{
setPluginManager
(
null
);
// use a fresh instance
super
.
setUp
();
}
public
class
PluginManagerTest
{
@Rule
public
JenkinsRule
r
=
new
JenkinsRule
()
{
@Override
public
void
before
()
throws
Throwable
{
setPluginManager
(
null
);
super
.
before
();
}
};
@Rule
public
TemporaryFolder
tmp
=
new
TemporaryFolder
();
/**
* Manual submission form.
*/
public
void
testU
ploadJpi
()
throws
Exception
{
HtmlPage
page
=
new
WebClient
().
goTo
(
"pluginManager/advanced"
);
@Test
public
void
u
ploadJpi
()
throws
Exception
{
HtmlPage
page
=
r
.
create
WebClient
().
goTo
(
"pluginManager/advanced"
);
HtmlForm
f
=
page
.
getFormByName
(
"uploadPlugin"
);
File
dir
=
env
.
temporaryDirectoryAllocator
.
allocate
();
File
dir
=
tmp
.
newFolder
();
File
plugin
=
new
File
(
dir
,
"tasks.jpi"
);
FileUtils
.
copyURLToFile
(
getClass
().
getClassLoader
().
getResource
(
"plugins/tasks.jpi"
),
plugin
);
f
.
getInputByName
(
"name"
).
setValueAttribute
(
plugin
.
getAbsolutePath
());
submit
(
f
);
r
.
submit
(
f
);
assertTrue
(
new
File
(
jenkins
.
getRootDir
(),
"plugins/tasks.jpi"
).
exists
()
);
assertTrue
(
new
File
(
r
.
jenkins
.
getRootDir
(),
"plugins/tasks.jpi"
).
exists
()
);
}
/**
* Manual submission form.
*/
public
void
testU
ploadHpi
()
throws
Exception
{
HtmlPage
page
=
new
WebClient
().
goTo
(
"pluginManager/advanced"
);
@Test
public
void
u
ploadHpi
()
throws
Exception
{
HtmlPage
page
=
r
.
create
WebClient
().
goTo
(
"pluginManager/advanced"
);
HtmlForm
f
=
page
.
getFormByName
(
"uploadPlugin"
);
File
dir
=
env
.
temporaryDirectoryAllocator
.
allocate
();
File
dir
=
tmp
.
newFolder
();
File
plugin
=
new
File
(
dir
,
"legacy.hpi"
);
FileUtils
.
copyURLToFile
(
getClass
().
getClassLoader
().
getResource
(
"plugins/legacy.hpi"
),
plugin
);
f
.
getInputByName
(
"name"
).
setValueAttribute
(
plugin
.
getAbsolutePath
());
submit
(
f
);
r
.
submit
(
f
);
// uploaded legacy plugins get renamed to *.jpi
assertTrue
(
new
File
(
jenkins
.
getRootDir
(),
"plugins/legacy.jpi"
).
exists
()
);
assertTrue
(
new
File
(
r
.
jenkins
.
getRootDir
(),
"plugins/legacy.jpi"
).
exists
()
);
}
/**
* Tests the effect of {@link WithPlugin}.
*/
@WithPlugin
(
"tasks.jpi"
)
public
void
testW
ithRecipeJpi
()
throws
Exception
{
assertNotNull
(
jenkins
.
getPlugin
(
"tasks"
));
@Test
public
void
w
ithRecipeJpi
()
throws
Exception
{
assertNotNull
(
r
.
jenkins
.
getPlugin
(
"tasks"
));
}
/**
* Tests the effect of {@link WithPlugin}.
*/
@WithPlugin
(
"legacy.hpi"
)
public
void
testW
ithRecipeHpi
()
throws
Exception
{
assertNotNull
(
jenkins
.
getPlugin
(
"legacy"
));
@Test
public
void
w
ithRecipeHpi
()
throws
Exception
{
assertNotNull
(
r
.
jenkins
.
getPlugin
(
"legacy"
));
}
/**
* Makes sure that plugins can see Maven2 plugin that's refactored out in 1.296.
*/
@WithPlugin
(
"tasks.jpi"
)
public
void
testO
ptionalMavenDependency
()
throws
Exception
{
@Test
public
void
o
ptionalMavenDependency
()
throws
Exception
{
PluginWrapper
.
Dependency
m2
=
null
;
PluginWrapper
tasks
=
jenkins
.
getPluginManager
().
getPlugin
(
"tasks"
);
PluginWrapper
tasks
=
r
.
jenkins
.
getPluginManager
().
getPlugin
(
"tasks"
);
for
(
PluginWrapper
.
Dependency
d
:
tasks
.
getOptionalDependencies
()
)
{
if
(
d
.
shortName
.
equals
(
"maven-plugin"
))
{
assertNull
(
m2
);
...
...
@@ -134,11 +141,11 @@ public class PluginManagerTest extends HudsonTestCase {
*/
@WithPlugin
(
"tasks.jpi"
)
@WithPluginManager
(
PluginManagerImpl_for_testUberClassLoaderIsAvailableDuringStart
.
class
)
public
void
testU
berClassLoaderIsAvailableDuringStart
()
{
assertTrue
(((
PluginManagerImpl_for_testUberClassLoaderIsAvailableDuringStart
)
jenkins
.
pluginManager
).
tested
);
@Test
public
void
u
berClassLoaderIsAvailableDuringStart
()
{
assertTrue
(((
PluginManagerImpl_for_testUberClassLoaderIsAvailableDuringStart
)
r
.
jenkins
.
pluginManager
).
tested
);
}
public
class
PluginManagerImpl_for_testUberClassLoaderIsAvailableDuringStart
extends
LocalPluginManager
{
public
static
class
PluginManagerImpl_for_testUberClassLoaderIsAvailableDuringStart
extends
LocalPluginManager
{
boolean
tested
;
public
PluginManagerImpl_for_testUberClassLoaderIsAvailableDuringStart
(
File
rootDir
)
{
...
...
@@ -170,10 +177,10 @@ public class PluginManagerTest extends HudsonTestCase {
* infinite cycle ensues.
*/
@Url
(
"http://jenkins.361315.n4.nabble.com/channel-example-and-plugin-classes-gives-ClassNotFoundException-td3756092.html"
)
public
void
testU
berClassLoaderDoesntUseContextClassLoader
()
throws
Exception
{
@Test
public
void
u
berClassLoaderDoesntUseContextClassLoader
()
throws
Exception
{
Thread
t
=
Thread
.
currentThread
();
URLClassLoader
ucl
=
new
URLClassLoader
(
new
URL
[
0
],
jenkins
.
pluginManager
.
uberClassLoader
);
URLClassLoader
ucl
=
new
URLClassLoader
(
new
URL
[
0
],
r
.
jenkins
.
pluginManager
.
uberClassLoader
);
ClassLoader
old
=
t
.
getContextClassLoader
();
t
.
setContextClassLoader
(
ucl
);
...
...
@@ -191,33 +198,33 @@ public class PluginManagerTest extends HudsonTestCase {
}
}
public
void
testI
nstallWithoutRestart
()
throws
Exception
{
@Test
public
void
i
nstallWithoutRestart
()
throws
Exception
{
URL
res
=
getClass
().
getClassLoader
().
getResource
(
"plugins/htmlpublisher.jpi"
);
File
f
=
new
File
(
jenkins
.
getRootDir
(),
"plugins/htmlpublisher.jpi"
);
File
f
=
new
File
(
r
.
jenkins
.
getRootDir
(),
"plugins/htmlpublisher.jpi"
);
FileUtils
.
copyURLToFile
(
res
,
f
);
jenkins
.
pluginManager
.
dynamicLoad
(
f
);
r
.
jenkins
.
pluginManager
.
dynamicLoad
(
f
);
Class
c
=
jenkins
.
getPluginManager
().
uberClassLoader
.
loadClass
(
"htmlpublisher.HtmlPublisher$DescriptorImpl"
);
assertNotNull
(
jenkins
.
getDescriptorByType
(
c
));
Class
c
=
r
.
jenkins
.
getPluginManager
().
uberClassLoader
.
loadClass
(
"htmlpublisher.HtmlPublisher$DescriptorImpl"
);
assertNotNull
(
r
.
jenkins
.
getDescriptorByType
(
c
));
}
public
void
testP
revalidateConfig
()
throws
Exception
{
PersistedList
<
UpdateSite
>
sites
=
jenkins
.
getUpdateCenter
().
getSites
();
@Test
public
void
p
revalidateConfig
()
throws
Exception
{
PersistedList
<
UpdateSite
>
sites
=
r
.
jenkins
.
getUpdateCenter
().
getSites
();
sites
.
clear
();
URL
url
=
PluginManagerTest
.
class
.
getResource
(
"/plugins/tasks-update-center.json"
);
UpdateSite
site
=
new
UpdateSite
(
UpdateCenter
.
ID_DEFAULT
,
url
.
toString
());
sites
.
add
(
site
);
assertEquals
(
FormValidation
.
ok
(),
site
.
updateDirectly
(
false
).
get
());
assertNotNull
(
site
.
getData
());
assertEquals
(
Collections
.
emptyList
(),
jenkins
.
getPluginManager
().
prevalidateConfig
(
new
StringInputStream
(
"<whatever><runant plugin=\"ant@1.1\"/></whatever>"
)));
assertNull
(
jenkins
.
getPluginManager
().
getPlugin
(
"tasks"
));
List
<
Future
<
UpdateCenterJob
>>
jobs
=
jenkins
.
getPluginManager
().
prevalidateConfig
(
new
StringInputStream
(
"<whatever><tasks plugin=\"tasks@2.23\"/></whatever>"
));
assertEquals
(
Collections
.
emptyList
(),
r
.
jenkins
.
getPluginManager
().
prevalidateConfig
(
new
StringInputStream
(
"<whatever><runant plugin=\"ant@1.1\"/></whatever>"
)));
assertNull
(
r
.
jenkins
.
getPluginManager
().
getPlugin
(
"tasks"
));
List
<
Future
<
UpdateCenterJob
>>
jobs
=
r
.
jenkins
.
getPluginManager
().
prevalidateConfig
(
new
StringInputStream
(
"<whatever><tasks plugin=\"tasks@2.23\"/></whatever>"
));
assertEquals
(
1
,
jobs
.
size
());
UpdateCenterJob
job
=
jobs
.
get
(
0
).
get
();
// blocks for completion
assertEquals
(
"InstallationJob"
,
job
.
getType
());
UpdateCenter
.
InstallationJob
ijob
=
(
UpdateCenter
.
InstallationJob
)
job
;
assertEquals
(
"tasks"
,
ijob
.
plugin
.
name
);
assertNotNull
(
jenkins
.
getPluginManager
().
getPlugin
(
"tasks"
));
assertNotNull
(
r
.
jenkins
.
getPluginManager
().
getPlugin
(
"tasks"
));
// TODO restart scheduled (SuccessButRequiresRestart) after upgrade or Support-Dynamic-Loading: false
// TODO dependencies installed or upgraded too
// TODO required plugin installed but inactive
...
...
@@ -257,7 +264,7 @@ public class PluginManagerTest extends HudsonTestCase {
* @throws Exception
*/
private
String
callDependerValue
()
throws
Exception
{
Class
<?>
c
=
jenkins
.
getPluginManager
().
uberClassLoader
.
loadClass
(
"org.jenkinsci.plugins.dependencytest.depender.Depender"
);
Class
<?>
c
=
r
.
jenkins
.
getPluginManager
().
uberClassLoader
.
loadClass
(
"org.jenkinsci.plugins.dependencytest.depender.Depender"
);
Method
m
=
c
.
getMethod
(
"getValue"
);
return
(
String
)
m
.
invoke
(
null
);
}
...
...
@@ -268,14 +275,14 @@ public class PluginManagerTest extends HudsonTestCase {
*
* @throws Exception
*/
public
void
testI
nstallDependingPluginWithoutRestart
()
throws
Exception
{
@Test
public
void
i
nstallDependingPluginWithoutRestart
()
throws
Exception
{
// Load dependee.
{
String
target
=
"dependee.hpi"
;
URL
src
=
getClass
().
getClassLoader
().
getResource
(
String
.
format
(
"plugins/%s"
,
target
));
File
dest
=
new
File
(
jenkins
.
getRootDir
(),
String
.
format
(
"plugins/%s"
,
target
));
File
dest
=
new
File
(
r
.
jenkins
.
getRootDir
(),
String
.
format
(
"plugins/%s"
,
target
));
FileUtils
.
copyURLToFile
(
src
,
dest
);
jenkins
.
pluginManager
.
dynamicLoad
(
dest
);
r
.
jenkins
.
pluginManager
.
dynamicLoad
(
dest
);
}
// before load depender, of course failed to call Depender.getValue()
...
...
@@ -286,22 +293,22 @@ public class PluginManagerTest extends HudsonTestCase {
}
// No extensions exist.
assertTrue
(
jenkins
.
getExtensionList
(
"org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint"
).
isEmpty
());
assertTrue
(
r
.
jenkins
.
getExtensionList
(
"org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint"
).
isEmpty
());
// Load depender.
{
String
target
=
"depender.hpi"
;
URL
src
=
getClass
().
getClassLoader
().
getResource
(
String
.
format
(
"plugins/%s"
,
target
));
File
dest
=
new
File
(
jenkins
.
getRootDir
(),
String
.
format
(
"plugins/%s"
,
target
));
File
dest
=
new
File
(
r
.
jenkins
.
getRootDir
(),
String
.
format
(
"plugins/%s"
,
target
));
FileUtils
.
copyURLToFile
(
src
,
dest
);
jenkins
.
pluginManager
.
dynamicLoad
(
dest
);
r
.
jenkins
.
pluginManager
.
dynamicLoad
(
dest
);
}
// depender successfully accesses to dependee.
assertEquals
(
"dependee"
,
callDependerValue
());
// Extension in depender is loaded.
assertFalse
(
jenkins
.
getExtensionList
(
"org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint"
).
isEmpty
());
assertFalse
(
r
.
jenkins
.
getExtensionList
(
"org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint"
).
isEmpty
());
}
/**
...
...
@@ -311,14 +318,14 @@ public class PluginManagerTest extends HudsonTestCase {
* @throws Exception
*/
@Bug
(
19976
)
public
void
testI
nstallDependedPluginWithoutRestart
()
throws
Exception
{
@Test
public
void
i
nstallDependedPluginWithoutRestart
()
throws
Exception
{
// Load depender.
{
String
target
=
"depender.hpi"
;
URL
src
=
getClass
().
getClassLoader
().
getResource
(
String
.
format
(
"plugins/%s"
,
target
));
File
dest
=
new
File
(
jenkins
.
getRootDir
(),
String
.
format
(
"plugins/%s"
,
target
));
File
dest
=
new
File
(
r
.
jenkins
.
getRootDir
(),
String
.
format
(
"plugins/%s"
,
target
));
FileUtils
.
copyURLToFile
(
src
,
dest
);
jenkins
.
pluginManager
.
dynamicLoad
(
dest
);
r
.
jenkins
.
pluginManager
.
dynamicLoad
(
dest
);
}
// before load dependee, depender does not access to dependee.
...
...
@@ -326,7 +333,7 @@ public class PluginManagerTest extends HudsonTestCase {
// before load dependee, of course failed to list extensions for dependee.
try
{
jenkins
.
getExtensionList
(
"org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint"
);
r
.
jenkins
.
getExtensionList
(
"org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint"
);
fail
();
}
catch
(
ClassNotFoundException
_
){
}
...
...
@@ -335,9 +342,9 @@ public class PluginManagerTest extends HudsonTestCase {
{
String
target
=
"dependee.hpi"
;
URL
src
=
getClass
().
getClassLoader
().
getResource
(
String
.
format
(
"plugins/%s"
,
target
));
File
dest
=
new
File
(
jenkins
.
getRootDir
(),
String
.
format
(
"plugins/%s"
,
target
));
File
dest
=
new
File
(
r
.
jenkins
.
getRootDir
(),
String
.
format
(
"plugins/%s"
,
target
));
FileUtils
.
copyURLToFile
(
src
,
dest
);
jenkins
.
pluginManager
.
dynamicLoad
(
dest
);
r
.
jenkins
.
pluginManager
.
dynamicLoad
(
dest
);
}
// (MUST) Not throws an exception
...
...
@@ -346,7 +353,7 @@ public class PluginManagerTest extends HudsonTestCase {
// No extensions exist.
// extensions in depender is not loaded.
assertTrue
(
jenkins
.
getExtensionList
(
"org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint"
).
isEmpty
());
assertTrue
(
r
.
jenkins
.
getExtensionList
(
"org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint"
).
isEmpty
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录