Search in sources :

Example 51 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class PolicyOverrideNotificationMessageExtractorTest method createBomComponentDetailsMissingBomComponentTest.

@Test
public void createBomComponentDetailsMissingBomComponentTest() throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    Mockito.doThrow(new IntegrationRestException(HttpMethod.GET, new HttpUrl("https://google.com"), HttpStatus.NOT_FOUND.value(), "httpStatusMessageTest", "httpResponseContentTest", "IntegrationRestExceptionForAlertTest")).when(blackDuckApiClient).getResponse(Mockito.any(), Mockito.any());
    List<BomComponentDetails> bomComponentDetailsList = extractor.createBomComponentDetails(policyOverrideUniquePolicyNotificationContent, blackDuckServicesFactory);
    assertEquals(1, bomComponentDetailsList.size());
    BomComponentDetails testBomComponentDetails = bomComponentDetailsList.get(0);
    assertEquals(COMPONENT, testBomComponentDetails.getComponent());
    assertEquals(1, testBomComponentDetails.getComponentConcerns().size());
    assertTrue(testBomComponentDetails.getComponentVersion().isPresent());
    assertEquals(COMPONENT_VERSION.getValue(), testBomComponentDetails.getComponentVersion().get().getValue());
    assertTrue(testBomComponentDetails.getRelevantPolicies().isEmpty());
    assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_LICENSE, testBomComponentDetails.getLicense().getValue());
    assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_USAGE, testBomComponentDetails.getUsage());
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 52 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class PolicyOverrideNotificationMessageExtractorTest method createProjectVersionComponentVersionView.

private ProjectVersionComponentVersionView createProjectVersionComponentVersionView() throws IntegrationException {
    ProjectVersionComponentVersionView projectVersionComponentVersionView = new ProjectVersionComponentVersionView();
    projectVersionComponentVersionView.setComponentName(COMPONENT.getValue());
    projectVersionComponentVersionView.setComponentVersion(COMPONENT_VERSION_URL);
    projectVersionComponentVersionView.setComponentVersionName(COMPONENT_VERSION.getValue());
    projectVersionComponentVersionView.setPolicyStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION);
    projectVersionComponentVersionView.setUsages(List.of(UsageType.DYNAMICALLY_LINKED));
    ProjectVersionComponentVersionLicensesView projectVersionComponentVersionLicensesView = new ProjectVersionComponentVersionLicensesView();
    projectVersionComponentVersionLicensesView.setLicense("http://licenseLink");
    projectVersionComponentVersionLicensesView.setLicenseDisplay(LICENSE_DISPLAY);
    projectVersionComponentVersionView.setLicenses(List.of(projectVersionComponentVersionLicensesView));
    ResourceLink resourceLink = new ResourceLink();
    resourceLink.setHref(new HttpUrl("https://someHref"));
    resourceLink.setRel("policy-rules");
    ResourceMetadata meta = new ResourceMetadata();
    meta.setHref(new HttpUrl("https://someUrl"));
    meta.setLinks(List.of(resourceLink));
    projectVersionComponentVersionView.setMeta(meta);
    return projectVersionComponentVersionView;
}
Also used : ProjectVersionComponentVersionLicensesView(com.synopsys.integration.blackduck.api.generated.component.ProjectVersionComponentVersionLicensesView) ResourceLink(com.synopsys.integration.blackduck.api.core.ResourceLink) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 53 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class BlackDuckProjectSyncTaskTest method createProjectView.

private ProjectView createProjectView(String name, String description, String href) throws IntegrationException {
    HttpUrl projectUrl = new HttpUrl(href);
    ResourceLink usersLink = new ResourceLink();
    usersLink.setRel(ProjectView.USERS_LINK);
    usersLink.setHref(projectUrl.appendRelativeUrl(ProjectView.USERS_LINK));
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    resourceMetadata.setHref(new HttpUrl(href));
    resourceMetadata.setLinks(List.of(usersLink));
    ProjectView projectView = new ProjectView();
    projectView.setName(name);
    projectView.setDescription(description);
    projectView.setMeta(resourceMetadata);
    return projectView;
}
Also used : ResourceLink(com.synopsys.integration.blackduck.api.core.ResourceLink) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 54 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class BlackDuckProjectSyncTaskTest method testRun.

@Test
public void testRun() throws Exception {
    MockProviderDataAccessor providerDataAccessor = new MockProviderDataAccessor();
    ApiDiscovery apiDiscovery = new ApiDiscovery(new HttpUrl("https://someblackduckserver"));
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    ProjectUsersService projectUsersService = Mockito.mock(ProjectUsersService.class);
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
    Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
    Long providerConfigId = 1000L;
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getConfigId()).thenReturn(providerConfigId);
    Mockito.when(blackDuckProperties.createBlackDuckHttpClientAndLogErrors(Mockito.any())).thenReturn(Optional.of(Mockito.mock(BlackDuckHttpClient.class)));
    Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(), Mockito.any())).thenReturn(blackDuckServicesFactory);
    ProjectView projectView = createProjectView("project", "description1", "https://projectUrl1");
    ProjectView projectView2 = createProjectView("project2", "description2", "https://projectUrl2");
    ProjectView projectView3 = createProjectView("project3", "description3", "https://projectUrl3");
    Mockito.when(blackDuckApiClient.getAllResponses(Mockito.eq(apiDiscovery.metaProjectsLink()))).thenReturn(List.of(projectView, projectView2, projectView3));
    Mockito.doReturn(null).when(blackDuckApiClient).getResponse(Mockito.any(BlackDuckRequest.class));
    String email1 = "user1@email.com";
    String email2 = "user2@email.com";
    String email3 = "user3@email.com";
    String email4 = "user4@email.com";
    UserView user1 = createUserView(email1, true);
    UserView user2 = createUserView(email2, true);
    UserView user3 = createUserView(email3, true);
    UserView user4 = createUserView(email4, true);
    Mockito.when(blackDuckApiClient.getAllResponses(Mockito.eq(apiDiscovery.metaUsersLink()))).thenReturn(List.of(user1, user2, user3, user4));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView))).thenReturn(new HashSet<>(List.of(user2, user4)));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView2))).thenReturn(new HashSet<>(List.of(user3)));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView3))).thenReturn(new HashSet<>(List.of(user1, user2, user3)));
    Mockito.doNothing().when(projectUsersService).addUserToProject(Mockito.any(), Mockito.any(UserView.class));
    BlackDuckDataSyncTask projectSyncTask = new BlackDuckDataSyncTask(new BlackDuckProviderKey(), null, providerDataAccessor, blackDuckProperties);
    projectSyncTask.run();
    assertEquals(3, providerDataAccessor.getProjectsByProviderConfigId(providerConfigId).size());
    Mockito.when(blackDuckApiClient.getAllResponses(Mockito.eq(apiDiscovery.metaProjectsLink()))).thenReturn(List.of(projectView, projectView2));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView))).thenReturn(new HashSet<>(List.of(user2, user4)));
    Mockito.when(projectUsersService.getAllActiveUsersForProject(ArgumentMatchers.same(projectView2))).thenReturn(new HashSet<>(List.of(user3)));
    Mockito.when(blackDuckApiClient.getAllResponses(ArgumentMatchers.same(projectView2.metaUsersLink()))).thenReturn(List.of());
    projectSyncTask = new BlackDuckDataSyncTask(new BlackDuckProviderKey(), null, providerDataAccessor, blackDuckProperties);
    projectSyncTask.run();
    assertEquals(2, providerDataAccessor.getProjectsByProviderConfigId(providerConfigId).size());
}
Also used : ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) MockProviderDataAccessor(com.synopsys.integration.alert.provider.blackduck.MockProviderDataAccessor) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckRequest(com.synopsys.integration.blackduck.service.request.BlackDuckRequest) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) Test(org.junit.jupiter.api.Test)

Example 55 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class ProjectNotificationMessageExtractorTest method extractTest.

@Test
public void extractTest() throws IntegrationException {
    NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
    Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl("https://a.blackduck.server.example.com"));
    Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
    Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.anyLong())).thenReturn(blackDuckServicesFactory);
    ProjectNotificationContent projectNotificationContent = createProjectNotificationContent();
    NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(projectNotificationContent);
    ProjectNotificationMessageExtractor extractor = new ProjectNotificationMessageExtractor(providerKey, servicesFactoryCache);
    ProviderMessageHolder providerMessageHolder = extractor.extract(notificationContentWrapper, projectNotificationContent);
    assertEquals(1, providerMessageHolder.getProjectMessages().size());
    assertEquals(0, providerMessageHolder.getSimpleMessages().size());
    ProjectMessage projectMessage = providerMessageHolder.getProjectMessages().get(0);
    assertEquals(MessageReason.PROJECT_STATUS, projectMessage.getMessageReason());
    assertTrue(projectMessage.getOperation().isPresent());
    assertEquals(ProjectOperation.CREATE, projectMessage.getOperation().get());
    assertTrue(projectMessage.getBomComponents().isEmpty());
    assertEquals(PROJECT, projectMessage.getProject().getValue());
    assertTrue(projectMessage.getProject().getUrl().isPresent());
    assertEquals(PROJECT_URL, projectMessage.getProject().getUrl().get());
    assertFalse(projectMessage.getProjectVersion().isPresent());
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) HttpUrl(com.synopsys.integration.rest.HttpUrl) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper) Test(org.junit.jupiter.api.Test)

Aggregations

HttpUrl (com.synopsys.integration.rest.HttpUrl)65 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)35 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)29 Test (org.junit.jupiter.api.Test)28 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)23 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)21 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)18 IntegrationException (com.synopsys.integration.exception.IntegrationException)15 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)15 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)13 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)9 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)9 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)7 ProjectVersionComponentVersionLicensesView (com.synopsys.integration.blackduck.api.generated.component.ProjectVersionComponentVersionLicensesView)7 ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)6 ComponentVersionUpgradeGuidanceView (com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)6 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)6 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)6 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)5