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());
}
}
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());
}
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());
}
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();
}
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());
}
Aggregations