Search in sources :

Example 1 with ComponentsView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentsView in project blackduck-common by blackducksoftware.

the class ComponentServiceTestIT method testOriginIdMismatch.

@Test
public void testOriginIdMismatch() throws Exception {
    ExternalId cyclerExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, "cycler", "0.10.0");
    List<ComponentsView> searchResults = componentService.getAllSearchResults(cyclerExternalId);
    assertEquals(1, searchResults.size());
    assertTrue(searchResults.get(0).getComponentName().equalsIgnoreCase("cycler"));
    assertTrue(searchResults.get(0).getVersionName().equals("0.10.0"));
    Optional<ComponentsView> componentView = componentService.getFirstOrEmptyResult(cyclerExternalId);
    assertTrue(componentView.isPresent());
    assertTrue(componentView.get().getComponentName().equalsIgnoreCase("cycler"));
    assertTrue(componentView.get().getVersionName().equals("0.10.0"));
    componentView = componentService.getSingleOrEmptyResult(cyclerExternalId);
    assertTrue(componentView.isPresent());
    assertTrue(componentView.get().getComponentName().equalsIgnoreCase("cycler"));
    assertTrue(componentView.get().getVersionName().equals("0.10.0"));
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView) Test(org.junit.jupiter.api.Test)

Example 2 with ComponentsView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentsView in project blackduck-common by blackducksoftware.

the class ComponentServiceTestIT method retrieveCommonsFileupload.

@NotNull
private ComponentVersionView retrieveCommonsFileupload(ComponentService componentService) throws IntegrationException {
    ExternalId commonsFileuploadExternalId = externalIdFactory.createMavenExternalId("commons-fileupload", "commons-fileupload", "1.2.1");
    Optional<ComponentsView> componentsView = componentService.getFirstOrEmptyResult(commonsFileuploadExternalId);
    return componentService.getComponentVersionView(componentsView.get()).get();
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ComponentsView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentsView in project blackduck-common by blackducksoftware.

the class VulnerabilityDataServiceTestIT method testGetCommonsFileUploadVulns.

@Test
public void testGetCommonsFileUploadVulns() throws Exception {
    BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
    ComponentService componentService = blackDuckServicesFactory.createComponentService();
    SimpleBdioFactory simpleBdioFactory = new SimpleBdioFactory();
    ExternalIdFactory externalIdFactory = simpleBdioFactory.getExternalIdFactory();
    ExternalId commonsFileUploadExternalId = externalIdFactory.createMavenExternalId("commons-fileupload", "commons-fileupload", "1.2.2");
    Optional<ComponentsView> searchResult = componentService.getFirstOrEmptyResult(commonsFileUploadExternalId);
    Optional<ComponentVersionView> componentVersionView = componentService.getComponentVersionView(searchResult.get());
    ComponentVersionVulnerabilities componentVersionVulnerabilities = componentService.getComponentVersionVulnerabilities(componentVersionView.get());
    List<VulnerabilityView> vulnerabilities = componentVersionVulnerabilities.getVulnerabilities();
    System.out.println(vulnerabilities);
    assertNotNull(vulnerabilities);
    assertFalse(vulnerabilities.isEmpty());
    ExternalId integrationCommonExternalId = externalIdFactory.createMavenExternalId("com.blackducksoftware.integration", "integration-common", "15.0.0");
    searchResult = componentService.getFirstOrEmptyResult(integrationCommonExternalId);
    componentVersionView = componentService.getComponentVersionView(searchResult.get());
    componentVersionVulnerabilities = componentService.getComponentVersionVulnerabilities(componentVersionView.get());
    vulnerabilities = componentVersionVulnerabilities.getVulnerabilities();
    System.out.println(vulnerabilities);
    assertNotNull(vulnerabilities);
    assertTrue(vulnerabilities.isEmpty());
}
Also used : ComponentVersionVulnerabilities(com.synopsys.integration.blackduck.service.model.ComponentVersionVulnerabilities) SimpleBdioFactory(com.synopsys.integration.bdio.SimpleBdioFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView) VulnerabilityView(com.synopsys.integration.blackduck.api.generated.view.VulnerabilityView) Test(org.junit.jupiter.api.Test)

Example 4 with ComponentsView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentsView in project blackduck-common by blackducksoftware.

the class CheckPolicyForProjectVersionRecipeTest method constructTestPolicy.

private PolicyRuleView constructTestPolicy(ComponentService componentService) throws IntegrationException {
    ExternalId externalId = constructExternalId();
    Optional<ComponentsView> searchResult = componentService.getSingleOrEmptyResult(externalId);
    ComponentVersionView componentVersionView = componentService.getComponentVersionView(searchResult.get()).get();
    /*
         * using the PolicyRuleExpressionSetBuilder we can build the expression
         * set for a PolicyRuleView
         */
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addComponentVersionCondition(PolicyRuleConditionOperatorType.EQ, componentVersionView);
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName("Test Rule" + System.currentTimeMillis());
    policyRuleView.setEnabled(true);
    policyRuleView.setOverridable(true);
    policyRuleView.setExpression(expressionSet);
    return policyRuleView;
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView)

Example 5 with ComponentsView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentsView in project hub-alert by blackducksoftware.

the class BlackDuckProviderService method createBlackDuckPolicyRuleView.

public PolicyRuleView createBlackDuckPolicyRuleView(String policyName, Supplier<ExternalId> externalIdSupplier) throws IntegrationException {
    setupBlackDuckServicesFactory();
    ComponentService componentService = blackDuckServicesFactory.createComponentService();
    ExternalId externalId = externalIdSupplier.get();
    ComponentsView searchResult = componentService.getSingleOrEmptyResult(externalId).orElseThrow(() -> new IntegrationException(String.format("Could not find the ComponentsView for component: %s", externalId.getName())));
    ComponentVersionView componentVersionView = componentService.getComponentVersionView(searchResult).orElseThrow(() -> new IntegrationException(String.format("Could not find the ComponentVersionView for component: %s", searchResult.getComponentName())));
    PolicyRuleExpressionSetBuilder builder = new PolicyRuleExpressionSetBuilder();
    builder.addComponentVersionCondition(PolicyRuleConditionOperatorType.EQ, componentVersionView);
    PolicyRuleExpressionView expressionSet = builder.createPolicyRuleExpressionView();
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName(policyName);
    policyRuleView.setEnabled(true);
    policyRuleView.setOverridable(true);
    policyRuleView.setExpression(expressionSet);
    return policyRuleView;
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) PolicyRuleExpressionSetBuilder(com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ComponentService(com.synopsys.integration.blackduck.service.dataservice.ComponentService) ComponentsView(com.synopsys.integration.blackduck.api.generated.response.ComponentsView)

Aggregations

ComponentsView (com.synopsys.integration.blackduck.api.generated.response.ComponentsView)11 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)7 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)6 PolicyRuleExpressionView (com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView)4 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)4 PolicyRuleExpressionSetBuilder (com.synopsys.integration.blackduck.service.model.PolicyRuleExpressionSetBuilder)4 Test (org.junit.jupiter.api.Test)3 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)2 ComponentService (com.synopsys.integration.blackduck.service.dataservice.ComponentService)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 SimpleBdioFactory (com.synopsys.integration.bdio.SimpleBdioFactory)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 ProjectVersionVulnerableBomComponentsView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionVulnerableBomComponentsView)1 VulnerabilityView (com.synopsys.integration.blackduck.api.generated.view.VulnerabilityView)1 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)1 BlackDuckQuery (com.synopsys.integration.blackduck.http.BlackDuckQuery)1 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 ComponentVersionVulnerabilities (com.synopsys.integration.blackduck.service.model.ComponentVersionVulnerabilities)1