Search in sources :

Example 21 with BufferedIntLogger

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());
}
Also used : BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger)

Example 22 with BufferedIntLogger

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);
}
Also used : ScanBatch(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) Test(org.junit.jupiter.api.Test)

Example 23 with BufferedIntLogger

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);
}
Also used : ScanBatch(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) Test(org.junit.jupiter.api.Test)

Example 24 with BufferedIntLogger

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());
}
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 25 with BufferedIntLogger

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());
}
Also used : BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) NameVersion(com.synopsys.integration.util.NameVersion) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) File(java.io.File) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)26 Test (org.junit.jupiter.api.Test)20 IntLogger (com.synopsys.integration.log.IntLogger)8 File (java.io.File)7 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)6 NotificationTaskRange (com.synopsys.integration.blackduck.service.model.NotificationTaskRange)6 HttpUrl (com.synopsys.integration.rest.HttpUrl)6 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)5 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)5 VersionBomCodeLocationBomComputedNotificationUserView (com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView)5 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)5 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)5 NotificationService (com.synopsys.integration.blackduck.service.dataservice.NotificationService)5 HashSet (java.util.HashSet)5 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)4 BlackDuckServerConfigBuilder (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder)4 BlackDuckResponseResolver (com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Gson (com.google.gson.Gson)3 UploadBatchRunner (com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner)3