Search in sources :

Example 16 with TestProperties

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

the class EmailGlobalTestActionTest method testPermissionConfigValidTest.

@Test
public void testPermissionConfigValidTest() throws AlertException {
    TestProperties testProperties = new TestProperties();
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailChannelMessagingService emailChannelMessagingService = Mockito.mock(EmailChannelMessagingService.class);
    Mockito.when(emailChannelMessagingService.sendMessage(Mockito.any(), Mockito.any())).thenReturn(new MessageResult("PASS"));
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, emailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
    EmailGlobalConfigModel globalConfigModel = createValidEmailGlobalConfigModel(testProperties);
    ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck("noreply@synopsys.com", globalConfigModel);
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertTrue(response.isSuccessful());
    assertTrue(response.hasContent());
    assertFalse(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) Test(org.junit.jupiter.api.Test)

Example 17 with TestProperties

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

the class EmailGlobalTestActionTest method testConfigITTest.

@Test
@Tags(value = { @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void testConfigITTest() {
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    TestProperties testProperties = new TestProperties();
    String emailAddress = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailChannelMessagingService validEmailChannelMessagingService = createValidEmailChannelMessagingService(emailAddress);
    EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, validEmailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
    EmailGlobalConfigModel globalConfigModel = createValidEmailGlobalConfigModel(testProperties);
    ConfigurationTestResult testResult = emailGlobalTestAction.testConfigModelContent(emailAddress, globalConfigModel);
    assertTrue(testResult.isSuccess(), "Expected the message result to not have errors");
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) ConfigurationTestResult(com.synopsys.integration.alert.common.message.model.ConfigurationTestResult) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Example 18 with TestProperties

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

the class SlackChannelTestIT method init.

@BeforeEach
public void init() {
    gson = new Gson();
    properties = new TestProperties();
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) Gson(com.google.gson.Gson) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with TestProperties

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

the class BlackDuckSSOConfigRetrieverTest method createBlackDuckProperties.

private BlackDuckProperties createBlackDuckProperties() {
    TestProperties testProperties = new TestProperties();
    String blackDuckUrl = testProperties.getBlackDuckURL();
    String blackDuckApiKey = testProperties.getBlackDuckAPIToken();
    String blackDuckTimeout = testProperties.getOptionalProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TIMEOUT).orElse("300");
    MockAlertProperties mockAlertProperties = new MockAlertProperties();
    ProxyManager mockProxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(mockProxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(0L, 0L, null, null, ConfigContextEnum.GLOBAL);
    configurationModel.put(createConfigFieldModel(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED, Boolean.TRUE.toString()));
    configurationModel.put(createConfigFieldModel(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, BlackDuckSSOConfigRetrieverTest.class.getSimpleName()));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_URL, blackDuckUrl));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, blackDuckApiKey));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT, blackDuckTimeout));
    return new BlackDuckProperties(0L, new Gson(), BlackDuckServicesFactory.createDefaultObjectMapper(), mockAlertProperties, mockProxyManager, configurationModel);
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) Gson(com.google.gson.Gson)

Example 20 with TestProperties

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

the class EmailMessagingServiceTest method sendAuthenticatedMessage.

@Test
public void sendAuthenticatedMessage() throws MessagingException, AlertException {
    TestProperties testProperties = new TestProperties();
    FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
    EmailMessagingService emailMessagingService = new EmailMessagingService(freemarkerTemplatingService);
    Session mockSession = Mockito.mock(Session.class);
    Transport mockTransport = Mockito.mock(Transport.class);
    Mockito.doNothing().when(mockTransport).connect();
    Mockito.doNothing().when(mockTransport).close();
    Mockito.when(mockSession.getTransport()).thenReturn(mockTransport);
    Mockito.when(mockSession.getProperties()).thenReturn(testProperties.getProperties());
    Message message = new MimeMessage(mockSession);
    Mockito.doNothing().when(mockTransport).sendMessage(Mockito.eq(message), Mockito.any());
    emailMessagingService.sendMessages(true, null, -1, null, null, mockSession, List.of(message));
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) FreemarkerTemplatingService(com.synopsys.integration.alert.service.email.template.FreemarkerTemplatingService) EmailMessagingService(com.synopsys.integration.alert.service.email.EmailMessagingService) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Transport(javax.mail.Transport) Session(javax.mail.Session) Test(org.junit.jupiter.api.Test)

Aggregations

TestProperties (com.synopsys.integration.alert.test.common.TestProperties)24 Test (org.junit.jupiter.api.Test)10 Gson (com.google.gson.Gson)6 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)5 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)4 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)4 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)4 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)4 TestTags (com.synopsys.integration.alert.test.common.TestTags)4 Tags (org.junit.jupiter.api.Tags)4 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)3 GsonBuilder (com.google.gson.GsonBuilder)2 IssueTrackerCallbackInfoCreator (com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator)2 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)2 ConfigurationTestResult (com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)2 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)2