Search in sources :

Example 1 with ValidationResults

use of com.blackducksoftware.integration.validator.ValidationResults in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testValidConfig.

@Test
@Override
public void testValidConfig() throws Exception {
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(null, null, null);
    final String url = "https://www.google.com/";
    final String user = "User";
    final String password = "Password";
    HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setHubUrl(url);
    serverConfigBuilder.setUsername(user);
    serverConfigBuilder.setUsername(password);
    try {
        configActions.validateHubConfiguration(serverConfigBuilder);
        fail();
    } catch (final AlertFieldException e) {
        assertNotNull(e);
        assertEquals("There were issues with the configuration.", e.getMessage());
        assertTrue(!e.getFieldErrors().isEmpty());
    }
    final HubServerConfigValidator validator = Mockito.mock(HubServerConfigValidator.class);
    serverConfigBuilder = Mockito.spy(serverConfigBuilder);
    Mockito.when(serverConfigBuilder.createValidator()).thenReturn(validator);
    Mockito.when(validator.assertValid()).thenReturn(new ValidationResults());
    try {
        configActions.validateHubConfiguration(serverConfigBuilder);
    } catch (final AlertFieldException e) {
        fail();
    }
}
Also used : ValidationResults(com.blackducksoftware.integration.validator.ValidationResults) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) HubServerConfigValidator(com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 2 with ValidationResults

use of com.blackducksoftware.integration.validator.ValidationResults in project hub-alert by blackducksoftware.

the class GlobalHubConfigActions method validateHubConfiguration.

public void validateHubConfiguration(final HubServerConfigBuilder hubServerConfigBuilder) throws AlertFieldException {
    final AbstractValidator validator = hubServerConfigBuilder.createValidator();
    final ValidationResults results = validator.assertValid();
    if (!results.getResultMap().isEmpty()) {
        final Map<String, String> fieldErrors = new HashMap<>();
        for (final Entry<FieldEnum, Set<ValidationResult>> result : results.getResultMap().entrySet()) {
            final Set<ValidationResult> validationResult = result.getValue();
            final List<String> errors = new ArrayList<>();
            for (final ValidationResult currentValidationResult : validationResult) {
                errors.add(currentValidationResult.getMessage());
            }
            fieldErrors.put(result.getKey().getKey(), StringUtils.join(errors, " , "));
        }
        throw new AlertFieldException("There were issues with the configuration.", fieldErrors);
    }
}
Also used : Set(java.util.Set) AbstractValidator(com.blackducksoftware.integration.validator.AbstractValidator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) ValidationResult(com.blackducksoftware.integration.validator.ValidationResult) FieldEnum(com.blackducksoftware.integration.validator.FieldEnum) ValidationResults(com.blackducksoftware.integration.validator.ValidationResults)

Example 3 with ValidationResults

use of com.blackducksoftware.integration.validator.ValidationResults in project hub-alert by blackducksoftware.

the class LoginActions method validateHubConfiguration.

public void validateHubConfiguration(final HubServerConfigBuilder hubServerConfigBuilder) throws AlertFieldException {
    final AbstractValidator validator = hubServerConfigBuilder.createValidator();
    final ValidationResults results = validator.assertValid();
    if (!results.getResultMap().isEmpty()) {
        final Map<String, String> fieldErrors = new HashMap<>();
        for (final Entry<FieldEnum, Set<ValidationResult>> result : results.getResultMap().entrySet()) {
            final Set<ValidationResult> validationResult = result.getValue();
            final List<String> errors = new ArrayList<>();
            for (final ValidationResult currentValidationResult : validationResult) {
                errors.add(currentValidationResult.getMessage());
            }
            final String key = result.getKey().getKey();
            final String errorMessage = StringUtils.join(errors, " , ");
            fieldErrors.put(key, errorMessage);
        }
        throw new AlertFieldException("There were issues with the configuration.", fieldErrors);
    }
}
Also used : Set(java.util.Set) AbstractValidator(com.blackducksoftware.integration.validator.AbstractValidator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) ValidationResult(com.blackducksoftware.integration.validator.ValidationResult) FieldEnum(com.blackducksoftware.integration.validator.FieldEnum) ValidationResults(com.blackducksoftware.integration.validator.ValidationResults)

Aggregations

AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)3 ValidationResults (com.blackducksoftware.integration.validator.ValidationResults)3 AbstractValidator (com.blackducksoftware.integration.validator.AbstractValidator)2 FieldEnum (com.blackducksoftware.integration.validator.FieldEnum)2 ValidationResult (com.blackducksoftware.integration.validator.ValidationResult)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)1 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)1 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)1 HubServerConfigValidator (com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator)1 Test (org.junit.Test)1