Search in sources :

Example 6 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.

the class BlackDuckJsonTransformerTest method setup.

@BeforeAll
public static void setup() {
    BlackDuckJsonTransformerTest.gson = BlackDuckServicesFactory.createDefaultGson();
    BlackDuckJsonTransformerTest.objectMapper = BlackDuckServicesFactory.createDefaultObjectMapper();
    BlackDuckJsonTransformerTest.blackDuckResponseResolver = new BlackDuckResponseResolver(gson);
    BlackDuckJsonTransformerTest.logger = new BufferedIntLogger();
    BlackDuckJsonTransformerTest.blackDuckJsonTransformer = new BlackDuckJsonTransformer(gson, objectMapper, blackDuckResponseResolver, logger);
}
Also used : BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.

the class BdioUploadRecipeTest method testBdioUploadAndMapToVersion.

@Test
public void testBdioUploadAndMapToVersion() throws InterruptedException, IntegrationException {
    assertCodeLocationDoesNotExist();
    File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_without_project_section.jsonld");
    // in this case we upload the bdio but we have to map it to a project and version ourselves since the Project information is missing in the bdio file
    IntLogger logger = new BufferedIntLogger();
    UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
    BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
    codeLocationCreationService.createCodeLocations(scanRequest);
    // now that the file is uploaded, we want to lookup the code location that was created by the upload. in this case we know the name of the code location that was specified in the bdio file
    Optional<CodeLocationView> optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
    int maxAttempts = 6;
    int attempt = 0;
    while (!optionalCodeLocationView.isPresent() && attempt < maxAttempts) {
        // creating the code location can take a few seconds
        attempt++;
        Thread.sleep(5000);
        optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
    }
    CodeLocationView codeLocationView = optionalCodeLocationView.get();
    // then we map the code location to a version
    String versionName = "27.0.0-SNAPSHOT";
    ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectAndVersion);
    projectService.createProject(projectSyncModel.createProjectRequest());
    projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
    List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    assertTrue(versionCodeLocations.isEmpty());
    NotificationTaskRange notificationTaskRange = codeLocationCreationService.calculateCodeLocationRange();
    System.out.println(RestConstants.formatDate(notificationTaskRange.getStartDate()));
    System.out.println(RestConstants.formatDate(notificationTaskRange.getEndDate()));
    codeLocationService.mapCodeLocation(codeLocationView, projectVersionWrapper.get().getProjectVersionView());
    CodeLocationWaitResult waitResult = codeLocationCreationService.waitForCodeLocations(notificationTaskRange, projectAndVersion, new HashSet<>(Arrays.asList(codeLocationView.getName())), 1, 3 * 60);
    System.out.println("wait status: " + waitResult.getStatus());
    if (waitResult.getErrorMessage().isPresent()) {
        System.out.println(waitResult.getErrorMessage().get());
    }
    waitResult.getCodeLocationNames().stream().forEach(System.out::println);
    assertEquals(CodeLocationWaitResult.Status.COMPLETE, waitResult.getStatus());
    assertEquals(1, waitResult.getCodeLocationNames().size());
    assertTrue(waitResult.getCodeLocationNames().contains(codeLocationName));
    versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
    assertEquals(codeLocationName, versionCodeLocation.getName());
}
Also used : ProjectSyncModel(com.synopsys.integration.blackduck.service.model.ProjectSyncModel) CodeLocationWaitResult(com.synopsys.integration.blackduck.codelocation.CodeLocationWaitResult) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) File(java.io.File) UploadBatchRunner(com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner) Test(org.junit.jupiter.api.Test)

Example 8 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.

the class BdioUploadRecipeTest method testBdioUpload.

@Test
public void testBdioUpload() throws IntegrationException, InterruptedException {
    assertCodeLocationDoesNotExist();
    File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_with_project_section.jsonld");
    // in this case we can upload the bdio and it will be mapped to a project and version because it has the Project information within the bdio file
    IntLogger logger = new BufferedIntLogger();
    UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
    BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
    codeLocationCreationService.createCodeLocationsAndWait(scanRequest, 15 * 60);
    projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
    assertTrue(projectVersionWrapper.isPresent());
    List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
    assertEquals(1, versionCodeLocations.size());
    CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
    assertEquals(codeLocationName, versionCodeLocation.getName());
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) File(java.io.File) UploadBatchRunner(com.synopsys.integration.blackduck.codelocation.bdiolegacy.UploadBatchRunner) Test(org.junit.jupiter.api.Test)

Example 9 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.

the class CodeLocationWaiterTest method testAllCodeLocationsFoundImmediately.

@Test
public void testAllCodeLocationsFoundImmediately() throws InterruptedException, IntegrationException {
    BufferedIntLogger logger = new BufferedIntLogger();
    MockCodeLocationData mockCodeLocationData = twoCodeLocations();
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationUserView first = createTestNotification("one");
    NotificationUserView second = createTestNotification("two");
    Mockito.when(mockNotificationService.getAllUserNotifications(Mockito.any(), Mockito.any())).thenReturn(Arrays.asList(first, second));
    NotificationTaskRange notificationTaskRange = createTestRange();
    Set<String> codeLocationNames = new HashSet<>(Arrays.asList("one", "two"));
    CodeLocationWaiter codeLocationWaiter = new CodeLocationWaiter(logger, mockCodeLocationData.mockBlackDuckApiClient, mockCodeLocationData.mockProjectService, mockNotificationService);
    CodeLocationWaitResult codeLocationWaitResult = codeLocationWaiter.checkCodeLocationsAddedToBom(new UserView(), notificationTaskRange, mockCodeLocationData.testProjectAndVersion, codeLocationNames, 2, 0, 5);
    assertTrue(CodeLocationWaitResult.Status.COMPLETE == codeLocationWaitResult.getStatus(), "Status was not COMPLETE but was " + codeLocationWaitResult.getStatus());
    assertTrue(codeLocationWaitResult.getCodeLocationNames().contains("one"));
    assertTrue(codeLocationWaitResult.getCodeLocationNames().contains("two"));
    assertFalse(codeLocationWaitResult.getErrorMessage().isPresent());
}
Also used : NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) VersionBomCodeLocationBomComputedNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.VersionBomCodeLocationBomComputedNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) NotificationService(com.synopsys.integration.blackduck.service.dataservice.NotificationService) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with BufferedIntLogger

use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.

the class ScannerZipInstallerTest method testActualDownload.

@Test
void testActualDownload() throws Exception {
    String signatureScannerDownloadPath = TestingPropertyKey.TEST_BLACKDUCK_SIGNATURE_SCANNER_DOWNLOAD_PATH.fromEnvironment();
    String blackDuckUrl = TestingPropertyKey.TEST_BLACK_DUCK_SERVER_URL.fromEnvironment();
    String blackDuckUsername = TestingPropertyKey.TEST_USERNAME.fromEnvironment();
    String blackDuckPassword = TestingPropertyKey.TEST_PASSWORD.fromEnvironment();
    assertTrue(StringUtils.isNotBlank(signatureScannerDownloadPath));
    IntLogger logger = new BufferedIntLogger();
    BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = BlackDuckServerConfig.newCredentialsBuilder();
    blackDuckServerConfigBuilder.setUrl(blackDuckUrl);
    blackDuckServerConfigBuilder.setUsername(blackDuckUsername);
    blackDuckServerConfigBuilder.setPassword(blackDuckPassword);
    blackDuckServerConfigBuilder.setTimeoutInSeconds(120);
    blackDuckServerConfigBuilder.setTrustCert(true);
    blackDuckServerConfigBuilder.setLogger(logger);
    BlackDuckServerConfig blackDuckServerConfig = blackDuckServerConfigBuilder.build();
    BlackDuckHttpClient blackDuckHttpClient = blackDuckServerConfig.createBlackDuckHttpClient(logger);
    BlackDuckServicesFactory blackDuckServicesFactory = blackDuckServerConfig.createBlackDuckServicesFactory(blackDuckHttpClient, logger);
    BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
    OperatingSystemType operatingSystemType = OperatingSystemType.determineFromSystem();
    ScanPathsUtility scanPathsUtility = new ScanPathsUtility(logger, IntEnvironmentVariables.includeSystemEnv(), operatingSystemType);
    CleanupZipExpander cleanupZipExpander = new CleanupZipExpander(logger);
    KeyStoreHelper keyStoreHelper = new KeyStoreHelper(logger);
    File downloadTarget = new File(signatureScannerDownloadPath);
    ScannerZipInstaller scannerZipInstaller = new ScannerZipInstaller(logger, new SignatureScannerClient(blackDuckHttpClient), blackDuckRegistrationService, cleanupZipExpander, scanPathsUtility, keyStoreHelper, new HttpUrl(blackDuckUrl), operatingSystemType, downloadTarget);
    scannerZipInstaller.installOrUpdateScanner();
    ScanPaths scanPaths = scanPathsUtility.searchForScanPaths(downloadTarget);
    assertTrue(scanPaths.isManagedByLibrary());
    assertTrue(StringUtils.isNotBlank(scanPaths.getPathToJavaExecutable()));
    assertTrue(StringUtils.isNotBlank(scanPaths.getPathToOneJar()));
    assertTrue(StringUtils.isNotBlank(scanPaths.getPathToScanExecutable()));
    assertTrue(new File(scanPaths.getPathToJavaExecutable()).canExecute());
    assertTrue(new File(scanPaths.getPathToOneJar()).canExecute());
    assertTrue(new File(scanPaths.getPathToScanExecutable()).canExecute());
}
Also used : BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) KeyStoreHelper(com.synopsys.integration.blackduck.keystore.KeyStoreHelper) ScannerZipInstaller(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScannerZipInstaller) IntLogger(com.synopsys.integration.log.IntLogger) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) BlackDuckRegistrationService(com.synopsys.integration.blackduck.service.dataservice.BlackDuckRegistrationService) CleanupZipExpander(com.synopsys.integration.util.CleanupZipExpander) OperatingSystemType(com.synopsys.integration.util.OperatingSystemType) ScanPaths(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanPaths) ScanPathsUtility(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanPathsUtility) File(java.io.File) SignatureScannerClient(com.synopsys.integration.blackduck.http.client.SignatureScannerClient) Test(org.junit.jupiter.api.Test)

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