Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pentaLiker
DolphinScheduler
提交
b4a6d544
DolphinScheduler
项目概览
pentaLiker
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b4a6d544
编写于
1月 15, 2020
作者:
一子三木
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add BaseServiceTest BaseServiceTest UT
上级
ec13974e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
192 addition
and
0 deletion
+192
-0
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/BaseDAGServiceTest.java
...ache/dolphinscheduler/api/service/BaseDAGServiceTest.java
+50
-0
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/BaseServiceTest.java
.../apache/dolphinscheduler/api/service/BaseServiceTest.java
+140
-0
pom.xml
pom.xml
+2
-0
未找到文件。
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/BaseDAGServiceTest.java
0 → 100644
浏览文件 @
b4a6d544
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.api.service
;
import
org.apache.dolphinscheduler.common.graph.DAG
;
import
org.apache.dolphinscheduler.common.model.TaskNode
;
import
org.apache.dolphinscheduler.common.model.TaskNodeRelation
;
import
org.apache.dolphinscheduler.dao.entity.ProcessInstance
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.junit.MockitoJUnitRunner
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
BaseDAGServiceTest
{
@Test
public
void
testProcessInstance2DAG
(){
ProcessInstance
processInstance
=
new
ProcessInstance
();
processInstance
.
setProcessInstanceJson
(
"{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-61567\","
+
"\"name\":\"开始\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo '1'\"},"
+
"\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\","
+
"\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\","
+
"\"workerGroupId\":-1,\"preTasks\":[]},{\"type\":\"SHELL\",\"id\":\"tasks-6-3ug5ej\",\"name\":\"结束\","
+
"\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo '1'\"},\"description\":\"\","
+
"\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\","
+
"\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\","
+
"\"workerGroupId\":-1,\"preTasks\":[\"开始\"]}],\"tenantId\":-1,\"timeout\":0}"
);
DAG
<
String
,
TaskNode
,
TaskNodeRelation
>
relationDAG
=
BaseDAGService
.
processInstance2DAG
(
processInstance
);
Assert
.
assertTrue
(
relationDAG
.
containsNode
(
"开始"
));
}
}
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/BaseServiceTest.java
0 → 100644
浏览文件 @
b4a6d544
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.api.service
;
import
org.apache.dolphinscheduler.api.enums.Status
;
import
org.apache.dolphinscheduler.api.utils.Result
;
import
org.apache.dolphinscheduler.common.Constants
;
import
org.apache.dolphinscheduler.common.enums.UserType
;
import
org.apache.dolphinscheduler.common.utils.HadoopUtils
;
import
org.apache.dolphinscheduler.dao.entity.User
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.powermock.api.mockito.PowerMockito
;
import
org.powermock.core.classloader.annotations.PowerMockIgnore
;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.mock.web.MockCookie
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
javax.servlet.http.Cookie
;
import
java.util.HashMap
;
import
java.util.Map
;
@RunWith
(
PowerMockRunner
.
class
)
@PowerMockIgnore
({
"sun.security.*"
,
"javax.net.*"
})
@PrepareForTest
({
HadoopUtils
.
class
})
public
class
BaseServiceTest
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BaseServiceTest
.
class
);
private
BaseService
baseService
;
@Mock
private
HadoopUtils
hadoopUtils
;
@Before
public
void
setUp
()
{
baseService
=
new
BaseService
();
}
@Test
public
void
testIsAdmin
(){
User
user
=
new
User
();
user
.
setUserType
(
UserType
.
ADMIN_USER
);
//ADMIN_USER
boolean
isAdmin
=
baseService
.
isAdmin
(
user
);
Assert
.
assertTrue
(
isAdmin
);
//GENERAL_USER
user
.
setUserType
(
UserType
.
GENERAL_USER
);
isAdmin
=
baseService
.
isAdmin
(
user
);
Assert
.
assertFalse
(
isAdmin
);
}
@Test
public
void
testPutMsg
(){
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
baseService
.
putMsg
(
result
,
Status
.
SUCCESS
);
Assert
.
assertEquals
(
Status
.
SUCCESS
,
result
.
get
(
Constants
.
STATUS
));
//has params
baseService
.
putMsg
(
result
,
Status
.
PROJECT_NOT_FOUNT
,
"test"
);
}
@Test
public
void
testPutMsgTwo
(){
Result
result
=
new
Result
();
baseService
.
putMsg
(
result
,
Status
.
SUCCESS
);
Assert
.
assertEquals
(
Status
.
SUCCESS
.
getMsg
(),
result
.
getMsg
());
//has params
baseService
.
putMsg
(
result
,
Status
.
PROJECT_NOT_FOUNT
,
"test"
);
}
@Test
public
void
testGetCookie
(){
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
MockCookie
mockCookie
=
new
MockCookie
(
"userId"
,
"1"
);
request
.
setCookies
(
mockCookie
);
//cookie is not null
Cookie
cookie
=
BaseService
.
getCookie
(
request
,
"userId"
);
Assert
.
assertNotNull
(
cookie
);
//cookie is null
cookie
=
BaseService
.
getCookie
(
request
,
"userName"
);
Assert
.
assertNull
(
cookie
);
}
@Test
public
void
testCreateTenantDirIfNotExists
(){
PowerMockito
.
mockStatic
(
HadoopUtils
.
class
);
PowerMockito
.
when
(
HadoopUtils
.
getInstance
()).
thenReturn
(
hadoopUtils
);
try
{
baseService
.
createTenantDirIfNotExists
(
"test"
);
}
catch
(
Exception
e
)
{
Assert
.
assertTrue
(
false
);
logger
.
error
(
"CreateTenantDirIfNotExists error "
,
e
);
e
.
printStackTrace
();
}
}
@Test
public
void
testHasPerm
(){
User
user
=
new
User
();
user
.
setId
(
1
);
//create user
boolean
hasPerm
=
baseService
.
hasPerm
(
user
,
1
);
Assert
.
assertTrue
(
hasPerm
);
//admin
user
.
setId
(
2
);
user
.
setUserType
(
UserType
.
ADMIN_USER
);
hasPerm
=
baseService
.
hasPerm
(
user
,
1
);
Assert
.
assertTrue
(
hasPerm
);
}
}
pom.xml
浏览文件 @
b4a6d544
...
...
@@ -694,6 +694,8 @@
<include>
**/api/service/ProcessDefinitionServiceTest.java
</include>
<include>
**/api/service/UdfFuncServiceTest.java
</include>
<include>
**/api/service/ResourcesServiceTest.java
</include>
<include>
**/api/service/BaseServiceTest.java
</include>
<include>
**/api/service/BaseDAGServiceTest.java
</include>
<include>
**/alert/utils/ExcelUtilsTest.java
</include>
<include>
**/alert/utils/FuncUtilsTest.java
</include>
<include>
**/alert/utils/JSONUtilsTest.java
</include>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录