Search in sources :

Example 1 with BlackDuckServices

use of com.synopsys.integration.blackduck.comprehensive.BlackDuckServices in project blackduck-common by blackducksoftware.

the class CodeLocationServiceTestIT method uploadAndVerifyCodeLocation.

private void uploadAndVerifyCodeLocation(int numberOfCodeLocations, int codeLocationToTest) throws IntegrationException, IOException {
    List<String> codeLocationNames = populateCodeLocationNames(numberOfCodeLocations);
    String codeLocationToValidate = codeLocationNames.get(codeLocationToTest - 1);
    // Pre-clean test data
    deleteCodeLocationByName(blackDuckServices, codeLocationNames);
    deleteProjectByName(blackDuckServices);
    // Verify code location does not exist
    assertEquals(Optional.empty(), blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationToValidate), String.format("Code location %s should not exist", codeLocationToValidate));
    try {
        createAndUploadSimpleBdioObject(codeLocationNames);
        // Verify code location now exists using getSomeMatchingResponses()
        Predicate<CodeLocationView> nameMatcherPredicate = codeLocationView -> CodeLocationService.NAME_MATCHER.test(codeLocationToValidate, codeLocationView);
        BlackDuckRequestBuilder blackDuckRequestBuilder = new BlackDuckRequestBuilder().commonGet().setLimit(2);
        BlackDuckMultipleRequest<CodeLocationView> requestMultiple = blackDuckRequestBuilder.buildBlackDuckRequest(blackDuckServices.apiDiscovery.metaCodelocationsLink());
        List<CodeLocationView> foundCodeLocation = blackDuckServices.blackDuckApiClient.getSomeMatchingResponses(requestMultiple, nameMatcherPredicate, 1);
        assertEquals(1, foundCodeLocation.size(), String.format("Matching code locations should be 1 but is %d", foundCodeLocation.size()));
        assertEquals(codeLocationToValidate, foundCodeLocation.get(0).getName(), "Found code location does not equal expected");
        // Verify code location now exists using getCodeLocationByName()
        assertTrue(blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationToValidate).isPresent(), "Code location is empty after uploading.");
        assertEquals(codeLocationToValidate, blackDuckServices.codeLocationService.getCodeLocationByName(codeLocationToValidate).get().getName(), "Found code location does not equal expected");
    } finally {
        // Post-clean test data
        deleteCodeLocationByName(blackDuckServices, codeLocationNames);
        deleteProjectByName(blackDuckServices);
    }
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) Assertions.fail(org.junit.jupiter.api.Assertions.fail) IntStream(java.util.stream.IntStream) IntegrationException(com.synopsys.integration.exception.IntegrationException) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) BlackDuckServices(com.synopsys.integration.blackduck.comprehensive.BlackDuckServices) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) HttpUrl(com.synopsys.integration.rest.HttpUrl) SimpleBdioFactory(com.synopsys.integration.bdio.SimpleBdioFactory) NameVersion(com.synopsys.integration.util.NameVersion) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Tag(org.junit.jupiter.api.Tag) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) Predicate(java.util.function.Predicate) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) File(java.io.File) Test(org.junit.jupiter.api.Test) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) List(java.util.List) TimingExtension(com.synopsys.integration.blackduck.TimingExtension) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) TestingPropertyKey(com.synopsys.integration.blackduck.http.client.TestingPropertyKey) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IntHttpClientTestHelper(com.synopsys.integration.blackduck.http.client.IntHttpClientTestHelper) Optional(java.util.Optional) Result(com.synopsys.integration.blackduck.codelocation.Result) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)

Example 2 with BlackDuckServices

use of com.synopsys.integration.blackduck.comprehensive.BlackDuckServices in project blackduck-common by blackducksoftware.

the class BinaryScanUploadServiceTestIT method testCodeLocationFromBinaryScanUpload.

@Test
@Disabled
public // disabled because special config is needed to support /api/uploads (binary scan)
void testCodeLocationFromBinaryScanUpload() throws Exception {
    BlackDuckServices blackDuckServices = new BlackDuckServices(intHttpClientTestHelper);
    BinaryScanData binaryScanData = createBinaryScanData(blackDuckServices, createTestBinaryScan());
    assertBinaryUploadCompleted(blackDuckServices, binaryScanData);
}
Also used : BlackDuckServices(com.synopsys.integration.blackduck.comprehensive.BlackDuckServices) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with BlackDuckServices

use of com.synopsys.integration.blackduck.comprehensive.BlackDuckServices in project blackduck-common by blackducksoftware.

the class BinaryScanUploadServiceTestIT method testCodeLocationFromBinaryScanUploadWhenNotConfigured.

@Test
public void testCodeLocationFromBinaryScanUploadWhenNotConfigured() throws Exception {
    BlackDuckServices blackDuckServices = new BlackDuckServices(intHttpClientTestHelper);
    BinaryScanData binaryScanData = createBinaryScanData(blackDuckServices, createTestBinaryScan());
    BinaryScanUploadService binaryScanUploadService = blackDuckServices.blackDuckServicesFactory.createBinaryScanUploadService();
    BinaryScanBatchOutput binaryScanBatchOutput = binaryScanUploadService.uploadBinaryScanAndWait(binaryScanData.binaryScan, 15 * 60);
    BufferedIntLogger logger = new BufferedIntLogger();
    try {
        binaryScanBatchOutput.throwExceptionForError(logger);
    } catch (Exception e) {
        assertTrue(e instanceof BlackDuckIntegrationException);
        assertTrue(e.getMessage().startsWith("Error when uploading binary scan"));
        assertTrue(logger.getOutputString(LogLevel.ERROR).contains(e.getMessage()));
    }
}
Also used : BlackDuckServices(com.synopsys.integration.blackduck.comprehensive.BlackDuckServices) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) BufferedIntLogger(com.synopsys.integration.log.BufferedIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) Test(org.junit.jupiter.api.Test)

Example 4 with BlackDuckServices

use of com.synopsys.integration.blackduck.comprehensive.BlackDuckServices in project blackduck-common by blackducksoftware.

the class BinaryScanUploadServiceTestIT method testJapaneseCharactersForBinaryUpload.

@Test
@Disabled
public // also, because as of 2020.8.0, binary upload doesn't support utf-8
void testJapaneseCharactersForBinaryUpload() throws IntegrationException, InterruptedException {
    BlackDuckServices blackDuckServices = new BlackDuckServices(intHttpClientTestHelper);
    File binaryFile = getTestBinaryFile();
    BinaryScan binaryScan = new BinaryScan(binaryFile, JAPANESE_PROJECT_NAME, JAPANESE_VERSION_NAME, JAPANESE_CODE_LOCATION_NAME);
    BinaryScanData binaryScanData = createBinaryScanData(blackDuckServices, binaryScan);
    assertBinaryUploadCompleted(blackDuckServices, binaryScanData);
    Optional<ProjectVersionWrapper> optionalProjectVersionWrapper = blackDuckServices.projectService.getProjectVersion(JAPANESE_PROJECT_NAME, JAPANESE_VERSION_NAME);
    Optional<CodeLocationView> optionalCodeLocationView = blackDuckServices.codeLocationService.getCodeLocationByName(JAPANESE_CODE_LOCATION_NAME);
    assertTrue(optionalProjectVersionWrapper.isPresent());
    assertTrue(optionalCodeLocationView.isPresent());
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) BlackDuckServices(com.synopsys.integration.blackduck.comprehensive.BlackDuckServices) 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

BlackDuckServices (com.synopsys.integration.blackduck.comprehensive.BlackDuckServices)4 Test (org.junit.jupiter.api.Test)4 Disabled (org.junit.jupiter.api.Disabled)3 CodeLocationView (com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 BufferedIntLogger (com.synopsys.integration.log.BufferedIntLogger)2 File (java.io.File)2 SimpleBdioFactory (com.synopsys.integration.bdio.SimpleBdioFactory)1 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)1 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 TimingExtension (com.synopsys.integration.blackduck.TimingExtension)1 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)1 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)1 Result (com.synopsys.integration.blackduck.codelocation.Result)1 BdioUploadCodeLocationCreationRequest (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest)1 BdioUploadService (com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService)1 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)1 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)1