Search in sources :

Example 6 with MockAlertProperties

use of com.synopsys.integration.alert.test.common.MockAlertProperties in project hub-alert by blackducksoftware.

the class AuthenticationConfigurationValidatorTest method createValidatorAsserter.

private GlobalConfigurationValidatorAsserter createValidatorAsserter(Map<String, FieldValueModel> keyToValues) {
    AlertProperties mockAlertProperties = new MockAlertProperties();
    FilePersistenceUtil filePersistenceUtil = new FilePersistenceUtil(mockAlertProperties, new Gson());
    return new GlobalConfigurationValidatorAsserter(new AuthenticationDescriptorKey().getUniversalKey(), new AuthenticationConfigurationFieldModelValidator(filePersistenceUtil), keyToValues);
}
Also used : FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) Gson(com.google.gson.Gson) AlertProperties(com.synopsys.integration.alert.common.AlertProperties) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) GlobalConfigurationValidatorAsserter(com.synopsys.integration.alert.test.common.channel.GlobalConfigurationValidatorAsserter) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey)

Example 7 with MockAlertProperties

use of com.synopsys.integration.alert.test.common.MockAlertProperties in project hub-alert by blackducksoftware.

the class ChannelRestConnectionFactoryTest method testConnectionFields.

@Test
void testConnectionFields() {
    String baseUrl = "https://example-base-url";
    final String host = "host";
    final int port = 1;
    CredentialsBuilder builder = Credentials.newBuilder();
    builder.setUsername("username");
    builder.setPassword("password");
    Credentials credentials = builder.build();
    ProxyInfoBuilder proxyBuilder = ProxyInfo.newBuilder();
    proxyBuilder.setHost(host);
    proxyBuilder.setPort(port);
    proxyBuilder.setCredentials(credentials);
    proxyBuilder.setNtlmDomain(null);
    proxyBuilder.setNtlmWorkstation(null);
    ProxyInfo expectedProxyInfo = proxyBuilder.build();
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    testAlertProperties.setAlertTrustCertificate(true);
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(baseUrl)).thenReturn(expectedProxyInfo);
    ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(testAlertProperties, proxyManager, gson);
    IntHttpClient intHttpClient = channelRestConnectionFactory.createIntHttpClient(baseUrl);
    assertNotNull(intHttpClient);
    assertEquals(expectedProxyInfo, intHttpClient.getProxyInfo());
}
Also used : ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) CredentialsBuilder(com.synopsys.integration.rest.credentials.CredentialsBuilder) Credentials(com.synopsys.integration.rest.credentials.Credentials) ProxyInfoBuilder(com.synopsys.integration.rest.proxy.ProxyInfoBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with MockAlertProperties

use of com.synopsys.integration.alert.test.common.MockAlertProperties in project hub-alert by blackducksoftware.

the class EmailChannelTestIT method sendEmailTest.

@Test
@Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION)
public void sendEmailTest() {
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    String testEmailRecipient = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
    EmailAttachmentFileCreator emailAttachmentFileCreator = new EmailAttachmentFileCreator(testAlertProperties, new MessageContentGroupCsvCreator(), gson);
    FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
    EmailMessagingService emailMessagingService = new EmailMessagingService(freemarkerTemplatingService);
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailChannelMessagingService emailChannelMessagingService = new EmailChannelMessagingService(testAlertProperties, emailMessagingService, emailAttachmentFileCreator);
    EmailGlobalConfigModel emailGlobalConfig = createEmailGlobalConfig();
    EmailGlobalConfigAccessor emailConfigurationAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
    Mockito.when(emailConfigurationAccessor.getConfiguration()).thenReturn(Optional.of(emailGlobalConfig));
    JobEmailAddressValidator emailAddressValidator = Mockito.mock(JobEmailAddressValidator.class);
    Mockito.when(emailAddressValidator.validate(Mockito.any(), Mockito.anyCollection())).thenReturn(new ValidatedEmailAddresses(Set.of(testEmailRecipient), Set.of()));
    EmailAddressGatherer emailAddressGatherer = new EmailAddressGatherer(null, null);
    EmailChannelMessageConverter emailChannelMessageConverter = new EmailChannelMessageConverter(new EmailChannelMessageFormatter());
    EmailChannelMessageSender emailChannelMessageSender = new EmailChannelMessageSender(emailConfigurationAccessor, emailAddressGatherer, emailChannelMessagingService, emailAddressValidator, javamailPropertiesFactory);
    EmailChannel emailChannel = new EmailChannel(emailChannelMessageConverter, emailChannelMessageSender);
    List<String> emailAddresses = List.of(testEmailRecipient);
    EmailJobDetailsModel emailJobDetails = new EmailJobDetailsModel(null, EmailChannelTestIT.class.getSimpleName(), false, true, EmailAttachmentFormat.NONE.name(), emailAddresses);
    EmailITTestAssertions.assertSendSimpleMessageSuccess(emailChannel, emailJobDetails);
}
Also used : MessageContentGroupCsvCreator(com.synopsys.integration.alert.channel.email.attachment.MessageContentGroupCsvCreator) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailMessagingService(com.synopsys.integration.alert.service.email.EmailMessagingService) EmailAttachmentFileCreator(com.synopsys.integration.alert.channel.email.attachment.EmailAttachmentFileCreator) EmailAddressGatherer(com.synopsys.integration.alert.channel.email.distribution.address.EmailAddressGatherer) FreemarkerTemplatingService(com.synopsys.integration.alert.service.email.template.FreemarkerTemplatingService) JobEmailAddressValidator(com.synopsys.integration.alert.channel.email.distribution.address.JobEmailAddressValidator) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) ValidatedEmailAddresses(com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 9 with MockAlertProperties

use of com.synopsys.integration.alert.test.common.MockAlertProperties in project hub-alert by blackducksoftware.

the class EmailGlobalFieldModelTestActionTest method createValidEmailChannelMessagingService.

private EmailChannelMessagingService createValidEmailChannelMessagingService(String emailAddress) {
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    JobEmailAddressValidator emailAddressValidator = Mockito.mock(JobEmailAddressValidator.class);
    Mockito.when(emailAddressValidator.validate(Mockito.any(), Mockito.anyCollection())).thenReturn(new ValidatedEmailAddresses(Set.of(emailAddress), Set.of()));
    Gson gson = new Gson();
    MessageContentGroupCsvCreator messageContentGroupCsvCreator = new MessageContentGroupCsvCreator();
    EmailAttachmentFileCreator emailAttachmentFileCreator = new EmailAttachmentFileCreator(testAlertProperties, messageContentGroupCsvCreator, gson);
    FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
    EmailMessagingService emailMessagingService = new EmailMessagingService(freemarkerTemplatingService);
    return new EmailChannelMessagingService(testAlertProperties, emailMessagingService, emailAttachmentFileCreator);
}
Also used : MessageContentGroupCsvCreator(com.synopsys.integration.alert.channel.email.attachment.MessageContentGroupCsvCreator) FreemarkerTemplatingService(com.synopsys.integration.alert.service.email.template.FreemarkerTemplatingService) EmailMessagingService(com.synopsys.integration.alert.service.email.EmailMessagingService) JobEmailAddressValidator(com.synopsys.integration.alert.channel.email.distribution.address.JobEmailAddressValidator) EmailAttachmentFileCreator(com.synopsys.integration.alert.channel.email.attachment.EmailAttachmentFileCreator) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) Gson(com.google.gson.Gson) ValidatedEmailAddresses(com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)

Example 10 with MockAlertProperties

use of com.synopsys.integration.alert.test.common.MockAlertProperties in project hub-alert by blackducksoftware.

the class SettingsEncryptionCrudActionsTest method getOneNotInitializedTest.

@Test
void getOneNotInitializedTest() {
    MockAlertProperties alertPropertiesNoEncryption = new MockAlertProperties();
    alertPropertiesNoEncryption.setEncryptionPassword("");
    alertPropertiesNoEncryption.setEncryptionSalt("");
    FilePersistenceUtil filePersistenceUtilWithoutProperties = new FilePersistenceUtil(alertPropertiesNoEncryption, gson);
    EncryptionUtility encryptionUtilityWithoutProperties = new EncryptionUtility(alertPropertiesNoEncryption, filePersistenceUtilWithoutProperties);
    SettingsEncryptionCrudActions configActions = new SettingsEncryptionCrudActions(authorizationManager, encryptionUtilityWithoutProperties, validator, settingsDescriptorKey);
    ActionResponse<SettingsEncryptionModel> actionResponse = configActions.getOne();
    assertTrue(actionResponse.isError());
    assertFalse(actionResponse.hasContent());
    assertEquals(HttpStatus.NOT_FOUND, actionResponse.getHttpStatus());
}
Also used : SettingsEncryptionCrudActions(com.synopsys.integration.alert.component.settings.encryption.action.SettingsEncryptionCrudActions) FilePersistenceUtil(com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil) SettingsEncryptionModel(com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) Test(org.junit.jupiter.api.Test)

Aggregations

MockAlertProperties (com.synopsys.integration.alert.test.common.MockAlertProperties)19 Test (org.junit.jupiter.api.Test)10 Gson (com.google.gson.Gson)9 EmailAttachmentFileCreator (com.synopsys.integration.alert.channel.email.attachment.EmailAttachmentFileCreator)7 MessageContentGroupCsvCreator (com.synopsys.integration.alert.channel.email.attachment.MessageContentGroupCsvCreator)7 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)7 EmailMessagingService (com.synopsys.integration.alert.service.email.EmailMessagingService)7 JobEmailAddressValidator (com.synopsys.integration.alert.channel.email.distribution.address.JobEmailAddressValidator)6 ValidatedEmailAddresses (com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses)6 FreemarkerTemplatingService (com.synopsys.integration.alert.service.email.template.FreemarkerTemplatingService)6 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)5 FilePersistenceUtil (com.synopsys.integration.alert.common.persistence.util.FilePersistenceUtil)5 EmailAddressGatherer (com.synopsys.integration.alert.channel.email.distribution.address.EmailAddressGatherer)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)4 SettingsEncryptionModel (com.synopsys.integration.alert.component.settings.encryption.model.SettingsEncryptionModel)4 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)4 ChannelRestConnectionFactory (com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory)3 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)3 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)2