Search in sources :

Example 1 with ProjectVersionPolicyStatusView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView in project blackduck-common by blackducksoftware.

the class PolicyStatusDescriptionTest method getCountTest.

@Test
public void getCountTest() {
    ProjectVersionPolicyStatusView policyStatusItem = createProjectVersionPolicyStatusView();
    PolicyStatusDescription test = new PolicyStatusDescription(policyStatusItem);
    int expectedInViolationOverall = 4;
    int expectedNotInViolationOverall = 1;
    int expectedBlockerSeverity = 3;
    int expectedTrivialSeverity = 1;
    int expectedMajorSeverity = 0;
    int actualInViolationOverall = test.getCountOfStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION);
    int actualNotInViolationOverall = test.getCountOfStatus(ProjectVersionComponentPolicyStatusType.NOT_IN_VIOLATION);
    int actualBlockerSeverity = test.getCountOfSeverity(PolicyRuleSeverityType.BLOCKER);
    int actualTrivialSeverity = test.getCountOfSeverity(PolicyRuleSeverityType.TRIVIAL);
    int actualMajorSeverity = test.getCountOfSeverity(PolicyRuleSeverityType.MAJOR);
    Assertions.assertEquals(expectedInViolationOverall, actualInViolationOverall);
    Assertions.assertEquals(expectedNotInViolationOverall, actualNotInViolationOverall);
    Assertions.assertEquals(expectedBlockerSeverity, actualBlockerSeverity);
    Assertions.assertEquals(expectedTrivialSeverity, actualTrivialSeverity);
    Assertions.assertEquals(expectedMajorSeverity, actualMajorSeverity);
}
Also used : PolicyStatusDescription(com.synopsys.integration.blackduck.service.model.PolicyStatusDescription) ProjectVersionPolicyStatusView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView) Test(org.junit.jupiter.api.Test)

Example 2 with ProjectVersionPolicyStatusView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView in project blackduck-common by blackducksoftware.

the class CheckPolicyForProjectVersionRecipeTest method testCheckingThePolicyForAProjectVersion.

@Test
public void testCheckingThePolicyForAProjectVersion() throws IntegrationException {
    ExternalId externalId = constructExternalId();
    /*
         * We add a new component to the Version that will violate our 'Test
         * Rule'
         */
    projectBomService.addComponentToProjectVersion(externalId, projectVersionWrapper.getProjectVersionView());
    ProjectVersionPolicyStatusView policyStatus = projectBomService.getPolicyStatusForVersion(projectVersionWrapper.getProjectVersionView()).get();
    Assertions.assertEquals(ProjectVersionComponentPolicyStatusType.IN_VIOLATION, policyStatus.getOverallStatus());
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ProjectVersionPolicyStatusView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectVersionPolicyStatusView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView in project blackduck-common by blackducksoftware.

the class ComprehensiveCookbookTestIT method completePolicyCheck.

private void completePolicyCheck(BlackDuckServices blackDuckServices, CheckPolicyData checkPolicyData) throws IntegrationException {
    // the project/version should now be created
    Optional<ProjectVersionWrapper> projectVersionWrapper = blackDuckServices.projectService.getProjectVersion(checkPolicyData.projectName, checkPolicyData.projectVersionName);
    assertTrue(projectVersionWrapper.isPresent());
    ProjectVersionView projectVersion = projectVersionWrapper.get().getProjectVersionView();
    assertNotNull(projectVersion);
    // check that we have components in the BOM
    List<ProjectVersionComponentVersionView> bomComponents = blackDuckServices.blackDuckApiClient.getAllResponses(projectVersion.metaComponentsLink());
    assertTrue(bomComponents.size() > 0);
    // Look for testComponent in BOM
    ProjectVersionComponentVersionView foundComp = null;
    for (ProjectVersionComponentVersionView comp : bomComponents) {
        if (checkPolicyData.componentName.equals(comp.getComponentName()) && (checkPolicyData.componentVersion.equals(comp.getComponentVersionName()))) {
            foundComp = comp;
        }
    }
    assertNotNull(foundComp);
    assertEquals("DYNAMICALLY_LINKED", foundComp.getUsages().get(0).toString());
    // verify the policy
    ProjectVersionView projectVersionView = projectVersionWrapper.get().getProjectVersionView();
    Optional<ProjectVersionPolicyStatusView> policyStatusItem = blackDuckServices.projectBomService.getPolicyStatusForVersion(projectVersionView);
    assertTrue(policyStatusItem.isPresent());
    assertEquals(ProjectVersionComponentPolicyStatusType.IN_VIOLATION, policyStatusItem.get().getOverallStatus());
    Optional<PolicyRuleView> checkPolicyRule = blackDuckServices.policyRuleService.getPolicyRuleViewByName(checkPolicyData.policyRuleName);
    assertTrue(checkPolicyRule.isPresent());
    deletePolicyData(blackDuckServices, checkPolicyData);
}
Also used : ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) ProjectVersionPolicyStatusView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView)

Example 4 with ProjectVersionPolicyStatusView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView in project blackduck-common by blackducksoftware.

the class BlackDuckApiClientTest method testGettingResponseWhenLinkPresent.

@Test
public void testGettingResponseWhenLinkPresent() throws IOException, IntegrationException {
    IntLogger logger = new BufferedIntLogger();
    BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
    Gson gson = BlackDuckServicesFactory.createDefaultGson();
    ObjectMapper objectMapper = BlackDuckServicesFactory.createDefaultObjectMapper();
    BlackDuckResponseResolver blackDuckResponseResolver = new BlackDuckResponseResolver(gson);
    BlackDuckJsonTransformer blackDuckJsonTransformer = new BlackDuckJsonTransformer(gson, objectMapper, blackDuckResponseResolver, logger);
    BlackDuckResponseTransformer blackDuckResponseTransformer = new BlackDuckResponseTransformer(blackDuckHttpClient, blackDuckJsonTransformer);
    BlackDuckResponsesTransformer blackDuckResponsesTransformer = new BlackDuckResponsesTransformer(blackDuckHttpClient, blackDuckJsonTransformer);
    InputStream inputStream = getClass().getResourceAsStream("/json/ProjectVersionView_complete.json");
    String completeJson = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
    ProjectVersionView projectVersionView = blackDuckJsonTransformer.getResponseAs(completeJson, ProjectVersionView.class);
    InputStream responseInputStream = getClass().getResourceAsStream("/json/VersionBomPolicyStatusView.json");
    String responseContentString = IOUtils.toString(responseInputStream, StandardCharsets.UTF_8);
    Response mockedResponse = Mockito.mock(Response.class);
    Mockito.when(mockedResponse.getContentString()).thenReturn(responseContentString);
    Mockito.when(blackDuckHttpClient.execute(Mockito.any(BlackDuckRequest.class))).thenReturn(mockedResponse);
    BlackDuckApiClient blackDuckApiClient = new BlackDuckApiClient(blackDuckHttpClient, blackDuckJsonTransformer, blackDuckResponseTransformer, blackDuckResponsesTransformer);
    ProjectVersionPolicyStatusView projectVersionPolicyStatusView = blackDuckApiClient.getResponse(projectVersionView.metaPolicyStatusLink());
    assertEquals(ProjectVersionComponentPolicyStatusType.IN_VIOLATION, projectVersionPolicyStatusView.getOverallStatus());
}
Also used : BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) InputStream(java.io.InputStream) Gson(com.google.gson.Gson) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) ProjectVersionPolicyStatusView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView) Response(com.synopsys.integration.rest.response.Response) BlackDuckJsonTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckJsonTransformer) BlackDuckResponseTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponseTransformer) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckRequest(com.synopsys.integration.blackduck.service.request.BlackDuckRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BlackDuckResponsesTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectVersionPolicyStatusView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView in project blackduck-common by blackducksoftware.

the class PolicyStatusDescriptionTest method createProjectVersionPolicyStatusView.

private ProjectVersionPolicyStatusView createProjectVersionPolicyStatusView() {
    NameValuePairView blockerViolation = new NameValuePairView();
    blockerViolation.setName(PolicyRuleSeverityType.BLOCKER.name());
    blockerViolation.setValue(3);
    NameValuePairView trivialViolation = new NameValuePairView();
    trivialViolation.setName(PolicyRuleSeverityType.TRIVIAL.name());
    trivialViolation.setValue(1);
    List<NameValuePairView> violations = new ArrayList<>();
    violations.add(blockerViolation);
    violations.add(trivialViolation);
    ProjectVersionPolicyStatusComponentVersionPolicyViolationDetailsView projectVersionPolicyStatusComponentVersionPolicyViolationDetailsView = new ProjectVersionPolicyStatusComponentVersionPolicyViolationDetailsView();
    projectVersionPolicyStatusComponentVersionPolicyViolationDetailsView.setSeverityLevels(violations);
    NameValuePairView inViolation = new NameValuePairView();
    inViolation.setName(ProjectVersionComponentPolicyStatusType.IN_VIOLATION.name());
    inViolation.setValue(4);
    NameValuePairView notInViolation = new NameValuePairView();
    notInViolation.setName(ProjectVersionComponentPolicyStatusType.NOT_IN_VIOLATION.name());
    notInViolation.setValue(1);
    List<NameValuePairView> statuses = new ArrayList<>();
    statuses.add(inViolation);
    statuses.add(notInViolation);
    ProjectVersionPolicyStatusView policyStatusItem = new ProjectVersionPolicyStatusView();
    policyStatusItem.setComponentVersionPolicyViolationDetails(projectVersionPolicyStatusComponentVersionPolicyViolationDetailsView);
    policyStatusItem.setComponentVersionStatusCounts(statuses);
    policyStatusItem.setOverallStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION);
    return policyStatusItem;
}
Also used : ProjectVersionPolicyStatusComponentVersionPolicyViolationDetailsView(com.synopsys.integration.blackduck.api.generated.component.ProjectVersionPolicyStatusComponentVersionPolicyViolationDetailsView) ArrayList(java.util.ArrayList) NameValuePairView(com.synopsys.integration.blackduck.api.manual.temporary.component.NameValuePairView) ProjectVersionPolicyStatusView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView)

Aggregations

ProjectVersionPolicyStatusView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionPolicyStatusView)6 Test (org.junit.jupiter.api.Test)4 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)2 PolicyStatusDescription (com.synopsys.integration.blackduck.service.model.PolicyStatusDescription)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Gson (com.google.gson.Gson)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 ProjectVersionPolicyStatusComponentVersionPolicyViolationDetailsView (com.synopsys.integration.blackduck.api.generated.component.ProjectVersionPolicyStatusComponentVersionPolicyViolationDetailsView)1 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)1 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)1 NameValuePairView (com.synopsys.integration.blackduck.api.manual.temporary.component.NameValuePairView)1 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1 BlackDuckJsonTransformer (com.synopsys.integration.blackduck.http.transform.BlackDuckJsonTransformer)1 BlackDuckResponseTransformer (com.synopsys.integration.blackduck.http.transform.BlackDuckResponseTransformer)1 BlackDuckResponsesTransformer (com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer)1 BlackDuckResponseResolver (com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver)1 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 BlackDuckRequest (com.synopsys.integration.blackduck.service.request.BlackDuckRequest)1 BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)1 IntLogger (com.synopsys.integration.log.IntLogger)1