Search in sources :

Example 6 with HttpFailureException

use of co.cask.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.

the class RestStreamClientTest method testNotExistStreamCreateWriter.

@Test
public void testNotExistStreamCreateWriter() throws IOException {
    try {
        StreamWriter streamWriter = streamClient.createWriter(TestUtils.NOT_FOUND_STREAM_NAME);
        assertNotNull(streamWriter);
        assertEquals(RestStreamWriter.class, streamWriter.getClass());
        RestStreamWriter restStreamWriter = (RestStreamWriter) streamWriter;
        assertEquals(TestUtils.SUCCESS_STREAM_NAME, restStreamWriter.getStreamName());
        Assert.fail("Expected HttpFailureException");
    } catch (HttpFailureException e) {
        Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, e.getStatusCode());
    }
}
Also used : HttpFailureException(co.cask.common.http.exception.HttpFailureException) StreamWriter(co.cask.cdap.client.StreamWriter) Test(org.junit.Test)

Example 7 with HttpFailureException

use of co.cask.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.

the class RestStreamClientTest method testNotAuthorizedUnknownTokenSetTTL.

@Test
public void testNotAuthorizedUnknownTokenSetTTL() throws IOException {
    AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
    AccessToken accessToken = Mockito.mock(AccessToken.class);
    Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
    Mockito.when(accessToken.getValue()).thenReturn("test");
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    createClient(authClient);
    try {
        streamClient.setTTL(TestUtils.AUTH_STREAM_NAME, STREAM_TTL);
        Assert.fail("Expected HttpFailureException");
    } catch (HttpFailureException e) {
        Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
    }
}
Also used : HttpFailureException(co.cask.common.http.exception.HttpFailureException) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) Test(org.junit.Test)

Example 8 with HttpFailureException

use of co.cask.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.

the class RestStreamClientTest method testNotAuthorizedEmptyTokenTruncate.

@Test
public void testNotAuthorizedEmptyTokenTruncate() throws IOException {
    AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
    AccessToken accessToken = Mockito.mock(AccessToken.class);
    Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
    Mockito.when(accessToken.getValue()).thenReturn(StringUtils.EMPTY);
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    createClient(authClient);
    try {
        streamClient.truncate(TestUtils.AUTH_STREAM_NAME);
        Assert.fail("Expected HttpFailureException");
    } catch (HttpFailureException e) {
        Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
    }
}
Also used : HttpFailureException(co.cask.common.http.exception.HttpFailureException) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) Test(org.junit.Test)

Example 9 with HttpFailureException

use of co.cask.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.

the class RestStreamClientTest method testNotAuthorizedEmptyTokenCreate.

@Test
public void testNotAuthorizedEmptyTokenCreate() throws IOException {
    AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
    AccessToken accessToken = Mockito.mock(AccessToken.class);
    Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
    Mockito.when(accessToken.getValue()).thenReturn(StringUtils.EMPTY);
    Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
    createClient(authClient);
    try {
        streamClient.create(TestUtils.AUTH_STREAM_NAME);
        Assert.fail("Expected HttpFailureException");
    } catch (HttpFailureException e) {
        Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
    }
}
Also used : HttpFailureException(co.cask.common.http.exception.HttpFailureException) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) Test(org.junit.Test)

Aggregations

HttpFailureException (co.cask.common.http.exception.HttpFailureException)9 Test (org.junit.Test)9 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)8 AuthenticationClient (co.cask.cdap.security.authentication.client.AuthenticationClient)8 StreamWriter (co.cask.cdap.client.StreamWriter)1