Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
4c64de67
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,发现更多精彩内容 >>
提交
4c64de67
编写于
7月 15, 2016
作者:
J
Jason Song
提交者:
GitHub
7月 15, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #326 from lepdou/ut
ut
上级
189c2188
835fdcbb
变更
26
隐藏空白更改
内联
并排
Showing
26 changed file
with
568 addition
and
45 deletion
+568
-45
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/aop/NamespaceLockAspect.java
...ramework/apollo/adminservice/aop/NamespaceLockAspect.java
+6
-2
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/NamespaceLockController.java
...ollo/adminservice/controller/NamespaceLockController.java
+0
-1
apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/AllTests.java
...ava/com/ctrip/framework/apollo/adminservice/AllTests.java
+2
-1
apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/aop/NamespaceLockTest.java
.../framework/apollo/adminservice/aop/NamespaceLockTest.java
+150
-0
apollo-adminservice/src/test/resources/controller/cleanup.sql
...lo-adminservice/src/test/resources/controller/cleanup.sql
+2
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java
.../framework/apollo/portal/service/AppNamespaceService.java
+1
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java
...work/apollo/portal/service/RoleInitializationService.java
+3
-4
apollo-portal/src/main/resources/static/scripts/controller/config/ConfigNamespaceController.js
...ic/scripts/controller/config/ConfigNamespaceController.js
+2
-0
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
...ces/static/scripts/directive/namespace-panel-directive.js
+4
-4
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/AbstractIntegrationTest.java
...trip/framework/apollo/portal/AbstractIntegrationTest.java
+1
-1
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/AbstractUnitTest.java
...a/com/ctrip/framework/apollo/portal/AbstractUnitTest.java
+9
-0
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/AllTests.java
...test/java/com/ctrip/framework/apollo/portal/AllTests.java
+8
-1
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/ServiceExceptionTest.java
...m/ctrip/framework/apollo/portal/ServiceExceptionTest.java
+1
-1
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/AppNamespaceServiceTest.java
...mework/apollo/portal/service/AppNamespaceServiceTest.java
+130
-0
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigServiceTest.java
...ip/framework/apollo/portal/service/ConfigServiceTest.java
+1
-1
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java
...framework/apollo/portal/service/NamespaceServiceTest.java
+1
-1
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/RoleInitializationServiceTest.java
.../apollo/portal/service/RoleInitializationServiceTest.java
+159
-0
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/RolePermissionServiceTest.java
...work/apollo/portal/service/RolePermissionServiceTest.java
+18
-18
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/txtresolver/FileTextResolverTest.java
...ollo/portal/service/txtresolver/FileTextResolverTest.java
+54
-0
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/txtresolver/PropertyResolverTest.java
...ollo/portal/service/txtresolver/PropertyResolverTest.java
+6
-8
apollo-portal/src/test/resources/sql/appnamespaceservice/init-appnamespace.sql
...t/resources/sql/appnamespaceservice/init-appnamespace.sql
+9
-0
apollo-portal/src/test/resources/sql/cleanup.sql
apollo-portal/src/test/resources/sql/cleanup.sql
+1
-0
apollo-portal/src/test/resources/sql/permission/insert-test-permissions.sql
...test/resources/sql/permission/insert-test-permissions.sql
+0
-0
apollo-portal/src/test/resources/sql/permission/insert-test-rolepermissions.sql
.../resources/sql/permission/insert-test-rolepermissions.sql
+0
-0
apollo-portal/src/test/resources/sql/permission/insert-test-roles.sql
...l/src/test/resources/sql/permission/insert-test-roles.sql
+0
-0
apollo-portal/src/test/resources/sql/permission/insert-test-userroles.sql
...c/test/resources/sql/permission/insert-test-userroles.sql
+0
-0
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/aop/NamespaceLockAspect.java
浏览文件 @
4c64de67
...
@@ -71,7 +71,7 @@ public class NamespaceLockAspect {
...
@@ -71,7 +71,7 @@ public class NamespaceLockAspect {
acquireLock
(
item
.
getNamespaceId
(),
operator
);
acquireLock
(
item
.
getNamespaceId
(),
operator
);
}
}
private
void
acquireLock
(
String
appId
,
String
clusterName
,
String
namespaceName
,
void
acquireLock
(
String
appId
,
String
clusterName
,
String
namespaceName
,
String
currentUser
)
{
String
currentUser
)
{
if
(
apolloSwitcher
.
isNamespaceLockSwitchOff
())
{
if
(
apolloSwitcher
.
isNamespaceLockSwitchOff
())
{
return
;
return
;
...
@@ -82,7 +82,11 @@ public class NamespaceLockAspect {
...
@@ -82,7 +82,11 @@ public class NamespaceLockAspect {
acquireLock
(
namespace
,
currentUser
);
acquireLock
(
namespace
,
currentUser
);
}
}
private
void
acquireLock
(
long
namespaceId
,
String
currentUser
)
{
void
acquireLock
(
long
namespaceId
,
String
currentUser
)
{
if
(
apolloSwitcher
.
isNamespaceLockSwitchOff
())
{
return
;
}
Namespace
namespace
=
namespaceService
.
findOne
(
namespaceId
);
Namespace
namespace
=
namespaceService
.
findOne
(
namespaceId
);
acquireLock
(
namespace
,
currentUser
);
acquireLock
(
namespace
,
currentUser
);
...
...
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/NamespaceLockController.java
浏览文件 @
4c64de67
...
@@ -8,7 +8,6 @@ import com.ctrip.framework.apollo.biz.utils.ApolloSwitcher;
...
@@ -8,7 +8,6 @@ import com.ctrip.framework.apollo.biz.utils.ApolloSwitcher;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.dto.NamespaceLockDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceLockDTO
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.exception.NotFoundException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
...
apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/AllTests.java
浏览文件 @
4c64de67
...
@@ -4,6 +4,7 @@ import org.junit.runner.RunWith;
...
@@ -4,6 +4,7 @@ import org.junit.runner.RunWith;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
org.junit.runners.Suite.SuiteClasses
;
import
com.ctrip.framework.apollo.adminservice.aop.NamespaceLockTest
;
import
com.ctrip.framework.apollo.adminservice.controller.AppControllerTest
;
import
com.ctrip.framework.apollo.adminservice.controller.AppControllerTest
;
import
com.ctrip.framework.apollo.adminservice.controller.ControllerExceptionTest
;
import
com.ctrip.framework.apollo.adminservice.controller.ControllerExceptionTest
;
import
com.ctrip.framework.apollo.adminservice.controller.ControllerIntegrationExceptionTest
;
import
com.ctrip.framework.apollo.adminservice.controller.ControllerIntegrationExceptionTest
;
...
@@ -12,7 +13,7 @@ import com.ctrip.framework.apollo.adminservice.controller.ReleaseControllerTest;
...
@@ -12,7 +13,7 @@ import com.ctrip.framework.apollo.adminservice.controller.ReleaseControllerTest;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
AppControllerTest
.
class
,
ReleaseControllerTest
.
class
,
ItemSetControllerTest
.
class
,
@SuiteClasses
({
AppControllerTest
.
class
,
ReleaseControllerTest
.
class
,
ItemSetControllerTest
.
class
,
ControllerExceptionTest
.
class
,
ControllerIntegrationExceptionTest
.
class
})
ControllerExceptionTest
.
class
,
ControllerIntegrationExceptionTest
.
class
,
NamespaceLockTest
.
class
})
public
class
AllTests
{
public
class
AllTests
{
}
}
apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/aop/NamespaceLockTest.java
0 → 100644
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.adminservice.aop
;
import
com.ctrip.framework.apollo.biz.entity.Namespace
;
import
com.ctrip.framework.apollo.biz.entity.NamespaceLock
;
import
com.ctrip.framework.apollo.biz.service.ItemService
;
import
com.ctrip.framework.apollo.biz.service.NamespaceLockService
;
import
com.ctrip.framework.apollo.biz.service.NamespaceService
;
import
com.ctrip.framework.apollo.biz.utils.ApolloSwitcher
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyLong
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
NamespaceLockTest
{
private
static
final
String
APP
=
"app-test"
;
private
static
final
String
CLUSTER
=
"cluster-test"
;
private
static
final
String
NAMESPACE
=
"namespace-test"
;
private
static
final
String
CURRENT_USER
=
"user-test"
;
private
static
final
String
ANOTHER_USER
=
"user-test2"
;
private
static
final
long
NAMESPACE_ID
=
100
;
@Mock
private
NamespaceLockService
namespaceLockService
;
@Mock
private
NamespaceService
namespaceService
;
@Mock
private
ItemService
itemService
;
@Mock
private
ApolloSwitcher
apolloSwitcher
;
@InjectMocks
NamespaceLockAspect
namespaceLockAspect
;
@Test
public
void
acquireLockWithNotLockedAndSwitchON
()
{
when
(
apolloSwitcher
.
isNamespaceLockSwitchOff
()).
thenReturn
(
true
);
namespaceLockAspect
.
acquireLock
(
APP
,
CLUSTER
,
NAMESPACE
,
CURRENT_USER
);
verify
(
namespaceService
,
times
(
0
)).
findOne
(
APP
,
CLUSTER
,
NAMESPACE
);
}
@Test
public
void
acquireLockWithNotLockedAndSwitchOFF
()
{
when
(
apolloSwitcher
.
isNamespaceLockSwitchOff
()).
thenReturn
(
false
);
when
(
namespaceService
.
findOne
(
APP
,
CLUSTER
,
NAMESPACE
)).
thenReturn
(
mockNamespace
());
when
(
namespaceLockService
.
findLock
(
anyLong
())).
thenReturn
(
null
);
namespaceLockAspect
.
acquireLock
(
APP
,
CLUSTER
,
NAMESPACE
,
CURRENT_USER
);
verify
(
apolloSwitcher
).
isNamespaceLockSwitchOff
();
verify
(
namespaceService
).
findOne
(
APP
,
CLUSTER
,
NAMESPACE
);
verify
(
namespaceLockService
).
findLock
(
anyLong
());
verify
(
namespaceLockService
).
tryLock
(
any
());
}
@Test
(
expected
=
BadRequestException
.
class
)
public
void
acquireLockWithAlreadyLockedByOtherGuy
()
{
when
(
apolloSwitcher
.
isNamespaceLockSwitchOff
()).
thenReturn
(
false
);
when
(
namespaceService
.
findOne
(
APP
,
CLUSTER
,
NAMESPACE
)).
thenReturn
(
mockNamespace
());
when
(
namespaceLockService
.
findLock
(
NAMESPACE_ID
)).
thenReturn
(
mockNamespaceLock
(
ANOTHER_USER
));
namespaceLockAspect
.
acquireLock
(
APP
,
CLUSTER
,
NAMESPACE
,
CURRENT_USER
);
verify
(
apolloSwitcher
).
isNamespaceLockSwitchOff
();
verify
(
namespaceService
).
findOne
(
APP
,
CLUSTER
,
NAMESPACE
);
verify
(
namespaceLockService
).
findLock
(
NAMESPACE_ID
);
}
@Test
public
void
acquireLockWithAlreadyLockedBySelf
()
{
when
(
apolloSwitcher
.
isNamespaceLockSwitchOff
()).
thenReturn
(
false
);
when
(
namespaceService
.
findOne
(
APP
,
CLUSTER
,
NAMESPACE
)).
thenReturn
(
mockNamespace
());
when
(
namespaceLockService
.
findLock
(
NAMESPACE_ID
)).
thenReturn
(
mockNamespaceLock
(
CURRENT_USER
));
namespaceLockAspect
.
acquireLock
(
APP
,
CLUSTER
,
NAMESPACE
,
CURRENT_USER
);
verify
(
apolloSwitcher
).
isNamespaceLockSwitchOff
();
verify
(
namespaceService
).
findOne
(
APP
,
CLUSTER
,
NAMESPACE
);
verify
(
namespaceLockService
).
findLock
(
NAMESPACE_ID
);
}
@Test
public
void
acquireLockWithNamespaceIdSwitchOn
(){
when
(
apolloSwitcher
.
isNamespaceLockSwitchOff
()).
thenReturn
(
false
);
when
(
namespaceService
.
findOne
(
NAMESPACE_ID
)).
thenReturn
(
mockNamespace
());
when
(
namespaceLockService
.
findLock
(
NAMESPACE_ID
)).
thenReturn
(
null
);
namespaceLockAspect
.
acquireLock
(
NAMESPACE_ID
,
CURRENT_USER
);
verify
(
apolloSwitcher
).
isNamespaceLockSwitchOff
();
verify
(
namespaceService
).
findOne
(
NAMESPACE_ID
);
verify
(
namespaceLockService
).
findLock
(
NAMESPACE_ID
);
verify
(
namespaceLockService
).
tryLock
(
any
());
}
@Test
(
expected
=
ServiceException
.
class
)
public
void
testDuplicateLock
(){
when
(
apolloSwitcher
.
isNamespaceLockSwitchOff
()).
thenReturn
(
false
);
when
(
namespaceService
.
findOne
(
NAMESPACE_ID
)).
thenReturn
(
mockNamespace
());
when
(
namespaceLockService
.
findLock
(
NAMESPACE_ID
)).
thenReturn
(
null
);
when
(
namespaceLockService
.
tryLock
(
any
())).
thenThrow
(
DataIntegrityViolationException
.
class
);
namespaceLockAspect
.
acquireLock
(
NAMESPACE_ID
,
CURRENT_USER
);
verify
(
apolloSwitcher
).
isNamespaceLockSwitchOff
();
verify
(
namespaceService
).
findOne
(
NAMESPACE_ID
);
verify
(
namespaceLockService
,
times
(
2
)).
findLock
(
NAMESPACE_ID
);
verify
(
namespaceLockService
).
tryLock
(
any
());
}
private
Namespace
mockNamespace
()
{
Namespace
namespace
=
new
Namespace
();
namespace
.
setId
(
NAMESPACE_ID
);
namespace
.
setAppId
(
APP
);
namespace
.
setClusterName
(
CLUSTER
);
namespace
.
setNamespaceName
(
NAMESPACE
);
return
namespace
;
}
private
NamespaceLock
mockNamespaceLock
(
String
locedUser
)
{
NamespaceLock
lock
=
new
NamespaceLock
();
lock
.
setNamespaceId
(
NAMESPACE_ID
);
lock
.
setDataChangeCreatedBy
(
locedUser
);
return
lock
;
}
}
apollo-adminservice/src/test/resources/controller/cleanup.sql
浏览文件 @
4c64de67
...
@@ -3,4 +3,6 @@ DELETE FROM Namespace;
...
@@ -3,4 +3,6 @@ DELETE FROM Namespace;
DELETE
FROM
AppNamespace
;
DELETE
FROM
AppNamespace
;
DELETE
FROM
Cluster
;
DELETE
FROM
Cluster
;
DELETE
FROM
App
;
DELETE
FROM
App
;
DELETE
FROM
NamespaceLock
;
DELETE
FROM
ServerConfig
;
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java
浏览文件 @
4c64de67
...
@@ -65,8 +65,7 @@ public class AppNamespaceService {
...
@@ -65,8 +65,7 @@ public class AppNamespaceService {
@Transactional
@Transactional
public
AppNamespace
createAppNamespaceInLocal
(
AppNamespace
appNamespace
)
{
public
AppNamespace
createAppNamespaceInLocal
(
AppNamespace
appNamespace
)
{
// unique check
// unique check
if
(
appNamespace
.
isPublic
()
&&
if
(
appNamespace
.
isPublic
()
&&
findPublicAppNamespace
(
appNamespace
.
getName
())
!=
null
)
{
appNamespaceRepository
.
findByNameAndIsPublic
(
appNamespace
.
getName
(),
true
)
!=
null
)
{
throw
new
BadRequestException
(
appNamespace
.
getName
()
+
"已存在"
);
throw
new
BadRequestException
(
appNamespace
.
getName
()
+
"已存在"
);
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java
浏览文件 @
4c64de67
...
@@ -102,13 +102,12 @@ public class RoleInitializationService {
...
@@ -102,13 +102,12 @@ public class RoleInitializationService {
private
void
createDefaultNamespaceRole
(
String
appId
,
String
namespaceName
,
String
permissionType
,
String
roleName
)
{
private
void
createDefaultNamespaceRole
(
String
appId
,
String
namespaceName
,
String
permissionType
,
String
roleName
)
{
Permission
Permission
permisson
=
modifyDefaultNsPermission
=
createPermisson
(
RoleUtils
.
buildNamespaceTargetId
(
appId
,
namespaceName
),
permissionType
);
createPermisson
(
RoleUtils
.
buildNamespaceTargetId
(
appId
,
namespaceName
),
permissionType
);
Permission
created
ModifyDefaultNsPermission
=
rolePermissionService
.
createPermission
(
modifyDefaultNsPermissi
on
);
Permission
created
Permission
=
rolePermissionService
.
createPermission
(
permiss
on
);
Role
role
=
createRole
(
roleName
);
Role
role
=
createRole
(
roleName
);
rolePermissionService
rolePermissionService
.
createRoleWithPermissions
(
role
,
Sets
.
newHashSet
(
created
ModifyDefaultNs
Permission
.
getId
()));
.
createRoleWithPermissions
(
role
,
Sets
.
newHashSet
(
createdPermission
.
getId
()));
}
}
}
}
apollo-portal/src/main/resources/static/scripts/controller/config/ConfigNamespaceController.js
浏览文件 @
4c64de67
...
@@ -99,9 +99,11 @@ application_module.controller("ConfigNamespaceController",
...
@@ -99,9 +99,11 @@ application_module.controller("ConfigNamespaceController",
toastr
.
success
(
"
更新成功, 如需生效请发布
"
);
toastr
.
success
(
"
更新成功, 如需生效请发布
"
);
//refresh all namespace items
//refresh all namespace items
$rootScope
.
refreshNamespaces
();
$rootScope
.
refreshNamespaces
();
return
true
;
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
更新失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
更新失败
"
);
return
false
;
}
}
);
);
}
}
...
...
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
浏览文件 @
4c64de67
...
@@ -120,10 +120,10 @@ directive_module.directive('apollonspanel',
...
@@ -120,10 +120,10 @@ directive_module.directive('apollonspanel',
}
}
function
modifyByText
(
namespace
)
{
function
modifyByText
(
namespace
)
{
scope
.
commitChange
(
namespace
);
if
(
scope
.
commitChange
(
namespace
)){
namespace
.
commited
=
true
;
namespace
.
commited
=
true
;
toggleTextEditStatus
(
namespace
);
toggleTextEditStatus
(
namespace
);
}
}
}
function
goToParentAppConfigPage
(
namespace
)
{
function
goToParentAppConfigPage
(
namespace
)
{
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/Abstract
Portal
Test.java
→
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/Abstract
Integration
Test.java
浏览文件 @
4c64de67
...
@@ -15,7 +15,7 @@ import javax.annotation.PostConstruct;
...
@@ -15,7 +15,7 @@ import javax.annotation.PostConstruct;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
PortalApplication
.
class
)
@SpringApplicationConfiguration
(
classes
=
PortalApplication
.
class
)
@WebIntegrationTest
(
randomPort
=
true
)
@WebIntegrationTest
(
randomPort
=
true
)
public
abstract
class
Abstract
Portal
Test
{
public
abstract
class
Abstract
Integration
Test
{
RestTemplate
restTemplate
=
new
TestRestTemplate
(
"apollo"
,
""
);
RestTemplate
restTemplate
=
new
TestRestTemplate
(
"apollo"
,
""
);
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/AbstractUnitTest.java
0 → 100644
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.portal
;
import
org.junit.runner.RunWith
;
import
org.mockito.runners.MockitoJUnitRunner
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
abstract
class
AbstractUnitTest
{
}
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/AllTests.java
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.portal
;
package
com.ctrip.framework.apollo.portal
;
import
com.ctrip.framework.apollo.portal.service.AppNamespaceServiceTest
;
import
com.ctrip.framework.apollo.portal.service.ConfigServiceTest
;
import
com.ctrip.framework.apollo.portal.service.NamespaceServiceTest
;
import
com.ctrip.framework.apollo.portal.service.RoleInitializationServiceTest
;
import
com.ctrip.framework.apollo.portal.service.RolePermissionServiceTest
;
import
com.ctrip.framework.apollo.portal.service.RolePermissionServiceTest
;
import
com.ctrip.framework.apollo.portal.service.txtresolver.FileTextResolverTest
;
import
com.ctrip.framework.apollo.portal.service.txtresolver.PropertyResolverTest
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite
;
...
@@ -10,7 +16,8 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -10,7 +16,8 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
@SuiteClasses
({
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
NamespaceServiceTest
.
class
,
ServiceExceptionTest
.
class
,
RolePermissionServiceTest
.
class
NamespaceServiceTest
.
class
,
ServiceExceptionTest
.
class
,
RolePermissionServiceTest
.
class
,
AppNamespaceServiceTest
.
class
,
RoleInitializationServiceTest
.
class
,
FileTextResolverTest
.
class
})
})
public
class
AllTests
{
public
class
AllTests
{
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/ServiceExceptionTest.java
浏览文件 @
4c64de67
...
@@ -30,7 +30,7 @@ import com.ctrip.framework.apollo.portal.service.UserService;
...
@@ -30,7 +30,7 @@ import com.ctrip.framework.apollo.portal.service.UserService;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
public
class
ServiceExceptionTest
extends
Abstract
Portal
Test
{
public
class
ServiceExceptionTest
extends
Abstract
Integration
Test
{
@Autowired
@Autowired
private
AppController
appController
;
private
AppController
appController
;
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/AppNamespaceServiceTest.java
0 → 100644
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.portal.service
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.AbstractIntegrationTest
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.jdbc.Sql
;
import
java.util.List
;
public
class
AppNamespaceServiceTest
extends
AbstractIntegrationTest
{
@Autowired
private
AppNamespaceService
appNamespaceService
;
private
final
String
APP
=
"app-test"
;
@Test
@Sql
(
scripts
=
"/sql/appnamespaceservice/init-appnamespace.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testFindPublicAppNamespace
()
{
List
<
AppNamespace
>
appNamespaceList
=
appNamespaceService
.
findPublicAppNamespaces
();
Assert
.
assertNotNull
(
appNamespaceList
);
Assert
.
assertEquals
(
5
,
appNamespaceList
.
size
());
}
@Test
@Sql
(
scripts
=
"/sql/appnamespaceservice/init-appnamespace.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testFindPublicAppNamespaceByName
()
{
Assert
.
assertNotNull
(
appNamespaceService
.
findPublicAppNamespace
(
"datasourcexml"
));
Assert
.
assertNull
(
appNamespaceService
.
findPublicAppNamespace
(
"TFF.song0711-02"
));
}
@Test
@Sql
(
scripts
=
"/sql/appnamespaceservice/init-appnamespace.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testFindPublicAppNamespaceByAppAndName
()
{
Assert
.
assertNotNull
(
appNamespaceService
.
findByAppIdAndName
(
"100003173"
,
"datasourcexml"
));
Assert
.
assertNull
(
appNamespaceService
.
findByAppIdAndName
(
"100003173"
,
"TFF.song0711-02"
));
}
@Test
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreateDefaultAppNamespace
()
{
appNamespaceService
.
createDefaultAppNamespace
(
APP
);
AppNamespace
appNamespace
=
appNamespaceService
.
findByAppIdAndName
(
APP
,
ConfigConsts
.
NAMESPACE_APPLICATION
);
Assert
.
assertNotNull
(
appNamespace
);
Assert
.
assertEquals
(
ConfigFileFormat
.
Properties
.
getValue
(),
appNamespace
.
getFormat
());
}
@Test
(
expected
=
BadRequestException
.
class
)
@Sql
(
scripts
=
"/sql/appnamespaceservice/init-appnamespace.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreatePublicAppNamespaceExisted
()
{
AppNamespace
appNamespace
=
assmbleBaseAppNamespace
();
appNamespace
.
setPublic
(
true
);
appNamespace
.
setName
(
"FX.old"
);
appNamespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
}
@Test
@Sql
(
scripts
=
"/sql/appnamespaceservice/init-appnamespace.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreatePublicAppNamespaceNotExisted
()
{
AppNamespace
appNamespace
=
assmbleBaseAppNamespace
();
appNamespace
.
setPublic
(
true
);
appNamespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
AppNamespace
createdAppNamespace
=
appNamespaceService
.
findPublicAppNamespace
(
appNamespace
.
getName
());
Assert
.
assertNotNull
(
createdAppNamespace
);
Assert
.
assertEquals
(
appNamespace
.
getName
(),
createdAppNamespace
.
getName
());
}
@Test
(
expected
=
BadRequestException
.
class
)
@Sql
(
scripts
=
"/sql/appnamespaceservice/init-appnamespace.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreatePrivateAppNamespaceExisted
()
{
AppNamespace
appNamespace
=
assmbleBaseAppNamespace
();
appNamespace
.
setPublic
(
false
);
appNamespace
.
setName
(
"datasource.xml"
);
appNamespace
.
setAppId
(
"100003173"
);
appNamespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
}
@Test
@Sql
(
scripts
=
"/sql/appnamespaceservice/init-appnamespace.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreatePrivateAppNamespaceNotExisted
()
{
AppNamespace
appNamespace
=
assmbleBaseAppNamespace
();
appNamespace
.
setPublic
(
false
);
appNamespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
AppNamespace
createdAppNamespace
=
appNamespaceService
.
findByAppIdAndName
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
Assert
.
assertNotNull
(
createdAppNamespace
);
Assert
.
assertEquals
(
appNamespace
.
getName
(),
createdAppNamespace
.
getName
());
}
private
AppNamespace
assmbleBaseAppNamespace
()
{
AppNamespace
appNamespace
=
new
AppNamespace
();
appNamespace
.
setName
(
"appNamespace"
);
appNamespace
.
setAppId
(
"1000"
);
appNamespace
.
setFormat
(
ConfigFileFormat
.
XML
.
getValue
());
return
appNamespace
;
}
}
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/ConfigServiceTest.java
→
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/
service/
ConfigServiceTest.java
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.portal
;
package
com.ctrip.framework.apollo.portal
.service
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/NamespaceServiceTest.java
→
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/
service/
NamespaceServiceTest.java
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.portal
;
package
com.ctrip.framework.apollo.portal
.service
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/RoleInitializationServiceTest.java
0 → 100644
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.portal.service
;
import
com.google.common.collect.Sets
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.portal.AbstractUnitTest
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.constant.PermissionType
;
import
com.ctrip.framework.apollo.portal.entity.po.Permission
;
import
com.ctrip.framework.apollo.portal.entity.po.Role
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
import
com.ctrip.framework.apollo.portal.util.RoleUtils
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anySet
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
RoleInitializationServiceTest
extends
AbstractUnitTest
{
private
final
String
APP_ID
=
"1000"
;
private
final
String
APP_NAME
=
"app-test"
;
private
final
String
CLUSTER
=
"cluster-test"
;
private
final
String
NAMESPACE
=
"namespace-test"
;
private
final
String
CURRENT_USER
=
"user"
;
@Mock
private
RolePermissionService
rolePermissionService
;
@Mock
private
UserInfoHolder
userInfoHolder
;
@InjectMocks
private
RoleInitializationService
roleInitializationService
;
@Test
public
void
testInitAppRoleHasInitBefore
(){
when
(
rolePermissionService
.
findRoleByRoleName
(
anyString
())).
thenReturn
(
mockRole
(
RoleUtils
.
buildAppMasterRoleName
(
APP_ID
)));
roleInitializationService
.
initAppRoles
(
mockApp
());
verify
(
rolePermissionService
,
times
(
1
)).
findRoleByRoleName
(
RoleUtils
.
buildAppMasterRoleName
(
APP_ID
));
verify
(
rolePermissionService
,
times
(
0
)).
assignRoleToUsers
(
anyString
(),
anySet
(),
anyString
());
}
@Test
public
void
testInitAppRole
(){
when
(
rolePermissionService
.
findRoleByRoleName
(
anyString
())).
thenReturn
(
null
);
when
(
userInfoHolder
.
getUser
()).
thenReturn
(
mockUser
());
when
(
rolePermissionService
.
createPermission
(
any
())).
thenReturn
(
mockPermission
());
roleInitializationService
.
initAppRoles
(
mockApp
());
verify
(
rolePermissionService
,
times
(
3
)).
findRoleByRoleName
(
anyString
());
verify
(
rolePermissionService
,
times
(
1
)).
assignRoleToUsers
(
RoleUtils
.
buildAppMasterRoleName
(
APP_ID
),
Sets
.
newHashSet
(
CURRENT_USER
),
CURRENT_USER
);
verify
(
rolePermissionService
,
times
(
2
)).
createPermission
(
any
());
verify
(
rolePermissionService
,
times
(
3
)).
createRoleWithPermissions
(
any
(),
anySet
());
}
@Test
public
void
testInitNamespaceRoleHasExisted
(){
String
modifyNamespaceRoleName
=
RoleUtils
.
buildModifyNamespaceRoleName
(
APP_ID
,
NAMESPACE
);
when
(
rolePermissionService
.
findRoleByRoleName
(
modifyNamespaceRoleName
)).
thenReturn
(
mockRole
(
modifyNamespaceRoleName
));
String
releaseNamespaceRoleName
=
RoleUtils
.
buildReleaseNamespaceRoleName
(
APP_ID
,
NAMESPACE
);
when
(
rolePermissionService
.
findRoleByRoleName
(
releaseNamespaceRoleName
)).
thenReturn
(
mockRole
(
releaseNamespaceRoleName
));
roleInitializationService
.
initNamespaceRoles
(
APP_ID
,
NAMESPACE
);
verify
(
rolePermissionService
,
times
(
2
)).
findRoleByRoleName
(
anyString
());
verify
(
rolePermissionService
,
times
(
0
)).
createPermission
(
any
());
verify
(
rolePermissionService
,
times
(
0
)).
createRoleWithPermissions
(
any
(),
anySet
());
}
@Test
public
void
testInitNamespaceRoleNotExisted
(){
String
modifyNamespaceRoleName
=
RoleUtils
.
buildModifyNamespaceRoleName
(
APP_ID
,
NAMESPACE
);
when
(
rolePermissionService
.
findRoleByRoleName
(
modifyNamespaceRoleName
)).
thenReturn
(
null
);
String
releaseNamespaceRoleName
=
RoleUtils
.
buildReleaseNamespaceRoleName
(
APP_ID
,
NAMESPACE
);
when
(
rolePermissionService
.
findRoleByRoleName
(
releaseNamespaceRoleName
)).
thenReturn
(
null
);
when
(
userInfoHolder
.
getUser
()).
thenReturn
(
mockUser
());
when
(
rolePermissionService
.
createPermission
(
any
())).
thenReturn
(
mockPermission
());
roleInitializationService
.
initNamespaceRoles
(
APP_ID
,
NAMESPACE
);
verify
(
rolePermissionService
,
times
(
2
)).
findRoleByRoleName
(
anyString
());
verify
(
rolePermissionService
,
times
(
2
)).
createPermission
(
any
());
verify
(
rolePermissionService
,
times
(
2
)).
createRoleWithPermissions
(
any
(),
anySet
());
}
@Test
public
void
testInitNamespaceRoleModifyNSExisted
(){
String
modifyNamespaceRoleName
=
RoleUtils
.
buildModifyNamespaceRoleName
(
APP_ID
,
NAMESPACE
);
when
(
rolePermissionService
.
findRoleByRoleName
(
modifyNamespaceRoleName
)).
thenReturn
(
mockRole
(
modifyNamespaceRoleName
));
String
releaseNamespaceRoleName
=
RoleUtils
.
buildReleaseNamespaceRoleName
(
APP_ID
,
NAMESPACE
);
when
(
rolePermissionService
.
findRoleByRoleName
(
releaseNamespaceRoleName
)).
thenReturn
(
null
);
when
(
userInfoHolder
.
getUser
()).
thenReturn
(
mockUser
());
when
(
rolePermissionService
.
createPermission
(
any
())).
thenReturn
(
mockPermission
());
roleInitializationService
.
initNamespaceRoles
(
APP_ID
,
NAMESPACE
);
verify
(
rolePermissionService
,
times
(
2
)).
findRoleByRoleName
(
anyString
());
verify
(
rolePermissionService
,
times
(
1
)).
createPermission
(
any
());
verify
(
rolePermissionService
,
times
(
1
)).
createRoleWithPermissions
(
any
(),
anySet
());
}
private
App
mockApp
(){
App
app
=
new
App
();
app
.
setAppId
(
APP_ID
);
app
.
setName
(
APP_NAME
);
app
.
setOrgName
(
"xx"
);
app
.
setOrgId
(
"1"
);
app
.
setOwnerName
(
CURRENT_USER
);
app
.
setDataChangeCreatedBy
(
CURRENT_USER
);
return
app
;
}
private
Role
mockRole
(
String
roleName
){
Role
role
=
new
Role
();
role
.
setRoleName
(
roleName
);
return
role
;
}
private
UserInfo
mockUser
(){
UserInfo
userInfo
=
new
UserInfo
();
userInfo
.
setUserId
(
CURRENT_USER
);
return
userInfo
;
}
private
Permission
mockPermission
(){
Permission
permission
=
new
Permission
();
permission
.
setPermissionType
(
PermissionType
.
MODIFY_NAMESPACE
);
permission
.
setTargetId
(
RoleUtils
.
buildNamespaceTargetId
(
APP_ID
,
NAMESPACE
));
return
permission
;
}
}
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/RolePermissionServiceTest.java
浏览文件 @
4c64de67
...
@@ -4,7 +4,7 @@ import com.google.common.collect.FluentIterable;
...
@@ -4,7 +4,7 @@ import com.google.common.collect.FluentIterable;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.Sets
;
import
com.ctrip.framework.apollo.common.entity.BaseEntity
;
import
com.ctrip.framework.apollo.common.entity.BaseEntity
;
import
com.ctrip.framework.apollo.portal.Abstract
Portal
Test
;
import
com.ctrip.framework.apollo.portal.Abstract
Integration
Test
;
import
com.ctrip.framework.apollo.portal.entity.po.Permission
;
import
com.ctrip.framework.apollo.portal.entity.po.Permission
;
import
com.ctrip.framework.apollo.portal.entity.po.Role
;
import
com.ctrip.framework.apollo.portal.entity.po.Role
;
import
com.ctrip.framework.apollo.portal.entity.po.RolePermission
;
import
com.ctrip.framework.apollo.portal.entity.po.RolePermission
;
...
@@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue;
...
@@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
public
class
RolePermissionServiceTest
extends
Abstract
Portal
Test
{
public
class
RolePermissionServiceTest
extends
Abstract
Integration
Test
{
@Autowired
@Autowired
private
RolePermissionService
rolePermissionService
;
private
RolePermissionService
rolePermissionService
;
...
@@ -73,7 +73,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -73,7 +73,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
(
expected
=
IllegalStateException
.
class
)
@Test
(
expected
=
IllegalStateException
.
class
)
@Sql
(
scripts
=
"/sql/insert-test-permissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-permissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreatePermissionWithPermissionExisted
()
throws
Exception
{
public
void
testCreatePermissionWithPermissionExisted
()
throws
Exception
{
String
someTargetId
=
"someTargetId"
;
String
someTargetId
=
"someTargetId"
;
...
@@ -119,7 +119,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -119,7 +119,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
(
expected
=
IllegalStateException
.
class
)
@Test
(
expected
=
IllegalStateException
.
class
)
@Sql
(
scripts
=
"/sql/insert-test-permissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-permissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreatePermissionsWithPermissionsExisted
()
throws
Exception
{
public
void
testCreatePermissionsWithPermissionsExisted
()
throws
Exception
{
String
someTargetId
=
"someTargetId"
;
String
someTargetId
=
"someTargetId"
;
...
@@ -134,7 +134,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -134,7 +134,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
@Test
@Sql
(
scripts
=
"/sql/insert-test-permissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-permissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreateRoleWithPermissions
()
throws
Exception
{
public
void
testCreateRoleWithPermissions
()
throws
Exception
{
String
someRoleName
=
"someRoleName"
;
String
someRoleName
=
"someRoleName"
;
...
@@ -158,7 +158,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -158,7 +158,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
(
expected
=
IllegalStateException
.
class
)
@Test
(
expected
=
IllegalStateException
.
class
)
@Sql
(
scripts
=
"/sql/insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreateRoleWithPermissionsWithRoleExisted
()
throws
Exception
{
public
void
testCreateRoleWithPermissionsWithRoleExisted
()
throws
Exception
{
String
someRoleName
=
"someRoleName"
;
String
someRoleName
=
"someRoleName"
;
...
@@ -168,7 +168,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -168,7 +168,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
@Test
@Sql
(
scripts
=
"/sql/insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testAssignRoleToUsers
()
throws
Exception
{
public
void
testAssignRoleToUsers
()
throws
Exception
{
String
someRoleName
=
"someRoleName"
;
String
someRoleName
=
"someRoleName"
;
...
@@ -208,8 +208,8 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -208,8 +208,8 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
@Test
@Sql
(
scripts
=
"/sql/insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testAssignRoleToUsersWithUserRolesExisted
()
throws
Exception
{
public
void
testAssignRoleToUsersWithUserRolesExisted
()
throws
Exception
{
String
someRoleName
=
"someRoleName"
;
String
someRoleName
=
"someRoleName"
;
...
@@ -236,8 +236,8 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -236,8 +236,8 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
@Test
@Sql
(
scripts
=
"/sql/insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testRemoveRoleFromUsers
()
throws
Exception
{
public
void
testRemoveRoleFromUsers
()
throws
Exception
{
String
someRoleName
=
"someRoleName"
;
String
someRoleName
=
"someRoleName"
;
...
@@ -257,7 +257,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -257,7 +257,7 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
(
expected
=
IllegalStateException
.
class
)
@Test
(
expected
=
IllegalStateException
.
class
)
@Sql
(
scripts
=
"/sql/insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testRemoveRoleFromUsersWithRoleNotExisted
()
throws
Exception
{
public
void
testRemoveRoleFromUsersWithRoleNotExisted
()
throws
Exception
{
String
someRoleName
=
"someRoleName"
;
String
someRoleName
=
"someRoleName"
;
...
@@ -270,8 +270,8 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -270,8 +270,8 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
@Test
@Sql
(
scripts
=
"/sql/insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testQueryUsersWithRole
()
throws
Exception
{
public
void
testQueryUsersWithRole
()
throws
Exception
{
String
someRoleName
=
"someRoleName"
;
String
someRoleName
=
"someRoleName"
;
...
@@ -284,10 +284,10 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
...
@@ -284,10 +284,10 @@ public class RolePermissionServiceTest extends AbstractPortalTest {
}
}
@Test
@Test
@Sql
(
scripts
=
"/sql/insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-roles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/insert-test-permissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-permissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-userroles.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/insert-test-rolepermissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/
permission/
insert-test-rolepermissions.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
@Sql
(
scripts
=
"/sql/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testUserHasPermission
()
throws
Exception
{
public
void
testUserHasPermission
()
throws
Exception
{
String
someTargetId
=
"someTargetId"
;
String
someTargetId
=
"someTargetId"
;
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/txtresolver/FileTextResolverTest.java
0 → 100644
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.portal.service.txtresolver
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.portal.AbstractUnitTest
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
java.util.Arrays
;
import
java.util.Collections
;
public
class
FileTextResolverTest
extends
AbstractUnitTest
{
@InjectMocks
private
FileTextResolver
resolver
;
private
final
String
CONFIG_TEXT
=
"config_text"
;
private
final
long
NAMESPACE
=
1000
;
@Test
public
void
testCreateItem
(){
ItemChangeSets
changeSets
=
resolver
.
resolve
(
NAMESPACE
,
CONFIG_TEXT
,
Collections
.
emptyList
());
Assert
.
assertEquals
(
1
,
changeSets
.
getCreateItems
().
size
());
Assert
.
assertEquals
(
0
,
changeSets
.
getUpdateItems
().
size
());
Assert
.
assertEquals
(
0
,
changeSets
.
getDeleteItems
().
size
());
ItemDTO
createdItem
=
changeSets
.
getCreateItems
().
get
(
0
);
Assert
.
assertEquals
(
CONFIG_TEXT
,
createdItem
.
getValue
());
}
@Test
public
void
testUpdateItem
(){
ItemDTO
existedItem
=
new
ItemDTO
();
existedItem
.
setId
(
1000
);
existedItem
.
setKey
(
ConfigConsts
.
CONFIG_FILE_CONTENT_KEY
);
existedItem
.
setValue
(
"before"
);
ItemChangeSets
changeSets
=
resolver
.
resolve
(
NAMESPACE
,
CONFIG_TEXT
,
Arrays
.
asList
(
existedItem
));
Assert
.
assertEquals
(
0
,
changeSets
.
getCreateItems
().
size
());
Assert
.
assertEquals
(
1
,
changeSets
.
getUpdateItems
().
size
());
Assert
.
assertEquals
(
0
,
changeSets
.
getDeleteItems
().
size
());
ItemDTO
updatedItem
=
changeSets
.
getUpdateItems
().
get
(
0
);
Assert
.
assertEquals
(
CONFIG_TEXT
,
updatedItem
.
getValue
());
}
}
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/PropertyResolverTest.java
→
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/
service/txtresolver/
PropertyResolverTest.java
浏览文件 @
4c64de67
package
com.ctrip.framework.apollo.portal
;
package
com.ctrip.framework.apollo.portal
.service.txtresolver
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.
service.txtresolver.ConfigTextResolver
;
import
com.ctrip.framework.apollo.portal.
AbstractUnitTest
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.mockito.InjectMocks
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
public
class
PropertyResolverTest
extends
Abstract
Portal
Test
{
public
class
PropertyResolverTest
extends
Abstract
Unit
Test
{
@Autowired
@InjectMocks
@Qualifier
(
"propertyResolver"
)
private
PropertyResolver
resolver
;
private
ConfigTextResolver
resolver
;
@Test
@Test
public
void
testEmptyText
()
{
public
void
testEmptyText
()
{
...
...
apollo-portal/src/test/resources/sql/appnamespaceservice/init-appnamespace.sql
0 → 100644
浏览文件 @
4c64de67
INSERT
INTO
`appnamespace`
(
`Id`
,
`Name`
,
`AppId`
,
`Format`
,
`IsPublic`
,
`Comment`
,
`IsDeleted`
,
`DataChange_CreatedBy`
,
`DataChange_CreatedTime`
,
`DataChange_LastModifiedBy`
,
`DataChange_LastTime`
)
VALUES
(
139
,
'FX.old'
,
'100003173'
,
'properties'
,
1
,
''
,
0
,
'zhanglea'
,
'2016-07-11 10:00:58'
,
'zhanglea'
,
'2016-07-11 10:00:58'
),
(
140
,
'SCC.song0711-03'
,
'song0711-01'
,
'properties'
,
1
,
''
,
0
,
'song_s'
,
'2016-07-11 10:04:09'
,
'song_s'
,
'2016-07-11 10:04:09'
),
(
141
,
'SCC.song0711-04'
,
'song0711-01'
,
'properties'
,
1
,
''
,
0
,
'song_s'
,
'2016-07-11 10:06:29'
,
'song_s'
,
'2016-07-11 10:06:29'
),
(
142
,
'application'
,
'song0711-02'
,
'properties'
,
1
,
'default app namespace'
,
0
,
'song_s'
,
'2016-07-11 11:18:24'
,
'song_s'
,
'2016-07-11 11:18:24'
),
(
143
,
'TFF.song0711-02'
,
'song0711-02'
,
'properties'
,
0
,
''
,
0
,
'song_s'
,
'2016-07-11 11:15:11'
,
'song_s'
,
'2016-07-11 11:15:11'
),
(
144
,
'datasourcexml'
,
'100003173'
,
'xml'
,
1
,
''
,
0
,
'apollo'
,
'2016-07-11 12:08:29'
,
'apollo'
,
'2016-07-11 12:08:29'
),
(
145
,
'datasource.xml'
,
'100003173'
,
'xml'
,
0
,
''
,
0
,
'apollo'
,
'2016-07-11 12:09:30'
,
'apollo'
,
'2016-07-11 12:09:30'
);
apollo-portal/src/test/resources/sql/cleanup.sql
浏览文件 @
4c64de67
...
@@ -2,3 +2,4 @@ delete from Permission;
...
@@ -2,3 +2,4 @@ delete from Permission;
delete
from
Role
;
delete
from
Role
;
delete
from
RolePermission
;
delete
from
RolePermission
;
delete
from
UserRole
;
delete
from
UserRole
;
delete
from
AppNamespace
;
apollo-portal/src/test/resources/sql/insert-test-permissions.sql
→
apollo-portal/src/test/resources/sql/
permission/
insert-test-permissions.sql
浏览文件 @
4c64de67
文件已移动
apollo-portal/src/test/resources/sql/insert-test-rolepermissions.sql
→
apollo-portal/src/test/resources/sql/
permission/
insert-test-rolepermissions.sql
浏览文件 @
4c64de67
文件已移动
apollo-portal/src/test/resources/sql/insert-test-roles.sql
→
apollo-portal/src/test/resources/sql/
permission/
insert-test-roles.sql
浏览文件 @
4c64de67
文件已移动
apollo-portal/src/test/resources/sql/insert-test-userroles.sql
→
apollo-portal/src/test/resources/sql/
permission/
insert-test-userroles.sql
浏览文件 @
4c64de67
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录