Search in sources :

Example 11 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationValidatorTest method verifyMalformedUrl.

@Test
void verifyMalformedUrl() {
    String badUrl = "notAValidUrl";
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, badUrl, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(1, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
    for (AlertFieldStatus status : alertFieldStatuses) {
        assertEquals("url", status.getFieldName(), "Validation reported an error for an unexpected field.");
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 12 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationValidatorTest method verifyValidConfig.

@Test
void verifyValidConfig() {
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(0, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 13 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class BlackDuckGlobalConfigurationFieldModelValidatorTest method nonUniqueName.

@Test
public void nonUniqueName() {
    String duplicateName = "duplicateName";
    Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
    FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of(duplicateName), true);
    defaultKeyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, apiKeyFieldValueModel);
    FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
    ConfigurationFieldModel configurationFieldModel = Mockito.mock(ConfigurationFieldModel.class);
    Mockito.when(configurationFieldModel.getFieldValue()).thenReturn(Optional.of(duplicateName));
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModel.getDescriptorContext()).thenReturn(ConfigContextEnum.GLOBAL);
    Mockito.when(configurationModel.getField(Mockito.any())).thenReturn(Optional.of(configurationFieldModel));
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(Mockito.any())).thenReturn(List.of(configurationModel));
    BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(configurationModelConfigurationAccessor);
    Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
    assertEquals(1, alertFieldStatuses.size());
    AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElse(null);
    assertNotNull(alertFieldStatus);
    assertEquals(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, alertFieldStatus.getFieldName());
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test)

Example 14 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class BlackDuckGlobalConfigurationFieldModelValidatorTest method verifyValidConfiguration.

/*
     * Provider config name: Required, no duplicate names
     * Url: required, valid Url
     * API key: required, Specific length
     * Timeout: required, long timeout warning, < 0 timeout error
     */
@Test
public void verifyValidConfiguration() {
    Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
    FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
    BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(createDefaultConfigurationAccessor());
    Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
    assertEquals(0, alertFieldStatuses.size());
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test)

Example 15 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class AzureBoardsGlobalConfigurationFieldModelValidatorTest method oauthRequestIsRunningError.

@Test
public void oauthRequestIsRunningError() {
    OAuthRequestValidator oAuthRequestValidator = new OAuthRequestValidator();
    oAuthRequestValidator.addAuthorizationRequest("test");
    AzureBoardsGlobalConfigurationFieldModelValidator azureBoardsGlobalConfigurationValidator = new AzureBoardsGlobalConfigurationFieldModelValidator(oAuthRequestValidator);
    Set<AlertFieldStatus> fieldStatuses = azureBoardsGlobalConfigurationValidator.validate(new FieldModel(new AzureBoardsChannelKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), createValidKeyToValues()));
    assertEquals(1, fieldStatuses.size());
    AlertFieldStatus alertFieldStatus = fieldStatuses.stream().findFirst().orElse(null);
    assertNotNull(alertFieldStatus);
    assertEquals(AzureBoardsDescriptor.KEY_OAUTH, alertFieldStatus.getFieldName());
}
Also used : OAuthRequestValidator(com.synopsys.integration.alert.channel.azure.boards.oauth.OAuthRequestValidator) AzureBoardsChannelKey(com.synopsys.integration.alert.descriptor.api.AzureBoardsChannelKey) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) Test(org.junit.jupiter.api.Test)

Aggregations

AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)50 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)23 Test (org.junit.jupiter.api.Test)23 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)11 ArrayList (java.util.ArrayList)11 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)10 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Component (org.springframework.stereotype.Component)9 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)8 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)8 List (java.util.List)8 Optional (java.util.Optional)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6