Search in sources :

Example 1 with SessionInformation

use of com.ibm.cloud.cloudant.v1.model.SessionInformation in project cloudant-java-sdk by IBM.

the class Cloudant method getSessionInformation.

/**
 * Retrieve current session cookie information.
 *
 * Retrieves information about the authenticated user's session.
 *
 * @param getSessionInformationOptions the {@link GetSessionInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SessionInformation}
 */
public ServiceCall<SessionInformation> getSessionInformation(GetSessionInformationOptions getSessionInformationOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_session"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSessionInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<SessionInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SessionInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : SessionInformation(com.ibm.cloud.cloudant.v1.model.SessionInformation) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Example 2 with SessionInformation

use of com.ibm.cloud.cloudant.v1.model.SessionInformation in project cloudant-java-sdk by IBM.

the class SessionInformationTest method testSessionInformation.

@Test
public void testSessionInformation() throws Throwable {
    SessionInformation sessionInformationModel = new SessionInformation();
    assertNull(sessionInformationModel.isOk());
    assertNull(sessionInformationModel.getInfo());
    assertNull(sessionInformationModel.getUserCtx());
}
Also used : SessionInformation(com.ibm.cloud.cloudant.v1.model.SessionInformation) Test(org.testng.annotations.Test)

Example 3 with SessionInformation

use of com.ibm.cloud.cloudant.v1.model.SessionInformation in project cloudant-java-sdk by IBM.

the class CloudantTest method testGetSessionInformationWOptions.

@Test
public void testGetSessionInformationWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"ok\": true, \"info\": {\"authenticated\": \"authenticated\", \"authentication_db\": \"authenticationDb\", \"authentication_handlers\": [\"authenticationHandlers\"]}, \"userCtx\": {\"db\": \"db\", \"name\": \"name\", \"roles\": [\"_reader\"]}}";
    String getSessionInformationPath = "/_session";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetSessionInformationOptions model
    GetSessionInformationOptions getSessionInformationOptionsModel = new GetSessionInformationOptions();
    // Invoke operation with valid options model (positive test)
    Response<SessionInformation> response = cloudantService.getSessionInformation(getSessionInformationOptionsModel).execute();
    assertNotNull(response);
    SessionInformation responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getSessionInformationPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetSessionInformationOptions(com.ibm.cloud.cloudant.v1.model.GetSessionInformationOptions) SessionInformation(com.ibm.cloud.cloudant.v1.model.SessionInformation) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SessionInformation (com.ibm.cloud.cloudant.v1.model.SessionInformation)3 Test (org.testng.annotations.Test)2 GetSessionInformationOptions (com.ibm.cloud.cloudant.v1.model.GetSessionInformationOptions)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1