use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.
the class SettingsProxyTestActionTestIT method testWithPermissionCheckTest.
@Test
void testWithPermissionCheckTest() {
SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
assertTrue(testResult.isSuccessful());
assertTrue(testResult.getContent().isPresent());
ValidationResponseModel validationResponseModel = testResult.getContent().get();
assertFalse(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.
the class SettingsProxyControllerTestIT method testCreate.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testCreate() throws Exception {
SettingsProxyModel settingsProxyModel = createSettingsProxyModel(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
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);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isCreated());
}
use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.
the class SettingsProxyControllerTestIT method testCreateTwice.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testCreateTwice() throws Exception {
createDefaultSettingsProxyModel(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(AssertionFailedError::new);
SettingsProxyModel newSettingsProxyModel = new SettingsProxyModel();
newSettingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
newSettingsProxyModel.setProxyHost("newHostname");
newSettingsProxyModel.setProxyPort(678);
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(newSettingsProxyModel)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isBadRequest());
}
use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel 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 com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.
the class SettingsProxyControllerTestIT method testUpdate.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testUpdate() throws Exception {
createDefaultSettingsProxyModel(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(AssertionFailedError::new);
SettingsProxyModel newSettingsProxyModel = new SettingsProxyModel();
newSettingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
newSettingsProxyModel.setProxyHost("newHostname");
newSettingsProxyModel.setProxyPort(678);
String url = AlertRestConstants.SETTINGS_PROXY_PATH;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(newSettingsProxyModel)).contentType(contentType);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
Aggregations