-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corrected groups controller and added testing
- Loading branch information
Showing
7 changed files
with
221 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
...net2/tier/shibboleth/admin/ui/security/controller/GroupsControllerIntegrationTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| package edu.internet2.tier.shibboleth.admin.ui.security.controller | ||
|
|
||
|
|
||
| import groovy.json.JsonOutput | ||
| import org.springframework.beans.factory.annotation.Autowired | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
| import org.springframework.boot.test.context.SpringBootTest | ||
| import org.springframework.http.MediaType | ||
| import org.springframework.security.test.context.support.WithMockUser | ||
| import org.springframework.test.annotation.Rollback | ||
| import org.springframework.test.context.ActiveProfiles | ||
| import org.springframework.test.web.servlet.MockMvc | ||
| import org.springframework.test.web.servlet.result.MockMvcResultHandlers | ||
| import org.springframework.transaction.annotation.Transactional | ||
|
|
||
| import spock.lang.Ignore | ||
| import spock.lang.Specification | ||
|
|
||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
|
||
| @SpringBootTest | ||
| @AutoConfigureMockMvc | ||
| @ActiveProfiles(["no-auth", "dev"]) | ||
| @Transactional | ||
| class GroupsControllerIntegrationTests extends Specification { | ||
| @Autowired | ||
| private MockMvc mockMvc | ||
|
|
||
| static RESOURCE_URI = '/api/admin/groups' | ||
|
|
||
| @Rollback | ||
| @WithMockUser(value = "admin", roles = ["ADMIN"]) | ||
| def 'POST new group persists properly'() { | ||
| given: | ||
| def newGroup = [name: 'Foo', | ||
| description: 'Bar', | ||
| resourceId: 'FooBar'] | ||
|
|
||
| def expectedJson = """ | ||
| { | ||
| "name":"Foo", | ||
| "description":"Bar", | ||
| "resourceId":"FooBar" | ||
| } | ||
| """ | ||
|
|
||
| when: | ||
| def result = mockMvc.perform(post(RESOURCE_URI) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(JsonOutput.toJson(newGroup)) | ||
| .accept(MediaType.APPLICATION_JSON)) | ||
|
|
||
| then: | ||
| result.andExpect(status().isCreated()) | ||
| .andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(content().json(expectedJson, false)) | ||
|
|
||
| when: 'Try to create with an existing resource id' | ||
| result = mockMvc.perform(post(RESOURCE_URI) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(JsonOutput.toJson(newGroup)) | ||
| .accept(MediaType.APPLICATION_JSON)) | ||
|
|
||
| then: 'Expecting method not allowed' | ||
| result.andExpect(status().isMethodNotAllowed()) | ||
| } | ||
|
|
||
| @Rollback | ||
| @WithMockUser(value = "admin", roles = ["ADMIN"]) | ||
| def 'PUT (update) existing group persists properly'() { | ||
| given: | ||
| def group = [name: 'NOT AAA', | ||
| description: 'updated AAA', | ||
| resourceId: 'AAA'] | ||
|
|
||
| def expectedJson = """ | ||
| { | ||
| "name":"NOT AAA", | ||
| "description":"updated AAA", | ||
| "resourceId":"AAA" | ||
| } | ||
| """ | ||
| when: | ||
| def result = mockMvc.perform(put(RESOURCE_URI) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(JsonOutput.toJson(group)) | ||
| .accept(MediaType.APPLICATION_JSON)) | ||
|
|
||
| then: | ||
| result.andExpect(status().isOk()) | ||
| .andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(content().json(expectedJson, false)) | ||
|
|
||
| when: 'Try to update with a non-existing resource id' | ||
| def newGroup = [name: 'XXXXX', | ||
| description: 'should not work', | ||
| resourceId: 'XXXX'] | ||
| def notFoundresult = mockMvc.perform(put(RESOURCE_URI) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(JsonOutput.toJson(newGroup)) | ||
| .accept(MediaType.APPLICATION_JSON)) | ||
|
|
||
| then: 'Expecting nothing happened because the object was not found' | ||
| notFoundresult.andExpect(status().isNotFound()) | ||
| } | ||
|
|
||
| @WithMockUser(value = "admin", roles = ["ADMIN"]) | ||
| def 'GET checks for groups (when there are existing groups)'() { | ||
| given: | ||
| def expectedJson = """ | ||
| [ | ||
| { | ||
| "name":"A1", | ||
| "description":"AAA Group", | ||
| "resourceId":"AAA" | ||
| }, | ||
| { | ||
| "name":"B1", | ||
| "description":"BBB Group", | ||
| "resourceId":"BBB" | ||
| } | ||
| ]""" | ||
| when: 'GET request is made for ALL groups in the system, and system has groups in it' | ||
| def result = mockMvc.perform(get(RESOURCE_URI)) | ||
| then: 'Request completed with HTTP 200 and returned a list of users' | ||
| result.andExpect(status().isOk()) | ||
| .andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(content().json(expectedJson, false)) | ||
| when: 'GET request for a single specific group in a system that has groups' | ||
| def singleGroupRequest = mockMvc.perform(get("$RESOURCE_URI/BBB")) | ||
| then: 'GET request for a single specific group completed with HTTP 200' | ||
| singleGroupRequest.andExpect(status().isOk()) | ||
| when: 'GET request for a single non-existent group in a system that has groups' | ||
| def nonexistentGroupRequest = mockMvc.perform(get("$RESOURCE_URI/CCC")) | ||
| then: 'The group not found' | ||
| nonexistentGroupRequest.andExpect(status().isNotFound()) | ||
| } | ||
| @Rollback | ||
| @WithMockUser(value = "admin", roles = ["ADMIN"]) | ||
| def 'DELETE ONE existing group'() { | ||
| when: 'GET request for a single specific group in a system that has groups' | ||
| def result = mockMvc.perform(get("$RESOURCE_URI/BBB")) | ||
| then: 'GET request for a single specific group completed with HTTP 200' | ||
| result.andExpect(status().isOk()) | ||
| when: 'DELETE request is made' | ||
| result = mockMvc.perform(delete("$RESOURCE_URI/BBB")) | ||
| then: 'DELETE was successful' | ||
| result.andExpect(status().isNoContent()) | ||
| when: 'GET request for a single specific group just deleted' | ||
| result = mockMvc.perform(get("$RESOURCE_URI/BBB")) | ||
| then: 'The group not found' | ||
| result.andExpect(status().isNotFound()) | ||
| when: 'DELETE request for a single specific group that does not exist' | ||
| result = mockMvc.perform(delete("$RESOURCE_URI/CCCC")) | ||
| then: 'The group not found' | ||
| result.andExpect(status().isNotFound()) | ||
| //ADD conflict test when the group has users | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters