Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
66c4f954
Commit
66c4f954
authored
Jul 15, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unit test
parent
d13244c8
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
563 additions
and
40 deletions
+563
-40
NamespaceLockAspect.java
...ramework/apollo/adminservice/aop/NamespaceLockAspect.java
+2
-2
NamespaceLockController.java
...ollo/adminservice/controller/NamespaceLockController.java
+0
-1
AllTests.java
...ava/com/ctrip/framework/apollo/adminservice/AllTests.java
+2
-1
NamespaceLockTest.java
.../framework/apollo/adminservice/aop/NamespaceLockTest.java
+150
-0
cleanup.sql
...lo-adminservice/src/test/resources/controller/cleanup.sql
+2
-0
AppNamespaceService.java
.../framework/apollo/portal/service/AppNamespaceService.java
+1
-2
RoleInitializationService.java
...work/apollo/portal/service/RoleInitializationService.java
+3
-4
ConfigNamespaceController.js
...ic/scripts/controller/config/ConfigNamespaceController.js
+2
-0
namespace-panel-directive.js
...ces/static/scripts/directive/namespace-panel-directive.js
+4
-4
AbstractIntegrationTest.java
...trip/framework/apollo/portal/AbstractIntegrationTest.java
+1
-1
AbstractUnitTest.java
...a/com/ctrip/framework/apollo/portal/AbstractUnitTest.java
+9
-0
AllTests.java
...test/java/com/ctrip/framework/apollo/portal/AllTests.java
+8
-1
ServiceExceptionTest.java
...m/ctrip/framework/apollo/portal/ServiceExceptionTest.java
+1
-1
AppNamespaceServiceTest.java
...mework/apollo/portal/service/AppNamespaceServiceTest.java
+130
-0
ConfigServiceTest.java
...ip/framework/apollo/portal/service/ConfigServiceTest.java
+1
-1
NamespaceServiceTest.java
...framework/apollo/portal/service/NamespaceServiceTest.java
+1
-1
RoleInitializationServiceTest.java
.../apollo/portal/service/RoleInitializationServiceTest.java
+159
-0
RolePermissionServiceTest.java
...work/apollo/portal/service/RolePermissionServiceTest.java
+18
-18
FileTextResolverTest.java
...ollo/portal/service/txtresolver/FileTextResolverTest.java
+56
-0
PropertyResolverTest.java
...ollo/portal/service/txtresolver/PropertyResolverTest.java
+3
-3
init-appnamespace.sql
...t/resources/sql/appnamespaceservice/init-appnamespace.sql
+9
-0
cleanup.sql
apollo-portal/src/test/resources/sql/cleanup.sql
+1
-0
insert-test-permissions.sql
...test/resources/sql/permission/insert-test-permissions.sql
+0
-0
insert-test-rolepermissions.sql
.../resources/sql/permission/insert-test-rolepermissions.sql
+0
-0
insert-test-roles.sql
...l/src/test/resources/sql/permission/insert-test-roles.sql
+0
-0
insert-test-userroles.sql
...c/test/resources/sql/permission/insert-test-userroles.sql
+0
-0
No files found.
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/aop/NamespaceLockAspect.java
View file @
66c4f954
...
@@ -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,7 @@ public class NamespaceLockAspect {
...
@@ -82,7 +82,7 @@ public class NamespaceLockAspect {
acquireLock
(
namespace
,
currentUser
);
acquireLock
(
namespace
,
currentUser
);
}
}
private
void
acquireLock
(
long
namespaceId
,
String
currentUser
)
{
void
acquireLock
(
long
namespaceId
,
String
currentUser
)
{
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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
...
@@ -119,10 +119,10 @@ directive_module.directive('apollonspanel',
...
@@ -119,10 +119,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
);
}
}
}
//local method
//local method
...
...
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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
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
View file @
66c4f954
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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
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
View file @
66c4f954
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
View file @
66c4f954
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
View file @
66c4f954
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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
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.AbstractIntegrationTest
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
java.util.Arrays
;
import
java.util.Collections
;
public
class
FileTextResolverTest
extends
AbstractIntegrationTest
{
@Qualifier
(
"fileTextResolver"
)
@Autowired
private
ConfigTextResolver
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
View file @
66c4f954
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.
AbstractIntegrationTest
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -15,7 +15,7 @@ import java.util.Arrays;
...
@@ -15,7 +15,7 @@ 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
Integration
Test
{
@Autowired
@Autowired
@Qualifier
(
"propertyResolver"
)
@Qualifier
(
"propertyResolver"
)
...
...
apollo-portal/src/test/resources/sql/appnamespaceservice/init-appnamespace.sql
0 → 100644
View file @
66c4f954
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
View file @
66c4f954
...
@@ -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
View file @
66c4f954
File moved
apollo-portal/src/test/resources/sql/insert-test-rolepermissions.sql
→
apollo-portal/src/test/resources/sql/
permission/
insert-test-rolepermissions.sql
View file @
66c4f954
File moved
apollo-portal/src/test/resources/sql/insert-test-roles.sql
→
apollo-portal/src/test/resources/sql/
permission/
insert-test-roles.sql
View file @
66c4f954
File moved
apollo-portal/src/test/resources/sql/insert-test-userroles.sql
→
apollo-portal/src/test/resources/sql/
permission/
insert-test-userroles.sql
View file @
66c4f954
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment