Search in sources :

Example 11 with TestProperties

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

the class AlertIntegrationTestConfiguration method initBlackDuckData.

// FIXME delete
@Deprecated(forRemoval = true)
public void initBlackDuckData() throws AlertException {
    TestProperties testProperties = new TestProperties();
    ConfigurationFieldModel blackDuckURLField = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
    blackDuckURLField.setFieldValue(testProperties.getBlackDuckURL());
    ConfigurationFieldModel blackDuckAPITokenField = ConfigurationFieldModel.createSensitive(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
    blackDuckAPITokenField.setFieldValue(testProperties.getBlackDuckAPIToken());
    ConfigurationFieldModel blackDuckTimeoutField = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
    blackDuckTimeoutField.setFieldValue(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TIMEOUT));
    BlackDuckProviderKey blackDuckProviderKey = new BlackDuckProviderKey();
    ConfigurationModel blackDuckConfiguration = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(blackDuckProviderKey, ConfigContextEnum.GLOBAL).stream().findFirst().orElse(configurationModelConfigurationAccessor.createConfiguration(blackDuckProviderKey, ConfigContextEnum.GLOBAL, List.of(blackDuckURLField, blackDuckAPITokenField, blackDuckTimeoutField)));
    configurationModelConfigurationAccessor.updateConfiguration(blackDuckConfiguration.getConfigurationId(), List.of(blackDuckURLField, blackDuckAPITokenField, blackDuckTimeoutField));
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) 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)

Example 12 with TestProperties

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

the class NotificationReceivedEventHandlerTestIT method init.

@BeforeEach
public void init() {
    properties = new TestProperties();
    ConfigurationFieldModel providerConfigEnabled = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
    providerConfigEnabled.setFieldValue("TRUE");
    ConfigurationFieldModel providerConfigName = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
    providerConfigName.setFieldValue("blackduck-config");
    ConfigurationFieldModel blackduckUrl = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
    blackduckUrl.setFieldValue(properties.getBlackDuckURL());
    ConfigurationFieldModel blackduckApiKey = ConfigurationFieldModel.createSensitive(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
    blackduckApiKey.setFieldValue(properties.getBlackDuckAPIToken());
    ConfigurationFieldModel blackduckTimeout = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
    blackduckTimeout.setFieldValue(String.valueOf(BlackDuckProperties.DEFAULT_TIMEOUT));
    ConfigurationModel blackduckConfigurationModel = defaultConfigurationAccessor.createConfiguration(blackDuckProviderKey, ConfigContextEnum.GLOBAL, List.of(providerConfigEnabled, providerConfigName, blackduckUrl, blackduckApiKey, blackduckTimeout));
    blackDuckGlobalConfigId = blackduckConfigurationModel.getConfigurationId();
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with TestProperties

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

the class JiraCloudSummaryFieldLengthTestIT method createJiraCloudMessageSender.

private static IssueTrackerMessageSender<String> createJiraCloudMessageSender() throws AlertException {
    TestProperties testProperties = new TestProperties();
    Gson gson = new GsonBuilder().create();
    IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
    JiraCloudMessageSenderFactory jiraCloudMessageSenderFactory = new JiraCloudMessageSenderFactory(gson, ChannelKeys.JIRA_CLOUD, createJiraCloudPropertiesFactory(testProperties), new IssueTrackerCallbackInfoCreator(), issueCategoryRetriever);
    JiraCloudJobDetailsModel jiraCloudJobDetails = createJiraCloudJobDetails(testProperties);
    return jiraCloudMessageSenderFactory.createMessageSender(jiraCloudJobDetails);
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) JiraCloudMessageSenderFactory(com.synopsys.integration.alert.channel.jira.cloud.distribution.JiraCloudMessageSenderFactory) JiraCloudJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)

Example 14 with TestProperties

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

the class AuthenticationActionsTestIT method userLoginWithBadCredentialsTest.

@Test
public void userLoginWithBadCredentialsTest() {
    AlertAuthenticationProvider authenticationProvider = Mockito.mock(AlertAuthenticationProvider.class);
    Mockito.when(authenticationProvider.authenticate(Mockito.any())).thenThrow(new BadCredentialsException("Bad credentials test"));
    AuthenticationActions authenticationActions = new AuthenticationActions(authenticationProvider, csrfTokenRepository);
    HttpServletRequest servletRequest = new MockHttpServletRequest();
    HttpServletResponse servletResponse = new MockHttpServletResponse();
    TestProperties testProperties = new TestProperties();
    MockLoginRestModel mockLoginRestModel = new MockLoginRestModel();
    mockLoginRestModel.setAlertUsername(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_USERNAME));
    mockLoginRestModel.setAlertPassword(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_PASSWORD));
    ActionResponse<Void> response = authenticationActions.authenticateUser(servletRequest, servletResponse, mockLoginRestModel.createRestModel());
    assertTrue(response.isError());
    assertEquals(HttpStatus.UNAUTHORIZED, response.getHttpStatus());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TestProperties(com.synopsys.integration.alert.test.common.TestProperties) MockLoginRestModel(com.synopsys.integration.alert.mock.model.MockLoginRestModel) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) AlertAuthenticationProvider(com.synopsys.integration.alert.component.authentication.security.AlertAuthenticationProvider) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 15 with TestProperties

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

the class AuthenticationControllerTestIT method testLogin.

@Test
public void testLogin() throws Exception {
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(loginUrl);
    TestProperties testProperties = new TestProperties();
    MockLoginRestModel mockLoginRestModel = new MockLoginRestModel();
    mockLoginRestModel.setAlertUsername(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_USERNAME));
    mockLoginRestModel.setAlertPassword(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_PASSWORD));
    ReflectionTestUtils.setField(alertProperties, "alertTrustCertificate", Boolean.valueOf(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TRUST_HTTPS_CERT)));
    String restModel = mockLoginRestModel.getRestModelJson();
    request.content(restModel);
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) MockLoginRestModel(com.synopsys.integration.alert.mock.model.MockLoginRestModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) 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