Search in sources :

Example 11 with CodeLocationView

use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView 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 12 with CodeLocationView

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

the class BdioUploadRecipeTest method assertCodeLocationDoesNotExist.

private void assertCodeLocationDoesNotExist() throws IntegrationException, InterruptedException {
    Optional<CodeLocationView> optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
    if (optionalCodeLocationView.isPresent()) {
        deleteCodeLocation(codeLocationName);
    }
    ResilientJobConfig waitJobConfig = new ResilientJobConfig(logger, 30, ResilientJobConfig.CURRENT_TIME_SUPPLIER, 5);
    WaitJob.waitFor(waitJobConfig, () -> !codeLocationService.getCodeLocationByName(codeLocationName).isPresent(), "code location not found");
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ResilientJobConfig(com.synopsys.integration.wait.ResilientJobConfig)

Example 13 with CodeLocationView

use of com.synopsys.integration.blackduck.api.generated.view.CodeLocationView 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 14 with CodeLocationView

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

the class CodeLocationWaiterTest method createTestView.

private CodeLocationView createTestView(String name) throws IntegrationException {
    ResourceMetadata meta = new ResourceMetadata();
    meta.setHref(hrefFromName(name));
    CodeLocationView codeLocationView = new CodeLocationView();
    codeLocationView.setName(name);
    codeLocationView.setMeta(meta);
    return codeLocationView;
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata)

Example 15 with CodeLocationView

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

the class CodeLocationsRetrieverTest method listWithDuplicates.

private List<CodeLocationView> listWithDuplicates() {
    List<CodeLocationView> codeLocations = new LinkedList<>();
    for (Map.Entry<String, String> entry : expectedResults().entrySet()) {
        codeLocations.add(createCodeLocation(entry.getKey(), entry.getValue()));
    }
    CodeLocationView toDuplicate = codeLocations.get(2);
    codeLocations.add(createCodeLocation(toDuplicate.getHref().string(), toDuplicate.getName()));
    return codeLocations;
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Aggregations

CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)26 Test (org.junit.jupiter.api.Test)9 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)8 File (java.io.File)7 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)6 HttpUrl (com.synopsys.integration.rest.HttpUrl)6 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)5 IntLogger (com.synopsys.integration.log.IntLogger)5 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)4 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)4 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)4 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)4 NameVersion (com.synopsys.integration.util.NameVersion)4 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)3 NullNode (com.fasterxml.jackson.databind.node.NullNode)3 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest)3 BdioUploadService (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService)3 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)3