use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class ScanCommandTest method assertLogging.
private void assertLogging(ScanCommand scanCommand, int expectedPostLogSize) throws IntegrationException {
BufferedIntLogger bufferedLogger = new BufferedIntLogger();
assertEquals(0, bufferedLogger.getOutputList(LogLevel.WARN).size());
scanCommand.createCommandForProcessBuilder(bufferedLogger, Mockito.mock(ScanPaths.class), scanCommand.getOutputDirectory().getAbsolutePath());
assertEquals(expectedPostLogSize, bufferedLogger.getOutputList(LogLevel.WARN).size());
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class ScanCommandTest method testSnippetScanLoggingWhenDryRun.
@Test
public void testSnippetScanLoggingWhenDryRun() throws IntegrationException {
scanBatchBuilder.snippetMatching(SnippetMatching.FULL_SNIPPET_MATCHING);
ScanBatch scanBatch = scanBatchBuilder.build();
ScanCommand scanCommand = assertCommand(scanBatch);
assertLogging(scanCommand, 0);
BufferedIntLogger bufferedLogger;
scanBatchBuilder.dryRun(true);
scanBatch = scanBatchBuilder.build();
scanCommand = assertCommand(scanBatch);
assertLogging(scanCommand, 1);
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class ScanCommandTest method testLicenseSearchDryRun.
@Test
public void testLicenseSearchDryRun() throws IntegrationException {
scanBatchBuilder.licenseSearch(true);
ScanBatch scanBatch = scanBatchBuilder.build();
ScanCommand scanCommand = assertCommand(scanBatch);
assertLogging(scanCommand, 0);
BufferedIntLogger bufferedLogger;
scanBatchBuilder.dryRun(true);
scanBatch = scanBatchBuilder.build();
scanCommand = assertCommand(scanBatch);
assertLogging(scanCommand, 1);
}
use of com.synopsys.integration.log.BufferedIntLogger 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.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class CodeLocationServiceTestIT method testMappingWithProjectCodeCreator.
@Test
@Disabled
// ejk 2020-09-17 disabling this until I can figure out a better way to create the required elements for the test to pass
void testMappingWithProjectCodeCreator() throws IntegrationException, InterruptedException {
/*
This test requires a project/version: code_location_mapping_test_donotdelete/code_location_mapping_test_donotdelete
Also, it requires a user, project_code_scanner, with the Project Code Scanner role on the above project.
*/
String codeLocationName = "bdio to be mapped";
File bdioFile = new File(getClass().getResource("/bdio/bdio_without_project.jsonld").getFile());
UploadTarget uploadTarget = UploadTarget.createDefault(new NameVersion("inaccurate", "inaccurate"), codeLocationName, bdioFile);
BdioUploadService bdioUploadService = blackDuckServices.blackDuckServicesFactory.createBdioUploadService();
bdioUploadService.uploadBdio(uploadTarget);
UserView projectCodeScanner = blackDuckServices.blackDuckServicesFactory.createUserGroupService().getUserByUsername("project_code_scanner").get();
Optional<CodeLocationView> codeLocationView = blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationName);
int attempts = 0;
while (!codeLocationView.isPresent()) {
attempts++;
if (attempts > 15) {
fail("code location not created fast enough");
}
Thread.sleep(5000);
codeLocationView = blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationName);
}
assertTrue(StringUtils.isBlank(codeLocationView.get().getMappedProjectVersion()));
HttpUrl codeLocationUrl = codeLocationView.get().getHref();
// now use the project code scanner user
BufferedIntLogger logger = new BufferedIntLogger();
BlackDuckServerConfigBuilder projectCodeScannerBuilder = BlackDuckServerConfig.newBuilder();
projectCodeScannerBuilder.setUrl(intHttpClientTestHelper.getProperty(TestingPropertyKey.TEST_BLACK_DUCK_SERVER_URL));
projectCodeScannerBuilder.setUsername("project_code_scanner");
projectCodeScannerBuilder.setPassword("super_secure_password");
projectCodeScannerBuilder.setTrustCert(true);
BlackDuckServicesFactory specialFactory = projectCodeScannerBuilder.build().createBlackDuckServicesFactory(logger);
Optional<ProjectVersionWrapper> projectVersionWrapper = specialFactory.createProjectService().getProjectVersion(new NameVersion("code_location_mapping_test_donotdelete", "code_location_mapping_test_donotdelete"));
assertTrue(projectVersionWrapper.isPresent());
CodeLocationService specialCodeLocationService = specialFactory.createCodeLocationService();
specialCodeLocationService.mapCodeLocation(codeLocationUrl, projectVersionWrapper.get().getProjectVersionView());
codeLocationView = blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationName);
assertTrue(codeLocationView.isPresent());
assertEquals(projectVersionWrapper.get().getProjectVersionView().getHref().string(), codeLocationView.get().getMappedProjectVersion());
blackDuckServices.blackDuckApiClient.delete(codeLocationView.get());
}
Aggregations