Search in sources :

Example 11 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class IssueTrackerTransitionFieldModelTestActionTest method testAndAssertHasErrors.

private static void testAndAssertHasErrors(IssueTrackerMessageSender<String> messageSender) {
    IssueTrackerTransitionTestAction<String> transitionTestAction = new IssueTrackerTransitionTestAction<>(messageSender, FIELD_STATUS_CREATOR);
    Optional<MessageResult> optionalMessageResult = transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.OPEN, EXISTING_ISSUE_DETAILS, PROJECT_ISSUE_MODEL);
    assertTrue(optionalMessageResult.isPresent(), EXPECTED_MESSAGE_RESULT);
    MessageResult messageResult = optionalMessageResult.get();
    assertTrue(messageResult.hasErrors(), EXPECTED_ERRORS);
}
Also used : MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult)

Example 12 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class BlackDuckDistributionFieldModelTestAction method testConfig.

@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
    ArrayList<AlertFieldStatus> fieldStatuses = new ArrayList<>();
    Optional<Long> optionalProviderConfigId = registeredFieldValues.getLong(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
    if (optionalProviderConfigId.isPresent()) {
        Long providerConfigId = optionalProviderConfigId.get();
        boolean filterByProjects = registeredFieldValues.getBoolean(ProviderDescriptor.KEY_FILTER_BY_PROJECT).orElse(false);
        if (filterByProjects) {
            Collection<String> configuredProjects = registeredFieldValues.getAllStrings(ProviderDescriptor.KEY_CONFIGURED_PROJECT);
            validateSelectedProjectExists(providerConfigId, configuredProjects).ifPresent(fieldStatuses::add);
            Optional<String> optionalProjectNamePattern = registeredFieldValues.getString(ProviderDescriptor.KEY_PROJECT_NAME_PATTERN);
            optionalProjectNamePattern.flatMap(projectNamePattern -> validatePatternMatchesProject(providerConfigId, projectNamePattern)).ifPresent(fieldStatuses::add);
            registeredFieldValues.getString(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN).flatMap(projectVersionNamePattern -> validatePatternMatchesProjectVersion(providerConfigId, projectVersionNamePattern, optionalProjectNamePattern.orElse(null), configuredProjects)).ifPresent(fieldStatuses::add);
        }
        BlackDuckProperties blackDuckProperties = null;
        Optional<ConfigurationModel> providerConfigurationOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
        if (providerConfigurationOptional.isPresent()) {
            ConfigurationModel providerConfiguration = providerConfigurationOptional.get();
            StatefulProvider statefulProvider = blackDuckProvider.createStatefulProvider(providerConfiguration);
            blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
        }
        if (null != blackDuckProperties) {
            BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
            if (!blackDuckAPITokenValidator.isApiTokenValid()) {
                fieldStatuses.add(AlertFieldStatus.error(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, "User permission failed, cannot read notifications from Black Duck."));
            }
        }
    } else {
        fieldStatuses.add(AlertFieldStatus.error(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, "A provider configuration is required"));
    }
    if (MessageResult.hasFieldStatusBySeverity(fieldStatuses, FieldStatusSeverity.ERROR)) {
        return new MessageResult("There were errors with the BlackDuck provider fields", fieldStatuses);
    }
    return new MessageResult("Successfully tested BlackDuck provider fields", fieldStatuses);
}
Also used : BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) FieldStatusSeverity(com.synopsys.integration.alert.common.descriptor.config.field.errors.FieldStatusSeverity) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) IntegrationException(com.synopsys.integration.exception.IntegrationException) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Nullable(org.springframework.lang.Nullable) ProviderDescriptor(com.synopsys.integration.alert.api.provider.ProviderDescriptor) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) BlackDuckApiTokenValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) Collectors(java.util.stream.Collectors) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ArrayList(java.util.ArrayList) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) BlackDuckApiTokenValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckApiTokenValidator)

Example 13 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class JiraGlobalFieldModelTestActionTest method testConfigSuccessTest.

@Test
public void testConfigSuccessTest() throws IntegrationException {
    Mockito.doReturn(true).when(testAction).canUserGetIssues(Mockito.any());
    Mockito.doReturn(false).when(testAction).isAppCheckEnabled(Mockito.any());
    MessageResult messageResult = testAction.testConfig("0", null, null);
    assertNotNull(messageResult, "Expected a non-null message result");
}
Also used : MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) Test(org.junit.jupiter.api.Test)

Example 14 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class EmailGlobalFieldModelTestActionTest method testConfigITTest.

@Test
@Tags(value = { @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void testConfigITTest() {
    TestProperties testProperties = new TestProperties();
    String emailAddress = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
    FieldModel validFieldModel = createFieldModelToTest(emailAddress);
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailChannelMessagingService validEmailChannelMessagingService = createValidEmailChannelMessagingService(emailAddress);
    EmailGlobalFieldModelTestAction emailGlobalFieldModelTestAction = new EmailGlobalFieldModelTestAction(validEmailChannelMessagingService, javamailPropertiesFactory);
    FieldUtility validFieldUtility = createValidEmailGlobalFieldUtility(testProperties);
    try {
        MessageResult messageResult = emailGlobalFieldModelTestAction.testConfig("0", validFieldModel, validFieldUtility);
        assertFalse(messageResult.hasErrors(), "Expected the message result to not have errors");
        assertFalse(messageResult.hasWarnings(), "Expected the message result to not have warnings");
    } catch (AlertException e) {
        fail("An exception was thrown where none was expected", e);
    }
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Example 15 with MessageResult

use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.

the class EmailGlobalTestAction method testConfigModelContent.

public ConfigurationTestResult testConfigModelContent(String testAddress, EmailGlobalConfigModel emailGlobalConfigModel) {
    if (StringUtils.isBlank(testAddress)) {
        return ConfigurationTestResult.failure("Could not determine what email address to send this content to. testAddress was not provided or was blank. Please provide a valid email address to test the configuration.");
    }
    try {
        InternetAddress emailAddress = new InternetAddress(testAddress);
        emailAddress.validate();
    } catch (AddressException ex) {
        return ConfigurationTestResult.failure(String.format("%s is not a valid email address. %s", testAddress, ex.getMessage()));
    }
    EmailChannelMessageModel testMessage = EmailChannelMessageModel.simple(TEST_SUBJECT_LINE, TEST_MESSAGE_CONTENT, "", "");
    SmtpConfigBuilder smtpConfigBuilder = SmtpConfig.builder();
    smtpConfigBuilder.setJavamailProperties(javamailPropertiesFactory.createJavaMailProperties(emailGlobalConfigModel));
    emailGlobalConfigModel.getSmtpFrom().ifPresent(smtpConfigBuilder::setSmtpFrom);
    emailGlobalConfigModel.getSmtpHost().ifPresent(smtpConfigBuilder::setSmtpHost);
    emailGlobalConfigModel.getSmtpPort().ifPresent(smtpConfigBuilder::setSmtpPort);
    emailGlobalConfigModel.getSmtpAuth().ifPresent(smtpConfigBuilder::setSmtpAuth);
    emailGlobalConfigModel.getSmtpUsername().ifPresent(smtpConfigBuilder::setSmtpUsername);
    if (BooleanUtils.toBoolean(emailGlobalConfigModel.getIsSmtpPasswordSet()) && emailGlobalConfigModel.getSmtpPassword().isEmpty()) {
        // TODO: This assumes if the password is saved but not provided we only test using the default configuration password.
        // If the UI supports multiple configurations in the future we should determine which configuration to get the password from.
        configurationAccessor.getConfiguration().flatMap(EmailGlobalConfigModel::getSmtpPassword).ifPresent(emailGlobalConfigModel::setSmtpPassword);
    }
    emailGlobalConfigModel.getSmtpPassword().ifPresent(smtpConfigBuilder::setSmtpPassword);
    SmtpConfig smtpConfig = smtpConfigBuilder.build();
    try {
        EmailTarget emailTarget = emailChannelMessagingService.createTarget(testMessage, testAddress);
        MessageResult messageResult = emailChannelMessagingService.sendMessage(smtpConfig, emailTarget);
        return ConfigurationTestResult.success(messageResult.getStatusMessage());
    } catch (AlertException ex) {
        return ConfigurationTestResult.failure(ex.getMessage());
    }
}
Also used : SmtpConfigBuilder(com.synopsys.integration.alert.service.email.SmtpConfigBuilder) SmtpConfig(com.synopsys.integration.alert.service.email.SmtpConfig) InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException) EmailChannelMessageModel(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessageModel) EmailTarget(com.synopsys.integration.alert.service.email.EmailTarget) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)39 Test (org.junit.jupiter.api.Test)25 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)22 List (java.util.List)12 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)11 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)10 UUID (java.util.UUID)9 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)8 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)8 OffsetDateTime (java.time.OffsetDateTime)8 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)7 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)7 IssueTrackerMessageSender (com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender)6 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)6 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)6 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)6 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)6 IssueTrackerMessageSenderFactory (com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSenderFactory)5 FrequencyType (com.synopsys.integration.alert.common.enumeration.FrequencyType)5 ProcessingType (com.synopsys.integration.alert.common.enumeration.ProcessingType)5