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