use of co.cask.cdap.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedUnknownTokenTruncate.
@Test
public void testNotAuthorizedUnknownTokenTruncate() 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");
streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build();
try {
streamClient.truncate(TestUtils.AUTH_STREAM_NAME);
Assert.fail("Expected HttpFailureException");
} catch (HttpFailureException e) {
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
}
}
use of co.cask.cdap.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());
}
}
use of co.cask.cdap.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedUnknownTokenGetTTL.
@Test
public void testNotAuthorizedUnknownTokenGetTTL() 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");
streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build();
try {
streamClient.getTTL(TestUtils.AUTH_STREAM_NAME);
Assert.fail("Expected HttpFailureException");
} catch (HttpFailureException e) {
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
}
}
use of co.cask.cdap.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedEmptyTokenGetTTL.
@Test
public void testNotAuthorizedEmptyTokenGetTTL() 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");
streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build();
try {
streamClient.getTTL(TestUtils.AUTH_STREAM_NAME);
Assert.fail("Expected HttpFailureException");
} catch (HttpFailureException e) {
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
}
}
use of co.cask.cdap.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedUnknownTokenCreate.
@Test
public void testNotAuthorizedUnknownTokenCreate() 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");
streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build();
try {
streamClient.create(TestUtils.AUTH_STREAM_NAME);
Assert.fail("Expected HttpFailureException");
} catch (HttpFailureException e) {
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
}
}
Aggregations