Search in sources :

Example 1 with WormholeUser

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

the class FacilitySoftwareControllerTest method facilitySoftwareQueryByPageExample1.

// query by currentUser
@Test
public void facilitySoftwareQueryByPageExample1() 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>();
    // not admin
    roles.add("queryFacility");
    user.setRoleNames(roles);
    userRepository.save(user);
    // userId of the facilitySoftware is '5b7d208d55368540fcba1692'
    FacilitySoftwareConfig facilitySoftware = createFacilitySoftware();
    facilitySoftware.setUserId("5b7d208d55368540fcba1692");
    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()));
    } 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 2 with WormholeUser

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

the class AuthControllerTest method testCreateToken.

@Test
public void testCreateToken() throws Exception {
    ValueOperations<String, String> valueOperations = Mockito.mock(ValueOperations.class);
    Mockito.doReturn(valueOperations).when(template).opsForValue();
    WormholeUser wormholeuser = createUser();
    wormholeuser.setUserName("tom");
    wormholeuser.setPassword("$2a$10$Vm8MLIkGwinuICfcqW5RDOoE.aJqnvsaPhnxl7.N4H7oLKVIu3o0.");
    wormholeuser.setRoleNames(Arrays.asList("admin"));
    userRepository.save(wormholeuser);
    this.mockMvc.perform(post("/v1/auth/token").contentType(MediaType.APPLICATION_JSON).content("{\"userName\":\"tom\",\"password\":\"123456\"}")).andExpect(status().isOk()).andDo(document("AuthController-CreateAccessToken-example", relaxedRequestFields(fieldWithPath("userName").description("A user name for flowgate Project"), fieldWithPath("password").description("A password for flowgate Project.")))).andReturn();
    userRepository.deleteById(wormholeuser.getId());
}
Also used : WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with WormholeUser

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

the class AuthControllerTest method readOneUserByUserNameExample1.

@Test
public void readOneUserByUserNameExample1() throws Exception {
    WormholeUserDetails userdetail = new WormholeUserDetails();
    String userId = UUID.randomUUID().toString();
    userdetail.setUserId(userId);
    List<String> rolenames = new ArrayList<String>();
    rolenames.add("sysuser");
    WormholeUser sysuser = new WormholeUser();
    sysuser.setRoleNames(rolenames);
    sysuser.setId(userId);
    sysuser.setUserName("lucy");
    userRepository.save(sysuser);
    Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
    this.mockMvc.perform(get("/v1/auth/user/username/" + sysuser.getUserName() + "")).andExpect(status().isOk()).andReturn();
    userRepository.deleteById(sysuser.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 4 with WormholeUser

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

the class AuthControllerTest method deleteUserExample.

@Test
public void deleteUserExample() throws Exception {
    WormholeUser user = createUser();
    userRepository.save(user);
    this.mockMvc.perform(delete("/v1/auth/user/{id}", user.getId())).andExpect(status().isOk()).andDo(document("AuthController-deleteUser-example", pathParameters(parameterWithName("id").description("The id of user, generated by flowgate.")))).andReturn();
}
Also used : WormholeUser(com.vmware.flowgate.common.model.WormholeUser) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with WormholeUser

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

the class AuthControllerTest method readUsersByPageExample.

@Test
public void readUsersByPageExample() throws Exception {
    WormholeUser user1 = createUser();
    userRepository.save(user1);
    this.mockMvc.perform(get("/v1/auth/user").param("currentPage", "1").param("pageSize", "5")).andExpect(status().isOk()).andDo(document("AuthController-readUsersByPage-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"))));
    userRepository.deleteById(user1.getId());
}
Also used : 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