Search in sources :

Example 21 with WormholeUser

use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.

the class AuthControllerTest method createUserExample.

@Test
public void createUserExample() throws Exception {
    WormholeUser user = createUser();
    this.mockMvc.perform(post("/v1/auth/user").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(user))).andExpect(status().isCreated()).andDo(document("AuthController-createUser-example", requestFields(fieldWithPath("id").description("ID of User, created by flowgate"), fieldWithPath("userName").description("userName.").type(JsonFieldType.STRING), fieldWithPath("gender").description("gender").type(JsonFieldType.NUMBER), fieldWithPath("password").description("password").type(JsonFieldType.STRING), fieldWithPath("mobile").description("mobile").type(JsonFieldType.STRING), fieldWithPath("status").description("status").type(JsonFieldType.NUMBER), fieldWithPath("createTime").description("createTime").type(Date.class), fieldWithPath("emailAddress").description("emailAddress").type(JsonFieldType.STRING), fieldWithPath("roleNames").description("roleNames").type(List.class), fieldWithPath("userGroupIDs").description("userGroupIDs").type(List.class), fieldWithPath("lastPasswordResetDate").description("lastPasswordResetDate").type(JsonFieldType.NUMBER)))).andReturn();
    userRepository.deleteById(user.getId());
}
Also used : WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 22 with WormholeUser

use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.

the class AuthControllerTest method updateUserExample.

@Test
public void updateUserExample() throws Exception {
    WormholeUserDetails userdetail = new WormholeUserDetails();
    String userId = UUID.randomUUID().toString();
    userdetail.setUserId(userId);
    List<String> rolenames = new ArrayList<String>();
    rolenames.add("admin");
    WormholeUser adminUser = new WormholeUser();
    adminUser.setUserName("admin");
    adminUser.setRoleNames(rolenames);
    adminUser.setId(userId);
    userRepository.save(adminUser);
    Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
    WormholeUser user = createUser();
    userRepository.save(user);
    this.mockMvc.perform(put("/v1/auth/user").contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(user))).andExpect(status().isOk()).andDo(document("AuthController-updateUser-example", requestFields(fieldWithPath("id").description("ID of User, created by flowgate"), fieldWithPath("userName").description("userName.").type(JsonFieldType.STRING), fieldWithPath("gender").description("gender").type(JsonFieldType.NUMBER), fieldWithPath("password").description("password").type(JsonFieldType.STRING), fieldWithPath("mobile").description("mobile").type(JsonFieldType.STRING), fieldWithPath("status").description("status").type(JsonFieldType.NUMBER), fieldWithPath("createTime").description("createTime").type(Date.class), fieldWithPath("emailAddress").description("emailAddress").type(JsonFieldType.STRING), fieldWithPath("roleNames").description("roleNames").type(List.class), fieldWithPath("userGroupIDs").description("userGroupIDs").type(List.class), fieldWithPath("lastPasswordResetDate").description("lastPasswordResetDate").type(JsonFieldType.NUMBER)))).andReturn();
    userRepository.deleteById(user.getId());
    userRepository.deleteById(adminUser.getId());
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 23 with WormholeUser

use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.

the class AuthControllerTest method readOneUserByUserNameExample2.

@Test
public void readOneUserByUserNameExample2() throws Exception {
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Forbidden");
    String userId = UUID.randomUUID().toString();
    WormholeUserDetails userdetail = new WormholeUserDetails();
    userdetail.setUserId(userId);
    List<String> rolenames = new ArrayList<String>();
    rolenames.add("sysuser");
    WormholeUser sysuser = createUser();
    sysuser.setId(userId);
    sysuser.setRoleNames(rolenames);
    sysuser.setUserName("lucy");
    userRepository.save(sysuser);
    Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
    MvcResult result = this.mockMvc.perform(get("/v1/auth/user/username/tom")).andExpect(status().isForbidden()).andReturn();
    if (result.getResolvedException() != null) {
        userRepository.deleteById(sysuser.getId());
        throw result.getResolvedException();
    }
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) MvcResult(org.springframework.test.web.servlet.MvcResult) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 24 with WormholeUser

use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.

the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageAndTypeExample.

// facilitySoftwareConfigsByType
@Test
public void facilitySoftwareQueryByPageAndTypeExample() throws Exception {
    WormholeUserDetails userDeails = createuser();
    userDeails.setUserId("5b7d208d55368540fcba1692");
    Mockito.doReturn(userDeails).when(tokenService).getCurrentUser(any());
    WormholeUser user = new WormholeUser();
    user.setId("5b7d208d55368540fcba1692");
    List<String> roles = new ArrayList<String>();
    roles.add("admin");
    user.setRoleNames(roles);
    userRepository.save(user);
    // userId of the facilitySoftware is not '5b7d208d55368540fcba1692'
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setPassword(EncryptionGuard.encode(facilitySoftware.getPassword()));
    facilitySoftwareRepository.save(facilitySoftware);
    int pageNumber = 1;
    int pageSize = 5;
    try {
        this.mockMvc.perform(get("/v1/facilitysoftware/page/{pageNumber}/pagesize/{pageSize}", pageNumber, pageSize).param("softwaretypes", "Nlyte")).andExpect(status().isOk()).andExpect(jsonPath("$..content[0].name").value(facilitySoftware.getName())).andExpect(jsonPath("$..content[0].userId").value(facilitySoftware.getUserId())).andExpect(jsonPath("$..content[0].type").value(facilitySoftware.getType().name())).andDo(document("facilitySoftware-queryByTypeAndPage-example", pathParameters(parameterWithName("pageNumber").description("Get datas for this page number."), parameterWithName("pageSize").description("The number of facilitysoftwares you want to get by every request.Default value: 20")), requestParameters(parameterWithName("softwaretypes").description("A list of software, maybe contain Nlyte/PowerIQ/InfoBlox/OpenManage/Labsdb"))));
    } finally {
        facilitySoftwareRepository.deleteById(facilitySoftware.getId());
        userRepository.deleteById(user.getId());
    }
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 25 with WormholeUser

use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.

the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageExample.

// admin can find all facilitySoftwareConfigs
@Test
public void facilitySoftwareQueryByPageExample() throws Exception {
    WormholeUserDetails userDeails = createuser();
    userDeails.setUserId("5b7d208d55368540fcba1692");
    Mockito.doReturn(userDeails).when(tokenService).getCurrentUser(any());
    WormholeUser user = new WormholeUser();
    user.setId("5b7d208d55368540fcba1692");
    List<String> roles = new ArrayList<String>();
    roles.add("admin");
    user.setRoleNames(roles);
    userRepository.save(user);
    // userId of the facilitySoftware is not '5b7d208d55368540fcba1692'
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setPassword(EncryptionGuard.encode(facilitySoftware.getPassword()));
    facilitySoftwareRepository.save(facilitySoftware);
    int pageNumber = 1;
    int pageSize = 5;
    try {
        this.mockMvc.perform(get("/v1/facilitysoftware/page/{pageNumber}/pagesize/{pageSize}", pageNumber, pageSize)).andExpect(status().isOk()).andExpect(jsonPath("$..content[0].name").value(facilitySoftware.getName())).andExpect(jsonPath("$..content[0].userId").value(facilitySoftware.getUserId())).andDo(document("facilitySoftware-queryByPage-example", pathParameters(parameterWithName("pageNumber").description("Get datas for this page number."), parameterWithName("pageSize").description("The number of facilitysoftwares you want to get by every request.Default value: 20"))));
    } finally {
        facilitySoftwareRepository.deleteById(facilitySoftware.getId());
        userRepository.deleteById(user.getId());
    }
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

WormholeUser (com.vmware.flowgate.common.model.WormholeUser)27 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)18 Test (org.junit.Test)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 ArrayList (java.util.ArrayList)14 MvcResult (org.springframework.test.web.servlet.MvcResult)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)4 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)3 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Date (java.util.Date)2 Optional (java.util.Optional)2 PageRequest (org.springframework.data.domain.PageRequest)2 AuthToken (com.vmware.flowgate.common.model.AuthToken)1 SoftwareType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType)1 AuthorityUtil (com.vmware.flowgate.util.AuthorityUtil)1 IOException (java.io.IOException)1 Cookie (javax.servlet.http.Cookie)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1