Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.37 KB | None | 0 0
  1. Рустам, [06.03.17 17:06]
  2. class PersonServiceAuthenticationSpec extends RestIntegrationBase {
  3.     String getBasePath() {"persons/"}
  4.  
  5.     @Shared
  6.     def ROLE_TO_USER = [
  7.             NO_ROLE: [name: null, password: null],
  8.             USER:    [name: 'user', password: 'password'],
  9.             ADMIN:   [name: 'admin', password: 'pwd']]
  10.  
  11.     @Unroll("calling #endpoint with user #user should return status #status")
  12.     def "test authentication of #endpoint"() {
  13.         given:
  14.             RestTemplate restTemplate = new TestRestTemplate(user.name, user.password)
  15.             RequestEntity request = RequestEntity.get(serviceURI(endpoint)).build()
  16.         when:
  17.             ResponseEntity response = restTemplate.exchange(request, Object)
  18.         then:
  19.             response.statusCode == status
  20.         where:
  21.             endpoint                  | user                 || status
  22.             ""                        | ROLE_TO_USER.NO_ROLE || HttpStatus.UNAUTHORIZED
  23.             ""                        | ROLE_TO_USER.USER    || HttpStatus.OK
  24.             ""                        | ROLE_TO_USER.ADMIN   || HttpStatus.OK
  25.             "search/byFirstName/John" | ROLE_TO_USER.NO_ROLE || HttpStatus.UNAUTHORIZED
  26.             "search/byFirstName/John" | ROLE_TO_USER.USER    || HttpStatus.OK
  27.             "search/byFirstName/John" | ROLE_TO_USER.ADMIN   || HttpStatus.OK }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement