/** * Builds a Get Storage response. * * @param response the response. * @param uri the URI of the incoming request. * * @throws JAXBException if a JAXB error occurred. */ private void buildGetStorageResponse(MockCloseableHttpResponse response, URI uri) throws JAXBException { Pattern pattern = Pattern.compile("/herd-app/rest/storages/(.*)"); Matcher matcher = pattern.matcher(uri.getPath()); if (matcher.find()) { Storage storage = getNewStorage(matcher.group(1)); response.setEntity(getHttpEntity(storage)); } }
@Test public void testGetBusinessObjectDataStorageFilesCreateResponse200BadContentReturnsNull() throws Exception { CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), false); httpResponse.setEntity(new StringEntity("invalid xml")); executeWithoutLogging(DataBridgeWebClient.class, () -> { BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse); assertNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse); }); }
MockCloseableHttpResponse response = new MockCloseableHttpResponse(statusLine, false); response.setEntity(new StringEntity("invalid xml"));
@Test public void testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponse() throws Exception { CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), false); httpResponse.setEntity(new StringEntity(xmlHelper.objectToXml(new BusinessObjectDataStorageFilesCreateResponse()))); BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse); assertNotNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse); }
@Test public void testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponseHttpResponseThrowsExceptionOnClose() throws Exception { CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), true); httpResponse.setEntity(new StringEntity(xmlHelper.objectToXml(new BusinessObjectDataStorageFilesCreateResponse()))); executeWithoutLogging(DataBridgeWebClient.class, () -> { BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse); assertNotNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse); }); }
/** * Builds a business object data status update response. * * @param response the response. * @param uri the URI of the incoming request. * * @throws JAXBException if a JAXB error occurred. */ private void buildPutBusinessObjectDataStatusResponse(MockCloseableHttpResponse response, URI uri) throws JAXBException { BusinessObjectDataStatusUpdateResponse businessObjectDataStatusUpdateResponse = new BusinessObjectDataStatusUpdateResponse(); response.setEntity(getHttpEntity(businessObjectDataStatusUpdateResponse)); }
@Test public void testGetBusinessObjectDataStorageFilesCreateResponse400BadContentThrows() throws Exception { int expectedStatusCode = 400; String expectedReasonPhrase = "testReasonPhrase"; String expectedErrorMessage = "invalid xml"; CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, expectedStatusCode, expectedReasonPhrase), false); httpResponse.setEntity(new StringEntity(expectedErrorMessage)); try { executeWithoutLogging(DataBridgeWebClient.class, () -> { dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse); }); Assert.fail("expected HttpErrorResponseException, but no exception was thrown"); } catch (Exception e) { assertEquals("thrown exception type", HttpErrorResponseException.class, e.getClass()); HttpErrorResponseException httpErrorResponseException = (HttpErrorResponseException) e; assertEquals("httpErrorResponseException responseMessage", expectedErrorMessage, httpErrorResponseException.getResponseMessage()); assertEquals("httpErrorResponseException statusCode", expectedStatusCode, httpErrorResponseException.getStatusCode()); assertEquals("httpErrorResponseException statusDescription", expectedReasonPhrase, httpErrorResponseException.getStatusDescription()); assertEquals("httpErrorResponseException message", "Failed to add storage files", httpErrorResponseException.getMessage()); } }
/** * Builds a business object data storage files create response. * * @param response the response. * @param uri the URI of the incoming request. * * @throws JAXBException if a JAXB error occurred. */ private void buildPostBusinessObjectDataStorageFilesResponse(MockCloseableHttpResponse response, URI uri) throws JAXBException { BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = new BusinessObjectDataStorageFilesCreateResponse(); response.setEntity(getHttpEntity(businessObjectDataStorageFilesCreateResponse)); }
@Test public void testGetBusinessObjectDataStorageFilesCreateResponse400Throws() throws Exception { int expectedStatusCode = 400; String expectedReasonPhrase = "testReasonPhrase"; String expectedErrorMessage = "testErrorMessage"; ErrorInformation errorInformation = new ErrorInformation(); errorInformation.setStatusCode(expectedStatusCode); errorInformation.setMessage(expectedErrorMessage); errorInformation.setStatusDescription(expectedReasonPhrase); String requestContent = xmlHelper.objectToXml(errorInformation); CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, expectedStatusCode, expectedReasonPhrase), false); httpResponse.setEntity(new StringEntity(requestContent)); try { dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse); Assert.fail("expected HttpErrorResponseException, but no exception was thrown"); } catch (Exception e) { assertEquals("thrown exception type", HttpErrorResponseException.class, e.getClass()); HttpErrorResponseException httpErrorResponseException = (HttpErrorResponseException) e; assertEquals("httpErrorResponseException responseMessage", expectedErrorMessage, httpErrorResponseException.getResponseMessage()); assertEquals("httpErrorResponseException statusCode", expectedStatusCode, httpErrorResponseException.getStatusCode()); assertEquals("httpErrorResponseException statusDescription", expectedReasonPhrase, httpErrorResponseException.getStatusDescription()); assertEquals("httpErrorResponseException message", "Failed to add storage files", httpErrorResponseException.getMessage()); } }
/** * Builds a business object definition response. * * @param response the response * @param uri the URI of the incoming request * * @throws JAXBException if a JAXB error occurred */ private void buildGetBusinessObjectDefinitionResponse(MockCloseableHttpResponse response, URI uri) throws JAXBException { Pattern pattern = Pattern.compile("/herd-app/rest/businessObjectDefinitions/namespaces/(.*)/businessObjectDefinitionNames/(.*)"); Matcher matcher = pattern.matcher(uri.getPath()); if (matcher.find()) { BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition(); businessObjectDefinition.setNamespace(matcher.group(1)); businessObjectDefinition.setBusinessObjectDefinitionName(matcher.group(2)); businessObjectDefinition.setDisplayName("testBusinessObjectDefinitionDisplayName"); response.setEntity(getHttpEntity(businessObjectDefinition)); } }
businessObjectFormatVersion + "/data-v0/process-date=2014-01-31"); response.setEntity(getHttpEntity(s3KeyPrefixInformation));
private void getBusinessObjectDataUploadCredentialResponse(MockCloseableHttpResponse response, URI uri) throws UnsupportedCharsetException, JAXBException { BusinessObjectDataUploadCredential businessObjectDataUploadCredential = new BusinessObjectDataUploadCredential(); AwsCredential awsCredential = new AwsCredential(); awsCredential.setAwsAccessKey(uri.toString()); businessObjectDataUploadCredential.setAwsCredential(awsCredential); response.setEntity(getHttpEntity(businessObjectDataUploadCredential)); }
private void getStorageUnitDownloadCredentialResponse(MockCloseableHttpResponse response, URI uri) throws UnsupportedCharsetException, JAXBException { StorageUnitDownloadCredential storageUnitDownloadCredential = new StorageUnitDownloadCredential(); AwsCredential awsCredential = new AwsCredential(); awsCredential.setAwsAccessKey(uri.toString()); storageUnitDownloadCredential.setAwsCredential(awsCredential); response.setEntity(getHttpEntity(storageUnitDownloadCredential)); } }
/** * Builds a business object data create response. * * @param response the response. * @param uri the URI of the incoming request. * * @throws JAXBException if a JAXB error occurred. */ private void buildPostBusinessObjectDataResponse(MockCloseableHttpResponse response, URI uri) throws JAXBException { BusinessObjectData businessObjectData = new BusinessObjectData(); List<StorageUnit> storageUnits = new ArrayList<>(); businessObjectData.setStorageUnits(storageUnits); StorageUnit storageUnit = new StorageUnit(); storageUnit.setStorageDirectory(new StorageDirectory("app-a/exchange-a/prc/txt/new-orders/frmt-v0/data-v0/process-date=2014-01-31")); storageUnits.add(storageUnit); response.setEntity(getHttpEntity(businessObjectData)); }
response.setEntity(getHttpEntity(businessObjectDataVersions));
businessObjectData.setVersion(0); response.setEntity(getHttpEntity(businessObjectData));
response.setEntity(getHttpEntity(businessObjectDataSearchResult));