Search in sources :

Example 21 with KnoxSession

use of org.apache.knox.gateway.shell.KnoxSession in project knox by apache.

the class TokenTest method testToken.

private void testToken(boolean setDoAsUser, String doAsUser) {
    KnoxSession knoxSession = createMock(KnoxSession.class);
    expect(knoxSession.base()).andReturn("http://localhost/base").atLeastOnce();
    replay(knoxSession);
    Get.Request request = (setDoAsUser) ? Token.get(knoxSession, doAsUser) : Token.get(knoxSession);
    if (setDoAsUser) {
        assertEquals(doAsUser, request.getDoAsUser());
    } else {
        assertNull(request.getDoAsUser());
    }
    if (setDoAsUser && StringUtils.isNotEmpty(doAsUser)) {
        assertEquals("http://localhost/base/knoxtoken/api/v1/token?doAs=" + doAsUser, request.getRequestURI().toString());
    } else {
        assertEquals("http://localhost/base/knoxtoken/api/v1/token", request.getRequestURI().toString());
    }
    assertSame(knoxSession, request.getSession());
    verify(knoxSession);
}
Also used : KnoxSession(org.apache.knox.gateway.shell.KnoxSession)

Example 22 with KnoxSession

use of org.apache.knox.gateway.shell.KnoxSession in project knox by apache.

the class GetTest method testGetRequest.

private void testGetRequest(boolean setDoAsUser, String doAsUser) {
    KnoxSession knoxSession = createMock(KnoxSession.class);
    expect(knoxSession.base()).andReturn("http://localhost/base").atLeastOnce();
    replay(knoxSession);
    Get.Request request = (setDoAsUser) ? new Get.Request(knoxSession, doAsUser) : new Get.Request(knoxSession);
    if (setDoAsUser) {
        assertEquals(doAsUser, request.getDoAsUser());
    } else {
        assertNull(request.getDoAsUser());
    }
    if (setDoAsUser && StringUtils.isNotEmpty(doAsUser)) {
        assertEquals("http://localhost/base/knoxtoken/api/v1/token?doAs=" + doAsUser, request.getRequestURI().toString());
    } else {
        assertEquals("http://localhost/base/knoxtoken/api/v1/token", request.getRequestURI().toString());
    }
    assertSame(knoxSession, request.getSession());
    verify(knoxSession);
}
Also used : KnoxSession(org.apache.knox.gateway.shell.KnoxSession)

Aggregations

KnoxSession (org.apache.knox.gateway.shell.KnoxSession)22 IOException (java.io.IOException)12 Callable (java.util.concurrent.Callable)6 Test (org.junit.Test)6 KnoxShellException (org.apache.knox.gateway.shell.KnoxShellException)5 URISyntaxException (java.net.URISyntaxException)2 HttpEntity (org.apache.http.HttpEntity)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 HttpPost (org.apache.http.client.methods.HttpPost)2 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)2 CredentialCollectionException (org.apache.knox.gateway.shell.CredentialCollectionException)2 HashMap (java.util.HashMap)1 CredentialCollector (org.apache.knox.gateway.shell.CredentialCollector)1 KnoxShellTable (org.apache.knox.gateway.shell.table.KnoxShellTable)1