Search in sources :

Example 1 with WormholeRole

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());
}
Also used : WormholeRole(com.vmware.flowgate.common.model.WormholeRole) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with WormholeRole

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();
    }
}
Also used : WormholeRole(com.vmware.flowgate.common.model.WormholeRole) MvcResult(org.springframework.test.web.servlet.MvcResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with WormholeRole

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());
}
Also used : WormholeRole(com.vmware.flowgate.common.model.WormholeRole) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with WormholeRole

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());
}
Also used : WormholeRole(com.vmware.flowgate.common.model.WormholeRole) List(java.util.List) ArrayList(java.util.ArrayList) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with WormholeRole

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());
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) WormholeRole(com.vmware.flowgate.common.model.WormholeRole) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WormholeRole (com.vmware.flowgate.common.model.WormholeRole)9 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 ArrayList (java.util.ArrayList)4 List (java.util.List)3 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 PageRequest (org.springframework.data.domain.PageRequest)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1