use of org.testcontainers.shaded.com.google.common.reflect.TypeToken in project hub-alert by blackducksoftware.
the class SettingsProxyControllerTestIT method createDefaultSettingsProxyModel.
private Optional<SettingsProxyModel> createDefaultSettingsProxyModel(String configurationName) throws Exception {
SettingsProxyModel settingsProxyModel = createSettingsProxyModel(configurationName);
String url = AlertRestConstants.SETTINGS_PROXY_PATH;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(settingsProxyModel)).contentType(contentType);
MvcResult mvcResult = mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isCreated()).andReturn();
String response = mvcResult.getResponse().getContentAsString();
TypeToken<SettingsProxyModel> settingsProxyModelType = new TypeToken<>() {
};
SettingsProxyModel newSettingsProxyModel = gson.fromJson(response, settingsProxyModelType.getType());
return Optional.of(newSettingsProxyModel);
}
use of org.testcontainers.shaded.com.google.common.reflect.TypeToken in project hub-alert by blackducksoftware.
the class RoleControllerTestIT method createRolePermissionModel.
private Optional<RolePermissionModel> createRolePermissionModel() throws Exception {
PermissionModel permissionModel = new PermissionModel(blackDuckProviderKey.getUniversalKey(), context, true, true, true, true, true, true, true, true);
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel));
String url = RoleController.ROLE_BASE_PATH;
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);
MvcResult mvcResult = mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isCreated()).andReturn();
String response = mvcResult.getResponse().getContentAsString();
TypeToken rolePermissionModelType = new TypeToken<RolePermissionModel>() {
};
RolePermissionModel newRolePermissionModel = gson.fromJson(response, rolePermissionModelType.getType());
return Optional.of(newRolePermissionModel);
}
use of org.testcontainers.shaded.com.google.common.reflect.TypeToken in project hub-alert by blackducksoftware.
the class UserControllerTestIT method createDefaultUserConfig.
private Optional<UserConfig> createDefaultUserConfig() 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);
MvcResult mvcResult = mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isCreated()).andReturn();
String response = mvcResult.getResponse().getContentAsString();
TypeToken userConfigType = new TypeToken<UserConfig>() {
};
UserConfig newUserConfig = gson.fromJson(response, userConfigType.getType());
return Optional.of(newUserConfig);
}
Aggregations