Search in sources :

Example 6 with BlackDuckSystemValidator

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

use of com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator 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)

Example 8 with BlackDuckSystemValidator

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

the class BlackDuckAccumulatorTest method runValidateFalseTest.

@Test
public void runValidateFalseTest() {
    BlackDuckProperties invalidProperties = createBlackDuckProperties();
    BlackDuckSystemValidator validator = createBlackDuckValidator(invalidProperties, false);
    BlackDuckNotificationRetrieverFactory notificationRetrieverFactory = Mockito.mock(BlackDuckNotificationRetrieverFactory.class);
    BlackDuckAccumulator accumulator = new BlackDuckAccumulator(BLACK_DUCK_PROVIDER_KEY, null, null, null, invalidProperties, validator, null, notificationRetrieverFactory);
    accumulator.run();
    Mockito.verify(notificationRetrieverFactory, Mockito.times(0)).createBlackDuckNotificationRetriever(invalidProperties);
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) Test(org.junit.jupiter.api.Test)

Example 9 with BlackDuckSystemValidator

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

the class SystemValidatorTest method testValidateHubValidProvider.

@Test
public void testValidateHubValidProvider() throws Exception {
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("https://alert.example.com:443/alert"));
    Mockito.when(blackDuckProperties.getApiToken()).thenReturn("Test Api Key");
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    BlackDuckServerConfig serverConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(serverConfig.canConnect(Mockito.any(IntLogger.class))).thenReturn(true);
    Mockito.when(blackDuckProperties.createBlackDuckServerConfig(Mockito.any(IntLogger.class))).thenReturn(serverConfig);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility, Mockito.times(0)).addSystemMessage(Mockito.anyString(), Mockito.any(SystemMessageSeverity.class), Mockito.any(SystemMessageType.class));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) SystemMessageSeverity(com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity) SystemMessageType(com.synopsys.integration.alert.common.enumeration.SystemMessageType) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Example 10 with BlackDuckSystemValidator

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

the class SystemValidatorTest method testValidateHubInvalidProvider.

@Test
public void testValidateHubInvalidProvider() throws Exception {
    long configId = 1L;
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("https://localhost:443/alert"));
    Mockito.when(blackDuckProperties.getApiToken()).thenReturn("Test Api Key");
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    Mockito.when(blackDuckProperties.getConfigName()).thenReturn(DEFAULT_CONFIG_NAME);
    Mockito.when(blackDuckProperties.getConfigId()).thenReturn(configId);
    BlackDuckServerConfig serverConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(serverConfig.canConnect(Mockito.any(IntLogger.class))).thenReturn(false);
    Mockito.when(blackDuckProperties.createBlackDuckServerConfig(Mockito.any(IntLogger.class))).thenReturn(serverConfig);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    String localhostMessageType = BlackDuckSystemValidator.createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST);
    String connectivityMessageType = BlackDuckSystemValidator.createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_CONNECTIVITY);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility).addSystemMessage(Mockito.eq(String.format(BlackDuckSystemValidator.BLACKDUCK_LOCALHOST_ERROR_FORMAT, DEFAULT_CONFIG_NAME)), Mockito.eq(SystemMessageSeverity.WARNING), Mockito.eq(localhostMessageType));
    Mockito.verify(defaultSystemMessageUtility).addSystemMessage(Mockito.eq(String.format("Can not connect to the Black Duck server with the configuration '%s'.", DEFAULT_CONFIG_NAME)), Mockito.eq(SystemMessageSeverity.WARNING), Mockito.eq(connectivityMessageType));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Aggregations

BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)10 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)9 Test (org.junit.jupiter.api.Test)9 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)5 DefaultSystemMessageAccessor (com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor)5 BlackDuckProvider (com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider)5 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)4 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)4 IntLogger (com.synopsys.integration.log.IntLogger)4 ProviderTaskPropertiesAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)3 SystemMessageSeverity (com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity)2 SystemMessageType (com.synopsys.integration.alert.common.enumeration.SystemMessageType)2 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 EventManager (com.synopsys.integration.alert.api.event.EventManager)1 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)1 PageRetriever (com.synopsys.integration.alert.processor.api.filter.PageRetriever)1 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)1 Credentials (com.synopsys.integration.rest.credentials.Credentials)1 CredentialsBuilder (com.synopsys.integration.rest.credentials.CredentialsBuilder)1