Search in sources :

Example 71 with StatusLine

use of org.apache.http.StatusLine in project cdap-ingest by caskdata.

the class RestClientTest method testUnauthorizedResponseCodeAnalysis.

@Test
public void testUnauthorizedResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_UNAUTHORIZED, "Unauthorized");
    when(response.getStatusLine()).thenReturn(statusLine);
    TestUtils.verifyResponse(HttpStatus.SC_UNAUTHORIZED, response);
    verify(response).getStatusLine();
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 72 with StatusLine

use of org.apache.http.StatusLine in project cdap-ingest by caskdata.

the class RestClientTest method testNotAllowedResponseCodeAnalysis.

@Test
public void testNotAllowedResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
    when(response.getStatusLine()).thenReturn(statusLine);
    TestUtils.verifyResponse(HttpStatus.SC_METHOD_NOT_ALLOWED, response);
    verify(response, new VerificationMode() {

        @Override
        public void verify(VerificationData verificationData) {
            Assert.assertEquals(2, verificationData.getAllInvocations().size());
        }
    }).getStatusLine();
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) ProtocolVersion(org.apache.http.ProtocolVersion) VerificationMode(org.mockito.verification.VerificationMode) VerificationData(org.mockito.internal.verification.api.VerificationData) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 73 with StatusLine

use of org.apache.http.StatusLine in project cdap-ingest by caskdata.

the class RestClientTest method testNotFoundResponseCodeAnalysis.

@Test
public void testNotFoundResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_NOT_FOUND, "Not Found");
    when(response.getStatusLine()).thenReturn(statusLine);
    TestUtils.verifyResponse(HttpStatus.SC_NOT_FOUND, response);
    verify(response).getStatusLine();
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 74 with StatusLine

use of org.apache.http.StatusLine in project cdap-ingest by caskdata.

the class RestClientTest method testForbiddenResponseCodeAnalysis.

@Test
public void testForbiddenResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_FORBIDDEN, "Forbidden");
    when(response.getStatusLine()).thenReturn(statusLine);
    TestUtils.verifyResponse(HttpStatus.SC_FORBIDDEN, response);
    verify(response).getStatusLine();
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 75 with StatusLine

use of org.apache.http.StatusLine in project cdap-ingest by caskdata.

the class RestClientTest method testNotImplementedResponseCodeAnalysis.

@Test
public void testNotImplementedResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_NOT_IMPLEMENTED, "Not Implemented");
    when(response.getStatusLine()).thenReturn(statusLine);
    try {
        RestClient.responseCodeAnalysis(response);
        Assert.fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    }
    verify(response).getStatusLine();
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

StatusLine (org.apache.http.StatusLine)193 IOException (java.io.IOException)83 HttpResponse (org.apache.http.HttpResponse)76 HttpEntity (org.apache.http.HttpEntity)61 BasicStatusLine (org.apache.http.message.BasicStatusLine)46 ProtocolVersion (org.apache.http.ProtocolVersion)42 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)40 HttpGet (org.apache.http.client.methods.HttpGet)38 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)37 Header (org.apache.http.Header)36 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)34 Test (org.junit.Test)31 HttpPost (org.apache.http.client.methods.HttpPost)26 HashMap (java.util.HashMap)23 HttpResponseException (org.apache.http.client.HttpResponseException)23 StringEntity (org.apache.http.entity.StringEntity)23 URL (java.net.URL)20 BasicHeader (org.apache.http.message.BasicHeader)16 HttpURLConnection (java.net.HttpURLConnection)15 List (java.util.List)15