Search in sources :

Example 1 with TypeToken

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);
}
Also used : TypeToken(org.testcontainers.shaded.com.google.common.reflect.TypeToken) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) MvcResult(org.springframework.test.web.servlet.MvcResult) URI(java.net.URI)

Example 2 with TypeToken

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);
}
Also used : TypeToken(org.testcontainers.shaded.com.google.common.reflect.TypeToken) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MvcResult(org.springframework.test.web.servlet.MvcResult) URI(java.net.URI)

Example 3 with TypeToken

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);
}
Also used : TypeToken(org.testcontainers.shaded.com.google.common.reflect.TypeToken) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MvcResult(org.springframework.test.web.servlet.MvcResult) URI(java.net.URI)

Aggregations

URI (java.net.URI)3 MvcResult (org.springframework.test.web.servlet.MvcResult)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 TypeToken (org.testcontainers.shaded.com.google.common.reflect.TypeToken)3 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)1