Search in sources :

Example 1 with PagingDefaultsEditor

use of com.synopsys.integration.blackduck.service.request.PagingDefaultsEditor in project blackduck-common by blackducksoftware.

the class BlackDuckApiClientTestIT method testMediaType.

@Test
public void testMediaType() throws IntegrationException {
    IntLogger logger = new PrintStreamIntLogger(System.out, LogLevel.DEBUG);
    BlackDuckMediaTypeDiscoveryVerifier blackDuckMediaTypeDiscoveryVerifier = new BlackDuckMediaTypeDiscoveryVerifier();
    BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = BlackDuckServerConfig.newCredentialsBuilder();
    blackDuckServerConfigBuilder.setUrl(testHelper.getProperty(TestingPropertyKey.TEST_BLACK_DUCK_SERVER_URL));
    blackDuckServerConfigBuilder.setUsername(testHelper.getProperty(TestingPropertyKey.TEST_USERNAME));
    blackDuckServerConfigBuilder.setPassword(testHelper.getProperty(TestingPropertyKey.TEST_PASSWORD));
    blackDuckServerConfigBuilder.setTrustCert(Boolean.parseBoolean(testHelper.getProperty(TestingPropertyKey.TEST_TRUST_HTTPS_CERT)));
    BlackDuckHttpClient blackDuckHttpClient = blackDuckServerConfigBuilder.build().createBlackDuckHttpClient(logger);
    Gson gson = BlackDuckServicesFactory.createDefaultGson();
    ObjectMapper objectMapper = BlackDuckServicesFactory.createDefaultObjectMapper();
    BlackDuckResponseResolver blackDuckResponseResolver = new BlackDuckResponseResolver(gson);
    BlackDuckJsonTransformer blackDuckJsonTransformer = new BlackDuckJsonTransformer(gson, objectMapper, blackDuckResponseResolver, logger);
    BlackDuckResponseTransformer blackDuckResponseTransformer = new BlackDuckResponseTransformer(blackDuckHttpClient, blackDuckJsonTransformer);
    BlackDuckResponsesTransformer blackDuckResponsesTransformer = new BlackDuckResponsesTransformer(blackDuckHttpClient, blackDuckJsonTransformer);
    BlackDuckApiClient blackDuckApiClient = new BlackDuckApiClient(blackDuckHttpClient, blackDuckJsonTransformer, blackDuckResponseTransformer, blackDuckResponsesTransformer);
    ApiDiscovery apiDiscovery = new ApiDiscovery(blackDuckServerConfigBuilder.build().getBlackDuckUrl());
    assertNull(blackDuckMediaTypeDiscoveryVerifier.originalMediaType);
    assertNull(blackDuckMediaTypeDiscoveryVerifier.discoveredMediaType);
    BlackDuckRequestBuilder blackDuckRequestBuilder = new BlackDuckRequestBuilder().commonGet();
    BlackDuckMultipleRequest<ProjectView> requestMultiple = new BlackDuckMultipleRequest<>(blackDuckRequestBuilder, apiDiscovery.metaProjectsLink(), new PagingDefaultsEditor(), new AcceptHeaderEditor(blackDuckMediaTypeDiscoveryVerifier));
    List<ProjectView> projects = blackDuckApiClient.getSomeResponses(requestMultiple, 5);
    assertTrue(projects.size() > 0);
    assertEquals(null, blackDuckMediaTypeDiscoveryVerifier.originalMediaType);
    assertEquals("application/json", blackDuckMediaTypeDiscoveryVerifier.discoveredMediaType);
    blackDuckRequestBuilder = new BlackDuckRequestBuilder().commonGet();
    ProjectView firstProject = projects.get(0);
    UrlSingleResponse<ProjectView> projectViewUrlSingleResponse = new UrlSingleResponse<>(firstProject.getHref(), ProjectView.class);
    BlackDuckSingleRequest<ProjectView> requestSingle = new BlackDuckSingleRequest<>(blackDuckRequestBuilder, projectViewUrlSingleResponse, new PagingDefaultsEditor(), new AcceptHeaderEditor(blackDuckMediaTypeDiscoveryVerifier));
    ProjectView retrievedById = blackDuckApiClient.getResponse(requestSingle);
    assertEquals(null, blackDuckMediaTypeDiscoveryVerifier.originalMediaType);
    assertEquals("application/vnd.blackducksoftware.project-detail-4+json", blackDuckMediaTypeDiscoveryVerifier.discoveredMediaType);
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) BlackDuckSingleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckSingleRequest) BlackDuckServerConfigBuilder(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) AcceptHeaderEditor(com.synopsys.integration.blackduck.service.request.AcceptHeaderEditor) Gson(com.google.gson.Gson) IntLogger(com.synopsys.integration.log.IntLogger) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) BlackDuckJsonTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckJsonTransformer) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckResponseTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponseTransformer) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PagingDefaultsEditor(com.synopsys.integration.blackduck.service.request.PagingDefaultsEditor) BlackDuckResponsesTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Gson (com.google.gson.Gson)1 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)1 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)1 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)1 BlackDuckServerConfigBuilder (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder)1 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)1 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1 BlackDuckJsonTransformer (com.synopsys.integration.blackduck.http.transform.BlackDuckJsonTransformer)1 BlackDuckResponseTransformer (com.synopsys.integration.blackduck.http.transform.BlackDuckResponseTransformer)1 BlackDuckResponsesTransformer (com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer)1 BlackDuckResponseResolver (com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver)1 AcceptHeaderEditor (com.synopsys.integration.blackduck.service.request.AcceptHeaderEditor)1 BlackDuckMultipleRequest (com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest)1 BlackDuckSingleRequest (com.synopsys.integration.blackduck.service.request.BlackDuckSingleRequest)1 PagingDefaultsEditor (com.synopsys.integration.blackduck.service.request.PagingDefaultsEditor)1 IntLogger (com.synopsys.integration.log.IntLogger)1 PrintStreamIntLogger (com.synopsys.integration.log.PrintStreamIntLogger)1 Test (org.junit.jupiter.api.Test)1