DownloaderWebClient extends DataBridgeWebClient { public BusinessObjectData getBusinessObjectData(DownloaderInputManifestDto manifest) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { LOGGER.info("Retrieving business object data information from the registration server..."); StringBuilder uriPathBuilder = new StringBuilder(HERD_APP_REST_URI_PREFIX); uriPathBuilder.append("/businessObjectData"); uriPathBuilder.append("/namespaces/").append(manifest.getNamespace()); uriPathBuilder.append("/businessObjectDefinitionNames/").append(manifest.getBusinessObjectDefinitionName()); uriPathBuilder.append("/businessObjectFormatUsages/").append(manifest.getBusinessObjectFormatUsage()); uriPathBuilder.append("/businessObjectFormatFileTypes/").append(manifest.getBusinessObjectFormatFileType()); URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme()).setHost(regServerAccessParamsDto.getRegServerHost()).setPort(regServerAccessParamsDto.getRegServerPort()) .setPath(uriPathBuilder.toString()).setParameter("partitionKey", manifest.getPartitionKey()) .setParameter("partitionValue", manifest.getPartitionValue()) .setParameter("businessObjectFormatVersion", manifest.getBusinessObjectFormatVersion()) .setParameter("businessObjectDataVersion", manifest.getBusinessObjectDataVersion()); if (manifest.getSubPartitionValues() != null) { uriBuilder.setParameter("subPartitionValues", herdStringHelper.join(manifest.getSubPartitionValues(), "|", "\\")); } URI uri = uriBuilder.build(); CloseableHttpClient client = httpClientHelper .createHttpClient(regServerAccessParamsDto.isTrustSelfSignedCertificate(), regServerAccessParamsDto.isDisableHostnameVerification()); HttpGet request = new HttpGet(uri); request.addHeader("Accepts", "application/xml"); if (regServerAccessParamsDto.isUseSsl()) { request.addHeader(getAuthorizationHeader()); } LOGGER.info(String.format(" HTTP GET URI: %s", request.getURI().toString())); BusinessObjectData businessObjectData = getBusinessObjectData(httpClientOperations.execute(client, request), "retrieve business object data from the registration server"); LOGGER.info("Successfully retrieved business object data from the registration server."); return businessObjectData; }  BusinessObjectData getBusinessObjectData(DownloaderInputManifestDto manifest); S3KeyPrefixInformation getS3KeyPrefix(BusinessObjectData businessObjectData); StorageUnitDownloadCredential getStorageUnitDownloadCredential(DownloaderInputManifestDto manifest, String storageName);  }
@Test public void testGetBusinessObjectDataAssertNoAuthorizationHeaderWhenNoSsl() throws Exception { HttpClientOperations mockHttpClientOperations = mock(HttpClientOperations.class); HttpClientOperations originalHttpClientOperations = (HttpClientOperations) ReflectionTestUtils.getField(downloaderWebClient, "httpClientOperations"); ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", mockHttpClientOperations); try { CloseableHttpResponse closeableHttpResponse = mock(CloseableHttpResponse.class); when(mockHttpClientOperations.execute(any(), any())).thenReturn(closeableHttpResponse); when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK")); when(closeableHttpResponse.getEntity()).thenReturn(new StringEntity(xmlHelper.objectToXml(new BusinessObjectData()))); DownloaderInputManifestDto manifest = new DownloaderInputManifestDto(); downloaderWebClient.getRegServerAccessParamsDto().setUseSsl(false); downloaderWebClient.getBusinessObjectData(manifest); verify(mockHttpClientOperations).execute(any(), argThat(httpUriRequest -> httpUriRequest.getFirstHeader("Authorization") == null)); } finally { ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", originalHttpClientOperations); } }
@Test public void testGetData() throws Exception { uploadAndRegisterTestDataParents(downloaderWebClient); uploadTestDataFilesToS3(S3_TEST_PATH_V0); final UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); executeWithoutLogging(DataBridgeWebClient.class, new Command() { @Override public void execute() throws Exception { BusinessObjectData businessObjectData = downloaderWebClient.preRegisterBusinessObjectData(uploaderInputManifestDto, StorageEntity.MANAGED_STORAGE, false); BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectData); downloaderWebClient .addStorageFiles(businessObjectDataKey, uploaderInputManifestDto, getTestS3FileTransferRequestParamsDto(S3_TEST_PATH_V0 + "/"), StorageEntity.MANAGED_STORAGE); downloaderWebClient.updateBusinessObjectDataStatus(businessObjectDataKey, BusinessObjectDataStatusEntity.VALID); } }); DownloaderInputManifestDto downloaderInputManifestDto = getTestDownloaderInputManifestDto(); BusinessObjectData resultBusinessObjectData = downloaderWebClient.getBusinessObjectData(downloaderInputManifestDto); assertNotNull(resultBusinessObjectData); }