Skip to content

Package: AuthorizationServiceSteps

AuthorizationServiceSteps

nameinstructionbranchcomplexitylinemethod
AuthorizationServiceSteps(StepData, DBHelper)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
accessInfoServiceSanityCheck()
M: 53 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
accessPermissionFactorySanityCheck()
M: 90 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 21 C: 0
0%
M: 1 C: 0
0%
accessRoleFactorySanityCheck()
M: 77 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
accessRoleWithNameIsFinded(String)
M: 54 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
afterScenario()
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
beforeScenario(Scenario)
M: 148 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
chackThatNothingWasFound()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
chackThatSomethingWasFound()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkAccessInfoEntityPermissions()
M: 38 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
checkAccessInfoEntityRoles()
M: 43 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
checkAccessPermissionComparison()
M: 134 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 31 C: 0
0%
M: 1 C: 0
0%
checkAccessRoleComparison()
M: 93 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 25 C: 0
0%
M: 1 C: 0
0%
checkDomainAgainstCreator()
M: 57 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
checkDomainAgainstParameters(List)
M: 56 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
checkDomainComparison()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkDomainIsNull()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkDomainNotNull()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkEntityAgainstCreator()
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
checkFoundGroup()
M: 48 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
checkGroupAgainstCreator()
M: 42 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
checkGroupIsNull()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkGroupName(String)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkGroupNotNull()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkIncreasedCountResult(Long)
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
checkLastRoleAgainstCreator()
M: 39 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
checkNoGroupWasFound()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkPermissionComparison()
M: 175 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 40 C: 0
0%
M: 1 C: 0
0%
checkPermissionsAgainstList(List)
M: 60 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
checkPermissionsAgainstRole()
M: 63 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
checkRoleEqualityMethod()
M: 59 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
checkRoleForUpdates()
M: 52 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
checkRolePermissionConstructors()
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
checkRolePermissionEqualityMethod()
M: 98 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
checkThatAccessInfoEntityExists()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkThatAccessRoleWasCreated()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkThatAnAccessInfoEntityWasFound()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkThatAnAccessInfoEntityWasNotFound()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkThatAnAccessPermissionWasFound()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkThatAnAccessRoleEntityWasFound()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkThatNoPermissionWasFound()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkThatRoleWasCreated()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkThatTheGroupWasFound()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkThatThePermissionsWereRemoved()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkThatTheRolesWereRemoved()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
checkUpdatedGroup()
M: 48 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
countAccesRolesInScope(Integer)
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
countAccessInfoEntitiesInScope(Integer)
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
countDomainEntries()
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
countGroupEntries()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
countGroupsInScope(int)
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
countPermissionsForScope(Integer)
M: 34 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
countRolePermissionsInScope(Integer)
M: 34 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
countRolesInScope(int)
M: 33 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
createAListOfDomains(List)
M: 77 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
createAListOfGroups(List)
M: 66 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
createAListOfRolePermissions(List)
M: 98 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 24 C: 0
0%
M: 1 C: 0
0%
createAListOfRoles(List)
M: 111 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
createAccessInfoEntity()
M: 85 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 21 C: 0
0%
M: 1 C: 0
0%
createAccessRole()
M: 54 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
createCleanAccessInfoEntity()
M: 57 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
createPermissionEntries()
M: 86 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
createPermissionsForDomain(String)
M: 116 C: 0
0%
M: 8 C: 0
0%
M: 7 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
deleteGroupWithName(String)
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
deleteGroupWithRandomId()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
deleteLastCreatedAccessInfoEntity()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
deleteLastCreatedAccessRoleEntry()
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
deleteLastCreatedDomain()
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
deleteLastCreatedPermission()
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
deleteLastCreatedRolePermission()
M: 21 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
deleteRandomDomainId()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
deleteRoleWithName(String)
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
findDomainByRememberedId()
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
findGroupByRememberedId(String)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
findLastCreatedAccessInfoEntity()
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
findLastCreatedAccessRole()
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
findLastCreatedRolePermission()
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
findPermissionsForTheLastCreatedRole()
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
findRoleWithName(String)
M: 35 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
findTheAccessInfoEntityByUserId()
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
findTheLastCreatedAccessPermission()
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
findThePermissionsOfTheLastAccessInfoEntity()
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
findTheRolesOfTheLastAccessInfoEntity()
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iAddAccessRoleToUserInChildAccount(String, String, String)
M: 84 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
iAddAccessRolesToUser(String)
M: 81 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
iAddPermissionsToTheRole()
M: 72 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
iChangeDevicesGroup()
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
iChangeTheGroupDescriptionTo(String, String)
M: 36 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iChangeTheGroupNameTo(String, String)
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iCountTheAccessRolesFromUser(String)
M: 54 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
iCountTheAccessRolesFromUserInChildAccount(String)
M: 54 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
iCountTheRolesInTheDatabase()
M: 34 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iCreateAGroupWithName(String)
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iCreateANewRoleEntityFromTheExistingCreator()
M: 38 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iCreateRoleInSubaccount(String, String)
M: 43 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iCreateRoles(int)
M: 38 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iCreateTheAccessInfoEntities()
M: 109 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
iCreateTheAccessInfoEntityInChildAccount(String)
M: 90 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
iCreateTheFollowingRolePermissionInSubaccount(String, List)
M: 103 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 25 C: 0
0%
M: 1 C: 0
0%
iCreateTheGroupWithName(String, String)
M: 35 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iCreateTheRoles(List)
M: 63 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
iDeleteAccessRolePermissions()
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
iDeleteTheDefaultRolePermission()
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iDeleteTheLastCreatedAdminRolePermissions()
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iDeleteTheLastCreatedRolePermissions()
M: 32 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iDeleteTheRoleWithNameAndDescription(String, String)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iFindARoleWithDescription(String)
M: 46 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iFindGrantedUsersWithName(List)
M: 43 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iFindLastCreatedGroup(String)
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
iFindRoleWithName(String)
M: 53 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
iFindSpecificRoleInChildAccount(String, String)
M: 35 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
iFindTheGroupWithDescription(String)
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
iPrepareARoleCreatorWithNameAndDescription(String, String)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
iSearchForAGroupNamed(String)
M: 42 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
iSearchForAccessRolesFromTheLastUser(String)
M: 52 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iSearchForTheGroupWithDescription(String)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iSearchForThePermissionsOfFoundedRoleInSubaccount(String, String)
M: 90 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
iSearchForThePermissionsOfTheRole(String)
M: 80 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
iSearchGrantedUserToRole()
M: 83 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
iTryToCreateInvalidGroups()
M: 53 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
iTryToCreateRolesWithInvalidCharactersInDescription(String)
M: 60 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
iTryToCreateRolesWithInvalidCharactersInName(String)
M: 50 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
iTryToCreateTheGroupWithInvalidCharactersInNameAndDescription(String, String)
M: 54 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
iTryToCreateTheGroupWithSpecialCharactersInDescription(String)
M: 60 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
iUpdateTheGroupDescriptionFromTo(String, String)
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iUpdateTheGroupDescriptionFromToDescriptionWithSpecialCharacters(String)
M: 77 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
iUpdateTheGroupNameFromTo(String, String)
M: 29 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
iUpdateTheGroupNameFromToNameWithSpecialCharacters(String, String)
M: 54 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
iUpdateTheRoleDescriptionTo(String)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iUpdateTheRoleName(String)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
iUpdateTheRoleNameWithSpecialCharacters(String)
M: 74 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
lambda$checkDomainComparison$0()
M: 95 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
performRoleFactorySanityChecks()
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
performRolePermissionFactorySanityChecks()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
permissionFactorySanityChecks()
M: 99 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 23 C: 0
0%
M: 1 C: 0
0%
provideInvalidRoleObjectID()
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
provideRoleForDomain(String)
M: 64 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
queryForGroup(String, int)
M: 61 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
queryForLastUserAccessInfoEntities()
M: 62 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
queryForNamedDomain(String)
M: 47 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
queryForRoleInScope(String, Integer)
M: 62 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
roleInChildAccountIsFound(String, String)
M: 34 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
searchForRandomId()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
selectExistingDomain(String)
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
setConfigurationValue(List)
M: 69 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
setGroupConfigurationValue(List)
M: 69 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
setInitialCount()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setRoleServiceConfig(int, List)
M: 36 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tryToDeleteGroupWithName(String)
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
updateGroupWithFalseId()
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
updateLastGroupName(String)
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
updateRoleNameTo(String)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
verifyThatRolePermissionsMatch()
M: 37 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
verifyThatRolesMatch()
M: 52 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2020, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.authorization.steps;
14:
15: import cucumber.api.Scenario;
16: import cucumber.api.java.After;
17: import cucumber.api.java.Before;
18: import cucumber.api.java.en.And;
19: import cucumber.api.java.en.Given;
20: import cucumber.api.java.en.Then;
21: import cucumber.api.java.en.When;
22: import cucumber.runtime.java.guice.ScenarioScoped;
23: import org.apache.shiro.SecurityUtils;
24: import org.eclipse.kapua.KapuaException;
25: import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
26: import org.eclipse.kapua.commons.security.KapuaSession;
27: import org.eclipse.kapua.commons.util.xml.XmlUtil;
28: import org.eclipse.kapua.locator.KapuaLocator;
29: import org.eclipse.kapua.model.KapuaNamedEntityAttributes;
30: import org.eclipse.kapua.model.domain.Actions;
31: import org.eclipse.kapua.model.id.KapuaId;
32: import org.eclipse.kapua.model.query.predicate.AttributePredicate;
33: import org.eclipse.kapua.qa.common.DBHelper;
34: import org.eclipse.kapua.qa.common.StepData;
35: import org.eclipse.kapua.qa.common.TestBase;
36: import org.eclipse.kapua.qa.common.TestDomain;
37: import org.eclipse.kapua.qa.common.TestJAXBContextProvider;
38: import org.eclipse.kapua.qa.common.cucumber.CucUser;
39: import org.eclipse.kapua.qa.common.cucumber.CucRolePermission;
40: import org.eclipse.kapua.qa.common.cucumber.CucDomain;
41: import org.eclipse.kapua.qa.common.cucumber.CucGroup;
42: import org.eclipse.kapua.qa.common.cucumber.CucRole;
43: import org.eclipse.kapua.qa.common.cucumber.CucConfig;
44: import org.eclipse.kapua.service.account.Account;
45: import org.eclipse.kapua.service.authorization.access.AccessInfo;
46: import org.eclipse.kapua.service.authorization.access.AccessInfoAttributes;
47: import org.eclipse.kapua.service.authorization.access.AccessInfoCreator;
48: import org.eclipse.kapua.service.authorization.access.AccessInfoFactory;
49: import org.eclipse.kapua.service.authorization.access.AccessInfoListResult;
50: import org.eclipse.kapua.service.authorization.access.AccessInfoQuery;
51: import org.eclipse.kapua.service.authorization.access.AccessInfoService;
52: import org.eclipse.kapua.service.authorization.access.AccessPermission;
53: import org.eclipse.kapua.service.authorization.access.AccessPermissionCreator;
54: import org.eclipse.kapua.service.authorization.access.AccessPermissionFactory;
55: import org.eclipse.kapua.service.authorization.access.AccessPermissionListResult;
56: import org.eclipse.kapua.service.authorization.access.AccessPermissionQuery;
57: import org.eclipse.kapua.service.authorization.access.AccessPermissionService;
58: import org.eclipse.kapua.service.authorization.access.AccessRole;
59: import org.eclipse.kapua.service.authorization.access.AccessRoleAttributes;
60: import org.eclipse.kapua.service.authorization.access.AccessRoleCreator;
61: import org.eclipse.kapua.service.authorization.access.AccessRoleFactory;
62: import org.eclipse.kapua.service.authorization.access.AccessRoleListResult;
63: import org.eclipse.kapua.service.authorization.access.AccessRoleQuery;
64: import org.eclipse.kapua.service.authorization.access.AccessRoleService;
65: import org.eclipse.kapua.service.authorization.domain.Domain;
66: import org.eclipse.kapua.service.authorization.domain.DomainCreator;
67: import org.eclipse.kapua.service.authorization.domain.DomainFactory;
68: import org.eclipse.kapua.service.authorization.domain.DomainListResult;
69: import org.eclipse.kapua.service.authorization.domain.DomainQuery;
70: import org.eclipse.kapua.service.authorization.domain.DomainRegistryService;
71: import org.eclipse.kapua.service.authorization.group.Group;
72: import org.eclipse.kapua.service.authorization.group.GroupCreator;
73: import org.eclipse.kapua.service.authorization.group.GroupFactory;
74: import org.eclipse.kapua.service.authorization.group.GroupListResult;
75: import org.eclipse.kapua.service.authorization.group.GroupQuery;
76: import org.eclipse.kapua.service.authorization.group.GroupService;
77: import org.eclipse.kapua.service.authorization.permission.Permission;
78: import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
79: import org.eclipse.kapua.service.authorization.role.Role;
80: import org.eclipse.kapua.service.authorization.role.RolePermission;
81: import org.eclipse.kapua.service.authorization.role.RoleListResult;
82: import org.eclipse.kapua.service.authorization.role.RolePermissionAttributes;
83: import org.eclipse.kapua.service.authorization.role.RolePermissionQuery;
84: import org.eclipse.kapua.service.authorization.role.RolePermissionListResult;
85: import org.eclipse.kapua.service.authorization.role.RoleQuery;
86: import org.eclipse.kapua.service.authorization.role.RoleCreator;
87: import org.eclipse.kapua.service.authorization.role.RolePermissionService;
88: import org.eclipse.kapua.service.authorization.role.RolePermissionFactory;
89: import org.eclipse.kapua.service.authorization.role.RoleFactory;
90: import org.eclipse.kapua.service.authorization.role.RoleService;
91: import org.eclipse.kapua.service.device.registry.Device;
92: import org.eclipse.kapua.service.authorization.role.RolePermissionCreator;
93: import org.eclipse.kapua.service.user.User;
94: import org.eclipse.kapua.service.user.UserFactory;
95: import org.eclipse.kapua.service.user.UserService;
96: import org.slf4j.Logger;
97: import org.slf4j.LoggerFactory;
98:
99: import javax.inject.Inject;
100: import java.util.ArrayList;
101: import java.util.HashMap;
102: import java.util.HashSet;
103: import java.util.List;
104: import java.util.Map;
105: import java.util.Set;
106:
107: // Implementation of Gherkin steps used to test miscellaneous Shiro
108: // authorization functionality.
109:
110: @ScenarioScoped
111: public class AuthorizationServiceSteps extends TestBase {
112:
113: private static final String ACCESS_INFO = "AccessInfo";
114: private static final String ACCESS_INFO_CREATOR = "AccessInfoCreator";
115: private static final String ACCESS_INFO_FOUND = "AccessInfoFound";
116: private static final String ACCESS_PERMISSIONS = "AccessPermissions";
117: private static final String ACCESS_PERMISSION_FOUND = "AccessPermissionFound";
118: private static final String ACCESS_ROLE = "AccessRole";
119: private static final String ACCESS_ROLES = "AccessRoles";
120: private static final String ACCESS_ROLE_FOUND = "AccessRoleFound";
121: private static final String CHILD_ACCOUNT_ACCESS_INFO = "ChildAccountAccessInfo";
122: private static final String CHILD_ACCOUNT_ROLE_PERMISSION = "ChildAccountRolePermission";
123: private static final String COUNT = "Count";
124: private static final String DOMAIN = "Domain";
125: private static final String DOMAIN_CREATOR = "DomainCreator";
126: private static final String DOMAIN_ID = "DomainId";
127: private static final String GROUP = "Group";
128: private static final String GROUP_CREATOR = "GroupCreator";
129: private static final String GROUP_SECOND = "GroupSecond";
130: private static final String GROUP_NAME = "GroupName";
131: private static final String LAST_ACCESS_PERMISSION = "LastAccessPermission";
132: private static final String LAST_ACCOUNT = "LastAccount";
133: private static final String LAST_ACCOUNT_ID = "LastAccountId";
134: private static final String PERMISSIONS = "Permissions";
135: private static final String PERMISSION_LIST = "PermissionList";
136: private static final String ROLE_CREATOR = "RoleCreator";
137: private static final String ROLE_FOUND = "RoleFound";
138: private static final String ROLE_IDS = "RoleIds";
139: private static final String ROLE_LIST = "RoleList";
140: private static final String ROLE_LIST_RESULT = "RoleListResult";
141: private static final String ROLE_NAME = "roleName";
142: private static final String ROLE_PERMISSION = "RolePermission";
143: private static final String ROLE_PERMISSIONS = "RolePermissions";
144: private static final String ROLE_PERMISSION_FOUND = "RolePermissionFound";
145:
146: private static final Logger logger = LoggerFactory.getLogger(AuthorizationServiceSteps.class);
147: private static final TestDomain TEST_DOMAIN = new TestDomain();
148:
149: // Various Authorization service references
150: private PermissionFactory permissionFactory;
151: private AccessInfoService accessInfoService;
152: private AccessInfoFactory accessInfoFactory;
153: private AccessPermissionService accessPermissionService;
154: private AccessPermissionFactory accessPermissionFactory;
155: private AccessRoleService accessRoleService;
156: private AccessRoleFactory accessRoleFactory;
157: private DomainRegistryService domainRegistryService;
158: private DomainFactory domainFactory;
159: private GroupService groupService;
160: private GroupFactory groupFactory;
161: private RoleService roleService;
162: private RoleFactory roleFactory;
163: private RolePermissionService rolePermissionService;
164: private RolePermissionFactory rolePermissionFactory;
165: private UserService userService;
166: private UserFactory userFactory;
167:
168: @Inject
169: public AuthorizationServiceSteps(StepData stepData, DBHelper dbHelper) {
170:
171: this.stepData = stepData;
172: this.database = dbHelper;
173: }
174:
175: // Database setup and tear-down steps
176: @Before
177: public void beforeScenario(Scenario scenario) {
178:
179: this.scenario = scenario;
180: database.setup();
181: stepData.clear();
182:
183: locator = KapuaLocator.getInstance();
184: accessInfoService = locator.getService(AccessInfoService.class);
185: accessInfoFactory = locator.getFactory(AccessInfoFactory.class);
186: accessPermissionService = locator.getService(AccessPermissionService.class);
187: accessPermissionFactory = locator.getFactory(AccessPermissionFactory.class);
188: accessRoleService = locator.getService(AccessRoleService.class);
189: accessRoleFactory = locator.getFactory(AccessRoleFactory.class);
190: domainRegistryService = locator.getService(DomainRegistryService.class);
191: domainFactory = locator.getFactory(DomainFactory.class);
192: groupService = locator.getService(GroupService.class);
193: groupFactory = locator.getFactory(GroupFactory.class);
194: roleService = locator.getService(RoleService.class);
195: roleFactory = locator.getFactory(RoleFactory.class);
196: rolePermissionService = locator.getService(RolePermissionService.class);
197: rolePermissionFactory = locator.getFactory(RolePermissionFactory.class);
198: permissionFactory = locator.getFactory(PermissionFactory.class);
199: userFactory = locator.getFactory(UserFactory.class);
200: userService = locator.getService(UserService.class);
201:
202:• if (isUnitTest()) {
203: // Create KapuaSession using KapuaSecurtiyUtils and kapua-sys user as logged in user.
204: // All operations on database are performed using system user.
205: // Only for unit tests. Integration tests assume that a real logon is performed.
206: KapuaSession kapuaSession = new KapuaSession(null, SYS_SCOPE_ID, SYS_USER_ID);
207: KapuaSecurityUtils.setSession(kapuaSession);
208: }
209:
210: XmlUtil.setContextProvider(new TestJAXBContextProvider());
211: }
212:
213: @After
214: public void afterScenario() {
215:
216: // Clean up the database
217: try {
218: logger.info("Logging out in cleanup");
219:• if (isIntegrationTest()) {
220: database.deleteAll();
221: SecurityUtils.getSubject().logout();
222: } else {
223: database.dropAll();
224: database.close();
225: }
226: KapuaSecurityUtils.clearSession();
227: } catch (Exception e) {
228: logger.error("Failed to log out in @After", e);
229: }
230: }
231:
232: // Cucumber test steps
233:
234: @When("^I configure the role service$")
235: public void setConfigurationValue(List<CucConfig> cucConfigs)
236: throws Exception {
237:
238: Map<String, Object> valueMap = new HashMap<>();
239: KapuaId scopeId;
240: KapuaId parentScopeId;
241: Account tmpAccount = (Account) stepData.get(LAST_ACCOUNT);
242:
243:• if (tmpAccount != null) {
244: scopeId = tmpAccount.getId();
245: parentScopeId = tmpAccount.getScopeId();
246: } else {
247: scopeId = SYS_SCOPE_ID;
248: parentScopeId = SYS_SCOPE_ID;
249: }
250:
251:• for (CucConfig config : cucConfigs) {
252: config.addConfigToMap(valueMap);
253:• if (config.getScopeId() != null) {
254: scopeId = getKapuaId(config.getScopeId());
255: }
256:• if (config.getParentId() != null) {
257: parentScopeId = getKapuaId(config.getParentId());
258: }
259: }
260: try {
261: primeException();
262: roleService.setConfigValues(scopeId, parentScopeId, valueMap);
263: } catch (KapuaException ex) {
264: verifyException(ex);
265: }
266: }
267:
268: @When("^I configure the role service for the account with the id (\\d+)$")
269: public void setRoleServiceConfig(int accountId, List<CucConfig> cucConfigs)
270: throws Exception {
271:
272: Map<String, Object> valueMap = new HashMap<>();
273: KapuaId accId = getKapuaId(accountId);
274:
275:• for (CucConfig config : cucConfigs) {
276: config.addConfigToMap(valueMap);
277: }
278:
279: primeException();
280: try {
281: roleService.setConfigValues(accId, SYS_SCOPE_ID, valueMap);
282: } catch (KapuaException ex) {
283: verifyException(ex);
284: }
285: }
286:
287: @Given("^I create the following role(?:|s)$")
288: public void createAListOfRoles(List<CucRole> roles)
289: throws Exception {
290:
291: Domain domain = (Domain) stepData.get(DOMAIN);
292: RoleCreator roleCreator = null;
293: Set<Permission> permissions;
294: Role role = null;
295:
296: stepData.remove(PERMISSIONS);
297: stepData.remove(ROLE_CREATOR);
298: stepData.remove("Role");
299:
300: primeException();
301:• for (CucRole tmpRole : roles) {
302: tmpRole.doParse();
303: permissions = new HashSet<>();
304:• if ((tmpRole.getActions() != null) && (tmpRole.getActions().size() > 0)) {
305:• for (Actions tmpAct : tmpRole.getActions()) {
306: permissions.add(permissionFactory.newPermission(domain.getDomain(), tmpAct, tmpRole.getScopeId()));
307: }
308: }
309: roleCreator = roleFactory.newCreator(tmpRole.getScopeId());
310: roleCreator.setName(tmpRole.getName());
311: roleCreator.setPermissions(permissions);
312: try {
313: role = roleService.create(roleCreator);
314: stepData.put(PERMISSIONS, permissions);
315: stepData.put(ROLE_CREATOR, roleCreator);
316: stepData.put("Role", role);
317: } catch (KapuaException ex) {
318: verifyException(ex);
319: }
320: }
321: }
322:
323: @Given("^I create the following role permission(?:|s)$")
324: public void createAListOfRolePermissions(List<CucRolePermission> perms)
325: throws Exception {
326:
327: Role role = (Role) stepData.get("Role");
328: Domain domain = (Domain) stepData.get(DOMAIN);
329: RolePermission rolePermission = null;
330: ArrayList<RolePermission> rolePermissions = new ArrayList<>();
331:
332: stepData.remove(ROLE_PERMISSION);
333:
334: primeException();
335:• for (CucRolePermission tmpCPerm : perms) {
336: tmpCPerm.doParse();
337: assertNotNull(tmpCPerm.getScopeId());
338: assertNotNull(tmpCPerm.getAction());
339:
340: domain.setScopeId(tmpCPerm.getScopeId());
341:
342: RolePermissionCreator rolePermissionCreator = rolePermissionFactory.newCreator(tmpCPerm.getScopeId());
343: rolePermissionCreator.setRoleId(role.getId());
344: rolePermissionCreator.setPermission(permissionFactory.newPermission(domain.getDomain(), tmpCPerm.getAction(), tmpCPerm.getTargetScopeId()));
345:
346: try {
347: stepData.remove(ROLE_PERMISSIONS);
348: rolePermission = rolePermissionService.create(rolePermissionCreator);
349: rolePermissions.add(rolePermission);
350: stepData.put(ROLE_PERMISSIONS, rolePermissions);
351: } catch (KapuaException ex) {
352: verifyException(ex);
353: }
354: }
355:
356: stepData.put(ROLE_PERMISSION, rolePermission);
357: }
358:
359: @When("^I update the last created role name to \"(.+)\"$")
360: public void updateRoleNameTo(String name)
361: throws Exception {
362:
363: Role role = roleFactory.clone((Role) stepData.get("Role"));
364: role.setName(name);
365: Thread.sleep(200);
366:
367: try {
368: primeException();
369: roleService.update(role);
370: } catch (KapuaException ex) {
371: verifyException(ex);
372: }
373: }
374:
375: @When("^I examine the permissions for the last role$")
376: public void findPermissionsForTheLastCreatedRole()
377: throws Exception {
378:
379: Role role = (Role) stepData.get("Role");
380:
381: stepData.remove(PERMISSION_LIST);
382:
383: primeException();
384: try {
385: RolePermissionListResult permissionList = rolePermissionService.findByRoleId(
386: role.getScopeId(), role.getId());
387: stepData.put(PERMISSION_LIST, permissionList);
388: } catch (KapuaException ex) {
389: verifyException(ex);
390: }
391: }
392:
393: @When("^I search for the role with name \"(.*)\"$")
394: public void findRoleWithName(String roleName)
395: throws Exception {
396:
397: Role role = (Role) stepData.get("Role");
398: assertEquals(roleName, role.getName());
399:
400: stepData.remove(ROLE_FOUND);
401:
402: primeException();
403: try {
404: Role roleFound = roleService.find(role.getScopeId(), role.getId());
405: stepData.put(ROLE_FOUND, roleFound);
406: } catch (KapuaException ex) {
407: verifyException(ex);
408: }
409: }
410:
411: @When("^I search for the last created role permission$")
412: public void findLastCreatedRolePermission()
413: throws Exception {
414:
415: RolePermission rolePermission = (RolePermission) stepData.get(ROLE_PERMISSION);
416: stepData.remove(ROLE_PERMISSION_FOUND);
417:
418: primeException();
419: try {
420: RolePermission rolePermissionFound = rolePermissionService.find(
421: rolePermission.getScopeId(), rolePermission.getId());
422: stepData.put(ROLE_PERMISSION_FOUND, rolePermissionFound);
423: } catch (KapuaException ex) {
424: verifyException(ex);
425: }
426: }
427:
428: @When("^I search for a random role ID$")
429: public void searchForRandomId()
430: throws Exception {
431:
432: primeException();
433: try {
434: Role roleFound = roleService.find(SYS_SCOPE_ID, getKapuaId());
435: stepData.put(ROLE_FOUND, roleFound);
436: } catch (KapuaException ex) {
437: verifyException(ex);
438: }
439: }
440:
441: @When("^I delete the role with name \"([^\"]*)\"$")
442: public void deleteRoleWithName(String roleName)
443: throws Exception {
444:
445: Role role = (Role) stepData.get("Role");
446:
447: primeException();
448: try {
449: assertEquals(roleName, role.getName());
450: KapuaId roleId = role.getId();
451: roleService.delete(role.getScopeId(), roleId);
452: } catch (KapuaException ex) {
453: verifyException(ex);
454: }
455: }
456:
457: @When("^I delete the last created role permission$")
458: public void deleteLastCreatedRolePermission()
459: throws Exception {
460:
461: RolePermission rolePermission = (RolePermission) stepData.get(ROLE_PERMISSION);
462:
463: primeException();
464: try {
465: rolePermissionService.delete(rolePermission.getScopeId(), rolePermission.getId());
466: } catch (KapuaException ex) {
467: verifyException(ex);
468: }
469: }
470:
471: @When("^I count the roles in scope (\\d+)$")
472: public void countRolesInScope(int scope)
473: throws Exception {
474:
475: KapuaId tmpId = getKapuaId(scope);
476: RoleQuery tmpQuery = roleFactory.newQuery(tmpId);
477:
478: stepData.remove(COUNT);
479:
480: primeException();
481: try {
482: Long count = roleService.count(tmpQuery);
483: stepData.put(COUNT, count);
484: } catch (KapuaException ex) {
485: verifyException(ex);
486: }
487: }
488:
489: @When("^I count the role permissions in scope (\\d+)$")
490: public void countRolePermissionsInScope(Integer scope)
491: throws Exception {
492:
493: KapuaId tmpId = getKapuaId(scope);
494: RolePermissionQuery tmpQuery = rolePermissionFactory.newQuery(tmpId);
495:
496: stepData.remove(COUNT);
497:
498: primeException();
499: try {
500: Long count = rolePermissionService.count(tmpQuery);
501: stepData.put(COUNT, count);
502: } catch (KapuaException ex) {
503: verifyException(ex);
504: }
505: }
506:
507: @When("^I query for the role \"(.+)\" in scope (\\d+)$")
508: public void queryForRoleInScope(String name, Integer scope)
509: throws Exception {
510:
511: KapuaId tmpId = getKapuaId(scope);
512: RoleQuery tmpQuery = roleFactory.newQuery(tmpId);
513: tmpQuery.setPredicate(tmpQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, name, AttributePredicate.Operator.EQUAL));
514:
515: stepData.remove(ROLE_LIST);
516: stepData.remove(ROLE_FOUND);
517: stepData.remove(COUNT);
518:
519: primeException();
520: try {
521: RoleListResult roleList = roleService.query(tmpQuery);
522: stepData.put(ROLE_LIST, roleList);
523: stepData.put(ROLE_FOUND, roleList.getFirstItem());
524: stepData.put(COUNT, Long.valueOf(roleList.getSize()));
525: } catch (KapuaException ex) {
526: verifyException(ex);
527: }
528: }
529:
530: @Then("^The role was found$")
531: public void chackThatSomethingWasFound() {
532: assertNotNull(stepData.get(ROLE_FOUND));
533: }
534:
535: @Then("^I find no roles$")
536: public void chackThatNothingWasFound() {
537: assertNull(stepData.get(ROLE_FOUND));
538: }
539:
540: @Then("^I find no permissions$")
541: public void checkThatNoPermissionWasFound() {
542: assertNull(stepData.get(ROLE_PERMISSION_FOUND));
543: }
544:
545: @Then("^The role matches the creator$")
546: public void checkLastRoleAgainstCreator() {
547:
548: Role role = (Role) stepData.get("Role");
549: RoleCreator roleCreator = (RoleCreator) stepData.get(ROLE_CREATOR);
550:
551: assertNotNull(role);
552: assertNotNull(roleCreator);
553: assertEquals(roleCreator.getScopeId(), role.getScopeId());
554: assertEquals(roleCreator.getName(), role.getName());
555: assertNotNull(role.getCreatedBy());
556: assertNotNull(role.getCreatedOn());
557: assertNotNull(role.getModifiedBy());
558: assertNotNull(role.getModifiedOn());
559: }
560:
561: @Then("^The permissions match$")
562: public void checkPermissionsAgainstRole() {
563:
564: Set<Permission> permissions = (Set<Permission>) stepData.get(PERMISSIONS);
565: RolePermissionListResult permissionList = (RolePermissionListResult) stepData.get(PERMISSION_LIST);
566:
567: boolean found;
568: assertNotNull(permissions);
569: assertNotNull(permissionList);
570: assertEquals(permissions.size(), permissionList.getSize());
571:• if (permissions.size() > 0) {
572:• for (RolePermission tmpRolePerm : permissionList.getItems()) {
573: found = false;
574:• for (Permission tmpPerm : permissions) {
575:• if (tmpPerm.getAction() == tmpRolePerm.getPermission().getAction()) {
576: found = true;
577: break;
578: }
579: }
580: assertTrue(found);
581: }
582: }
583: }
584:
585: @Then("^I find the following actions$")
586: public void checkPermissionsAgainstList(List<CucRole> roles) {
587:
588: RolePermissionListResult permissionList = (RolePermissionListResult) stepData.get(PERMISSION_LIST);
589:
590: assertNotNull(roles);
591: assertEquals(1, roles.size());
592: CucRole tmpRole = roles.get(0);
593: assertNotNull(tmpRole);
594: tmpRole.doParse();
595: Set<Actions> actLst = tmpRole.getActions();
596: assertNotNull(actLst);
597: assertNotNull(permissionList);
598: assertNotEquals(0, permissionList.getSize());
599: assertEquals(actLst.size(), permissionList.getSize());
600:• for (RolePermission tmpPerm : permissionList.getItems()) {
601: assertTrue(actLst.contains(tmpPerm.getPermission().getAction()));
602: }
603: }
604:
605: @Then("^The correct role entry was found$")
606: public void verifyThatRolesMatch() {
607:
608: Role role = (Role) stepData.get("Role");
609: Role roleFound = (Role) stepData.get(ROLE_FOUND);
610:
611: assertNotNull(role);
612: assertNotNull(roleFound);
613: assertEquals(role.getId(), roleFound.getId());
614: assertEquals(role.getScopeId(), roleFound.getScopeId());
615: assertEquals(role.getName(), roleFound.getName());
616: assertEquals(role.getCreatedBy(), roleFound.getCreatedBy());
617: assertEquals(role.getCreatedOn(), roleFound.getCreatedOn());
618: assertEquals(role.getModifiedBy(), roleFound.getModifiedBy());
619: assertEquals(role.getModifiedOn(), roleFound.getModifiedOn());
620: }
621:
622: @Then("^The correct role permission entry was found$")
623: public void verifyThatRolePermissionsMatch() {
624:
625: RolePermission rolePermission = (RolePermission) stepData.get(ROLE_PERMISSION);
626: RolePermission rolePermissionFound = (RolePermission) stepData.get(ROLE_PERMISSION_FOUND);
627:
628: assertNotNull(rolePermission);
629: assertNotNull(rolePermissionFound);
630: assertEquals(rolePermission.getId(), rolePermissionFound.getId());
631: assertEquals(rolePermission.getScopeId(), rolePermissionFound.getScopeId());
632: assertEquals(rolePermission.getCreatedBy(), rolePermissionFound.getCreatedBy());
633: assertEquals(rolePermission.getCreatedOn(), rolePermissionFound.getCreatedOn());
634: }
635:
636: @Then("^The role was successfully updated$")
637: public void checkRoleForUpdates() {
638:
639: Role role = (Role) stepData.get("Role");
640: Role roleFound = (Role) stepData.get(ROLE_FOUND);
641:
642: assertNotNull(role);
643: assertNotNull(roleFound);
644: assertEquals(role.getId(), roleFound.getId());
645: assertEquals(role.getScopeId(), roleFound.getScopeId());
646: assertNotEquals(role.getName(), roleFound.getName());
647: assertEquals(role.getCreatedBy(), roleFound.getCreatedBy());
648: assertEquals(role.getCreatedOn(), roleFound.getCreatedOn());
649: assertEquals(role.getModifiedBy(), roleFound.getModifiedBy());
650: assertNotEquals(role.getModifiedOn(), roleFound.getModifiedOn());
651: }
652:
653: @Then("^The role factory returns sane results$")
654: public void performRoleFactorySanityChecks() {
655:
656: assertNotNull(roleFactory.newEntity(SYS_SCOPE_ID));
657: assertNotNull(roleFactory.newCreator(SYS_SCOPE_ID));
658: assertNotNull(roleFactory.newQuery(SYS_SCOPE_ID));
659: assertNotNull(roleFactory.newListResult());
660: assertNotNull(roleFactory.newRolePermission());
661: }
662:
663: @Then("^The role permission factory returns sane results$")
664: public void performRolePermissionFactorySanityChecks() {
665:
666: assertNotNull(rolePermissionFactory.newEntity(SYS_SCOPE_ID));
667: assertNotNull(rolePermissionFactory.newCreator(SYS_SCOPE_ID));
668: assertNotNull(rolePermissionFactory.newQuery(SYS_SCOPE_ID));
669: assertNotNull(rolePermissionFactory.newListResult());
670: }
671:
672: @Then("^The role comparator does its job$")
673: public void checkRoleEqualityMethod() {
674:
675: Role role1 = roleFactory.newEntity(SYS_SCOPE_ID);
676: Role role2 = roleFactory.newEntity(SYS_SCOPE_ID);
677: Integer miscObj = 10;
678:
679: assertNotNull(role1);
680: assertNotNull(role2);
681: assertNotNull(miscObj);
682:
683: assertTrue(role1.equals(role1));
684: assertFalse(role1.equals(null));
685: assertFalse(role1.equals(miscObj));
686: assertTrue(role1.equals(role2));
687: role2.setName("test_name_2");
688: assertFalse(role1.equals(role2));
689: role1.setName("test_name_1");
690: assertFalse(role1.equals(role2));
691: role2.setName("test_name_1");
692: assertTrue(role1.equals(role2));
693: }
694:
695: @Then("^The role permission comparator does its job$")
696: public void checkRolePermissionEqualityMethod() {
697: RolePermission perm1 = rolePermissionFactory.newEntity(SYS_SCOPE_ID);
698: RolePermission perm2 = rolePermissionFactory.newEntity(SYS_SCOPE_ID);
699: Integer miscObj = 1;
700: Permission tmpPermission1 = permissionFactory.newPermission(TEST_DOMAIN, Actions.read, SYS_SCOPE_ID);
701: Permission tmpPermission2 = permissionFactory.newPermission(TEST_DOMAIN, Actions.write, SYS_SCOPE_ID);
702: KapuaId tmpRoleId1 = getKapuaId();
703: KapuaId tmpRoleId2 = getKapuaId();
704:
705: assertNotNull(perm1);
706: assertNotNull(perm2);
707: assertTrue(perm1.equals(perm1));
708: assertFalse(perm1.equals(null));
709: assertFalse(perm1.equals(miscObj));
710: assertTrue(perm1.equals(perm2));
711:
712: perm2.setPermission(tmpPermission2);
713: assertFalse(perm1.equals(perm2));
714:
715: perm1.setPermission(tmpPermission1);
716: assertFalse(perm1.equals(perm2));
717:
718: perm2.setPermission(tmpPermission1);
719: assertTrue(perm1.equals(perm2));
720:
721: perm2.setRoleId(tmpRoleId1);
722: assertFalse(perm1.equals(perm2));
723: perm1.setRoleId(tmpRoleId1);
724: assertTrue(perm1.equals(perm2));
725: perm2.setRoleId(tmpRoleId2);
726: assertFalse(perm1.equals(perm2));
727: }
728:
729: @Then("^The role permission object constructors are sane$")
730: public void checkRolePermissionConstructors() {
731:
732: Permission tmpPermission = permissionFactory.newPermission(TEST_DOMAIN, Actions.read, SYS_SCOPE_ID);
733: KapuaId tmpRoleId = getKapuaId();
734:
735: RolePermission perm1 = rolePermissionFactory.newEntity(SYS_SCOPE_ID);
736: assertNotNull(perm1);
737: // RolePermission perm2 = new RolePermissionImpl(perm1);
738: // assertNotNull(perm2);
739: // assertTrue(perm1.equals(perm2));
740: // RolePermission perm3 = new RolePermissionImpl(SYS_SCOPE_ID, tmpPermission);
741: // assertNotNull(perm3);
742: // assertEquals(perm3.getPermission(), tmpPermission);
743: perm1.setRoleId(tmpRoleId);
744: assertEquals(tmpRoleId, perm1.getRoleId());
745: perm1.setPermission(tmpPermission);
746: assertEquals(perm1.getPermission(), tmpPermission);
747: }
748:
749: @Given("^I create the domain(?:|s)$")
750: public void createAListOfDomains(List<CucDomain> domains)
751: throws Exception {
752:
753: DomainCreator domainCreator = null;
754: Domain domain = null;
755:
756: stepData.remove(DOMAIN_CREATOR);
757: stepData.remove(DOMAIN);
758: stepData.remove(DOMAIN_ID);
759:
760: primeException();
761:• for (CucDomain tmpDom : domains) {
762: tmpDom.doParse();
763:
764: domainCreator = domainFactory.newCreator(tmpDom.getName());
765:• if (tmpDom.getActionSet() != null) {
766: domainCreator.setActions(tmpDom.getActionSet());
767: }
768: domainCreator.setServiceName(tmpDom.getServiceName());
769: stepData.put(DOMAIN_CREATOR, domainCreator);
770:
771: try {
772: domain = domainRegistryService.create(domainCreator);
773: stepData.put(DOMAIN, domain);
774:• if (domain != null) {
775: stepData.put(DOMAIN_ID, domain.getId());
776: }
777: } catch (KapuaException ex) {
778: verifyException(ex);
779: }
780: }
781: }
782:
783: @Given("^I select the domain \"(.+)\"$")
784: public void selectExistingDomain(String name)
785: throws Exception {
786:
787: DomainQuery query = domainFactory.newQuery(KapuaId.ANY);
788: query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name, AttributePredicate.Operator.EQUAL));
789:
790: try {
791: primeException();
792: DomainListResult domains = domainRegistryService.query(query);
793: stepData.put(DOMAIN, domains.getFirstItem());
794: } catch (KapuaException ex) {
795: verifyException(ex);
796: }
797: }
798:
799: @When("^I search for the last created domain$")
800: public void findDomainByRememberedId()
801: throws Exception {
802:
803: KapuaId domainId = (KapuaId) stepData.get(DOMAIN_ID);
804: stepData.remove(DOMAIN);
805:
806: try {
807: primeException();
808: Domain domain = domainRegistryService.find(null, domainId);
809: stepData.put(DOMAIN, domain);
810: } catch (KapuaException ex) {
811: verifyException(ex);
812: }
813: }
814:
815: @When("^I delete the last created domain$")
816: public void deleteLastCreatedDomain()
817: throws Exception {
818:
819: KapuaId domainId = (KapuaId) stepData.get(DOMAIN_ID);
820:
821: try {
822: primeException();
823: domainRegistryService.delete(null, domainId);
824: } catch (KapuaException ex) {
825: verifyException(ex);
826: }
827: }
828:
829: @When("^I try to delete domain with a random ID$")
830: public void deleteRandomDomainId()
831: throws Exception {
832:
833: try {
834: primeException();
835: domainRegistryService.delete(null, getKapuaId());
836: } catch (KapuaException ex) {
837: verifyException(ex);
838: }
839: }
840:
841: @When("^I count the domain entries in the database$")
842: public void countDomainEntries()
843: throws Exception {
844:
845: stepData.remove(COUNT);
846:
847: try {
848: primeException();
849: DomainQuery query = domainFactory.newQuery(null);
850: Long count = domainRegistryService.count(query);
851: stepData.put(COUNT, count);
852: } catch (KapuaException ex) {
853: verifyException(ex);
854: }
855: }
856:
857: @When("^I query for domains with the name \"(.+)\"$")
858: public void queryForNamedDomain(String name)
859: throws Exception {
860:
861: DomainQuery query = domainFactory.newQuery(null);
862: query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, name, AttributePredicate.Operator.EQUAL));
863:
864: stepData.remove("DomainList");
865: stepData.remove(COUNT);
866:
867: try {
868: primeException();
869: DomainListResult domainList = domainRegistryService.query(query);
870: stepData.put("DomainList", domainList);
871: stepData.put(COUNT, Long.valueOf(domainList.getSize()));
872: } catch (KapuaException ex) {
873: verifyException(ex);
874: }
875: }
876:
877: @Then("^This is the initial count$")
878: public void setInitialCount() {
879:
880: Long startCount = (Long) stepData.get(COUNT);
881: stepData.put("InitialCount", startCount);
882: }
883:
884: @Then("^A domain was created$")
885: public void checkDomainNotNull() {
886:
887: Domain domain = (Domain) stepData.get(DOMAIN);
888: assertNotNull(domain);
889: }
890:
891: @Then("^There is no domain$")
892: public void checkDomainIsNull() {
893:
894: Domain domain = (Domain) stepData.get(DOMAIN);
895: assertNull(domain);
896: }
897:
898: // The following test step is more of a filler. The only purpose is to achieve some coverage
899: // of the Domain object equals function.
900: // It must be noted that full coverage should be impossible, since the function tests for
901: // object member combinations that should be impossible to create.
902: // Some examples are domain objects with the same name but different service name members
903: // (the name entry is defined as unique in the database). Also it tests for null
904: // values for all 3 members, but the Domain service create method will reject any domain
905: // creator with a null value for any member variable.
906: // As such this step is of limited usefulness and should be taken with a grain of salt.
907: @Then("^I can compare domain objects$")
908: public void checkDomainComparison()
909: throws KapuaException {
910:
911: KapuaSecurityUtils.doPrivileged(() -> {
912: DomainCreator tmpCreator = domainFactory.newCreator("name_1");
913: tmpCreator.setServiceName("test");
914: HashSet<Actions> tmpAct = new HashSet<>();
915: tmpAct.add(Actions.read);
916: tmpAct.add(Actions.write);
917: tmpCreator.setActions(tmpAct);
918: Domain tmpDom1 = domainRegistryService.create(tmpCreator);
919: assertNotNull(tmpDom1);
920:
921: assertTrue(tmpDom1.equals(tmpDom1));
922: assertFalse(tmpDom1.equals(null));
923: assertFalse(tmpDom1.equals(String.valueOf("")));
924:
925: Domain tmpDom2 = null;
926: tmpDom2 = domainRegistryService.find(null, tmpDom1.getId());
927: assertNotNull(tmpDom2);
928:
929: tmpCreator.setName("name_2");
930: Domain tmpDom3 = domainRegistryService.create(tmpCreator);
931: assertNotNull(tmpDom3);
932:
933: tmpCreator.setName("name_3");
934: tmpAct.remove(Actions.write);
935: tmpCreator.setActions(tmpAct);
936: Domain tmpDom4 = domainRegistryService.create(tmpCreator);
937: assertNotNull(tmpDom4);
938:
939: assertTrue(tmpDom1.equals(tmpDom2));
940: assertFalse(tmpDom1.equals(tmpDom3));
941: assertFalse(tmpDom1.equals(tmpDom4));
942: return null;
943: });
944: }
945:
946: @Then("^The domain matches the creator$")
947: public void checkDomainAgainstCreator() {
948:
949: Domain domain = (Domain) stepData.get(DOMAIN);
950: DomainCreator domainCreator = (DomainCreator) stepData.get(DOMAIN_CREATOR);
951:
952: assertNotNull(domain);
953: assertNotNull(domain.getId());
954: assertNotNull(domainCreator);
955: assertEquals(domainCreator.getName(), domain.getName());
956:• if (domainCreator.getActions() != null) {
957: assertNotNull(domain.getActions());
958: assertEquals(domainCreator.getActions().size(), domain.getActions().size());
959:• for (Actions a : domainCreator.getActions()) {
960: assertTrue(domain.getActions().contains(a));
961: }
962: }
963: }
964:
965: @Then("^The domain matches the parameters$")
966: public void checkDomainAgainstParameters(List<CucDomain> domains) {
967:
968: Domain domain = (Domain) stepData.get(DOMAIN);
969:
970: assertEquals(1, domains.size());
971: CucDomain tmpDom = domains.get(0);
972: tmpDom.doParse();
973:
974:• if (tmpDom.getName() != null) {
975: assertEquals(tmpDom.getName(), domain.getName());
976: }
977:• if (tmpDom.getActionSet() != null) {
978: assertEquals(tmpDom.getActionSet().size(), domain.getActions().size());
979:• for (Actions a : tmpDom.getActionSet()) {
980: assertTrue(domain.getActions().contains(a));
981: }
982: }
983: }
984:
985: @Then("^(\\d+) more domains (?:was|were) created$")
986: public void checkIncreasedCountResult(Long cnt) {
987:
988: Long count = (Long) stepData.get(COUNT);
989: Long initialCount = (Long) stepData.get("InitialCount");
990:
991: assertEquals(cnt.longValue(), count.longValue() - initialCount.longValue());
992: }
993:
994: @When("^I configure the group service$")
995: public void setGroupConfigurationValue(List<CucConfig> cucConfigs)
996: throws Exception {
997:
998: Map<String, Object> valueMap = new HashMap<>();
999: KapuaId scopeId;
1000: KapuaId parentScopeId;
1001: Account tmpAccount = (Account) stepData.get(LAST_ACCOUNT);
1002:
1003:• if (tmpAccount != null) {
1004: scopeId = tmpAccount.getId();
1005: parentScopeId = tmpAccount.getScopeId();
1006: } else {
1007: scopeId = SYS_SCOPE_ID;
1008: parentScopeId = SYS_SCOPE_ID;
1009: }
1010:
1011:• for (CucConfig config : cucConfigs) {
1012: config.addConfigToMap(valueMap);
1013:• if (config.getScopeId() != null) {
1014: scopeId = getKapuaId(config.getScopeId());
1015: }
1016:• if (config.getParentId() != null) {
1017: parentScopeId = getKapuaId(config.getParentId());
1018: }
1019: }
1020: try {
1021: primeException();
1022: groupService.setConfigValues(scopeId, parentScopeId, valueMap);
1023: } catch (KapuaException ex) {
1024: verifyException(ex);
1025: }
1026: }
1027:
1028: @When("^I count the group entries in the database$")
1029: public void countGroupEntries()
1030: throws Exception {
1031:
1032: stepData.remove(COUNT);
1033: primeException();
1034: try {
1035: Long count = groupService.count(groupFactory.newQuery(SYS_SCOPE_ID));
1036: stepData.put(COUNT, count);
1037: } catch (KapuaException ex) {
1038: verifyException(ex);
1039: }
1040: }
1041:
1042: @Given("^I create the group(?:|s)$")
1043: public void createAListOfGroups(List<CucGroup> groups)
1044: throws Exception {
1045:
1046: Group group = null;
1047: GroupCreator groupCreator = null;
1048: stepData.remove(GROUP_CREATOR);
1049: stepData.remove(GROUP);
1050: stepData.remove("GroupId");
1051:
1052: primeException();
1053:• for (CucGroup tmpGrp : groups) {
1054: tmpGrp.doParse();
1055: groupCreator = groupFactory.newCreator(tmpGrp.getScopeId(), tmpGrp.getName());
1056:
1057: try {
1058: group = groupService.create(groupCreator);
1059: stepData.put(GROUP_CREATOR, groupCreator);
1060: stepData.put(GROUP, group);
1061: stepData.put("GroupId", group.getId());
1062: } catch (KapuaException ex) {
1063: verifyException(ex);
1064: }
1065: }
1066: }
1067:
1068: @When("^I update the group name to \"(.+)\"$")
1069: public void updateLastGroupName(String name)
1070: throws Exception {
1071:
1072: Group group = (Group) stepData.get(GROUP);
1073: group.setName(name);
1074: // Sleep for a bit to make sure the time stamps are really different!
1075: Thread.sleep(50);
1076:
1077: try {
1078: Group groupSecond = groupService.update(group);
1079: stepData.put(GROUP_SECOND, groupSecond);
1080: } catch (KapuaException ex) {
1081: verifyException(ex);
1082: }
1083:
1084: }
1085:
1086: @When("^I update the group with an incorrect ID$")
1087: public void updateGroupWithFalseId()
1088: throws Exception {
1089:
1090: Group group = (Group) stepData.get(GROUP);
1091: group.setId(getKapuaId());
1092:
1093: primeException();
1094: try {
1095: groupService.update(group);
1096: } catch (KapuaException ex) {
1097: verifyException(ex);
1098: }
1099: }
1100:
1101: @Then("^I delete the group with name \"([^\"]*)\"$")
1102: public void deleteGroupWithName(String groupName)
1103: throws Exception {
1104:
1105: primeException();
1106: try {
1107: GroupQuery tmpQuery = groupFactory.newQuery(getCurrentScopeId());
1108: tmpQuery.setPredicate(tmpQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL));
1109: Group group = groupService.query(tmpQuery).getFirstItem();
1110: groupService.delete(group.getScopeId(), group.getId());
1111: } catch (Exception ex) {
1112: verifyException(ex);
1113: }
1114: }
1115:
1116: @Then("^I try to delete the group with name \"([^\"]*)\"$")
1117: public void tryToDeleteGroupWithName(String groupName)
1118: throws Exception {
1119: Group group = (Group) stepData.get(GROUP);
1120:
1121: primeException();
1122: try {
1123: assertEquals(groupName, group.getName());
1124: groupService.delete(group.getScopeId(), group.getId());
1125: } catch (KapuaException ex) {
1126: verifyException(ex);
1127: }
1128: }
1129:
1130: @When("^I try to delete a random group id$")
1131: public void deleteGroupWithRandomId()
1132: throws Exception {
1133:
1134: primeException();
1135: try {
1136: groupService.delete(SYS_SCOPE_ID, getKapuaId());
1137: } catch (KapuaException ex) {
1138: verifyException(ex);
1139: }
1140: }
1141:
1142: @When("^I search for the group with name \"([^\"]*)\"$")
1143: public void findGroupByRememberedId(String groupName)
1144: throws Exception {
1145:
1146: Group group = (Group) stepData.get(GROUP);
1147: assertEquals(groupName, group.getName());
1148:
1149: primeException();
1150: try {
1151: Group groupSecond = groupService.find(group.getScopeId(), group.getId());
1152: stepData.put(GROUP_SECOND, groupSecond);
1153: } catch (KapuaException ex) {
1154: verifyException(ex);
1155: }
1156:
1157: }
1158:
1159: @When("^I count all the groups in scope (\\d+)$")
1160: public void countGroupsInScope(int scope)
1161: throws Exception {
1162:
1163: KapuaId tmpId = getKapuaId(scope);
1164: GroupQuery tmpQuery = groupFactory.newQuery(tmpId);
1165:
1166: primeException();
1167: try {
1168: Long count = groupService.count(tmpQuery);
1169: stepData.put(COUNT, count);
1170: } catch (KapuaException ex) {
1171: verifyException(ex);
1172: }
1173: }
1174:
1175: @When("^I query for the group \"(.+)\" in scope (\\d+)$")
1176: public void queryForGroup(String name, int scope)
1177: throws Exception {
1178:
1179: KapuaId tmpId = getKapuaId(scope);
1180: GroupQuery tmpQuery = groupFactory.newQuery(tmpId);
1181: tmpQuery.setPredicate(tmpQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, name, AttributePredicate.Operator.EQUAL));
1182:
1183: stepData.remove("GroupList");
1184: stepData.remove(GROUP);
1185: stepData.remove(COUNT);
1186:
1187: primeException();
1188: try {
1189: GroupListResult groupList = groupService.query(tmpQuery);
1190: stepData.put("GroupList", groupList);
1191: stepData.put(GROUP, groupList.getFirstItem());
1192: stepData.put(COUNT, Long.valueOf(groupList.getSize()));
1193: } catch (KapuaException ex) {
1194: verifyException(ex);
1195: }
1196: }
1197:
1198: @Then("^A group was created$")
1199: public void checkGroupNotNull() {
1200:
1201: assertNotNull(stepData.get(GROUP));
1202: }
1203:
1204: @Then("^No group was created$")
1205: public void checkGroupIsNull() {
1206:
1207: assertNull(stepData.get(GROUP));
1208: }
1209:
1210: @Then("^The group was found$")
1211: public void checkThatTheGroupWasFound() {
1212:
1213: assertNotNull(stepData.get(GROUP_SECOND));
1214: }
1215:
1216: @Then("^No group was found$")
1217: public void checkNoGroupWasFound() {
1218:
1219: assertNull(stepData.get(GROUP_SECOND));
1220: }
1221:
1222: @Then("^The group name is \"(.+)\"$")
1223: public void checkGroupName(String name) {
1224:
1225: Group group = (Group) stepData.get(GROUP);
1226: assertEquals(group.getName(), name.trim());
1227: }
1228:
1229: @Then("^The group matches the creator$")
1230: public void checkGroupAgainstCreator() {
1231:
1232: Group group = (Group) stepData.get(GROUP);
1233: GroupCreator groupCreator = (GroupCreator) stepData.get(GROUP_CREATOR);
1234:
1235: assertNotNull(group);
1236: assertNotNull(group.getId());
1237: assertNotNull(groupCreator);
1238: assertEquals(groupCreator.getScopeId(), group.getScopeId());
1239: assertEquals(groupCreator.getName(), group.getName());
1240: assertNotNull(group.getCreatedBy());
1241: assertNotNull(group.getCreatedOn());
1242: assertNotNull(group.getModifiedBy());
1243: assertNotNull(group.getModifiedOn());
1244: }
1245:
1246: @Then("^The group was correctly updated$")
1247: public void checkUpdatedGroup() {
1248:
1249: Group group = (Group) stepData.get(GROUP);
1250: Group groupSecond = (Group) stepData.get(GROUP_SECOND);
1251:
1252: assertNotNull(groupSecond);
1253: assertNotNull(groupSecond.getId());
1254: assertEquals(group.getScopeId(), groupSecond.getScopeId());
1255: assertEquals(group.getName(), groupSecond.getName());
1256: assertEquals(group.getCreatedBy(), groupSecond.getCreatedBy());
1257: assertEquals(group.getCreatedOn(), groupSecond.getCreatedOn());
1258: assertEquals(group.getModifiedBy(), groupSecond.getModifiedBy());
1259: assertNotEquals(group.getModifiedOn(), groupSecond.getModifiedOn());
1260: }
1261:
1262: @Then("^The group was correctly found$")
1263: public void checkFoundGroup() {
1264:
1265: Group group = (Group) stepData.get(GROUP);
1266: Group groupSecond = (Group) stepData.get(GROUP_SECOND);
1267:
1268: assertNotNull(groupSecond);
1269: assertNotNull(groupSecond.getId());
1270: assertEquals(group.getScopeId(), groupSecond.getScopeId());
1271: assertEquals(group.getName(), groupSecond.getName());
1272: assertEquals(group.getCreatedBy(), groupSecond.getCreatedBy());
1273: assertEquals(group.getCreatedOn(), groupSecond.getCreatedOn());
1274: assertEquals(group.getModifiedBy(), groupSecond.getModifiedBy());
1275: assertEquals(group.getModifiedOn(), groupSecond.getModifiedOn());
1276: }
1277:
1278: @Given("^The permission(?:|s) \"(.+)\"$")
1279: public void createPermissionsForDomain(String permList) {
1280:
1281: // Split the parameter string and make sure there is at least one item
1282: String[] tmpList = permList.toLowerCase().split(",");
1283: assertNotNull(tmpList);
1284: assertNotEquals(0, tmpList.length);
1285:
1286: // Parse the items and fill the list
1287: Set<Permission> permissions = new HashSet<>();
1288: KapuaId currId = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1289:
1290: // Get the current domain
1291: Domain curDomain = (Domain) stepData.get(DOMAIN);
1292:
1293:• for (String perm : tmpList) {
1294:• switch (perm.trim()) {
1295: case "read":
1296: permissions.add(permissionFactory.newPermission(curDomain.getDomain(), Actions.read, currId));
1297: break;
1298: case "write":
1299: permissions.add(permissionFactory.newPermission(curDomain.getDomain(), Actions.write, currId));
1300: break;
1301: case "delete":
1302: permissions.add(permissionFactory.newPermission(curDomain.getDomain(), Actions.delete, currId));
1303: break;
1304: case "connect":
1305: permissions.add(permissionFactory.newPermission(curDomain.getDomain(), Actions.connect, currId));
1306: break;
1307: case "execute":
1308: permissions.add(permissionFactory.newPermission(curDomain.getDomain(), Actions.execute, currId));
1309: break;
1310: }
1311: }
1312: // Make sure that there is at least one valid item
1313: assertFalse(permissions.isEmpty());
1314:
1315: stepData.put(PERMISSIONS, permissions);
1316: }
1317:
1318: @Given("^The role \"(.*)\"$")
1319: public void provideRoleForDomain(String name)
1320: throws Exception {
1321:
1322: KapuaId currId = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1323: Set<Permission> permissions = (Set<Permission>) stepData.get(PERMISSIONS);
1324:
1325: RoleCreator roleCreator = roleFactory.newCreator(currId);
1326: roleCreator.setName(name);
1327: roleCreator.setPermissions(permissions);
1328:
1329: try {
1330: primeException();
1331: stepData.remove("Role");
1332: stepData.remove(ROLE_IDS);
1333: Role role = roleService.create(roleCreator);
1334: stepData.put("Role", role);
1335: Set<KapuaId> roleIds = new HashSet<>();
1336: roleIds.add(role.getId());
1337: stepData.put(ROLE_IDS, roleIds);
1338: } catch (KapuaException e) {
1339: verifyException(e);
1340: }
1341: }
1342:
1343: @Given("^An invalid role ID$")
1344: public void provideInvalidRoleObjectID() {
1345:
1346: stepData.remove(ROLE_IDS);
1347: Set<KapuaId> roleIds = new HashSet<>();
1348: roleIds.add(getKapuaId());
1349: stepData.put(ROLE_IDS, roleIds);
1350: }
1351:
1352: @When("^I create the access role$")
1353: public void createAccessRole()
1354: throws Exception {
1355:
1356: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1357: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
1358: Role role = (Role) stepData.get("Role");
1359: AccessRoleCreator tmpCreator = accessRoleFactory.newCreator(currScope);
1360: tmpCreator.setAccessInfoId(accessInfo.getId());
1361: tmpCreator.setRoleId(role.getId());
1362:
1363: try {
1364: primeException();
1365: stepData.remove(ACCESS_ROLE);
1366: AccessRole accessRole = accessRoleService.create(tmpCreator);
1367: stepData.put(ACCESS_ROLE, accessRole);
1368: } catch (KapuaException e) {
1369: verifyException(e);
1370: }
1371: }
1372:
1373: @When("^I create a clean access info entity$")
1374: public void createCleanAccessInfoEntity()
1375: throws Exception {
1376:
1377: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1378: User tmpUser = (User) stepData.get("User");
1379: AccessInfoCreator accessInfoCreator = accessInfoFactory.newCreator(currScope);
1380: accessInfoCreator.setUserId(tmpUser.getId());
1381:
1382: stepData.remove(PERMISSIONS);
1383: stepData.remove(ROLE_IDS);
1384:
1385: try {
1386: primeException();
1387: stepData.put(ACCESS_INFO_CREATOR, accessInfoCreator);
1388: stepData.remove(ACCESS_INFO);
1389: AccessInfo accessInfo = accessInfoService.create(accessInfoCreator);
1390: stepData.put(ACCESS_INFO, accessInfo);
1391: } catch (KapuaException ex) {
1392: verifyException(ex);
1393: }
1394: }
1395:
1396: @When("^I create the access info entity$")
1397: public void createAccessInfoEntity()
1398: throws Exception {
1399:
1400: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1401: User tmpUser = (User) stepData.get("User");
1402: AccessInfoCreator accessInfoCreator = accessInfoFactory.newCreator(currScope);
1403: accessInfoCreator.setUserId(tmpUser.getId());
1404:
1405: Set<Permission> permissions = (Set<Permission>) stepData.get(PERMISSIONS);
1406: Set<KapuaId> roleIds = (Set<KapuaId>) stepData.get(ROLE_IDS);
1407:
1408:• if (permissions != null && !permissions.isEmpty()) {
1409: accessInfoCreator.setPermissions(permissions);
1410: } else {
1411: accessInfoCreator.setPermissions(null);
1412: }
1413:
1414:• if (roleIds != null && !roleIds.isEmpty()) {
1415: accessInfoCreator.setRoleIds(roleIds);
1416: } else {
1417: accessInfoCreator.setRoleIds(null);
1418: }
1419:
1420: try {
1421: primeException();
1422: stepData.put(ACCESS_INFO_CREATOR, accessInfoCreator);
1423: stepData.remove(ACCESS_INFO);
1424: AccessInfo accessInfo = accessInfoService.create(accessInfoCreator);
1425: stepData.put(ACCESS_INFO, accessInfo);
1426: } catch (KapuaException ex) {
1427: verifyException(ex);
1428: }
1429: }
1430:
1431: @When("^I search for the permissions of the last access info entity$")
1432: public void findThePermissionsOfTheLastAccessInfoEntity()
1433: throws Exception {
1434:
1435: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
1436:
1437: try {
1438: primeException();
1439: stepData.remove(ACCESS_PERMISSIONS);
1440: AccessPermissionListResult accessPermissions = accessPermissionService.findByAccessInfoId(
1441: accessInfo.getScopeId(), accessInfo.getId());
1442: stepData.put(ACCESS_PERMISSIONS, accessPermissions);
1443: } catch (KapuaException ex) {
1444: verifyException(ex);
1445: }
1446: }
1447:
1448: @When("^I search for the roles of the last access info entity$")
1449: public void findTheRolesOfTheLastAccessInfoEntity()
1450: throws Exception {
1451:
1452: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
1453:
1454: try {
1455: primeException();
1456: stepData.remove(ACCESS_ROLES);
1457: AccessRoleListResult accessRoles = accessRoleService.findByAccessInfoId(accessInfo.getScopeId(), accessInfo.getId());
1458: stepData.put(ACCESS_ROLES, accessRoles);
1459: } catch (KapuaException ex) {
1460: verifyException(ex);
1461: }
1462: }
1463:
1464: @When("^I search for the last created access info entity$")
1465: public void findLastCreatedAccessInfoEntity()
1466: throws Exception {
1467:
1468: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
1469:
1470: try {
1471: primeException();
1472: stepData.remove(ACCESS_INFO_FOUND);
1473: AccessInfo accessInfoFound = accessInfoService.find(accessInfo.getScopeId(), accessInfo.getId());
1474: stepData.put(ACCESS_INFO_FOUND, accessInfoFound);
1475: } catch (KapuaException ex) {
1476: verifyException(ex);
1477: }
1478: }
1479:
1480: @When("^I search for an access info entity by user ID$")
1481: public void findTheAccessInfoEntityByUserId()
1482: throws Exception {
1483:
1484: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1485: User tmpUser = (User) stepData.get("User");
1486:
1487: try {
1488: primeException();
1489: stepData.remove(ACCESS_INFO_FOUND);
1490: AccessInfo accessInfoFound = accessInfoService.findByUserId(currScope, tmpUser.getId());
1491: stepData.put(ACCESS_INFO_FOUND, accessInfoFound);
1492: } catch (KapuaException ex) {
1493: verifyException(ex);
1494: }
1495: }
1496:
1497: @When("^I search for the last created access role entity$")
1498: public void findLastCreatedAccessRole()
1499: throws Exception {
1500:
1501: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1502: AccessRole accessRole = (AccessRole) stepData.get(ACCESS_ROLE);
1503:
1504: try {
1505: primeException();
1506: stepData.remove(ACCESS_ROLE_FOUND);
1507: AccessRole accessRoleFound = accessRoleService.find(currScope, accessRole.getId());
1508: stepData.put(ACCESS_ROLE_FOUND, accessRoleFound);
1509: } catch (KapuaException ex) {
1510: verifyException(ex);
1511: }
1512: }
1513:
1514: @When("^I count the access roles in scope (\\d+)$")
1515: public void countAccesRolesInScope(Integer scope)
1516: throws Exception {
1517:
1518: AccessRoleQuery tmpQuery = accessRoleFactory.newQuery(getKapuaId(scope));
1519:
1520: try {
1521: primeException();
1522: stepData.remove(COUNT);
1523: Long count = accessRoleService.count(tmpQuery);
1524: stepData.put(COUNT, count);
1525: } catch (KapuaException ex) {
1526: verifyException(ex);
1527: }
1528: }
1529:
1530: @When("^I delete the last created access role entry$")
1531: public void deleteLastCreatedAccessRoleEntry()
1532: throws Exception {
1533:
1534: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1535: AccessRole accessRole = (AccessRole) stepData.get(ACCESS_ROLE);
1536:
1537: try {
1538: primeException();
1539: accessRoleService.delete(currScope, accessRole.getId());
1540: } catch (KapuaException e) {
1541: verifyException(e);
1542: }
1543: }
1544:
1545: @When("^I delete the existing access info entity$")
1546: public void deleteLastCreatedAccessInfoEntity()
1547: throws Exception {
1548:
1549: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1550: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
1551:
1552: try {
1553: primeException();
1554: accessInfoService.delete(currScope, accessInfo.getId());
1555: } catch (KapuaException ex) {
1556: verifyException(ex);
1557: }
1558: }
1559:
1560: @When("^I count the access info entities for scope (\\d+)$")
1561: public void countAccessInfoEntitiesInScope(Integer scope)
1562: throws Exception {
1563:
1564: AccessInfoQuery tmpQuery = accessInfoFactory.newQuery(getKapuaId(scope));
1565:
1566: try {
1567: primeException();
1568: stepData.remove(COUNT);
1569: Long count = accessInfoService.count(tmpQuery);
1570: stepData.put(COUNT, count);
1571: } catch (KapuaException ex) {
1572: verifyException(ex);
1573: }
1574: }
1575:
1576: @When("^I query for the access info entities for the last user$")
1577: public void queryForLastUserAccessInfoEntities()
1578: throws Exception {
1579:
1580: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1581: User user = (User) stepData.get("User");
1582:
1583: AccessInfoQuery tmpQuery = accessInfoFactory.newQuery(currScope);
1584: tmpQuery.setPredicate(tmpQuery.attributePredicate(AccessInfoAttributes.USER_ID, user.getId(), AttributePredicate.Operator.EQUAL));
1585:
1586: try {
1587: primeException();
1588: stepData.remove(COUNT);
1589: stepData.remove("AccessList");
1590: AccessInfoListResult accessList = accessInfoService.query(tmpQuery);
1591: stepData.put("AccessList", accessList);
1592:• if (accessList != null) {
1593: stepData.put(COUNT, Long.valueOf(accessList.getSize()));
1594: }
1595: } catch (KapuaException ex) {
1596: verifyException(ex);
1597: }
1598: }
1599:
1600: @When("^I create the permission(?:|s)$")
1601: public void createPermissionEntries()
1602: throws Exception {
1603:
1604: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
1605: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
1606: Set<Permission> permissions = (Set<Permission>) stepData.get(PERMISSIONS);
1607:
1608: AccessPermissionCreator accessPermissionCreator = accessPermissionFactory.newCreator(currScope);
1609: accessPermissionCreator.setAccessInfoId(accessInfo.getId());
1610:
1611: try {
1612: primeException();
1613: AccessPermission accessPermission = null;
1614: stepData.remove("AccessPermissionCreator");
1615: stepData.remove("AccessPermission");
1616: stepData.remove(LAST_ACCESS_PERMISSION);
1617:• for (Permission tmpPerm : permissions) {
1618: accessPermissionCreator.setPermission(tmpPerm);
1619: accessPermission = accessPermissionService.create(accessPermissionCreator);
1620: }
1621: stepData.put("AccessPermissionCreator", accessPermissionCreator);
1622:• if (accessPermission != null) {
1623: stepData.put("AccessPermission", accessPermission);
1624: stepData.put(LAST_ACCESS_PERMISSION, accessPermission);
1625: }
1626: } catch (KapuaException ex) {
1627: verifyException(ex);
1628: }
1629: }
1630:
1631: @When("^I search for the last created permission$")
1632: public void findTheLastCreatedAccessPermission()
1633: throws Exception {
1634:
1635: stepData.remove(ACCESS_PERMISSION_FOUND);
1636: AccessPermission permission = (AccessPermission) stepData.get(LAST_ACCESS_PERMISSION);
1637:
1638: try {
1639: AccessPermission accessPermissionFound = accessPermissionService.find(permission.getScopeId(), permission.getId());
1640: stepData.put(ACCESS_PERMISSION_FOUND, accessPermissionFound);
1641: } catch (KapuaException ex) {
1642: verifyException(ex);
1643: }
1644: }
1645:
1646: @When("^I delete the last created access permission$")
1647: public void deleteLastCreatedPermission()
1648: throws Exception {
1649:
1650: AccessPermission permission = (AccessPermission) stepData.get(LAST_ACCESS_PERMISSION);
1651:
1652: try {
1653: primeException();
1654: accessPermissionService.delete(permission.getScopeId(), permission.getId());
1655: } catch (KapuaException ex) {
1656: verifyException(ex);
1657: }
1658: }
1659:
1660: @When("^I count the permissions in scope (\\d+)$")
1661: public void countPermissionsForScope(Integer scope)
1662: throws Exception {
1663:
1664: KapuaId tmpId = getKapuaId(scope);
1665: AccessPermissionQuery tmpQuery = accessPermissionFactory.newQuery(tmpId);
1666:
1667: try {
1668: primeException();
1669: stepData.remove(COUNT);
1670: Long count = accessPermissionService.count(tmpQuery);
1671: stepData.put(COUNT, count);
1672: } catch (KapuaException ex) {
1673: verifyException(ex);
1674: }
1675: }
1676:
1677: @When("^I check the sanity of the access info factory$")
1678: public void accessInfoServiceSanityCheck()
1679: throws Exception {
1680:
1681: try {
1682: primeException();
1683:
1684: assertNotNull(accessInfoFactory.newCreator(getKapuaId()));
1685: assertNotNull(accessInfoFactory.newEntity(null));
1686: assertNotNull(accessInfoFactory.newQuery(getKapuaId()));
1687: assertNotNull(accessInfoFactory.newListResult());
1688:
1689: AccessInfoCreator tmpCreator = accessInfoFactory.newCreator(getKapuaId());
1690: assertNotNull(tmpCreator);
1691: // tmpCreator.setUserId(getKapuaId());
1692: //
1693: // AccessInfoCreator tmpCreator2 = new AccessInfoCreatorImpl(tmpCreator);
1694: // assertNotNull(tmpCreator2);
1695: // assertEquals(tmpCreator.getUserId(), tmpCreator2.getUserId());
1696:
1697: AccessInfo tmpAccInfo = accessInfoFactory.newEntity(getKapuaId());
1698: assertNotNull(tmpAccInfo);
1699: // tmpAccInfo.setUserId(getKapuaId());
1700: //
1701: // AccessInfo tmpAccInfo2 = new AccessInfoImpl(tmpAccInfo);
1702: // assertNotNull(tmpAccInfo2);
1703: // assertNotNull(tmpAccInfo2.getUserId());
1704: //
1705: // tmpAccInfo2.setUserId(null);
1706: // assertNull(tmpAccInfo2.getUserId());
1707:
1708: tmpAccInfo.setUserId(null);
1709: assertNull(tmpAccInfo.getUserId());
1710: } catch (Exception ex) {
1711: verifyException(ex);
1712: }
1713: }
1714:
1715: @When("^I check the sanity of the access permission factory$")
1716: public void accessPermissionFactorySanityCheck() {
1717: assertNotNull(accessPermissionFactory.newCreator(getKapuaId()));
1718: assertNotNull(accessPermissionFactory.newEntity(null));
1719: assertNotNull(accessPermissionFactory.newEntity(getKapuaId()));
1720: assertNotNull(accessPermissionFactory.newQuery(getKapuaId()));
1721: assertNotNull(accessPermissionFactory.newListResult());
1722:
1723: KapuaId tmpId = getKapuaId();
1724: AccessPermissionCreator tmpCreator = accessPermissionFactory.newCreator(tmpId);
1725: assertNotNull(tmpCreator);
1726: assertNotNull(tmpCreator.getScopeId());
1727: assertEquals(tmpId, tmpCreator.getScopeId());
1728:
1729: AccessPermission tmpAccPerm = accessPermissionFactory.newEntity(getKapuaId());
1730: assertNotNull(tmpAccPerm);
1731: tmpAccPerm.setAccessInfoId(getKapuaId());
1732: Permission tmpPerm = permissionFactory.newPermission(new TestDomain(), Actions.read, getKapuaId(), getKapuaId());
1733: tmpAccPerm.setPermission(tmpPerm);
1734: assertEquals(tmpPerm, tmpAccPerm.getPermission());
1735:
1736: // AccessPermission tmpAccPerm2 = new AccessPermissionImpl(tmpAccPerm);
1737: // assertNotNull(tmpAccPerm2);
1738: // assertEquals(tmpAccPerm.getAccessInfoId(), tmpAccPerm2.getAccessInfoId());
1739: // assertEquals(tmpAccPerm.getPermission(), tmpAccPerm2.getPermission());
1740:
1741: tmpAccPerm.setAccessInfoId(null);
1742: assertNull(tmpAccPerm.getAccessInfoId());
1743:
1744: // No typo. This is by design. When an object permissions are null, when asked for them, a
1745: // new set of empty permissions is returned instead.
1746: tmpAccPerm.setPermission(null);
1747: assertNotNull(tmpAccPerm.getPermission());
1748: }
1749:
1750: @When("^I check the sanity of the access role factory$")
1751: public void accessRoleFactorySanityCheck()
1752: throws Exception {
1753:
1754: try {
1755: primeException();
1756:
1757: assertNotNull(accessRoleFactory.newCreator(getKapuaId()));
1758: assertNotNull(accessRoleFactory.newEntity(getKapuaId()));
1759: assertNotNull(accessRoleFactory.newQuery(getKapuaId()));
1760: assertNotNull(accessRoleFactory.newListResult());
1761:
1762: KapuaId tmpId = getKapuaId();
1763: AccessRoleCreator tmpCreator = accessRoleFactory.newCreator(tmpId);
1764: assertNotNull(tmpCreator);
1765: assertNotNull(tmpCreator.getScopeId());
1766: assertEquals(tmpId, tmpCreator.getScopeId());
1767:
1768: AccessRole tmpRole = accessRoleFactory.newEntity(getKapuaId());
1769: assertNotNull(tmpRole);
1770: tmpRole.setAccessInfoId(getKapuaId());
1771: tmpRole.setRoleId(getKapuaId());
1772:
1773: // AccessRole tmpRole2 = new AccessRoleImpl(tmpRole);
1774: // assertNotNull(tmpRole2);
1775: // assertEquals(tmpRole.getRoleId(), tmpRole2.getRoleId());
1776: // assertEquals(tmpRole.getAccessInfoId(), tmpRole2.getAccessInfoId());
1777:
1778: tmpRole.setAccessInfoId(null);
1779: assertNull(tmpRole.getAccessInfoId());
1780:
1781: tmpRole.setRoleId(null);
1782: assertNull(tmpRole.getRoleId());
1783: } catch (KapuaException ex) {
1784: verifyException(ex);
1785: }
1786: }
1787:
1788: @Then("^A role entity was created$")
1789: public void checkThatRoleWasCreated() {
1790: Role role = (Role) stepData.get("Role");
1791: assertNotNull(role);
1792: }
1793:
1794: @Then("^An access role entity was created$")
1795: public void checkThatAccessRoleWasCreated() {
1796: AccessRole accessRole = (AccessRole) stepData.get(ACCESS_ROLE);
1797: assertNotNull(accessRole);
1798: }
1799:
1800: @Then("^I find an access role entity$")
1801: public void checkThatAnAccessRoleEntityWasFound() {
1802: AccessRole accessRoleFound = (AccessRole) stepData.get(ACCESS_ROLE_FOUND);
1803: assertNotNull(accessRoleFound);
1804: }
1805:
1806: @Then("^An access info entity was created$")
1807: public void checkThatAccessInfoEntityExists() {
1808: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
1809: assertNotNull(accessInfo);
1810: }
1811:
1812: @Then("^I find an accessinfo entity$")
1813: public void checkThatAnAccessInfoEntityWasFound() {
1814: AccessInfo accessInfoFound = (AccessInfo) stepData.get(ACCESS_INFO_FOUND);
1815: assertNotNull(accessInfoFound);
1816: }
1817:
1818: @Then("^I find no access info entity$")
1819: public void checkThatAnAccessInfoEntityWasNotFound() {
1820: AccessInfo accessInfoFound = (AccessInfo) stepData.get(ACCESS_INFO_FOUND);
1821: assertNull(accessInfoFound);
1822: }
1823:
1824: @Then("^I find an access permission entity$")
1825: public void checkThatAnAccessPermissionWasFound() {
1826: AccessPermission accessPermissionFound = (AccessPermission) stepData.get(ACCESS_PERMISSION_FOUND);
1827: assertNotNull(accessPermissionFound);
1828: }
1829:
1830: @Then("^There are no such access permissions$")
1831: public void checkThatThePermissionsWereRemoved() {
1832: AccessPermissionListResult accessPermissions = (AccessPermissionListResult) stepData.get(ACCESS_PERMISSIONS);
1833: assertEquals(0, accessPermissions.getSize());
1834: }
1835:
1836: @Then("^There are no such access roles$")
1837: public void checkThatTheRolesWereRemoved() {
1838: AccessRoleListResult accessRoles = (AccessRoleListResult) stepData.get(ACCESS_ROLES);
1839: assertEquals(0, accessRoles.getSize());
1840: }
1841:
1842: @Then("^The entity matches the creator$")
1843: public void checkEntityAgainstCreator() {
1844:
1845: AccessInfoCreator accessInfoCreator = (AccessInfoCreator) stepData.get(ACCESS_INFO_CREATOR);
1846: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
1847:
1848: assertEquals(accessInfoCreator.getUserId(), accessInfo.getUserId());
1849: assertEquals(accessInfoCreator.getScopeId(), accessInfo.getScopeId());
1850: }
1851:
1852: @Then("^The permissions match the creator$")
1853: public void checkAccessInfoEntityPermissions() {
1854:
1855: AccessInfoCreator accessInfoCreator = (AccessInfoCreator) stepData.get(ACCESS_INFO_CREATOR);
1856: AccessPermissionListResult accessPermissions = (AccessPermissionListResult) stepData.get(ACCESS_PERMISSIONS);
1857:
1858: assertEquals(accessInfoCreator.getPermissions().size(), accessPermissions.getSize());
1859:
1860:• for (int i = 0; i < accessPermissions.getSize(); i++) {
1861: assertTrue(accessInfoCreator.getPermissions().contains(accessPermissions.getItem(i).getPermission()));
1862: }
1863: }
1864:
1865: @Then("^The access info roles match the creator$")
1866: public void checkAccessInfoEntityRoles() {
1867:
1868: AccessInfoCreator accessInfoCreator = (AccessInfoCreator) stepData.get(ACCESS_INFO_CREATOR);
1869: AccessRoleListResult accessRoles = (AccessRoleListResult) stepData.get(ACCESS_ROLES);
1870:
1871: assertNotEquals(0, accessRoles.getSize());
1872: assertEquals(accessInfoCreator.getRoleIds().size(), accessRoles.getSize());
1873:
1874:• for (int i = 0; i < accessRoles.getSize(); i++) {
1875: assertTrue(accessInfoCreator.getRoleIds().contains(accessRoles.getItem(i).getRoleId()));
1876: }
1877: }
1878:
1879: // The following test step is more of a filler. The only purpose is to achieve some coverage
1880: // of the Access Role object equals function.
1881: // As such this step is of limited usefulness and should be taken with a grain of salt.
1882: @Then("^I can compare access role objects$")
1883: public void checkAccessRoleComparison() throws Exception {
1884:
1885: AccessRole accRole1 = accessRoleFactory.newEntity(getKapuaId());
1886: AccessRole accRole2 = accessRoleFactory.newEntity(getKapuaId());
1887:
1888: primeException();
1889: try {
1890: assertTrue(accRole1.equals(accRole1));
1891: assertFalse(accRole1.equals(null));
1892: assertFalse(accRole1.equals(Integer.valueOf(15)));
1893:
1894: assertTrue(accRole1.equals(accRole2));
1895:
1896: accRole2.setAccessInfoId(getKapuaId());
1897: assertFalse(accRole1.equals(accRole2));
1898:
1899: accRole1.setAccessInfoId(getKapuaId());
1900: accRole2.setAccessInfoId(null);
1901: assertFalse(accRole1.equals(accRole2));
1902:
1903: accRole2.setAccessInfoId(accRole1.getAccessInfoId());
1904: assertTrue(accRole1.equals(accRole2));
1905:
1906: accRole2.setRoleId(getKapuaId());
1907: assertFalse(accRole1.equals(accRole2));
1908:
1909: accRole1.setRoleId(getKapuaId());
1910: accRole2.setRoleId(null);
1911: assertFalse(accRole1.equals(accRole2));
1912:
1913: accRole2.setRoleId(accRole1.getRoleId());
1914: assertTrue(accRole1.equals(accRole2));
1915: } catch (KapuaException ex) {
1916: verifyException(ex);
1917: }
1918: }
1919:
1920: // The following test step is more of a filler. The only purpose is to achieve some coverage
1921: // of the Access Role object equals function.
1922: // As such this step is of limited usefulness and should be taken with a grain of salt.
1923: @Then("^I can compare access permission objects$")
1924: public void checkAccessPermissionComparison() {
1925:
1926: AccessPermission accPerm1 = accessPermissionFactory.newEntity(getKapuaId());
1927: AccessPermission accPerm2 = accessPermissionFactory.newEntity(getKapuaId());
1928: Permission tmpPerm1 = permissionFactory.newPermission(new TestDomain(), Actions.read, SYS_SCOPE_ID, getKapuaId());
1929: Permission tmpPerm2 = permissionFactory.newPermission(new TestDomain(), Actions.write, SYS_SCOPE_ID, getKapuaId());
1930:
1931: assertTrue(accPerm1.equals(accPerm1));
1932: assertFalse(accPerm1.equals(null));
1933: assertFalse(accPerm1.equals(Integer.valueOf(15)));
1934:
1935: assertTrue(accPerm1.equals(accPerm2));
1936:
1937: accPerm1.setAccessInfoId(null);
1938: accPerm2.setAccessInfoId(getKapuaId());
1939: assertFalse(accPerm1.equals(accPerm2));
1940:
1941: accPerm1.setAccessInfoId(getKapuaId());
1942: accPerm2.setAccessInfoId(null);
1943: assertFalse(accPerm1.equals(accPerm2));
1944:
1945: accPerm1.setAccessInfoId(getKapuaId());
1946: accPerm2.setAccessInfoId(getKapuaId());
1947: assertFalse(accPerm1.equals(accPerm2));
1948:
1949: accPerm2.setAccessInfoId(accPerm1.getAccessInfoId());
1950: assertTrue(accPerm1.equals(accPerm2));
1951:
1952: accPerm1.setPermission(null);
1953: accPerm2.setPermission(tmpPerm2);
1954: assertFalse(accPerm1.equals(accPerm2));
1955:
1956: accPerm1.setPermission(tmpPerm1);
1957: accPerm2.setPermission(null);
1958: assertFalse(accPerm1.equals(accPerm2));
1959:
1960: accPerm1.setPermission(tmpPerm1);
1961: accPerm2.setPermission(tmpPerm2);
1962: assertFalse(accPerm1.equals(accPerm2));
1963:
1964: accPerm2.setPermission(accPerm1.getPermission());
1965: assertTrue(accPerm1.equals(accPerm2));
1966: }
1967:
1968: // The following test step is more of a filler. The only purpose is to achieve some coverage
1969: // of the Authorization Permission factory.
1970: // As such this step is of limited usefulness and should be taken with a grain of salt.
1971: @Then("^The permission factory returns sane results$")
1972: public void permissionFactorySanityChecks()
1973: throws KapuaException {
1974:
1975: Permission tmpPerm = null;
1976: TestDomain tmpDomain = new TestDomain();
1977:
1978: tmpPerm = permissionFactory.newPermission(tmpDomain, Actions.read, SYS_SCOPE_ID);
1979: assertNotNull(tmpPerm);
1980: assertNotNull(tmpPerm.getDomain());
1981: assertEquals(tmpDomain.getName(), tmpPerm.getDomain());
1982: assertEquals(Actions.read, tmpPerm.getAction());
1983:
1984: tmpPerm = permissionFactory.newPermission(tmpDomain, Actions.write, SYS_SCOPE_ID, getKapuaId(9));
1985: assertNotNull(tmpPerm);
1986: assertNotNull(tmpPerm.getDomain());
1987: assertEquals(tmpDomain.getName(), tmpPerm.getDomain());
1988: assertEquals(Actions.write, tmpPerm.getAction());
1989: assertEquals(getKapuaId(9), tmpPerm.getGroupId());
1990: assertFalse(tmpPerm.getForwardable());
1991:
1992: tmpPerm = permissionFactory.newPermission(null, Actions.execute, SYS_SCOPE_ID, getKapuaId(9), true);
1993: assertNotNull(tmpPerm);
1994: assertEquals(Actions.execute, tmpPerm.getAction());
1995: assertTrue(tmpPerm.getForwardable());
1996:
1997: tmpDomain.setName(null);
1998: tmpPerm = permissionFactory.newPermission(tmpDomain, Actions.connect, SYS_SCOPE_ID, getKapuaId());
1999: assertNotNull(tmpPerm);
2000: assertEquals(Actions.connect, tmpPerm.getAction());
2001: }
2002:
2003: // The following test step is more of a filler. The only purpose is to achieve some coverage
2004: // of the Authorization Permission object equals function.
2005: // As such this step is of limited usefulness and should be taken with a grain of salt.
2006: @Then("^I can compare permission objects$")
2007: public void checkPermissionComparison() {
2008:
2009: Permission perm1 = permissionFactory.newPermission(new TestDomain("test_domain_1"), Actions.read, getKapuaId(10), getKapuaId(100));
2010: Permission perm2 = permissionFactory.newPermission(new TestDomain("test_domain_1"), Actions.read, getKapuaId(10), getKapuaId(100));
2011:
2012: assertTrue(perm1.equals(perm1));
2013: assertFalse(perm1.equals(null));
2014: assertFalse(perm1.equals(Integer.valueOf(10)));
2015:
2016: assertTrue(perm1.equals(perm2));
2017:
2018: perm1.setDomain(null);
2019: assertFalse(perm1.equals(perm2));
2020: perm2.setDomain(null);
2021: assertTrue(perm1.equals(perm2));
2022: perm1.setDomain("test_1");
2023: assertFalse(perm1.equals(perm2));
2024: perm2.setDomain("test_2");
2025: assertFalse(perm1.equals(perm2));
2026:
2027: perm1.setDomain("test");
2028: perm2.setDomain("test");
2029:
2030: perm1.setTargetScopeId(null);
2031: assertFalse(perm1.equals(perm2));
2032: perm2.setTargetScopeId(null);
2033: assertTrue(perm1.equals(perm2));
2034: perm1.setTargetScopeId(getKapuaId(10));
2035: assertFalse(perm1.equals(perm2));
2036: perm2.setTargetScopeId(getKapuaId(15));
2037: assertFalse(perm1.equals(perm2));
2038:
2039: perm1.setTargetScopeId(getKapuaId(10));
2040: perm2.setTargetScopeId(getKapuaId(10));
2041:
2042: perm1.setGroupId(null);
2043: assertFalse(perm1.equals(perm2));
2044: perm2.setGroupId(null);
2045: assertTrue(perm1.equals(perm2));
2046: perm1.setGroupId(getKapuaId(100));
2047: assertFalse(perm1.equals(perm2));
2048: perm2.setGroupId(getKapuaId(101));
2049: assertFalse(perm1.equals(perm2));
2050: perm2.setGroupId(getKapuaId(100));
2051: assertTrue(perm1.equals(perm2));
2052:
2053: perm1.setAction(Actions.read);
2054: perm2.setAction(Actions.write);
2055: assertFalse(perm1.equals(perm2));
2056: }
2057:
2058: @Then("^Access role with name \"([^\"]*)\" is found$")
2059: public void accessRoleWithNameIsFinded(String roleName) throws Exception {
2060:
2061: try {
2062: primeException();
2063: RoleQuery roleQuery = roleFactory.newQuery(getCurrentScopeId());
2064: roleQuery.setPredicate(roleQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, roleName));
2065: RoleListResult roleList = roleService.query(roleQuery);
2066:
2067: AccessRoleQuery accessRoleQuery = accessRoleFactory.newQuery(getCurrentScopeId());
2068: accessRoleQuery.setPredicate(accessRoleQuery.attributePredicate(AccessRoleAttributes.ROLE_ID, roleList.getFirstItem().getId()));
2069: AccessRoleListResult searchAccessRole = accessRoleService.query(accessRoleQuery);
2070:• assertTrue(searchAccessRole.getSize() > 0);
2071: } catch (KapuaException ex) {
2072: verifyException(ex);
2073: }
2074: }
2075:
2076: @And("^I create the roles$")
2077: public void iCreateTheRoles(List<CucRole> roleNames) throws Exception {
2078: RoleCreator roleCreator = roleFactory.newCreator(getCurrentScopeId());
2079: ArrayList<Role> roleArrayList = new ArrayList<Role>();
2080: stepData.remove(ROLE_LIST);
2081: Role role = null;
2082:• for (CucRole roleName : roleNames) {
2083: roleCreator.setName(roleName.getName());
2084: try {
2085: primeException();
2086: stepData.remove("Role");
2087: role = roleService.create(roleCreator);
2088: roleArrayList.add(role);
2089: stepData.put("Role", role);
2090: } catch (KapuaException ex) {
2091: verifyException(ex);
2092: }
2093: }
2094: stepData.put(ROLE_LIST, roleArrayList);
2095: }
2096:
2097: @And("^I add permissions to the role$")
2098: public void iAddPermissionsToTheRole() throws Exception {
2099: Role role = (Role) stepData.get("Role");
2100: Set<Permission> permissions = (Set<Permission>) stepData.get(PERMISSIONS);
2101: Set<RolePermission> rolePermissionList = new HashSet<>();
2102: RolePermissionCreator rolePermissionCreator = rolePermissionFactory.newCreator(getCurrentScopeId());
2103:• for (Permission permission : permissions) {
2104: rolePermissionCreator.setPermission(permission);
2105: rolePermissionCreator.setRoleId(role.getId());
2106:
2107: try {
2108: primeException();
2109: stepData.remove(ROLE_PERMISSION);
2110: RolePermission rolePermission = rolePermissionService.create(rolePermissionCreator);
2111: rolePermissionList.add(rolePermission);
2112: stepData.put(ROLE_PERMISSION, rolePermission);
2113: } catch (KapuaException ex) {
2114: verifyException(ex);
2115: }
2116: }
2117: stepData.put("RolePermissionList", rolePermissionList);
2118: }
2119:
2120: @And("^I add access roles to user \"([^\"]*)\"$")
2121: public void iAddAccessRolesToUser(String userName) throws Exception {
2122: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
2123: List<Role> roleList = (List<Role>) stepData.get(ROLE_LIST);
2124: User user = (User) stepData.get("User");
2125: assertEquals(userName, user.getName());
2126: AccessRoleCreator accessRoleCreator = accessRoleFactory.newCreator(getCurrentScopeId());
2127:
2128:• for (Role role : roleList) {
2129: accessRoleCreator.setAccessInfoId(accessInfo.getId());
2130: accessRoleCreator.setRoleId(role.getId());
2131: stepData.put("AccessRoleCreator", accessRoleCreator);
2132:
2133: try {
2134: primeException();
2135: stepData.remove(ACCESS_ROLE);
2136: AccessRole accessRole = accessRoleService.create(accessRoleCreator);
2137: stepData.put(ACCESS_ROLE, accessRole);
2138: stepData.put("AccessRoleId", accessRole.getId());
2139: } catch (KapuaException ex) {
2140: verifyException(ex);
2141: }
2142: }
2143: }
2144:
2145: @And("^I delete role permissions$")
2146: public void iDeleteAccessRolePermissions() throws Exception {
2147: RolePermission rolePermission = (RolePermission) stepData.get(ROLE_PERMISSION);
2148:
2149: try {
2150: rolePermissionService.delete(rolePermission.getScopeId(), rolePermission.getId());
2151: } catch (KapuaException ex) {
2152: verifyException(ex);
2153: }
2154: }
2155:
2156: @And("^I find the group with name \"([^\"]*)\"$")
2157: public void iFindLastCreatedGroup(String groupName) throws Exception {
2158: Group group = (Group) stepData.get(GROUP);
2159:
2160: try {
2161: primeException();
2162: assertEquals(groupName, group.getName());
2163: assertNotNull(groupService.find(getCurrentScopeId(), group.getId()));
2164: } catch (KapuaException ex) {
2165: verifyException(ex);
2166: }
2167: }
2168:
2169: @And("^I find a role with name \"([^\"]*)\"$")
2170: public void iFindRoleWithName(String roleName) throws Exception {
2171: try {
2172: primeException();
2173: RoleQuery roleQuery = roleFactory.newQuery(getCurrentScopeId());
2174: roleQuery.setPredicate(roleQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, roleName, AttributePredicate.Operator.EQUAL));
2175:
2176: stepData.remove(ROLE_LIST_RESULT);
2177: stepData.remove("Role");
2178: RoleListResult roleListResult = roleService.query(roleQuery);
2179: stepData.put(ROLE_LIST_RESULT, roleListResult);
2180: stepData.put("Role", roleListResult.getFirstItem());
2181:
2182:• assertTrue(roleListResult.getSize() > 0);
2183: } catch (KapuaException ke) {
2184: verifyException(ke);
2185: }
2186:
2187: }
2188:
2189: @And("^I create a group with name \"([^\"]*)\"$")
2190: public void iCreateAGroupWithName(String groupName) throws Exception {
2191: GroupCreator groupCreator = groupFactory.newCreator(getCurrentScopeId());
2192: groupCreator.setName(groupName);
2193:
2194: try {
2195: primeException();
2196: stepData.remove(GROUP);
2197: Group group = groupService.create(groupCreator);
2198: stepData.put(GROUP, group);
2199: } catch (KapuaException ex) {
2200: verifyException(ex);
2201: }
2202: }
2203:
2204: @And("^I try to create groups with invalid characters in name$")
2205: public void iTryToCreateInvalidGroups() throws Exception {
2206: GroupCreator groupCreator = groupFactory.newCreator(getCurrentScopeId());
2207: String invalidCharacters = "!\"#$%&'()=»Ç>:;<-.,⁄@‹›€*ı–°·‚_±Œ„‰?“‘”’ÉØ∏{}|ÆæÒÔÓÌÏÎÍÅ«";
2208:• for (int i = 0; i < invalidCharacters.length(); i++) {
2209: String groupName = GROUP + invalidCharacters.charAt(i);
2210: groupCreator.setName(groupName);
2211:
2212: try {
2213: primeException();
2214: stepData.remove(GROUP);
2215: Group group = groupService.create(groupCreator);
2216: stepData.put(GROUP, group);
2217: } catch (KapuaException ex) {
2218: verifyException(ex);
2219: }
2220: }
2221: }
2222:
2223: @And("^I delete the last created role permissions$")
2224: public void iDeleteTheLastCreatedRolePermissions() throws Exception {
2225: ArrayList<RolePermission> rolePermissions = (ArrayList<RolePermission>) stepData.get(ROLE_PERMISSIONS);
2226:
2227: try {
2228: primeException();
2229:• for (RolePermission rolePermission : rolePermissions) {
2230: rolePermissionService.delete(rolePermission.getScopeId(), rolePermission.getId());
2231: }
2232: } catch (KapuaException ex) {
2233: verifyException(ex);
2234: }
2235: }
2236:
2237: @And("^I search for the permissions of role \"([^\"]*)\"$")
2238: public void iSearchForThePermissionsOfTheRole(String roleName) throws Exception {
2239: Role role = (Role) stepData.get("Role");
2240: ArrayList<RolePermission> rolePermissionList = new ArrayList<>();
2241: assertEquals(roleName, role.getName());
2242:
2243: RolePermissionQuery rolePermissionQuery = rolePermissionFactory.newQuery(getCurrentScopeId());
2244: rolePermissionQuery.setPredicate(rolePermissionQuery.attributePredicate(RolePermissionAttributes.ROLE_ID, role.getId(), AttributePredicate.Operator.EQUAL));
2245:
2246: RolePermissionListResult rolePermissions = rolePermissionService.query(rolePermissionQuery);
2247: stepData.remove(ROLE_PERMISSIONS);
2248:• for (int i = 0; i < rolePermissions.getSize(); i++) {
2249: stepData.remove(ROLE_PERMISSION);
2250: RolePermission rolePermission = rolePermissions.getItem(i);
2251: stepData.put(ROLE_PERMISSION, rolePermission);
2252: rolePermissionList.add(rolePermission);
2253: }
2254: stepData.put(ROLE_PERMISSIONS, rolePermissionList);
2255:
2256: long rolePermissionListSize = rolePermissionList.size();
2257: stepData.put(COUNT, rolePermissionListSize);
2258: }
2259:
2260: @And("^I delete the default admin role permission$")
2261: public void iDeleteTheDefaultRolePermission() throws Exception {
2262: ArrayList<RolePermission> rolePermissions = (ArrayList<RolePermission>) stepData.get(ROLE_PERMISSIONS);
2263:
2264: primeException();
2265: try {
2266:• for (RolePermission rolePermission : rolePermissions) {
2267:• if (rolePermission.getId().equals(KapuaId.ONE)) {
2268: rolePermissionService.delete(getCurrentScopeId(), rolePermission.getId());
2269: }
2270: }
2271: } catch (KapuaException ex) {
2272: verifyException(ex);
2273: }
2274: }
2275:
2276: @And("^I delete all admin role permissions except default permission$")
2277: public void iDeleteTheLastCreatedAdminRolePermissions() throws Exception {
2278: ArrayList<RolePermission> rolePermissions = (ArrayList<RolePermission>) stepData.get(ROLE_PERMISSIONS);
2279:
2280: try {
2281: primeException();
2282:• for (RolePermission rolePermission : rolePermissions) {
2283:• if (!rolePermission.getId().equals(KapuaId.ONE)) {
2284: rolePermissionService.delete(rolePermission.getScopeId(), rolePermission.getId());
2285: }
2286: }
2287: } catch (KapuaException ex) {
2288: verifyException(ex);
2289: }
2290: }
2291:
2292: @And("^I count the access roles from user \"([^\"]*)\"$")
2293: public void iCountTheAccessRolesFromUser(String userName) throws Exception {
2294:
2295: User lastUser = (User) stepData.get("User");
2296: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
2297: AccessRoleQuery tmpQuery = accessRoleFactory.newQuery(getCurrentScopeId());
2298: tmpQuery.setPredicate(tmpQuery.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfo.getId(), AttributePredicate.Operator.EQUAL));
2299:
2300: assertEquals(userName, lastUser.getName());
2301:
2302: try {
2303: primeException();
2304: stepData.remove(COUNT);
2305: Long count = accessRoleService.count(tmpQuery);
2306: stepData.put(COUNT, count);
2307: } catch (KapuaException ex) {
2308: verifyException(ex);
2309: }
2310: }
2311:
2312: @When("^I search for granted user$")
2313: public void iSearchGrantedUserToRole() throws Exception {
2314:
2315: ArrayList<User> grantedUserList = new ArrayList<>();
2316: long grantedUsersCount = 0;
2317: try {
2318: primeException();
2319: AccessRoleQuery accessRoleQuery = accessRoleFactory.newQuery(getCurrentScopeId());
2320: AccessRoleListResult accessRoleList = accessRoleService.query(accessRoleQuery);
2321:
2322:• for (AccessRole a : accessRoleList.getItems()) {
2323: AccessInfo accessInfo = accessInfoService.find(getCurrentScopeId(), a.getAccessInfoId());
2324: User grantedUser = userService.find(getCurrentScopeId(), accessInfo.getUserId());
2325: stepData.put("GrantedUser", grantedUser);
2326:
2327:• if (!grantedUser.getId().equals(KapuaId.ONE)) {
2328: grantedUserList.add(grantedUser);
2329: grantedUsersCount = grantedUserList.size();
2330: }
2331: }
2332: stepData.put("GrantedUserList", grantedUserList);
2333: stepData.put(COUNT, grantedUsersCount);
2334: } catch (KapuaException ex) {
2335: verifyException(ex);
2336: }
2337: }
2338:
2339: @Then("^I find granted user(?:|s) with name$")
2340: public void iFindGrantedUsersWithName(List<CucUser> grantedUsers) throws Exception {
2341: ArrayList<String> grantedUserNames = new ArrayList<>();
2342: ArrayList<User> grantedUsersList = (ArrayList<User>) stepData.get("GrantedUserList");
2343:
2344:• for (User grantedUser : grantedUsersList) {
2345: grantedUserNames.add(grantedUser.getName());
2346: }
2347:
2348:• for (CucUser user : grantedUsers) {
2349: assertTrue(grantedUserNames.contains(user.getName()));
2350: }
2351: }
2352:
2353: @And("^I try to find role with name \"([^\"]*)\" in account \"([^\"]*)\"$")
2354: public void iFindSpecificRoleInChildAccount(String roleName, String accountName) throws Exception {
2355: Account account = (Account) stepData.get(LAST_ACCOUNT);
2356: assertEquals(accountName, account.getName());
2357:
2358: RoleQuery roleQuery = roleFactory.newQuery(account.getId());
2359:
2360: roleQuery.setPredicate(roleQuery.attributePredicate(KapuaNamedEntityAttributes.NAME, roleName, AttributePredicate.Operator.EQUAL));
2361:
2362: RoleListResult childRolesList = roleService.query(roleQuery);
2363: stepData.put("ChildRolesList", childRolesList);
2364: }
2365:
2366: @And("^I create role \"([^\"]*)\" in account \"([^\"]*)\"$")
2367: public void iCreateRoleInSubaccount(String roleName, String accountName) throws Exception {
2368: Account account = (Account) stepData.get(LAST_ACCOUNT);
2369: assertEquals(accountName, account.getName());
2370: RoleCreator roleCreator = null;
2371:
2372: roleCreator = roleFactory.newCreator(account.getId());
2373: roleCreator.setName(roleName);
2374: try {
2375: Role role = roleService.create(roleCreator);
2376: stepData.put(ROLE_CREATOR, roleCreator);
2377: stepData.put("Role", role);
2378: } catch (KapuaException ex) {
2379: verifyException(ex);
2380: }
2381: }
2382:
2383: @And("^I create the following role permission(?:|s) in account \"([^\"]*)\"$")
2384: public void iCreateTheFollowingRolePermissionInSubaccount(String accountName, List<CucRolePermission> perms) throws Exception {
2385:
2386: Role role = (Role) stepData.get("Role");
2387: Account account = (Account) stepData.get(LAST_ACCOUNT);
2388: assertEquals(accountName, account.getName());
2389: Domain domain = (Domain) stepData.get(DOMAIN);
2390: RolePermission rolePermission = null;
2391: ArrayList<RolePermission> rolePermissions = new ArrayList<>();
2392:
2393: stepData.remove(CHILD_ACCOUNT_ROLE_PERMISSION);
2394:
2395: primeException();
2396:• for (CucRolePermission tmpCPerm : perms) {
2397: tmpCPerm.doParse();
2398: assertNotNull(tmpCPerm.getScopeId());
2399: assertNotNull(tmpCPerm.getAction());
2400:
2401: domain.setScopeId(tmpCPerm.getScopeId());
2402:
2403: RolePermissionCreator rolePermissionCreator = rolePermissionFactory.newCreator(account.getId());
2404: rolePermissionCreator.setRoleId(role.getId());
2405: rolePermissionCreator.setPermission(permissionFactory.newPermission(domain.getDomain(), tmpCPerm.getAction(), tmpCPerm.getTargetScopeId()));
2406:
2407: try {
2408: stepData.remove("ChildAccountRolePermissions");
2409: rolePermission = rolePermissionService.create(rolePermissionCreator);
2410: rolePermissions.add(rolePermission);
2411: stepData.put("ChildAccountRolePermissions", rolePermissions);
2412: } catch (KapuaException ex) {
2413: verifyException(ex);
2414: }
2415: }
2416: }
2417:
2418: @And("^I search for the permissions of found role \"([^\"]*)\" in account \"([^\"]*)\"$")
2419: public void iSearchForThePermissionsOfFoundedRoleInSubaccount(String roleName, String accountName) throws Exception {
2420: Role role = (Role) stepData.get("Role");
2421: assertEquals(roleName, role.getName());
2422: Account account = (Account) stepData.get(LAST_ACCOUNT);
2423: assertEquals(accountName, account.getName());
2424: ArrayList<RolePermission> rolePermissionList = new ArrayList<>();
2425:
2426: RolePermissionQuery rolePermissionQuery = rolePermissionFactory.newQuery(account.getId());
2427: rolePermissionQuery.setPredicate(rolePermissionQuery.attributePredicate(RolePermissionAttributes.ROLE_ID, role.getId(), AttributePredicate.Operator.EQUAL));
2428:
2429: RolePermissionListResult rolePermissions = rolePermissionService.query(rolePermissionQuery);
2430: stepData.remove(CHILD_ACCOUNT_ROLE_PERMISSION);
2431:• for (int i = 0; i < rolePermissions.getSize(); i++) {
2432: stepData.remove(CHILD_ACCOUNT_ROLE_PERMISSION);
2433: RolePermission rolePermission = rolePermissions.getItem(i);
2434: stepData.put(CHILD_ACCOUNT_ROLE_PERMISSION, rolePermission);
2435: rolePermissionList.add(rolePermission);
2436: }
2437: stepData.put(CHILD_ACCOUNT_ROLE_PERMISSION, rolePermissionList);
2438:
2439: long rolePermissionListSize = rolePermissionList.size();
2440: stepData.put(COUNT, rolePermissionListSize);
2441: }
2442:
2443: @Then("^Role with name \"([^\"]*)\" in account \"([^\"]*)\" is found$")
2444: public void roleInChildAccountIsFound(String roleName, String accountName) {
2445: RoleListResult childRolesList = (RoleListResult) stepData.get("ChildRolesList");
2446: Role role = (Role) stepData.get("Role");
2447: Account account = (Account) stepData.get(LAST_ACCOUNT);
2448: assertEquals(roleName, role.getName());
2449: assertEquals(accountName, account.getName());
2450:
2451:• assertTrue(childRolesList.getSize() > 0);
2452: }
2453:
2454: @And("^I add access role \"([^\"]*)\" to user \"([^\"]*)\" in account \"([^\"]*)\"$")
2455: public void iAddAccessRoleToUserInChildAccount(String roleName, String childUserName, String accountName) throws Exception {
2456: AccessInfo accessInfo = (AccessInfo) stepData.get(CHILD_ACCOUNT_ACCESS_INFO);
2457: Account account = (Account) stepData.get(LAST_ACCOUNT);
2458: User childUser = (User) stepData.get("ChildAccountUser");
2459: Role role = (Role) stepData.get("Role");
2460: AccessRoleCreator accessRoleCreator = accessRoleFactory.newCreator(account.getId());
2461: accessRoleCreator.setAccessInfoId(accessInfo.getId());
2462: accessRoleCreator.setRoleId(role.getId());
2463: stepData.put("ChildAccountAccessRoleCreator", accessRoleCreator);
2464:
2465: assertEquals(roleName, role.getName());
2466: assertEquals(accountName, account.getName());
2467: assertEquals(childUserName, childUser.getName());
2468:
2469: try {
2470: primeException();
2471: stepData.remove("ChildAccountAccessRole");
2472: AccessRole accessRole = accessRoleService.create(accessRoleCreator);
2473: stepData.put("ChildAccountAccessRole", accessRole);
2474: stepData.put("ChildAccountAccessRoleId", accessRole.getId());
2475: } catch (KapuaException ex) {
2476: verifyException(ex);
2477: }
2478: }
2479:
2480: @And("^I create the access info entity in account \"([^\"]*)\"$")
2481: public void iCreateTheAccessInfoEntityInChildAccount(String accountName) throws Exception {
2482: Account account = (Account) stepData.get(LAST_ACCOUNT);
2483: User tmpUser = (User) stepData.get("ChildAccountUser");
2484: AccessInfoCreator accessInfoCreator = accessInfoFactory.newCreator(account.getId());
2485: accessInfoCreator.setUserId(tmpUser.getId());
2486:
2487: assertEquals(accountName, account.getName());
2488:
2489: Set<Permission> permissions = (Set<Permission>) stepData.get(PERMISSIONS);
2490: Set<KapuaId> roleIds = (Set<KapuaId>) stepData.get(ROLE_IDS);
2491:
2492:• if (permissions != null && !permissions.isEmpty()) {
2493: accessInfoCreator.setPermissions(permissions);
2494: } else {
2495: accessInfoCreator.setPermissions(null);
2496: }
2497:
2498:• if (roleIds != null && !roleIds.isEmpty()) {
2499: accessInfoCreator.setRoleIds(roleIds);
2500: } else {
2501: accessInfoCreator.setRoleIds(null);
2502: }
2503:
2504: try {
2505: primeException();
2506: stepData.put("ChildAccountAccessInfoCreator", accessInfoCreator);
2507: stepData.remove(CHILD_ACCOUNT_ACCESS_INFO);
2508: AccessInfo accessInfo = accessInfoService.create(accessInfoCreator);
2509: stepData.put(CHILD_ACCOUNT_ACCESS_INFO, accessInfo);
2510: } catch (KapuaException ex) {
2511: verifyException(ex);
2512: }
2513: }
2514:
2515: @And("^I search for access roles in user \"([^\"]*)\"$")
2516: public void iSearchForAccessRolesFromTheLastUser(String userName) throws Exception {
2517: AccessInfo accessInfo = (AccessInfo) stepData.get(ACCESS_INFO);
2518: User user = (User) stepData.get("User");
2519:
2520: assertEquals(userName, user.getName());
2521:
2522: AccessRoleQuery accessRoleQuery = accessRoleFactory.newQuery(getCurrentScopeId());
2523: accessRoleQuery.setPredicate(accessRoleQuery.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfo.getId(), AttributePredicate.Operator.EQUAL));
2524:
2525: try {
2526: primeException();
2527: AccessRoleListResult accessRoleListResult = accessRoleService.query(accessRoleQuery);
2528: stepData.put(COUNT, (long) accessRoleListResult.getSize());
2529: } catch (KapuaException ex) {
2530: verifyException(ex);
2531: }
2532: }
2533:
2534: @And("^I count the access roles from user in account \"([^\"]*)\"$")
2535: public void iCountTheAccessRolesFromUserInChildAccount(String accountName) throws Exception {
2536: Account account = (Account) stepData.get(LAST_ACCOUNT);
2537: AccessInfo accessInfo = (AccessInfo) stepData.get(CHILD_ACCOUNT_ACCESS_INFO);
2538: assertEquals(accountName, account.getName());
2539:
2540: AccessRoleQuery tmpQuery = accessRoleFactory.newQuery(account.getId());
2541: tmpQuery.setPredicate(tmpQuery.attributePredicate(AccessRoleAttributes.ACCESS_INFO_ID, accessInfo.getId(), AttributePredicate.Operator.EQUAL));
2542:
2543: try {
2544: primeException();
2545: stepData.remove(COUNT);
2546: Long count = accessRoleService.count(tmpQuery);
2547: stepData.put(COUNT, count);
2548: } catch (KapuaException ex) {
2549: verifyException(ex);
2550: }
2551: }
2552:
2553: @When("^I update the role name to \"([^\"]*)\"$")
2554: public void iUpdateTheRoleName(String newRoleName) throws Exception {
2555: Role role = (Role) stepData.get("Role");
2556: role.setName(newRoleName);
2557:
2558: try {
2559: primeException();
2560: stepData.remove("Role");
2561: Role newRole = roleService.update(role);
2562: stepData.put("Role", newRole);
2563: } catch (KapuaException ex) {
2564: verifyException(ex);
2565: }
2566: }
2567:
2568: @And("^I create the access info entities$")
2569: public void iCreateTheAccessInfoEntities() throws Exception {
2570: KapuaId currScope = (KapuaId) stepData.get(LAST_ACCOUNT_ID);
2571: ArrayList<User> userArray = (ArrayList<User>) stepData.get("UserList");
2572: AccessInfoCreator accessInfoCreator = accessInfoFactory.newCreator(currScope);
2573: ArrayList<AccessInfo> accessInfoList = new ArrayList<>();
2574:
2575: Set<Permission> permissions = (Set<Permission>) stepData.get(PERMISSIONS);
2576: Set<KapuaId> roleIds = (Set<KapuaId>) stepData.get(ROLE_IDS);
2577:
2578:• if (permissions != null && !permissions.isEmpty()) {
2579: accessInfoCreator.setPermissions(permissions);
2580: } else {
2581: accessInfoCreator.setPermissions(null);
2582: }
2583:
2584:• if (roleIds != null && !roleIds.isEmpty()) {
2585: accessInfoCreator.setRoleIds(roleIds);
2586: } else {
2587: accessInfoCreator.setRoleIds(null);
2588: }
2589:
2590:• for (User user : userArray) {
2591: accessInfoCreator.setUserId(user.getId());
2592: try {
2593: primeException();
2594: stepData.put(ACCESS_INFO_CREATOR, accessInfoCreator);
2595: stepData.remove(ACCESS_INFO);
2596: AccessInfo accessInfo = accessInfoService.create(accessInfoCreator);
2597: stepData.put(ACCESS_INFO, accessInfo);
2598: accessInfoList.add(accessInfo);
2599: } catch (KapuaException ex) {
2600: verifyException(ex);
2601: }
2602: }
2603: stepData.put("AccessInfoList", accessInfoList);
2604: }
2605:
2606: @Given("^I prepare a role creator with name \"([^\"]*)\" and description \"([^\"]*)\"$")
2607: public void iPrepareARoleCreatorWithNameAndDescription(String name, String description) {
2608: RoleCreator roleCreator = roleFactory.newCreator(SYS_SCOPE_ID);
2609: roleCreator.setName(name);
2610: roleCreator.setDescription(description);
2611:
2612: stepData.put(ROLE_CREATOR, roleCreator);
2613: }
2614:
2615: @When("^I create a new role entity from the existing creator$")
2616: public void iCreateANewRoleEntityFromTheExistingCreator() throws Exception {
2617: RoleCreator roleCreator = (RoleCreator) stepData.get(ROLE_CREATOR);
2618: primeException();
2619: try {
2620: stepData.remove("Role");
2621: stepData.remove("CurrentRoleId");
2622: Role role = roleService.create(roleCreator);
2623: stepData.put("Role", role);
2624: stepData.put("CurrentRoleId", role.getId());
2625: } catch (KapuaException ex) {
2626: verifyException(ex);
2627: }
2628: }
2629:
2630: @Given("^I create (\\d+) roles$")
2631: public void iCreateRoles(int num) throws Exception {
2632: primeException();
2633: try {
2634:• for (int i = 0; i < num; i++) {
2635: RoleCreator tmpCreator = roleFactory.newCreator(getCurrentScopeId());
2636: tmpCreator.setName(String.format("TestRoleNum%d", i));
2637: roleService.create(tmpCreator);
2638: }
2639: } catch (KapuaException ex) {
2640: verifyException(ex);
2641: }
2642: }
2643:
2644: @When("^I count the roles in the database$")
2645: public void iCountTheRolesInTheDatabase() throws Exception {
2646: RoleQuery tmpQuery = roleFactory.newQuery(getCurrentScopeId());
2647:
2648: primeException();
2649: try {
2650: stepData.remove(COUNT);
2651: Long count = roleService.count(tmpQuery);
2652: stepData.put(COUNT, count - 1);
2653: } catch (KapuaException ex) {
2654: verifyException(ex);
2655: }
2656: }
2657:
2658: @And("^I update the role description to \"([^\"]*)\"$")
2659: public void iUpdateTheRoleDescriptionTo(String newRoleDesc) throws Exception {
2660: Role role = (Role) stepData.get("Role");
2661: role.setDescription(newRoleDesc);
2662:
2663: try {
2664: primeException();
2665: stepData.remove("Role");
2666: Role newRole = roleService.update(role);
2667: stepData.put("Role", newRole);
2668: } catch (KapuaException ex) {
2669: verifyException(ex);
2670: }
2671: }
2672:
2673: @Then("^I delete the role with name \"([^\"]*)\" and description \"([^\"]*)\"$")
2674: public void iDeleteTheRoleWithNameAndDescription(String roleName, String roleDescription) throws Throwable {
2675: Role role = (Role) stepData.get("Role");
2676:
2677: primeException();
2678: try {
2679: assertEquals(roleName, role.getName());
2680: assertEquals(roleDescription, role.getDescription());
2681: KapuaId roleId = role.getId();
2682: roleService.delete(role.getScopeId(), roleId);
2683: } catch (KapuaException ex) {
2684: verifyException(ex);
2685: }
2686: }
2687:
2688: @Then("^I search for a role with description \"([^\"]*)\"$")
2689: public void iFindARoleWithDescription(String roleDesc) throws Throwable {
2690: try {
2691: primeException();
2692: RoleQuery roleQuery = roleFactory.newQuery(getCurrentScopeId());
2693: roleQuery.setPredicate(roleQuery.attributePredicate(KapuaNamedEntityAttributes.DESCRIPTION, roleDesc, AttributePredicate.Operator.EQUAL));
2694:
2695: stepData.remove(ROLE_LIST_RESULT);
2696: stepData.remove(ROLE_FOUND);
2697: RoleListResult roleListResult = roleService.query(roleQuery);
2698: stepData.put(ROLE_LIST_RESULT, roleListResult);
2699: stepData.put(ROLE_FOUND, roleListResult.getFirstItem());
2700: } catch (KapuaException ke) {
2701: verifyException(ke);
2702: }
2703: }
2704:
2705: @Given("^I try to create roles with invalid characters \"([^\"]*)\" in name$")
2706: public void iTryToCreateRolesWithInvalidCharactersInName(String invalidCharacters) throws Exception {
2707: RoleCreator roleCreator = roleFactory.newCreator(SYS_SCOPE_ID);
2708:• for (int i = 0; i < invalidCharacters.length(); i++) {
2709: String roleName = ROLE_NAME + invalidCharacters.charAt(i);
2710: roleCreator.setName(roleName);
2711:
2712: try {
2713: primeException();
2714: stepData.remove("Role");
2715: Role role = roleService.create(roleCreator);
2716: stepData.put("Role", role);
2717: } catch (KapuaException ex) {
2718: verifyException(ex);
2719: }
2720: }
2721: }
2722:
2723: @Given("^I try to create roles with invalid characters \"([^\"]*)\" in description$")
2724: public void iTryToCreateRolesWithInvalidCharactersInDescription(String invalidCharacters) throws Exception {
2725: RoleCreator roleCreator = roleFactory.newCreator(SYS_SCOPE_ID);
2726:• for (int i = 0; i < invalidCharacters.length(); i++) {
2727: String roleDescription = "roleDescription" + invalidCharacters.charAt(i);
2728: roleCreator.setDescription(roleDescription);
2729: roleCreator.setName(ROLE_NAME + i);
2730:
2731: try {
2732: primeException();
2733: stepData.remove("Role");
2734: Role role = roleService.create(roleCreator);
2735: stepData.put("Role", role);
2736: } catch (KapuaException ex) {
2737: verifyException(ex);
2738: }
2739: }
2740: }
2741:
2742: @Then("^I update the role name with special characters \"([^\"]*)\"$")
2743: public void iUpdateTheRoleNameWithSpecialCharacters(String invalidSymbols) throws Throwable {
2744: RoleCreator roleCreator = roleFactory.newCreator(SYS_SCOPE_ID);
2745:• for (int i = 0; i < invalidSymbols.length(); i++) {
2746: String roleName = ROLE_NAME + invalidSymbols.charAt(i);
2747: roleCreator.setName(ROLE_NAME + i);
2748:
2749: try {
2750: primeException();
2751: stepData.remove("Role");
2752: Role role = roleService.create(roleCreator);
2753: role.setName(ROLE_NAME + invalidSymbols.charAt(i));
2754: roleService.update(role);
2755: stepData.put("Role", role);
2756: } catch (KapuaException ex) {
2757: verifyException(ex);
2758: }
2759: }
2760: }
2761:
2762: @And("^I change the group name from \"([^\"]*)\" to \"([^\"]*)\"$")
2763: public void iChangeTheGroupNameTo(String groupName, String newGroupName) throws Throwable {
2764:
2765: try {
2766: GroupQuery query = groupFactory.newQuery(SYS_SCOPE_ID);
2767: query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL));
2768: GroupListResult queryResult = groupService.query(query);
2769: Group group = queryResult.getFirstItem();
2770: group.setName(newGroupName);
2771: groupService.update(group);
2772: stepData.put(GROUP, group);
2773: } catch (Exception e) {
2774: verifyException(e);
2775: }
2776: }
2777:
2778: @And("^I change the description of group with name \"([^\"]*)\" to \"([^\"]*)\"$")
2779: public void iChangeTheGroupDescriptionTo(String groupName, String groupDescription) throws Throwable {
2780:
2781: try {
2782: GroupQuery query = groupFactory.newQuery(SYS_SCOPE_ID);
2783: query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL));
2784: GroupListResult queryResult = groupService.query(query);
2785: Group group = queryResult.getFirstItem();
2786: group.setDescription(groupDescription);
2787: stepData.put(GROUP, group);
2788: } catch (Exception e) {
2789: verifyException(e);
2790: }
2791: }
2792:
2793: @And("^I search for a group named \"([^\"]*)\"$")
2794: public void iSearchForAGroupNamed(String groupName) throws Exception {
2795: try {
2796: stepData.remove(GROUP_SECOND);
2797: GroupQuery query = groupFactory.newQuery(SYS_SCOPE_ID);
2798: query.setPredicate(query.attributePredicate(KapuaNamedEntityAttributes.NAME, groupName, AttributePredicate.Operator.EQUAL));
2799: GroupListResult queryResult = groupService.query(query);
2800: Group foundGroup = queryResult.getFirstItem();
2801: stepData.put(GROUP_SECOND, foundGroup);
2802: stepData.put("queryResult", queryResult);
2803: } catch (Exception e) {
2804: verifyException(e);
2805: }
2806: }
2807:
2808: @And("^I change devices group$")
2809: public void iChangeDevicesGroup() throws Exception {
2810: Group group = (Group) stepData.get(GROUP);
2811: Device device = (Device) stepData.get("Device");
2812:
2813: try {
2814: device.setGroupId(group.getId());
2815: stepData.put("Device", device);
2816: } catch (Exception e) {
2817: verifyException(e);
2818: }
2819: }
2820:
2821: @Given("^I create the group with name \"([^\"]*)\" and description \"([^\"]*)\"$")
2822: public void iCreateTheGroupWithName(String groupName, String groupDescription) throws Exception {
2823: GroupCreator groupCreator = groupFactory.newCreator(getCurrentScopeId());
2824: groupCreator.setName(groupName);
2825: groupCreator.setDescription(groupDescription);
2826:
2827: try {
2828: primeException();
2829: stepData.remove(GROUP);
2830: Group group = groupService.create(groupCreator);
2831: stepData.put(GROUP, group);
2832: } catch (KapuaException ex) {
2833: verifyException(ex);
2834: }
2835: }
2836:
2837: @When("^I search for the group with description \"([^\"]*)\"$")
2838: public void iSearchForTheGroupWithDescription(String description) throws Exception {
2839:
2840: Group group = (Group) stepData.get(GROUP);
2841: assertEquals(description, group.getDescription());
2842:
2843: primeException();
2844: try {
2845: Group groupSecond = groupService.find(group.getScopeId(), group.getId());
2846: stepData.put(GROUP_SECOND, groupSecond);
2847: } catch (KapuaException ex) {
2848: verifyException(ex);
2849: }
2850: }
2851:
2852: @Then("^I find the group with description \"([^\"]*)\"$")
2853: public void iFindTheGroupWithDescription(String description) throws Exception {
2854: Group group = (Group) stepData.get(GROUP);
2855:
2856: try {
2857: primeException();
2858: assertEquals(description, group.getDescription());
2859: assertNotNull(groupService.find(getCurrentScopeId(), group.getId()));
2860: } catch (KapuaException ex) {
2861: verifyException(ex);
2862: }
2863: }
2864:
2865: @When("^I update the group name from \"([^\"]*)\" to \"([^\"]*)\"$")
2866: public void iUpdateTheGroupNameFromTo(String name1, String name2) throws Exception {
2867: Group group = (Group) stepData.get(GROUP);
2868: assertEquals(name1, group.getName());
2869: group.setName(name2);
2870:
2871: try {
2872: Group secondGroup = groupService.update(group);
2873: stepData.put(GROUP_SECOND, secondGroup);
2874: } catch (KapuaException ex) {
2875: verifyException(ex);
2876: }
2877: }
2878:
2879: @When("^I update the group description from \"([^\"]*)\" to \"([^\"]*)\"$")
2880: public void iUpdateTheGroupDescriptionFromTo(String description1, String description2) throws Exception {
2881: Group group = (Group) stepData.get(GROUP);
2882: assertEquals(description1, group.getDescription());
2883: group.setDescription(description2);
2884:
2885: try {
2886: Group groupSecond = groupService.update(group);
2887: stepData.put(GROUP_SECOND, groupSecond);
2888: } catch (KapuaException ex) {
2889: verifyException(ex);
2890: }
2891: }
2892:
2893: @And("^I try to create the group with invalid characters \"([^\"]*)\" in name and description \"([^\"]*)\"$")
2894: public void iTryToCreateTheGroupWithInvalidCharactersInNameAndDescription(String invalidSymbols, String description) throws Exception {
2895: GroupCreator groupCreator = groupFactory.newCreator(getCurrentScopeId());
2896:• for (int i = 0; i < invalidSymbols.length(); i++) {
2897: String groupName = GROUP_NAME + invalidSymbols.charAt(i);
2898: groupCreator.setName(groupName);
2899: groupCreator.setDescription(description);
2900:
2901: try {
2902: primeException();
2903: stepData.remove(GROUP);
2904: Group group = groupService.create(groupCreator);
2905: stepData.put(GROUP, group);
2906: } catch (KapuaException ex) {
2907: verifyException(ex);
2908: }
2909: }
2910: }
2911:
2912: @When("^I update the group name from \"([^\"]*)\" to name with special characters \"([^\"]*)\"$")
2913: public void iUpdateTheGroupNameFromToNameWithSpecialCharacters(String name, String invalidSymbols) throws Exception {
2914: Group group = (Group) stepData.get(GROUP);
2915: assertEquals(name, group.getName());
2916:• for (int i = 0; i < invalidSymbols.length(); i++) {
2917: String groupName = name + invalidSymbols.charAt(i);
2918: group.setName(groupName);
2919:
2920: try {
2921: primeException();
2922: stepData.remove(GROUP);
2923: Group secondGroup = groupService.update(group);
2924: stepData.put(GROUP_SECOND, secondGroup);
2925: } catch (KapuaException ex) {
2926: verifyException(ex);
2927: }
2928: }
2929: }
2930:
2931: @Given("^I try to create the group with special characters \"([^\"]*)\" in description$")
2932: public void iTryToCreateTheGroupWithSpecialCharactersInDescription(String invalidSymbols) throws Exception {
2933: GroupCreator groupCreator = groupFactory.newCreator(SYS_SCOPE_ID);
2934:• for (int i = 0; i < invalidSymbols.length(); i++) {
2935: String groupDescription = "description" + invalidSymbols.charAt(i);
2936: groupCreator.setDescription(groupDescription);
2937: groupCreator.setName(GROUP_NAME + i);
2938:
2939: try {
2940: primeException();
2941: stepData.remove(GROUP);
2942: Group group = groupService.create(groupCreator);
2943: stepData.put(GROUP, group);
2944: } catch (KapuaException ex) {
2945: verifyException(ex);
2946: }
2947: }
2948: }
2949:
2950: @When("^I update the group description to description with special characters \"([^\"]*)\"$")
2951: public void iUpdateTheGroupDescriptionFromToDescriptionWithSpecialCharacters(String invalidSymbols) throws Exception {
2952: GroupCreator groupCreator = groupFactory.newCreator(SYS_SCOPE_ID);
2953:• for (int i = 0; i < invalidSymbols.length(); i++) {
2954: String groupDescription = "description" + invalidSymbols.charAt(i);
2955: groupCreator.setDescription(groupDescription);
2956: groupCreator.setName(GROUP_NAME + i);
2957:
2958: try {
2959: primeException();
2960: stepData.remove(GROUP);
2961: Group group = groupService.create(groupCreator);
2962: group.setDescription("description" + invalidSymbols.charAt(i));
2963: groupService.update(group);
2964: stepData.put(GROUP, group);
2965: } catch (KapuaException ex) {
2966: verifyException(ex);
2967: }
2968: }
2969: }
2970:
2971: }