use of com.ibm.cloud.cloudant.v1.model.PostExplainOptions in project cloudant-java-sdk by IBM.
the class PostExplainOptionsTest method testPostExplainOptions.
@Test
public void testPostExplainOptions() throws Throwable {
PostExplainOptions postExplainOptionsModel = new PostExplainOptions.Builder().db("testString").selector(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).bookmark("testString").conflicts(true).executionStats(true).fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).limit(Long.valueOf("0")).skip(Long.valueOf("0")).sort(new java.util.ArrayList<java.util.Map<String, String>>(java.util.Arrays.asList(new java.util.HashMap<String, String>() {
{
put("foo", "asc");
}
}))).stable(true).update("true").useIndex(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).r(Long.valueOf("1")).build();
assertEquals(postExplainOptionsModel.db(), "testString");
assertEquals(postExplainOptionsModel.selector(), new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
assertEquals(postExplainOptionsModel.bookmark(), "testString");
assertEquals(postExplainOptionsModel.conflicts(), Boolean.valueOf(true));
assertEquals(postExplainOptionsModel.executionStats(), Boolean.valueOf(true));
assertEquals(postExplainOptionsModel.fields(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(postExplainOptionsModel.limit(), Long.valueOf("0"));
assertEquals(postExplainOptionsModel.skip(), Long.valueOf("0"));
assertEquals(postExplainOptionsModel.sort(), new java.util.ArrayList<java.util.Map<String, String>>(java.util.Arrays.asList(new java.util.HashMap<String, String>() {
{
put("foo", "asc");
}
})));
assertEquals(postExplainOptionsModel.stable(), Boolean.valueOf(true));
assertEquals(postExplainOptionsModel.update(), "true");
assertEquals(postExplainOptionsModel.useIndex(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(postExplainOptionsModel.r(), Long.valueOf("1"));
}
use of com.ibm.cloud.cloudant.v1.model.PostExplainOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostExplainWOptions.
@Test
public void testPostExplainWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"dbname\": \"dbname\", \"fields\": [\"fields\"], \"index\": {\"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\"}, \"limit\": 0, \"opts\": {\"mapKey\": \"anyValue\"}, \"range\": {\"end_key\": [\"anyValue\"], \"start_key\": [\"anyValue\"]}, \"selector\": {\"mapKey\": \"anyValue\"}, \"skip\": 0}";
String postExplainPath = "/testString/_explain";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the PostExplainOptions model
PostExplainOptions postExplainOptionsModel = new PostExplainOptions.Builder().db("testString").selector(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).bookmark("testString").conflicts(true).executionStats(true).fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).limit(Long.valueOf("0")).skip(Long.valueOf("0")).sort(new java.util.ArrayList<java.util.Map<String, String>>(java.util.Arrays.asList(new java.util.HashMap<String, String>() {
{
put("foo", "asc");
}
}))).stable(true).update("true").useIndex(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).r(Long.valueOf("1")).build();
// Invoke operation with valid options model (positive test)
Response<ExplainResult> response = cloudantService.postExplain(postExplainOptionsModel).execute();
assertNotNull(response);
ExplainResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, postExplainPath);
}
use of com.ibm.cloud.cloudant.v1.model.PostExplainOptions in project cloudant-java-sdk by IBM.
the class Cloudant method postExplain.
/**
* Retrieve information about which index is used for a query.
*
* Shows which index is being used by the query. Parameters are the same as the [`_find`
* endpoint](#query-an-index-by-using-selector-syntax).
*
* @param postExplainOptions the {@link PostExplainOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ExplainResult}
*/
public ServiceCall<ExplainResult> postExplain(PostExplainOptions postExplainOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postExplainOptions, "postExplainOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postExplainOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_explain", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postExplain");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.add("selector", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postExplainOptions.selector()));
if (postExplainOptions.bookmark() != null) {
contentJson.addProperty("bookmark", postExplainOptions.bookmark());
}
if (postExplainOptions.conflicts() != null) {
contentJson.addProperty("conflicts", postExplainOptions.conflicts());
}
if (postExplainOptions.executionStats() != null) {
contentJson.addProperty("execution_stats", postExplainOptions.executionStats());
}
if (postExplainOptions.fields() != null) {
contentJson.add("fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postExplainOptions.fields()));
}
if (postExplainOptions.limit() != null) {
contentJson.addProperty("limit", postExplainOptions.limit());
}
if (postExplainOptions.skip() != null) {
contentJson.addProperty("skip", postExplainOptions.skip());
}
if (postExplainOptions.sort() != null) {
contentJson.add("sort", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postExplainOptions.sort()));
}
if (postExplainOptions.stable() != null) {
contentJson.addProperty("stable", postExplainOptions.stable());
}
if (postExplainOptions.update() != null) {
contentJson.addProperty("update", postExplainOptions.update());
}
if (postExplainOptions.useIndex() != null) {
contentJson.add("use_index", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postExplainOptions.useIndex()));
}
if (postExplainOptions.r() != null) {
contentJson.addProperty("r", postExplainOptions.r());
}
builder.bodyJson(contentJson);
ResponseConverter<ExplainResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ExplainResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations