Search in sources :

Example 26 with CodeLocationView

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

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