use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class TestHelperConfigurationTest method testValidationWithError.
@Test
public void testValidationWithError() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.BAD_REQUEST, ValidationResponseModel.generalError("generalError")), () -> ConfigurationTestResult.success("Success"));
ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
assertEquals(HttpStatus.BAD_REQUEST, response.getHttpStatus());
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class ConfigurationValidationHelperTest method testValidationWithError.
@Test
public void testValidationWithError() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationValidationHelper validationHelper = new ConfigurationValidationHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = validationHelper.validate(() -> ValidationResponseModel.generalError("generalError"));
ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class SettingsProxyValidatorTest method validateWithoutHostAndPortTest.
@Test
void validateWithoutHostAndPortTest() {
SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
settingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
ValidationResponseModel validationResponseModel = settingsProxyValidator.validate(settingsProxyModel);
assertTrue(validationResponseModel.hasErrors());
assertEquals(2, validationResponseModel.getErrors().size());
assertTrue(validationResponseModel.getErrors().containsKey(SettingsProxyValidator.PROXY_HOST_FIELD_NAME));
assertTrue(validationResponseModel.getErrors().containsKey(SettingsProxyValidator.PROXY_PORT_FIELD_NAME));
}
use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class SettingsProxyTestActionTest method testWithPermissionCheckFailureTest.
@Test
void testWithPermissionCheckFailureTest() {
ConfigurationTestResult configurationTestResult = ConfigurationTestResult.failure("Failure");
ProxyTestService proxyTestService = Mockito.mock(ProxyTestService.class);
Mockito.when(proxyTestService.pingHost(Mockito.eq(TEST_URL), Mockito.any())).thenReturn(configurationTestResult);
SettingsProxyTestAction settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
ActionResponse<ValidationResponseModel> actionResponse = settingsProxyTestAction.testWithPermissionCheck(TEST_URL, defaultSettingsProxyModel);
assertTrue(actionResponse.isSuccessful());
assertTrue(actionResponse.hasContent());
Optional<ValidationResponseModel> validationResponseModel = actionResponse.getContent();
assertTrue(validationResponseModel.isPresent());
assertTrue(validationResponseModel.get().hasErrors());
}
use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class SettingsProxyValidatorTest method validatePasswordWithoutUsernameTest.
@Test
void validatePasswordWithoutUsernameTest() {
SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
settingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
settingsProxyModel.setProxyHost(HOST);
settingsProxyModel.setProxyPort(PORT);
settingsProxyModel.setProxyPassword(PASSWORD);
ValidationResponseModel validationResponseModel = settingsProxyValidator.validate(settingsProxyModel);
assertTrue(validationResponseModel.hasErrors());
assertEquals(1, validationResponseModel.getErrors().size());
assertTrue(validationResponseModel.getErrors().containsKey(SettingsProxyValidator.PROXY_USERNAME_FIELD_NAME));
}
Aggregations