use of com.vmware.flowgate.common.model.WormholeRole in project flowgate by vmware.
the class AuthControllerTest method readRoleByPageExample.
@Test
public void readRoleByPageExample() throws Exception {
WormholeRole role = createRole();
roleRepository.save(role);
this.mockMvc.perform(get("/v1/auth/role").param("currentPage", "1").param("pageSize", "5")).andExpect(status().isOk()).andDo(document("AuthController-readRoleByPage-example", requestParameters(parameterWithName("currentPage").description("The page you want to get"), parameterWithName("pageSize").description("The number of users you want to get by every request.Default value: 20"))));
roleRepository.deleteById(role.getId());
}
use of com.vmware.flowgate.common.model.WormholeRole in project flowgate by vmware.
the class AuthControllerTest method updateRoleExampleException.
@Test
public void updateRoleExampleException() throws Exception {
WormholeRole role = createRole();
role.setRoleName("sddcuser");
roleRepository.save(role);
WormholeRole role1 = createRole();
roleRepository.save(role1);
role1.setRoleName("sddcuser");
expectedEx.expect(WormholeRequestException.class);
expectedEx.expectMessage("The role name: " + role1.getRoleName() + " is already exsit.");
MvcResult result = this.mockMvc.perform(put("/v1/auth/role").contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(role1))).andReturn();
if (result.getResolvedException() != null) {
roleRepository.deleteById(role.getId());
roleRepository.deleteById(role1.getId());
throw result.getResolvedException();
}
}
use of com.vmware.flowgate.common.model.WormholeRole in project flowgate by vmware.
the class AuthControllerTest method updateRoleExample.
@Test
public void updateRoleExample() throws Exception {
WormholeRole role = createRole();
roleRepository.save(role);
role.setRoleName("sddcuser");
this.mockMvc.perform(put("/v1/auth/role").contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(role))).andExpect(status().isOk()).andDo(document("AuthController-updateRole-example", requestFields(fieldWithPath("id").description("ID of the Role, created by flowgate"), fieldWithPath("roleName").description("roleName."), fieldWithPath("privilegeNames").description("privilegeNames").type(String.class)))).andReturn();
WormholeRole role1 = roleRepository.findById(role.getId()).get();
TestCase.assertEquals("sddcuser", role1.getRoleName());
roleRepository.deleteById(role.getId());
}
use of com.vmware.flowgate.common.model.WormholeRole in project flowgate by vmware.
the class AuthControllerTest method createRoleExample.
@Test
public void createRoleExample() throws Exception {
WormholeRole role = createRole();
this.mockMvc.perform(post("/v1/auth/role").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(role))).andExpect(status().isCreated()).andDo(document("AuthController-createRole-example", requestFields(fieldWithPath("id").description("ID of role, created by flowgate"), fieldWithPath("roleName").description("roleName."), fieldWithPath("privilegeNames").description("list of privilegeNames").type(List.class))));
roleRepository.deleteById(role.getId());
}
use of com.vmware.flowgate.common.model.WormholeRole in project flowgate by vmware.
the class AuthController method updateRole.
// update a role
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/role", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateRole(@RequestBody WormholeRole role) {
Optional<WormholeRole> oldRoleOptional = roleRepository.findById(role.getId());
if (!oldRoleOptional.isPresent()) {
throw WormholeRequestException.NotFound("Role", "id", role.getId());
}
WormholeRole existingRole = roleRepository.findOneByRoleName(role.getRoleName());
if (existingRole != null && !existingRole.getId().equals(role.getId())) {
String message = "The role name: " + role.getRoleName() + " is already exsit.";
throw new WormholeRequestException(message);
}
WormholeRole old = oldRoleOptional.get();
if (role.getRoleName() != null && !"".equals(role.getRoleName().trim())) {
old.setRoleName(role.getRoleName());
}
if (role.getPrivilegeNames() != null) {
old.setPrivilegeNames(role.getPrivilegeNames());
}
roleRepository.save(old);
InitializeConfigureData.setPrivileges(role.getRoleName(), role.getPrivilegeNames());
}
Aggregations