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);
}
Aggregations