@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 testGetBusinessObjectDefinitionUseSsl() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setUseSsl(true); BusinessObjectDefinition result = retentionExpirationExporterWebClient.getBusinessObjectDefinition(NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME); assertNotNull(result); }
@Test public void testDestroyBusinessObjectData() throws Exception { retentionExpirationDestroyerWebClient.getRegServerAccessParamsDto().setUseSsl(false); BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey("test", "test", "test", "test", 0, "test", Collections.singletonList("test"), 0); BusinessObjectData result = retentionExpirationDestroyerWebClient.destroyBusinessObjectData(businessObjectDataKey); assertNotNull(result); }
@Test public void testDestroyBusinessObjectDataUseSsl() throws Exception { retentionExpirationDestroyerWebClient.getRegServerAccessParamsDto().setUseSsl(true); BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey("test", "test", "test", "test", 0, "test", Collections.singletonList("test"), 0); BusinessObjectData result = retentionExpirationDestroyerWebClient.destroyBusinessObjectData(businessObjectDataKey); assertNotNull(result); } }
@Test public void testGetBusinessObjectDefinition() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setUseSsl(false); BusinessObjectDefinition result = retentionExpirationExporterWebClient.getBusinessObjectDefinition(NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME); assertNotNull(result); }
@Before public void before() { dataBridgeWebClient = new DataBridgeWebClient() { }; RegServerAccessParamsDto regServerAccessParamsDto = new RegServerAccessParamsDto(); regServerAccessParamsDto.setUseSsl(false); regServerAccessParamsDto.setRegServerPort(8080); dataBridgeWebClient.setRegServerAccessParamsDto(regServerAccessParamsDto); dataBridgeWebClient.httpClientHelper = httpClientHelper; dataBridgeWebClient.httpClientOperations = httpClientOperations; dataBridgeWebClient.herdStringHelper = herdStringHelper; }
@Test public void testSearchBusinessObjectDataUseSsl() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setUseSsl(true); BusinessObjectDataSearchResult result = retentionExpirationExporterWebClient.searchBusinessObjectData(new BusinessObjectDataSearchRequest(), 1); assertNotNull(result); } }
/** * Calls preRegisterBusinessObjectData() method and makes assertions. * * @param attributes a map of business object data attributes * @param useSsl specifies whether to use SSL or not * * @throws JAXBException if a JAXB error was encountered * @throws IOException if an I/O error was encountered * @throws URISyntaxException if a URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */ private void testPreRegisterBusinessObjectData(HashMap<String, String> attributes, boolean useSsl) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(useSsl); UploaderInputManifestDto manifest = getUploaderInputManifestDto(); manifest.setAttributes(attributes); String storageName = "testStorage"; Boolean createNewVersion = false; BusinessObjectData businessObjectData = dataBridgeWebClient.preRegisterBusinessObjectData(manifest, storageName, createNewVersion); assertNotNull("businessObjectData", businessObjectData); }
/** * Calls getStorage() method and makes assertions. * * @param useSsl specifies whether to use SSL or not * * @throws JAXBException if a JAXB error was encountered * @throws IOException if an I/O error was encountered * @throws URISyntaxException if a URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */ private void testGetStorage(boolean useSsl) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(useSsl); String expectedStorageName = "testStorage"; Storage storage = dataBridgeWebClient.getStorage(expectedStorageName); assertNotNull("storage is null", storage); assertEquals("storage name", expectedStorageName, storage.getName()); }
/** * Calls updateBusinessObjectDataStatus() method and makes assertions. * * @param useSsl specifies whether to use SSL or not * * @throws JAXBException if a JAXB error was encountered * @throws IOException if an I/O error was encountered * @throws URISyntaxException if a URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */ private void testUpdateBusinessObjectDataStatus(List<String> subPartitionValues, boolean useSsl) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(useSsl); BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(); businessObjectDataKey.setSubPartitionValues(subPartitionValues); String businessObjectDataStatus = "testBusinessObjectDataStatus"; BusinessObjectDataStatusUpdateResponse businessObjectDataStatusUpdateResponse = dataBridgeWebClient.updateBusinessObjectDataStatus(businessObjectDataKey, businessObjectDataStatus); assertNotNull("businessObjectDataStatusUpdateResponse", businessObjectDataStatusUpdateResponse); } }
/** * Calls addStorageFiles() method and makes assertions. * * @param useSsl specifies whether to use SSL or not * * @throws JAXBException if a JAXB error was encountered * @throws IOException if an I/O error was encountered * @throws URISyntaxException if a URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */ private void testAddStorageFiles(boolean useSsl) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(useSsl); BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(); UploaderInputManifestDto manifest = getUploaderInputManifestDto(); S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); String storageName = "testStorage"; BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.addStorageFiles(businessObjectDataKey, manifest, s3FileTransferRequestParamsDto, storageName); assertNotNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse); }
@Test public void testAddStorageFilesResponse200BadContentReturnsNull() throws Exception { dataBridgeWebClient.regServerAccessParamsDto.setRegServerHost(MockHttpClientOperationsImpl.HOSTNAME_RESPOND_WITH_STATUS_CODE_200_AND_INVALID_CONTENT); dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(false); BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(); UploaderInputManifestDto manifest = getUploaderInputManifestDto(); S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); String storageName = "testStorage"; BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.addStorageFiles(businessObjectDataKey, manifest, s3FileTransferRequestParamsDto, storageName); assertNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse); }
/** * Calls getS3KeyPrefix() method and makes assertions. * * @param namespace the namespace * @param subPartitionValues the list of sub-partition values * @param businessObjectDataVersion the version of the business object data, may be null * @param useSsl specifies whether to use SSL or not * * @throws Exception if an error is encountered */ private void testGetS3KeyPrefix(String namespace, List<String> subPartitionValues, Integer businessObjectDataVersion, String storageName, boolean useSsl) throws Exception { dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(useSsl); DataBridgeBaseManifestDto manifest = getUploaderInputManifestDto(); manifest.setNamespace(namespace); manifest.setSubPartitionValues(subPartitionValues); manifest.setStorageName(storageName); Boolean createNewVersion = false; S3KeyPrefixInformation s3KeyPrefix = dataBridgeWebClient.getS3KeyPrefix(manifest, businessObjectDataVersion, createNewVersion); assertNotNull("s3KeyPrefix is null", s3KeyPrefix); }
@Test public void testSearchBusinessObjectDataPageNum1() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setUseSsl(false); BusinessObjectDataSearchResult result = retentionExpirationExporterWebClient.searchBusinessObjectData(new BusinessObjectDataSearchRequest(), 1); assertNotNull(result); assertEquals(2, CollectionUtils.size(result.getBusinessObjectDataElements())); }
@Test public void testSearchBusinessObjectDataPageNum2() throws Exception { retentionExpirationExporterWebClient.getRegServerAccessParamsDto().setUseSsl(false); BusinessObjectDataSearchResult result = retentionExpirationExporterWebClient.searchBusinessObjectData(new BusinessObjectDataSearchRequest(), 2); assertNotNull(result); assertEquals(0, CollectionUtils.size(result.getBusinessObjectDataElements())); }
@Test public void testGetBusinessObjectDataUploadCredential3() throws Exception { DataBridgeBaseManifestDto manifest = new DataBridgeBaseManifestDto(); manifest.setNamespace("test1"); manifest.setBusinessObjectDefinitionName("test2"); manifest.setBusinessObjectFormatUsage("test3"); manifest.setBusinessObjectFormatFileType("test4"); manifest.setBusinessObjectFormatVersion("test5"); manifest.setPartitionValue("test6"); manifest.setSubPartitionValues(Arrays.asList("test7", "test8")); String storageName = "test8"; Integer businessObjectDataVersion = null; Boolean createNewVersion = true; uploaderWebClient.getRegServerAccessParamsDto().setUseSsl(true); BusinessObjectDataUploadCredential businessObjectDataUploadCredential = uploaderWebClient.getBusinessObjectDataUploadCredential(manifest, storageName, businessObjectDataVersion, createNewVersion); Assert.assertNotNull(businessObjectDataUploadCredential); AwsCredential awsCredential = businessObjectDataUploadCredential.getAwsCredential(); Assert.assertNotNull(awsCredential); Assert.assertEquals("https://testWebServiceHostname:1234/herd-app/rest/businessObjectData/upload/credential/namespaces/test1" + "/businessObjectDefinitionNames/test2/businessObjectFormatUsages/test3/businessObjectFormatFileTypes/test4/businessObjectFormatVersions/test5" + "/partitionValues/test6?storageName=test8&subPartitionValues=test7%7Ctest8&createNewVersion=true", awsCredential.getAwsAccessKey()); }
@Test public void testGetBusinessObjectDataUploadCredential1() throws Exception { DataBridgeBaseManifestDto manifest = new DataBridgeBaseManifestDto(); manifest.setNamespace("test1"); manifest.setBusinessObjectDefinitionName("test2"); manifest.setBusinessObjectFormatUsage("test3"); manifest.setBusinessObjectFormatFileType("test4"); manifest.setBusinessObjectFormatVersion("test5"); manifest.setPartitionValue("test6"); manifest.setSubPartitionValues(Arrays.asList("test7", "test8")); String storageName = "test8"; Integer businessObjectDataVersion = 1234; Boolean createNewVersion = false; uploaderWebClient.getRegServerAccessParamsDto().setUseSsl(false); BusinessObjectDataUploadCredential businessObjectDataUploadCredential = uploaderWebClient.getBusinessObjectDataUploadCredential(manifest, storageName, businessObjectDataVersion, createNewVersion); Assert.assertNotNull(businessObjectDataUploadCredential); AwsCredential awsCredential = businessObjectDataUploadCredential.getAwsCredential(); Assert.assertNotNull(awsCredential); Assert.assertEquals("http://testWebServiceHostname:1234/herd-app/rest/businessObjectData/upload/credential/namespaces/test1" + "/businessObjectDefinitionNames/test2/businessObjectFormatUsages/test3/businessObjectFormatFileTypes/test4/businessObjectFormatVersions/test5" + "/partitionValues/test6?storageName=test8&subPartitionValues=test7%7Ctest8&businessObjectDataVersion=1234&createNewVersion=false", awsCredential.getAwsAccessKey()); }
@Test public void testGetBusinessObjectDataDownloadCredential2() throws Exception { DownloaderInputManifestDto manifest = new DownloaderInputManifestDto(); manifest.setNamespace("test1"); manifest.setBusinessObjectDefinitionName("test2"); manifest.setBusinessObjectFormatUsage("test3"); manifest.setBusinessObjectFormatFileType("test4"); manifest.setBusinessObjectFormatVersion("test5"); manifest.setPartitionValue("test6"); manifest.setBusinessObjectDataVersion("test9"); String storageName = "test10"; downloaderWebClient.getRegServerAccessParamsDto().setUseSsl(true); StorageUnitDownloadCredential storageUnitDownloadCredential = downloaderWebClient.getStorageUnitDownloadCredential(manifest, storageName); Assert.assertNotNull(storageUnitDownloadCredential); AwsCredential awsCredential = storageUnitDownloadCredential.getAwsCredential(); Assert.assertNotNull(awsCredential); Assert.assertEquals("https://testWebServiceHostname:1234/herd-app/rest/storageUnits/download/credential/namespaces/test1" + "/businessObjectDefinitionNames/test2/businessObjectFormatUsages/test3/businessObjectFormatFileTypes/test4/businessObjectFormatVersions/test5" + "/partitionValues/test6/businessObjectDataVersions/test9/storageNames/test10", awsCredential.getAwsAccessKey()); }
@Test public void testWebClientRegServerAccessParamsDtoSetterAndGetter() { // Create and initialize an instance of RegServerAccessParamsDto. RegServerAccessParamsDto regServerAccessParamsDto = new RegServerAccessParamsDto(); regServerAccessParamsDto.setRegServerHost(WEB_SERVICE_HOSTNAME); regServerAccessParamsDto.setRegServerPort(WEB_SERVICE_HTTPS_PORT); regServerAccessParamsDto.setUseSsl(true); regServerAccessParamsDto.setUsername(WEB_SERVICE_HTTPS_USERNAME); regServerAccessParamsDto.setPassword(WEB_SERVICE_HTTPS_PASSWORD); // Set the DTO. uploaderWebClient.setRegServerAccessParamsDto(regServerAccessParamsDto); // Retrieve the DTO and validate the results. RegServerAccessParamsDto resultRegServerAccessParamsDto = uploaderWebClient.getRegServerAccessParamsDto(); // validate the results. assertEquals(WEB_SERVICE_HOSTNAME, resultRegServerAccessParamsDto.getRegServerHost()); assertEquals(WEB_SERVICE_HTTPS_PORT, resultRegServerAccessParamsDto.getRegServerPort()); assertTrue(resultRegServerAccessParamsDto.isUseSsl()); assertEquals(WEB_SERVICE_HTTPS_USERNAME, resultRegServerAccessParamsDto.getUsername()); assertEquals(WEB_SERVICE_HTTPS_PASSWORD, resultRegServerAccessParamsDto.getPassword()); }
@Test public void testWebClientRegServerAccessParamsDtoSetterAndGetter() { // Create and initialize an instance of RegServerAccessParamsDto. RegServerAccessParamsDto regServerAccessParamsDto = new RegServerAccessParamsDto(); regServerAccessParamsDto.setRegServerHost(WEB_SERVICE_HOSTNAME); regServerAccessParamsDto.setRegServerPort(WEB_SERVICE_HTTPS_PORT); regServerAccessParamsDto.setUseSsl(true); regServerAccessParamsDto.setUsername(WEB_SERVICE_HTTPS_USERNAME); regServerAccessParamsDto.setPassword(WEB_SERVICE_HTTPS_PASSWORD); // Set the DTO. downloaderWebClient.setRegServerAccessParamsDto(regServerAccessParamsDto); // Retrieve the DTO and validate the results. RegServerAccessParamsDto resultRegServerAccessParamsDto = downloaderWebClient.getRegServerAccessParamsDto(); // validate the results. assertEquals(WEB_SERVICE_HOSTNAME, resultRegServerAccessParamsDto.getRegServerHost()); assertEquals(WEB_SERVICE_HTTPS_PORT, resultRegServerAccessParamsDto.getRegServerPort()); assertTrue(resultRegServerAccessParamsDto.isUseSsl()); assertEquals(WEB_SERVICE_HTTPS_USERNAME, resultRegServerAccessParamsDto.getUsername()); assertEquals(WEB_SERVICE_HTTPS_PASSWORD, resultRegServerAccessParamsDto.getPassword()); }