Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
a8ba1162
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,发现更多精彩内容 >>
提交
a8ba1162
编写于
12月 05, 2012
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduced MockFolder for testing.
上级
e4ca47e9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
210 addition
and
0 deletion
+210
-0
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
+8
-0
test/src/main/java/org/jvnet/hudson/test/MockFolder.java
test/src/main/java/org/jvnet/hudson/test/MockFolder.java
+160
-0
test/src/test/java/org/jvnet/hudson/test/MockFolderTest.java
test/src/test/java/org/jvnet/hudson/test/MockFolderTest.java
+42
-0
未找到文件。
test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
浏览文件 @
a8ba1162
...
...
@@ -739,6 +739,14 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
return
jenkins
.
createProject
(
MavenModuleSet
.
class
,
name
);
}
/**
* Creates a simple folder that other jobs can be placed in.
* @since 1.494
*/
public
MockFolder
createFolder
(
String
name
)
throws
IOException
{
return
jenkins
.
createProject
(
MockFolder
.
class
,
name
);
}
protected
String
createUniqueProjectName
()
{
return
"test"
+
jenkins
.
getItems
().
size
();
}
...
...
test/src/main/java/org/jvnet/hudson/test/MockFolder.java
0 → 100644
浏览文件 @
a8ba1162
/*
* The MIT License
*
* Copyright 2012 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
org.jvnet.hudson.test
;
import
hudson.Extension
;
import
hudson.model.AbstractItem
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Item
;
import
hudson.model.ItemGroup
;
import
hudson.model.ItemGroupMixIn
;
import
hudson.model.Job
;
import
hudson.model.TopLevelItem
;
import
hudson.model.TopLevelItemDescriptor
;
import
hudson.util.Function1
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
javax.servlet.ServletException
;
import
jenkins.model.Jenkins
;
import
jenkins.model.ModifiableTopLevelItemGroup
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
/**
* Minimal implementation of a modifiable item group akin to the CloudBees Folders plugin.
* No UI, just enough implementation to test functionality of code which should deal with item full names, etc.
* @since 1.494
*/
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
// the usual API mistakes
public
class
MockFolder
extends
AbstractItem
implements
ModifiableTopLevelItemGroup
,
TopLevelItem
{
// could be a ViewGroup too
private
transient
Map
<
String
,
TopLevelItem
>
items
=
new
TreeMap
<
String
,
TopLevelItem
>();
private
MockFolder
(
ItemGroup
parent
,
String
name
)
{
super
(
parent
,
name
);
}
@Override
public
void
onLoad
(
ItemGroup
<?
extends
Item
>
parent
,
String
name
)
throws
IOException
{
super
.
onLoad
(
parent
,
name
);
items
=
ItemGroupMixIn
.
loadChildren
(
this
,
jobs
(),
new
Function1
<
String
,
TopLevelItem
>()
{
public
String
call
(
TopLevelItem
item
)
{
return
item
.
getName
();
}
});
}
@Override
public
Collection
<
TopLevelItem
>
getItems
()
{
return
items
.
values
();
// could be filtered by Item.READ
}
@Override
public
TopLevelItem
getItem
(
String
name
)
{
return
items
.
get
(
name
);
}
@Override
public
Collection
<?
extends
Job
>
getAllJobs
()
{
Set
<
Job
>
jobs
=
new
HashSet
<
Job
>();
for
(
TopLevelItem
i
:
getItems
())
{
jobs
.
addAll
(
i
.
getAllJobs
());
}
return
jobs
;
}
private
File
jobs
()
{
return
new
File
(
getRootDir
(),
"jobs"
);
}
private
ItemGroupMixIn
mixin
()
{
return
new
ItemGroupMixIn
(
this
,
this
)
{
@Override
protected
void
add
(
TopLevelItem
item
)
{
items
.
put
(
item
.
getName
(),
item
);
}
@Override
protected
File
getRootDirFor
(
String
name
)
{
return
new
File
(
jobs
(),
name
);
}
};
}
@Override
public
<
T
extends
TopLevelItem
>
T
copy
(
T
src
,
String
name
)
throws
IOException
{
return
mixin
().
copy
(
src
,
name
);
}
@Override
public
TopLevelItem
createProjectFromXML
(
String
name
,
InputStream
xml
)
throws
IOException
{
return
mixin
().
createProjectFromXML
(
name
,
xml
);
}
@Override
public
TopLevelItem
createProject
(
TopLevelItemDescriptor
type
,
String
name
,
boolean
notify
)
throws
IOException
{
return
mixin
().
createProject
(
type
,
name
,
notify
);
}
/** Convenience method to create a {@link FreeStyleProject} or similar. */
public
<
T
extends
TopLevelItem
>
T
createProject
(
Class
<
T
>
type
,
String
name
)
throws
IOException
{
return
type
.
cast
(
createProject
((
TopLevelItemDescriptor
)
Jenkins
.
getInstance
().
getDescriptor
(
type
),
name
,
true
));
}
@Override
public
TopLevelItem
doCreateItem
(
StaplerRequest
req
,
StaplerResponse
rsp
)
throws
IOException
,
ServletException
{
return
mixin
().
createTopLevelItem
(
req
,
rsp
);
}
@Override
public
String
getUrlChildPrefix
()
{
return
"job"
;
}
@Override
public
File
getRootDirFor
(
TopLevelItem
child
)
{
return
new
File
(
jobs
(),
child
.
getName
());
}
@Override
public
void
onRenamed
(
TopLevelItem
item
,
String
oldName
,
String
newName
)
throws
IOException
{
items
.
remove
(
oldName
);
items
.
put
(
newName
,
item
);
}
@Override
public
void
onDeleted
(
TopLevelItem
item
)
throws
IOException
{
// could call ItemListener.onDeleted
items
.
remove
(
item
.
getName
());
}
@Override
public
TopLevelItemDescriptor
getDescriptor
()
{
return
Jenkins
.
getInstance
().
getDescriptorByType
(
DescriptorImpl
.
class
);
}
@Extension
public
static
class
DescriptorImpl
extends
TopLevelItemDescriptor
{
@Override
public
String
getDisplayName
()
{
return
"MockFolder"
;
}
@Override
public
TopLevelItem
newInstance
(
ItemGroup
parent
,
String
name
)
{
return
new
MockFolder
(
parent
,
name
);
}
}
}
test/src/test/java/org/jvnet/hudson/test/MockFolderTest.java
0 → 100644
浏览文件 @
a8ba1162
/*
* The MIT License
*
* Copyright 2012 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
org.jvnet.hudson.test
;
import
hudson.model.FreeStyleProject
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Rule
;
public
class
MockFolderTest
{
@Rule
public
JenkinsRule
j
=
new
JenkinsRule
();
@Test
public
void
basics
()
throws
Exception
{
MockFolder
dir
=
j
.
createFolder
(
"dir"
);
FreeStyleProject
p
=
dir
.
createProject
(
FreeStyleProject
.
class
,
"p"
);
assertEquals
(
"dir/p"
,
p
.
getFullName
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录