use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class RoleControllerTestIT method testUpdate.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testUpdate() throws Exception {
RolePermissionModel rolePermissionModel = createRolePermissionModel().orElseThrow(AssertionFailedError::new);
PermissionModel permissionModel = new PermissionModel(blackDuckProviderKey.getUniversalKey(), context, false, false, false, false, false, false, false, false);
RolePermissionModel updatedRolePermissionModel = new RolePermissionModel(rolePermissionModel.getId(), roleName, Set.of(permissionModel));
String url = RoleController.ROLE_BASE_PATH + String.format("/%s", rolePermissionModel.getId());
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(updatedRolePermissionModel)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class RoleControllerTestIT method testValidate.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testValidate() throws Exception {
RolePermissionModel rolePermissionModel = createRolePermissionModel().orElseThrow(AssertionFailedError::new);
String url = RoleController.ROLE_BASE_PATH + "/validate";
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(rolePermissionModel)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class UserControllerTestIT method testUpdate.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testUpdate() throws Exception {
UserConfig userConfig = createDefaultUserConfig().orElseThrow(AssertionFailedError::new);
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
UserConfig updatedUserConfig = new UserConfig(userConfig.getId(), userConfig.getUsername(), password, "newEmailAddress", roleNames, false, false, false, true, false, userConfig.getAuthenticationType(), false);
String url = UserController.USER_BASE_PATH + String.format("/%s", userConfig.getId());
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(updatedUserConfig)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class UserControllerTestIT method testGetAll.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetAll() throws Exception {
String url = UserController.USER_BASE_PATH;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.security.test.context.support.WithMockUser in project hub-alert by blackducksoftware.
the class UserControllerTestIT method testCreate.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testCreate() throws Exception {
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
UserConfig userConfig = new UserConfig(id.toString(), name, password, emailAddress, roleNames, false, false, false, true, false, authenticationType.name(), false);
String url = UserController.USER_BASE_PATH;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(userConfig)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isCreated());
}
Aggregations