Search in sources :

Example 1 with MockCloseableHttpResponse

use of org.finra.herd.dao.impl.MockCloseableHttpResponse in project herd by FINRAOS.

the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse200BadContentReturnsNull.

@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);
    });
}
Also used : BusinessObjectDataStorageFilesCreateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse) StringEntity(org.apache.http.entity.StringEntity) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 2 with MockCloseableHttpResponse

use of org.finra.herd.dao.impl.MockCloseableHttpResponse in project herd by FINRAOS.

the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse400Throws.

@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());
    }
}
Also used : ErrorInformation(org.finra.herd.model.api.xml.ErrorInformation) StringEntity(org.apache.http.entity.StringEntity) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 3 with MockCloseableHttpResponse

use of org.finra.herd.dao.impl.MockCloseableHttpResponse in project herd by FINRAOS.

the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponseHttpResponseThrowsExceptionOnClose.

@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);
    });
}
Also used : BusinessObjectDataStorageFilesCreateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse) StringEntity(org.apache.http.entity.StringEntity) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 4 with MockCloseableHttpResponse

use of org.finra.herd.dao.impl.MockCloseableHttpResponse in project herd by FINRAOS.

the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse400BadContentThrows.

@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());
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 5 with MockCloseableHttpResponse

use of org.finra.herd.dao.impl.MockCloseableHttpResponse in project herd by FINRAOS.

the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponse.

@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);
}
Also used : BusinessObjectDataStorageFilesCreateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse) StringEntity(org.apache.http.entity.StringEntity) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) MockCloseableHttpResponse(org.finra.herd.dao.impl.MockCloseableHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 StringEntity (org.apache.http.entity.StringEntity)5 BasicStatusLine (org.apache.http.message.BasicStatusLine)5 MockCloseableHttpResponse (org.finra.herd.dao.impl.MockCloseableHttpResponse)5 Test (org.junit.Test)5 BusinessObjectDataStorageFilesCreateResponse (org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse)3 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 JAXBException (javax.xml.bind.JAXBException)2 ErrorInformation (org.finra.herd.model.api.xml.ErrorInformation)1