Search in sources :

Example 1 with GetIndexesInformationOptions

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

the class Cloudant method getIndexesInformation.

/**
 * Retrieve information about all indexes.
 *
 * When you make a GET request to `/db/_index`, you get a list of all indexes used by Cloudant Query in the database,
 * including the primary index. In addition to the information available through this API, indexes are also stored in
 * the `indexes` property of design documents.
 *
 * @param getIndexesInformationOptions the {@link GetIndexesInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link IndexesInformation}
 */
public ServiceCall<IndexesInformation> getIndexesInformation(GetIndexesInformationOptions getIndexesInformationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getIndexesInformationOptions, "getIndexesInformationOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getIndexesInformationOptions.db());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_index", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getIndexesInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<IndexesInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<IndexesInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) IndexesInformation(com.ibm.cloud.cloudant.v1.model.IndexesInformation)

Example 2 with GetIndexesInformationOptions

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

the class CloudantTest method testGetIndexesInformationWOptions.

@Test
public void testGetIndexesInformationWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"total_rows\": 0, \"indexes\": [{\"ddoc\": \"ddoc\", \"def\": {\"default_analyzer\": {\"name\": \"classic\", \"stopwords\": [\"stopwords\"]}, \"default_field\": {\"analyzer\": {\"name\": \"classic\", \"stopwords\": [\"stopwords\"]}, \"enabled\": true}, \"fields\": [{\"name\": \"name\", \"type\": \"boolean\"}], \"index_array_lengths\": true, \"partial_filter_selector\": {\"mapKey\": \"anyValue\"}}, \"name\": \"name\", \"type\": \"json\"}]}";
    String getIndexesInformationPath = "/testString/_index";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetIndexesInformationOptions model
    GetIndexesInformationOptions getIndexesInformationOptionsModel = new GetIndexesInformationOptions.Builder().db("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<IndexesInformation> response = cloudantService.getIndexesInformation(getIndexesInformationOptionsModel).execute();
    assertNotNull(response);
    IndexesInformation 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, getIndexesInformationPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetIndexesInformationOptions(com.ibm.cloud.cloudant.v1.model.GetIndexesInformationOptions) IndexesInformation(com.ibm.cloud.cloudant.v1.model.IndexesInformation) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with GetIndexesInformationOptions

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

the class GetIndexesInformationOptionsTest method testGetIndexesInformationOptions.

@Test
public void testGetIndexesInformationOptions() throws Throwable {
    GetIndexesInformationOptions getIndexesInformationOptionsModel = new GetIndexesInformationOptions.Builder().db("testString").build();
    assertEquals(getIndexesInformationOptionsModel.db(), "testString");
}
Also used : GetIndexesInformationOptions(com.ibm.cloud.cloudant.v1.model.GetIndexesInformationOptions) Test(org.testng.annotations.Test)

Aggregations

GetIndexesInformationOptions (com.ibm.cloud.cloudant.v1.model.GetIndexesInformationOptions)2 IndexesInformation (com.ibm.cloud.cloudant.v1.model.IndexesInformation)2 Test (org.testng.annotations.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1