Search in sources :

Example 16 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties 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 17 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class BlackDuckNotificationRetrieverFactoryTest method createInvalidNotificationRetriever.

@Test
void createInvalidNotificationRetriever() {
    BlackDuckNotificationRetrieverFactory blackDuckNotificationRetrieverFactory = new BlackDuckNotificationRetrieverFactory();
    BlackDuckProperties blackDuckProperties = createBlackDuckProperties(null);
    Optional<BlackDuckNotificationRetriever> blackDuckNotificationRetrieverOptional = blackDuckNotificationRetrieverFactory.createBlackDuckNotificationRetriever(blackDuckProperties);
    assertTrue(blackDuckNotificationRetrieverOptional.isEmpty());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Test(org.junit.jupiter.api.Test)

Example 18 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class BlackDuckNotificationRetrieverFactoryTest method createValidNotificationRetriever.

@Test
void createValidNotificationRetriever() {
    BlackDuckNotificationRetrieverFactory blackDuckNotificationRetrieverFactory = new BlackDuckNotificationRetrieverFactory();
    BlackDuckProperties blackDuckProperties = createBlackDuckProperties(BLACKDUCK_URL);
    Optional<BlackDuckNotificationRetriever> blackDuckNotificationRetrieverOptional = blackDuckNotificationRetrieverFactory.createBlackDuckNotificationRetriever(blackDuckProperties);
    assertTrue(blackDuckNotificationRetrieverOptional.isPresent());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Test(org.junit.jupiter.api.Test)

Example 19 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class BlackDuckAccumulatorTest method runTest.

/**
 * This test should simulate a normal run of the accumulator with notifications present.
 */
@Test
public void runTest() throws Exception {
    ProviderTaskPropertiesAccessor taskPropertiesAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
    BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
    BlackDuckSystemValidator validator = createBlackDuckValidator(blackDuckProperties, true);
    PageRetriever pageRetriever = Mockito.mock(PageRetriever.class);
    StatefulAlertPage<NotificationUserView, IntegrationException> notificationPage = createMockNotificationPage(pageRetriever);
    BlackDuckNotificationRetriever notificationRetriever = Mockito.mock(BlackDuckNotificationRetriever.class);
    Mockito.when(notificationRetriever.retrievePageOfFilteredNotifications(Mockito.any(), Mockito.anyList())).thenReturn(notificationPage);
    Mockito.when(pageRetriever.retrieveNextPage(Mockito.anyInt(), Mockito.anyInt())).thenReturn(AlertPagedDetails.emptyPage());
    BlackDuckNotificationRetrieverFactory notificationRetrieverFactory = createBlackDuckNotificationRetrieverFactory(blackDuckProperties, notificationRetriever);
    NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
    Mockito.when(notificationAccessor.saveAllNotifications(Mockito.anyList())).thenAnswer(invocation -> invocation.getArgument(0));
    EventManager eventManager = Mockito.mock(EventManager.class);
    Mockito.doNothing().when(eventManager).sendEvent(Mockito.any(NotificationReceivedEvent.class));
    BlackDuckAccumulator accumulator = new BlackDuckAccumulator(BLACK_DUCK_PROVIDER_KEY, null, notificationAccessor, taskPropertiesAccessor, blackDuckProperties, validator, eventManager, notificationRetrieverFactory);
    accumulator.run();
    Mockito.verify(notificationAccessor, Mockito.times(1)).saveAllNotifications(Mockito.anyList());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) IntegrationException(com.synopsys.integration.exception.IntegrationException) EventManager(com.synopsys.integration.alert.api.event.EventManager) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) Test(org.junit.jupiter.api.Test)

Example 20 with BlackDuckProperties

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.

the class BlackDuckAccumulatorTest method runNotificationRetrieverThrowsException.

@Test
public void runNotificationRetrieverThrowsException() throws IntegrationException {
    ProviderTaskPropertiesAccessor taskPropertiesAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
    BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
    BlackDuckSystemValidator validator = createBlackDuckValidator(blackDuckProperties, true);
    BlackDuckNotificationRetriever notificationRetriever = Mockito.mock(BlackDuckNotificationRetriever.class);
    Mockito.when(notificationRetriever.retrievePageOfFilteredNotifications(Mockito.any(), Mockito.anyList())).thenThrow(new IntegrationException("Test Exception"));
    BlackDuckNotificationRetrieverFactory notificationRetrieverFactory = createBlackDuckNotificationRetrieverFactory(blackDuckProperties, notificationRetriever);
    NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
    BlackDuckAccumulator accumulator = new BlackDuckAccumulator(BLACK_DUCK_PROVIDER_KEY, null, notificationAccessor, taskPropertiesAccessor, blackDuckProperties, validator, null, notificationRetrieverFactory);
    accumulator.run();
    Mockito.verify(notificationAccessor, Mockito.times(0)).saveAllNotifications(Mockito.anyList());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) IntegrationException(com.synopsys.integration.exception.IntegrationException) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor) Test(org.junit.jupiter.api.Test)

Aggregations

BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)25 Test (org.junit.jupiter.api.Test)15 BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)9 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)7 DefaultSystemMessageAccessor (com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor)7 BlackDuckProvider (com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider)7 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)6 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)5 IntegrationException (com.synopsys.integration.exception.IntegrationException)5 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)4 IntLogger (com.synopsys.integration.log.IntLogger)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)3 ProviderTaskPropertiesAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)3 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)3 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)3 Gson (com.google.gson.Gson)2 SystemMessageSeverity (com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity)2 SystemMessageType (com.synopsys.integration.alert.common.enumeration.SystemMessageType)2