Search in sources :

Example 1 with GetSessionInformationOptions

use of com.ibm.cloud.cloudant.v1.model.GetSessionInformationOptions 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 GetSessionInformationOptions

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

the class GetSessionInformationOptionsTest method testGetSessionInformationOptions.

@Test
public void testGetSessionInformationOptions() throws Throwable {
    GetSessionInformationOptions getSessionInformationOptionsModel = new GetSessionInformationOptions();
    assertNotNull(getSessionInformationOptionsModel);
}
Also used : GetSessionInformationOptions(com.ibm.cloud.cloudant.v1.model.GetSessionInformationOptions) Test(org.testng.annotations.Test)

Example 3 with GetSessionInformationOptions

use of com.ibm.cloud.cloudant.v1.model.GetSessionInformationOptions 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

GetSessionInformationOptions (com.ibm.cloud.cloudant.v1.model.GetSessionInformationOptions)2 SessionInformation (com.ibm.cloud.cloudant.v1.model.SessionInformation)2 Test (org.testng.annotations.Test)2 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