use of co.cask.cdap.common.http.exception.HttpFailureException in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedEmptyTokenSetTTL.
@Test
public void testNotAuthorizedEmptyTokenSetTTL() 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.setTTL(TestUtils.AUTH_STREAM_NAME, STREAM_TTL);
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 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");
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 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");
streamClient = RestStreamClient.builder(testServerHost, testServerPort).authClient(authClient).build();
try {
streamClient.setTTL(TestUtils.AUTH_STREAM_NAME, STREAM_TTL);
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 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");
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