Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
7c02e344
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7c02e344
编写于
5月 12, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #187 from lepdou/multirequest
多环境操作容错处理
上级
dc493792
b01275e1
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
222 addition
and
212 deletion
+222
-212
apollo-common/src/main/java/com/ctrip/apollo/common/http/MultiResponseEntity.java
...ava/com/ctrip/apollo/common/http/MultiResponseEntity.java
+37
-0
apollo-common/src/main/java/com/ctrip/apollo/common/http/RichResponseEntity.java
...java/com/ctrip/apollo/common/http/RichResponseEntity.java
+37
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
...ava/com/ctrip/apollo/portal/controller/AppController.java
+48
-6
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/AppInfoVO.java
...c/main/java/com/ctrip/apollo/portal/entity/AppInfoVO.java
+0
-31
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/ClusterNavTree.java
...n/java/com/ctrip/apollo/portal/entity/ClusterNavTree.java
+0
-54
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/EnvClusterInfo.java
...n/java/com/ctrip/apollo/portal/entity/EnvClusterInfo.java
+32
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+21
-29
apollo-portal/src/main/resources/static/scripts/AppUtils.js
apollo-portal/src/main/resources/static/scripts/AppUtils.js
+12
-1
apollo-portal/src/main/resources/static/scripts/app.js
apollo-portal/src/main/resources/static/scripts/app.js
+1
-1
apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js
...esources/static/scripts/controller/NamespaceController.js
+2
-1
apollo-portal/src/main/resources/static/scripts/controller/app/ConfigBaseInfoController.js
...static/scripts/controller/app/ConfigBaseInfoController.js
+13
-5
apollo-portal/src/main/resources/static/scripts/controller/app/SyncConfigController.js
...ces/static/scripts/controller/app/SyncConfigController.js
+2
-1
apollo-portal/src/main/resources/static/scripts/services/AppService.js
.../src/main/resources/static/scripts/services/AppService.js
+15
-0
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
...ortal/src/test/java/com/ctrip/apollo/portal/AllTests.java
+2
-2
apollo-portal/src/test/java/com/ctrip/apollo/portal/AppServiceTest.java
...src/test/java/com/ctrip/apollo/portal/AppServiceTest.java
+0
-81
未找到文件。
apollo-common/src/main/java/com/ctrip/apollo/common/http/MultiResponseEntity.java
0 → 100644
浏览文件 @
7c02e344
package
com.ctrip.apollo.common.http
;
import
org.springframework.http.HttpStatus
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* 一个Response中包含多个ResponseEntity
*/
public
class
MultiResponseEntity
<
T
>
{
private
int
code
;
private
List
<
RichResponseEntity
<
T
>>
entities
=
new
LinkedList
<>();
private
MultiResponseEntity
(
HttpStatus
httpCode
)
{
this
.
code
=
httpCode
.
value
();
}
public
static
<
T
>
MultiResponseEntity
<
T
>
instance
(
HttpStatus
statusCode
)
{
return
new
MultiResponseEntity
<>(
statusCode
);
}
public
static
<
T
>
MultiResponseEntity
<
T
>
ok
()
{
return
new
MultiResponseEntity
<>(
HttpStatus
.
OK
);
}
public
void
addResponseEntity
(
RichResponseEntity
<
T
>
responseEntity
)
{
if
(
responseEntity
==
null
){
throw
new
IllegalArgumentException
(
"sub response entity can not be null"
);
}
entities
.
add
(
responseEntity
);
}
}
apollo-common/src/main/java/com/ctrip/apollo/common/http/RichResponseEntity.java
0 → 100644
浏览文件 @
7c02e344
package
com.ctrip.apollo.common.http
;
import
org.springframework.http.HttpStatus
;
public
class
RichResponseEntity
<
T
>{
private
int
code
;
private
Object
message
;
private
T
body
;
public
static
<
T
>
RichResponseEntity
<
T
>
ok
(
T
body
){
RichResponseEntity
<
T
>
richResponseEntity
=
new
RichResponseEntity
<>();
richResponseEntity
.
message
=
HttpStatus
.
OK
.
getReasonPhrase
();
richResponseEntity
.
code
=
HttpStatus
.
OK
.
value
();
richResponseEntity
.
body
=
body
;
return
richResponseEntity
;
}
public
static
<
T
>
RichResponseEntity
<
T
>
error
(
HttpStatus
httpCode
,
Object
message
){
RichResponseEntity
<
T
>
richResponseEntity
=
new
RichResponseEntity
<>();
richResponseEntity
.
message
=
message
;
richResponseEntity
.
code
=
httpCode
.
value
();
return
richResponseEntity
;
}
public
int
getCode
()
{
return
code
;
}
public
Object
getMessage
()
{
return
message
;
}
public
T
getBody
()
{
return
body
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
浏览文件 @
7c02e344
package
com.ctrip.apollo.portal.controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.HttpClientErrorException
;
import
com.ctrip.apollo.common.http.MultiResponseEntity
;
import
com.ctrip.apollo.common.http.RichResponseEntity
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.
entity.AppInfoVO
;
import
com.ctrip.apollo.portal.entity.
ClusterNavTree
;
import
com.ctrip.apollo.portal.
PortalSettings
;
import
com.ctrip.apollo.portal.entity.
EnvClusterInfo
;
import
com.ctrip.apollo.portal.service.AppService
;
import
java.util.List
;
...
...
@@ -25,6 +29,8 @@ public class AppController {
@Autowired
private
AppService
appService
;
@Autowired
private
PortalSettings
portalSettings
;
@RequestMapping
(
"/envs/{env}"
)
public
List
<
AppDTO
>
findAllApp
(
@PathVariable
String
env
){
...
...
@@ -35,12 +41,23 @@ public class AppController {
}
@RequestMapping
(
"/{appId}/navtree"
)
public
ClusterNavTree
nav
(
@PathVariable
String
appId
)
{
public
MultiResponseEntity
<
EnvClusterInfo
>
nav
(
@PathVariable
String
appId
)
{
if
(
StringUtils
.
isEmpty
(
appId
))
{
throw
new
BadRequestException
(
"app id can not be empty."
);
}
return
appService
.
buildClusterNavTree
(
appId
);
MultiResponseEntity
<
EnvClusterInfo
>
response
=
MultiResponseEntity
.
ok
();
List
<
Env
>
envs
=
portalSettings
.
getEnvs
();
for
(
Env
env
:
envs
)
{
try
{
response
.
addResponseEntity
(
RichResponseEntity
.
ok
(
appService
.
createEnvNavNode
(
env
,
appId
)));
}
catch
(
Exception
e
)
{
response
.
addResponseEntity
(
RichResponseEntity
.
error
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
"load env:"
+
env
.
name
()
+
" cluster error."
+
e
.
getMessage
()));
}
}
return
response
;
}
@RequestMapping
(
value
=
"/envs/{env}"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
...
...
@@ -57,13 +74,38 @@ public class AppController {
}
@RequestMapping
(
value
=
"/{appId}"
,
method
=
RequestMethod
.
GET
)
public
App
InfoV
O
load
(
@PathVariable
String
appId
){
public
App
DT
O
load
(
@PathVariable
String
appId
){
if
(
StringUtils
.
isEmpty
(
appId
)){
throw
new
BadRequestException
(
"app id can not be empty."
);
}
return
appService
.
load
(
appId
);
}
@RequestMapping
(
value
=
"/{appId}/miss_envs"
)
public
MultiResponseEntity
<
Env
>
findMissEnvs
(
@PathVariable
String
appId
)
{
MultiResponseEntity
<
Env
>
response
=
MultiResponseEntity
.
ok
();
for
(
Env
env
:
portalSettings
.
getEnvs
())
{
try
{
appService
.
load
(
env
,
appId
);
}
catch
(
Exception
e
)
{
if
(
e
instanceof
HttpClientErrorException
&&
((
HttpClientErrorException
)
e
).
getStatusCode
()
==
HttpStatus
.
NOT_FOUND
){
response
.
addResponseEntity
(
RichResponseEntity
.
ok
(
env
));
}
else
{
response
.
addResponseEntity
(
RichResponseEntity
.
error
(
HttpStatus
.
INTERNAL_SERVER_ERROR
,
String
.
format
(
"load appId:%s from env %s error."
,
appId
,
env
)
+
e
.
getMessage
()));
}
}
}
return
response
;
}
private
boolean
isInvalidApp
(
AppDTO
app
)
{
return
StringUtils
.
isContainEmpty
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerEmail
(),
app
.
getOwnerName
());
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/AppInfoVO.java
已删除
100644 → 0
浏览文件 @
dc493792
package
com.ctrip.apollo.portal.entity
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
java.util.List
;
public
class
AppInfoVO
{
private
AppDTO
app
;
/**
* 在创建app的时候可能在某些环境下创建失败
*/
private
List
<
Env
>
missEnvs
;
public
AppDTO
getApp
()
{
return
app
;
}
public
void
setApp
(
AppDTO
app
)
{
this
.
app
=
app
;
}
public
List
<
Env
>
getMissEnvs
()
{
return
missEnvs
;
}
public
void
setMissEnvs
(
List
<
Env
>
missEnvs
)
{
this
.
missEnvs
=
missEnvs
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/ClusterNavTree.java
已删除
100644 → 0
浏览文件 @
dc493792
package
com.ctrip.apollo.portal.entity
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
ClusterNavTree
{
private
List
<
Node
>
nodes
;
public
void
addNode
(
Node
node
){
if
(
nodes
==
null
){
nodes
=
new
LinkedList
<>();
}
nodes
.
add
(
node
);
}
public
static
class
Node
{
private
Env
env
;
private
List
<
ClusterDTO
>
clusters
;
public
Node
(
Env
env
){
this
.
env
=
env
;
}
public
Env
getEnv
()
{
return
env
;
}
public
void
setEnv
(
Env
env
)
{
this
.
env
=
env
;
}
public
List
<
ClusterDTO
>
getClusters
()
{
return
clusters
;
}
public
void
setClusters
(
List
<
ClusterDTO
>
clusters
)
{
this
.
clusters
=
clusters
;
}
}
public
List
<
Node
>
getNodes
()
{
return
nodes
;
}
public
void
setNodes
(
List
<
Node
>
nodes
)
{
this
.
nodes
=
nodes
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/EnvClusterInfo.java
0 → 100644
浏览文件 @
7c02e344
package
com.ctrip.apollo.portal.entity
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
java.util.List
;
public
class
EnvClusterInfo
{
private
Env
env
;
private
List
<
ClusterDTO
>
clusters
;
public
EnvClusterInfo
(
Env
env
){
this
.
env
=
env
;
}
public
Env
getEnv
()
{
return
env
;
}
public
void
setEnv
(
Env
env
)
{
this
.
env
=
env
;
}
public
List
<
ClusterDTO
>
getClusters
()
{
return
clusters
;
}
public
void
setClusters
(
List
<
ClusterDTO
>
clusters
)
{
this
.
clusters
=
clusters
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
浏览文件 @
7c02e344
package
com.ctrip.apollo.portal.service
;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.slf4j.Logger
;
...
...
@@ -18,69 +17,56 @@ import com.ctrip.apollo.core.exception.BadRequestException;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.portal.PortalSettings
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.AppInfoVO
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
import
com.ctrip.apollo.portal.entity.EnvClusterInfo
;
@Service
public
class
AppService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
AppService
.
class
);
@Autowired
private
ClusterService
clusterService
;
@Autowired
private
PortalSettings
portalSettings
;
@Autowired
private
AdminServiceAPI
.
AppAPI
appAPI
;
@Autowired
ClusterService
clusterService
;
public
List
<
AppDTO
>
findAll
(
Env
env
)
{
return
appAPI
.
findApps
(
env
);
}
public
App
InfoV
O
load
(
String
appId
)
{
public
App
DT
O
load
(
String
appId
)
{
//轮询环境直到能找到此app的信息
AppDTO
app
=
null
;
List
<
Env
>
missEnvs
=
new
LinkedList
<>()
;
boolean
isCallAdminServiceError
=
false
;
for
(
Env
env
:
portalSettings
.
getEnvs
())
{
try
{
app
=
appAPI
.
loadApp
(
env
,
appId
);
break
;
}
catch
(
HttpClientErrorException
e
)
{
//not exist maybe because create app fail.
if
(
e
.
getStatusCode
()
==
HttpStatus
.
NOT_FOUND
)
{
missEnvs
.
add
(
env
);
logger
.
warn
(
"app:{} in {} not exist"
,
appId
,
env
);
}
else
{
isCallAdminServiceError
=
true
;
logger
.
error
(
"load app info({}) from env:{} error."
,
appId
,
env
);
throw
new
ServiceException
(
"can not load app from all envs"
);
}
}
}
if
(
app
==
null
)
{
throw
new
BadRequestException
(
String
.
format
(
"invalid app id %s"
,
appId
));
if
(
isCallAdminServiceError
){
throw
new
ServiceException
(
"call admin service error"
);
}
else
{
throw
new
BadRequestException
(
String
.
format
(
"invalid app id %s"
,
appId
));
}
}
AppInfoVO
appInfo
=
new
AppInfoVO
();
appInfo
.
setApp
(
app
);
appInfo
.
setMissEnvs
(
missEnvs
);
return
appInfo
;
return
app
;
}
public
ClusterNavTree
buildClusterNavTree
(
String
appId
)
{
ClusterNavTree
tree
=
new
ClusterNavTree
();
List
<
Env
>
envs
=
portalSettings
.
getEnvs
();
for
(
Env
env
:
envs
)
{
ClusterNavTree
.
Node
clusterNode
=
new
ClusterNavTree
.
Node
(
env
);
clusterNode
.
setClusters
(
clusterService
.
findClusters
(
env
,
appId
));
tree
.
addNode
(
clusterNode
);
}
return
tree
;
public
AppDTO
load
(
Env
env
,
String
appId
){
return
appAPI
.
loadApp
(
env
,
appId
);
}
public
void
createAppInAllEnvs
(
AppDTO
app
)
{
...
...
@@ -104,4 +90,10 @@ public class AppService {
}
}
public
EnvClusterInfo
createEnvNavNode
(
Env
env
,
String
appId
){
EnvClusterInfo
node
=
new
EnvClusterInfo
(
env
);
node
.
setClusters
(
clusterService
.
findClusters
(
env
,
appId
));
return
node
;
}
}
apollo-portal/src/main/resources/static/scripts/AppUtils.js
浏览文件 @
7c02e344
appUtil
.
service
(
'
AppUtil
'
,
[
function
(
)
{
appUtil
.
service
(
'
AppUtil
'
,
[
'
toastr
'
,
function
(
toastr
)
{
return
{
errorMsg
:
function
(
response
)
{
...
...
@@ -22,6 +22,17 @@ appUtil.service('AppUtil', [function () {
result
[
kv
[
0
]]
=
kv
[
1
];
});
return
result
;
},
collectData
:
function
(
response
)
{
var
data
=
[];
response
.
entities
.
forEach
(
function
(
entity
)
{
if
(
entity
.
code
==
200
){
data
.
push
(
entity
.
body
);
}
else
{
toastr
.
warning
(
entity
.
message
);
}
});
return
data
;
}
}
}]);
apollo-portal/src/main/resources/static/scripts/app.js
浏览文件 @
7c02e344
...
...
@@ -2,7 +2,7 @@
var
appService
=
angular
.
module
(
'
app.service
'
,
[
'
ngResource
'
]);
/**utils*/
var
appUtil
=
angular
.
module
(
'
app.util
'
,
[]);
var
appUtil
=
angular
.
module
(
'
app.util
'
,
[
'
toastr
'
]);
/** directive */
var
directive_module
=
angular
.
module
(
'
apollo.directive
'
,
[
'
app.service
'
]);
...
...
apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js
浏览文件 @
7c02e344
...
...
@@ -11,7 +11,8 @@ namespace_module.controller("LinkNamespaceController",
////// load env //////
AppService
.
load_nav_tree
(
$scope
.
appId
).
then
(
function
(
result
)
{
$scope
.
namespaceIdentifers
=
[];
result
.
nodes
.
forEach
(
function
(
node
)
{
var
envClusterInfo
=
AppUtil
.
collectData
(
result
);
envClusterInfo
.
forEach
(
function
(
node
)
{
var
env
=
node
.
env
;
node
.
clusters
.
forEach
(
function
(
cluster
)
{
cluster
.
env
=
env
;
...
...
apollo-portal/src/main/resources/static/scripts/controller/app/ConfigBaseInfoController.js
浏览文件 @
7c02e344
...
...
@@ -16,7 +16,8 @@ application_module.controller("ConfigBaseInfoController",
AppService
.
load_nav_tree
(
$rootScope
.
pageContext
.
appId
).
then
(
function
(
result
)
{
var
navTree
=
[];
var
nodes
=
result
.
nodes
;
var
nodes
=
AppUtil
.
collectData
(
result
);
nodes
.
forEach
(
function
(
item
)
{
var
node
=
{};
//first nav
...
...
@@ -41,6 +42,7 @@ application_module.controller("ConfigBaseInfoController",
node
.
nodes
=
clusterNodes
;
navTree
.
push
(
node
);
});
$
(
'
#treeview
'
).
treeview
({
color
:
"
#797979
"
,
showBorder
:
true
,
...
...
@@ -57,22 +59,28 @@ application_module.controller("ConfigBaseInfoController",
$rootScope
.
refreshNamespaces
();
}
});
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
加载导航出错
"
);
});
////// app info //////
AppService
.
load
(
$rootScope
.
pageContext
.
appId
).
then
(
function
(
result
)
{
$scope
.
appBaseInfo
=
result
.
app
;
$scope
.
missEnvs
=
result
.
missEnvs
;
$scope
.
selectedEnvs
=
angular
.
copy
(
$scope
.
missEnvs
);
$scope
.
appBaseInfo
=
result
;
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
加载App信息出错
"
);
});
////// 补缺失的环境 //////
$scope
.
missEnvs
=
[];
AppService
.
find_miss_envs
(
$rootScope
.
pageContext
.
appId
).
then
(
function
(
result
)
{
$scope
.
missEnvs
=
AppUtil
.
collectData
(
result
);
},
function
(
result
)
{
console
.
log
(
AppUtil
.
errorMsg
(
result
));
});
$scope
.
toggleSelection
=
function
toggleSelection
(
env
)
{
var
idx
=
$scope
.
selectedEnvs
.
indexOf
(
env
);
...
...
apollo-portal/src/main/resources/static/scripts/controller/app/SyncConfigController.js
浏览文件 @
7c02e344
...
...
@@ -13,7 +13,8 @@ sync_item_module.controller("SyncItemController",
////// load env //////
AppService
.
load_nav_tree
(
$scope
.
pageContext
.
appId
).
then
(
function
(
result
)
{
$scope
.
namespaceIdentifers
=
[];
result
.
nodes
.
forEach
(
function
(
node
)
{
var
envClusterInfo
=
AppUtil
.
collectData
(
result
);
envClusterInfo
.
forEach
(
function
(
node
)
{
var
env
=
node
.
env
;
node
.
clusters
.
forEach
(
function
(
cluster
)
{
cluster
.
env
=
env
;
...
...
apollo-portal/src/main/resources/static/scripts/services/AppService.js
浏览文件 @
7c02e344
...
...
@@ -17,6 +17,10 @@ appService.service('AppService', ['$resource', '$q', function ($resource, $q) {
create_app
:
{
method
:
'
POST
'
,
url
:
'
/apps/envs/:env
'
},
find_miss_envs
:
{
method
:
'
GET
'
,
url
:
'
/apps/:appId/miss_envs
'
}
});
return
{
...
...
@@ -61,6 +65,17 @@ appService.service('AppService', ['$resource', '$q', function ($resource, $q) {
d
.
reject
(
result
);
});
return
d
.
promise
;
},
find_miss_envs
:
function
(
appId
)
{
var
d
=
$q
.
defer
();
app_resource
.
find_miss_envs
({
appId
:
appId
},
function
(
result
)
{
d
.
resolve
(
result
);
},
function
(
result
)
{
d
.
reject
(
result
);
});
return
d
.
promise
;
}
}
}]);
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
浏览文件 @
7c02e344
...
...
@@ -8,8 +8,8 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
AppServiceTest
.
class
,
NamespaceServiceTest
.
class
})
NamespaceServiceTest
.
class
})
public
class
AllTests
{
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/AppServiceTest.java
已删除
100644 → 0
浏览文件 @
dc493792
package
com.ctrip.apollo.portal
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
import
com.ctrip.apollo.portal.service.AppService
;
import
com.ctrip.apollo.portal.service.ClusterService
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
java.util.Arrays
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
AppServiceTest
{
@Mock
private
PortalSettings
settings
;
@Mock
private
ClusterService
clusterService
;
@Mock
private
AdminServiceAPI
.
AppAPI
appAPI
;
@InjectMocks
private
AppService
appService
;
@Test
public
void
testBuildNavTree
(){
String
appId
=
"6666"
;
ClusterDTO
c1
=
new
ClusterDTO
();
c1
.
setAppId
(
appId
);
c1
.
setName
(
"default"
);
c1
.
setId
(
1
);
ClusterDTO
c2
=
new
ClusterDTO
();
c2
.
setAppId
(
appId
);
c2
.
setName
(
"oy"
);
c2
.
setId
(
2
);
List
<
ClusterDTO
>
clusterDTOs
=
Arrays
.
asList
(
c1
,
c2
);
when
(
settings
.
getEnvs
()).
thenReturn
(
Arrays
.
asList
(
Env
.
DEV
,
Env
.
FAT
));
when
(
clusterService
.
findClusters
(
Env
.
DEV
,
appId
)).
thenReturn
(
clusterDTOs
);
when
(
clusterService
.
findClusters
(
Env
.
FAT
,
appId
)).
thenReturn
(
Arrays
.
asList
(
c1
));
ClusterNavTree
tree
=
appService
.
buildClusterNavTree
(
appId
);
assertEquals
(
2
,
tree
.
getNodes
().
size
());
ClusterNavTree
.
Node
node1
=
tree
.
getNodes
().
get
(
0
);
assertEquals
(
Env
.
DEV
,
node1
.
getEnv
());
assertEquals
(
2
,
node1
.
getClusters
().
size
());
assertEquals
(
"default"
,
node1
.
getClusters
().
get
(
0
).
getName
());
}
// @Test
// public void testSaveApp(){
// String appId = "6666";
// String appName = "hermas";
// AppDTO appDTO = new AppDTO();
// appDTO.setAppId(appId);
// appDTO.setName(appName);
// appDTO.setDataChangeLastModifiedBy("ll");
// appDTO.setDataChangeCreatedTime(new Date());
// appDTO.setOwnerEmail("qq@qq.com");
// appDTO.setOwnerName("zz");
//
// when(appService.createApp(appDTO)).thenReturn(appDTO);
//
// AppDTO createApp = appService.createApp(appDTO);
//
// assertEquals(appId, createApp.getAppId());
// assertEquals(appName, createApp.getName());
// }
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录