Search in sources :

Example 1 with CodeLocationView

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

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

the class CodeLocationServiceTestIT method deleteCodeLocationByName.

private void deleteCodeLocationByName(BlackDuckServices blackDuckServices, List<String> codeLocationNames) throws IntegrationException {
    Predicate<CodeLocationView> toDelete = (codeLocationView -> codeLocationNames.contains(codeLocationView.getName()));
    List<CodeLocationView> codeLocationsToDelete = blackDuckServices.blackDuckApiClient.getSomeMatchingResponses(blackDuckServices.apiDiscovery.metaCodelocationsLink(), toDelete, codeLocationNames.size());
    for (CodeLocationView codeLocationToDelete : codeLocationsToDelete) {
        blackDuckServices.blackDuckApiClient.delete(codeLocationToDelete);
    }
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)

Example 3 with CodeLocationView

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

the class CodeLocationService method getCodeLocationById.

public CodeLocationView getCodeLocationById(String codeLocationId) throws IntegrationException {
    BlackDuckPath blackDuckPath = new BlackDuckPath(ApiDiscovery.CODELOCATIONS_PATH.getPath() + "/" + codeLocationId, CodeLocationView.class, false);
    UrlSingleResponse<CodeLocationView> codeLocationResponse = apiDiscovery.metaSingleResponse(blackDuckPath);
    return blackDuckApiClient.getResponse(codeLocationResponse);
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) BlackDuckPath(com.synopsys.integration.blackduck.api.core.BlackDuckPath)

Example 4 with CodeLocationView

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

the class CodeLocationService method getCodeLocationByName.

public Optional<CodeLocationView> getCodeLocationByName(String codeLocationName) throws IntegrationException {
    BlackDuckQuery blackDuckQuery = new BlackDuckQuery("name", codeLocationName);
    BlackDuckRequestBuilder blackDuckRequestBuilder = new BlackDuckRequestBuilder().commonGet().addBlackDuckQuery(blackDuckQuery);
    Predicate<CodeLocationView> predicate = codeLocationView -> NAME_MATCHER.test(codeLocationName, codeLocationView);
    BlackDuckMultipleRequest<CodeLocationView> requestMultiple = blackDuckRequestBuilder.buildBlackDuckRequest(codeLocationsResponses);
    return blackDuckApiClient.getSomeMatchingResponses(requestMultiple, predicate, 1).stream().findFirst();
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ScanSummaryView(com.synopsys.integration.blackduck.api.manual.view.ScanSummaryView) DataService(com.synopsys.integration.blackduck.service.DataService) Predicate(java.util.function.Predicate) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) BiPredicate(java.util.function.BiPredicate) List(java.util.List) NullNode(com.fasterxml.jackson.databind.node.NullNode) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) Optional(java.util.Optional) BlackDuckPath(com.synopsys.integration.blackduck.api.core.BlackDuckPath) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)

Example 5 with CodeLocationView

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

the class CodeLocationService method mapCodeLocation.

public void mapCodeLocation(HttpUrl codeLocationUrl, ProjectVersionView projectVersionView) throws IntegrationException {
    CodeLocationView codeLocationView = createFakeCodeLocationView(codeLocationUrl);
    mapCodeLocation(codeLocationView, projectVersionView);
}
Also used : CodeLocationView(com.synopsys.integration.blackduck.api.generated.view.CodeLocationView)

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