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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations