use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method init.
@BeforeEach
void init() throws Exception {
blackDuckPropertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
Mockito.when(blackDuckPropertiesFactory.createProperties(Mockito.any(ConfigurationModel.class))).thenReturn(blackDuckProperties);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(blackDuckProperties.createBlackDuckHttpClient(Mockito.any(IntLogger.class))).thenReturn(blackDuckHttpClient);
blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(BlackDuckHttpClient.class), Mockito.any(IntLogger.class))).thenReturn(blackDuckServicesFactory);
projectService = Mockito.mock(ProjectService.class);
Mockito.when(blackDuckServicesFactory.createProjectService()).thenReturn(projectService);
blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
projectUsersService = Mockito.mock(ProjectUsersService.class);
Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
apiDiscovery = Mockito.mock(ApiDiscovery.class);
UrlMultipleResponses<UserView> usersLink = Mockito.mock(UrlMultipleResponses.class);
Mockito.when(apiDiscovery.metaUsersLink()).thenReturn(usersLink);
Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
configurationFieldModel.setFieldValue(PROVIDER_CONFIG_NAME);
configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
providerConfiguration = new ConfigurationModel(1L, 1L, "createdAt", "lastModified", ConfigContextEnum.GLOBAL, Map.of(PROVIDER_CONFIG_NAME, configurationFieldModel));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(1L)).thenReturn(Optional.of(providerConfiguration));
Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(providerConfiguration));
}
use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.
the class AbstractRuleViolationNotificationMessageExtractor method createBomComponentDetails.
private BomComponentDetails createBomComponentDetails(BlackDuckServicesFactory blackDuckServicesFactory, T notificationContent, ComponentVersionStatus componentVersionStatus) throws IntegrationException {
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
BlackDuckMessageBomComponentDetailsCreator bomComponentDetailsCreator = detailsCreatorFactory.createBomComponentDetailsCreator(blackDuckServicesFactory);
ComponentConcern policyConcern = policyComponentConcernCreator.fromPolicyInfo(notificationContent.getPolicyInfo(), itemOperation);
try {
ProjectVersionComponentVersionView bomComponent = blackDuckApiClient.getResponse(new HttpUrl(componentVersionStatus.getBomComponent()), ProjectVersionComponentVersionView.class);
return bomComponentDetailsCreator.createBomComponentDetails(bomComponent, policyConcern, ComponentUpgradeGuidance.none(), List.of());
} catch (IntegrationRestException e) {
bomComponent404Handler.logIf404OrThrow(e, componentVersionStatus.getComponentName(), componentVersionStatus.getComponentVersionName());
return bomComponentDetailsCreator.createMissingBomComponentDetails(componentVersionStatus.getComponentName(), createComponentUrl(componentVersionStatus), componentVersionStatus.getComponentVersionName(), createComponentVersionUrl(componentVersionStatus), List.of(policyConcern), ComponentUpgradeGuidance.none(), List.of());
}
}
use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getProjectVersionNamesByHref.
@Override
public AlertPagedModel<String> getProjectVersionNamesByHref(Long providerConfigId, String projectHref, int pageNumber) {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
try {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectView foundProject = blackDuckApiClient.getResponse(new HttpUrl(projectHref), ProjectView.class);
BlackDuckPageDefinition blackDuckPageDefinition = new BlackDuckPageDefinition(BlackDuckRequestBuilder.DEFAULT_LIMIT, pageNumber * BlackDuckRequestBuilder.DEFAULT_LIMIT);
BlackDuckMultipleRequest<ProjectVersionView> projectVersionSpec = new BlackDuckRequestBuilder().commonGet().setBlackDuckPageDefinition(blackDuckPageDefinition).buildBlackDuckRequest(foundProject.metaVersionsLink());
BlackDuckPageResponse<ProjectVersionView> pageResponse = blackDuckApiClient.getPageResponse(projectVersionSpec);
return new AlertPagedModel<>(pageResponse.getTotalCount(), pageNumber, BlackDuckRequestBuilder.DEFAULT_LIMIT, pageResponse.getItems()).transformContent(ProjectVersionView::getVersionName);
} catch (IntegrationException e) {
logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
}
}
return AlertPagedModel.empty(pageNumber, BlackDuckRequestBuilder.DEFAULT_LIMIT);
}
use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.
the class BlackDuckIssueTrackerCallbackEventHandler method handle.
@Override
public void handle(IssueTrackerCallbackEvent event) {
String eventId = event.getEventId();
logger.debug("Handling issue-tracker callback event with id '{}'", eventId);
IssueTrackerCallbackInfo callbackInfo = event.getCallbackInfo();
Optional<BlackDuckServicesFactory> optionalBlackDuckServicesFactory = createBlackDuckProperties(callbackInfo.getProviderConfigId()).flatMap(this::createBlackDuckServicesFactory);
if (optionalBlackDuckServicesFactory.isPresent()) {
BlackDuckServicesFactory blackDuckServicesFactory = optionalBlackDuckServicesFactory.get();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
IssueService blackDuckIssueService = blackDuckServicesFactory.createIssueService();
BlackDuckProviderIssueHandler blackDuckProviderIssueHandler = new BlackDuckProviderIssueHandler(gson, blackDuckApiClient, blackDuckIssueService);
BlackDuckProviderIssueModel issueModel = createBlackDuckIssueModel(event);
createOrUpdateBlackDuckIssue(blackDuckProviderIssueHandler, issueModel, callbackInfo);
}
logger.debug("Finished handling issue-tracker callback event with id '{}'", eventId);
}
use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.
the class BomEditNotificationDetailExtractorTest method createCache.
private NotificationExtractorBlackDuckServicesFactoryCache createCache(Long blackDuckConfigId, String projectName, String projectVersionName) throws IntegrationException {
ProjectView projectView = Mockito.mock(ProjectView.class);
Mockito.when(projectView.getName()).thenReturn(projectName);
ProjectVersionView projectVersionView = Mockito.mock(ProjectVersionView.class);
Mockito.when(projectVersionView.getVersionName()).thenReturn(projectVersionName);
BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectVersionView.class))).thenReturn(projectVersionView);
Mockito.when(blackDuckApiClient.getResponse(Mockito.eq(projectVersionView.metaProjectLink()))).thenReturn(projectView);
BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
NotificationExtractorBlackDuckServicesFactoryCache cache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
Mockito.when(cache.retrieveBlackDuckServicesFactory(Mockito.eq(blackDuckConfigId))).thenReturn(blackDuckServicesFactory);
return cache;
}
Aggregations