Search in sources :

Example 16 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine 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 17 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.

the class DownloaderWebClientTest method testGetBusinessObjectDataAssertNoAuthorizationHeaderWhenNoSsl.

@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);
    }
}
Also used : HttpVersion(org.apache.http.HttpVersion) Arrays(java.util.Arrays) BasicStatusLine(org.apache.http.message.BasicStatusLine) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) Mockito.doThrow(org.mockito.Mockito.doThrow) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) UploaderInputManifestDto(org.finra.herd.model.dto.UploaderInputManifestDto) Command(org.finra.herd.core.Command) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation) Storage(org.finra.herd.model.api.xml.Storage) DataBridgeWebClient(org.finra.herd.tools.common.databridge.DataBridgeWebClient) Assert.fail(org.junit.Assert.fail) Objects(com.google.common.base.Objects) DownloaderInputManifestDto(org.finra.herd.model.dto.DownloaderInputManifestDto) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) StorageUnitDownloadCredential(org.finra.herd.model.api.xml.StorageUnitDownloadCredential) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) StringEntity(org.apache.http.entity.StringEntity) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RegServerAccessParamsDto(org.finra.herd.model.dto.RegServerAccessParamsDto) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) HttpClientOperations(org.finra.herd.dao.HttpClientOperations) Matchers.argThat(org.mockito.Matchers.argThat) Assert(org.junit.Assert) AwsCredential(org.finra.herd.model.api.xml.AwsCredential) Assert.assertEquals(org.junit.Assert.assertEquals) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Mockito.mock(org.mockito.Mockito.mock) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) StringEntity(org.apache.http.entity.StringEntity) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) DownloaderInputManifestDto(org.finra.herd.model.dto.DownloaderInputManifestDto) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpClientOperations(org.finra.herd.dao.HttpClientOperations) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 18 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.

the class DownloaderWebClientTest method testGetBusinessObjectDataAssertNamespaceOptional.

@Test
public void testGetBusinessObjectDataAssertNamespaceOptional() throws Exception {
    HttpClientOperations mockHttpClientOperations = mock(HttpClientOperations.class);
    HttpClientOperations originalHttpClientOperations = (HttpClientOperations) ReflectionTestUtils.getField(downloaderWebClient, "httpClientOperations");
    ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", mockHttpClientOperations);
    try {
        String expectedHttpMethod = "GET";
        String expectedUri = "https://testWebServiceHostname:1234/herd-app/rest/businessObjectData" + "/businessObjectDefinitionNames/businessObjectDefinitionName/businessObjectFormatUsages/businessObjectFormatUsage" + "/businessObjectFormatFileTypes/businessObjectFormatFileType?partitionKey=partitionKey&partitionValue=partitionValue&" + "businessObjectFormatVersion=0&businessObjectDataVersion=1";
        CloseableHttpResponse closeableHttpResponse = mock(CloseableHttpResponse.class);
        when(mockHttpClientOperations.execute(any(), any())).thenReturn(closeableHttpResponse);
        when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
        BusinessObjectData expectedBusinessObjectData = new BusinessObjectData();
        expectedBusinessObjectData.setId(1234);
        StringEntity httpEntity = new StringEntity(xmlHelper.objectToXml(expectedBusinessObjectData));
        when(closeableHttpResponse.getEntity()).thenReturn(httpEntity);
        DownloaderInputManifestDto manifest = new DownloaderInputManifestDto();
        manifest.setBusinessObjectDefinitionName("businessObjectDefinitionName");
        manifest.setBusinessObjectFormatUsage("businessObjectFormatUsage");
        manifest.setBusinessObjectFormatFileType("businessObjectFormatFileType");
        manifest.setBusinessObjectFormatVersion("0");
        manifest.setPartitionKey("partitionKey");
        manifest.setPartitionValue("partitionValue");
        manifest.setBusinessObjectDataVersion("1");
        assertEquals(expectedBusinessObjectData.getId(), downloaderWebClient.getBusinessObjectData(manifest).getId());
        verify(mockHttpClientOperations).execute(any(), argThat(httpUriRequest -> Objects.equal(expectedHttpMethod, httpUriRequest.getMethod()) && Objects.equal(expectedUri, httpUriRequest.getURI().toString())));
    } finally {
        ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", originalHttpClientOperations);
    }
}
Also used : HttpVersion(org.apache.http.HttpVersion) Arrays(java.util.Arrays) BasicStatusLine(org.apache.http.message.BasicStatusLine) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) Mockito.doThrow(org.mockito.Mockito.doThrow) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) UploaderInputManifestDto(org.finra.herd.model.dto.UploaderInputManifestDto) Command(org.finra.herd.core.Command) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation) Storage(org.finra.herd.model.api.xml.Storage) DataBridgeWebClient(org.finra.herd.tools.common.databridge.DataBridgeWebClient) Assert.fail(org.junit.Assert.fail) Objects(com.google.common.base.Objects) DownloaderInputManifestDto(org.finra.herd.model.dto.DownloaderInputManifestDto) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) StorageUnitDownloadCredential(org.finra.herd.model.api.xml.StorageUnitDownloadCredential) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) StringEntity(org.apache.http.entity.StringEntity) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RegServerAccessParamsDto(org.finra.herd.model.dto.RegServerAccessParamsDto) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) HttpClientOperations(org.finra.herd.dao.HttpClientOperations) Matchers.argThat(org.mockito.Matchers.argThat) Assert(org.junit.Assert) AwsCredential(org.finra.herd.model.api.xml.AwsCredential) Assert.assertEquals(org.junit.Assert.assertEquals) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Mockito.mock(org.mockito.Mockito.mock) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) StringEntity(org.apache.http.entity.StringEntity) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) DownloaderInputManifestDto(org.finra.herd.model.dto.DownloaderInputManifestDto) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpClientOperations(org.finra.herd.dao.HttpClientOperations) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 19 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project scribejava by scribejava.

the class OauthAsyncCompletionHandlerTest method shouldReleaseLatchOnCancel.

@Test
public void shouldReleaseLatchOnCancel() throws Exception {
    handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER);
    final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok"));
    final BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(new ByteArrayInputStream(new byte[0]));
    response.setEntity(entity);
    handler.cancelled();
    assertNull(callback.getResponse());
    assertNotNull(callback.getThrowable());
    assertTrue(callback.getThrowable() instanceof CancellationException);
    // verify latch is released
    try {
        handler.getResult();
        fail();
    } catch (ExecutionException expected) {
    // expected
    }
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) CancellationException(java.util.concurrent.CancellationException) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) ProtocolVersion(org.apache.http.ProtocolVersion) ExecutionException(java.util.concurrent.ExecutionException) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 20 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project scribejava by scribejava.

the class OauthAsyncCompletionHandlerTest method shouldReleaseLatchOnSuccess.

@Test
public void shouldReleaseLatchOnSuccess() throws Exception {
    handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER);
    final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok"));
    final BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(new ByteArrayInputStream(new byte[0]));
    response.setEntity(entity);
    handler.completed(response);
    assertNotNull(callback.getResponse());
    assertNull(callback.getThrowable());
    // verify latch is released
    assertEquals("All good", handler.getResult());
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

BasicStatusLine (org.apache.http.message.BasicStatusLine)118 ProtocolVersion (org.apache.http.ProtocolVersion)67 Test (org.junit.Test)56 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)54 StatusLine (org.apache.http.StatusLine)45 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)33 StringEntity (org.apache.http.entity.StringEntity)32 ByteArrayInputStream (java.io.ByteArrayInputStream)29 HttpResponse (org.apache.http.HttpResponse)27 IOException (java.io.IOException)19 HttpEntity (org.apache.http.HttpEntity)19 BasicHeader (org.apache.http.message.BasicHeader)19 URL (java.net.URL)17 HttpURLConnection (java.net.HttpURLConnection)16 List (java.util.List)16 Header (org.apache.http.Header)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HashMap (java.util.HashMap)14 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)13 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)12