use of com.ibm.cloud.cloudant.v1.model.Analyzer 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);
}
use of com.ibm.cloud.cloudant.v1.model.Analyzer in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetDesignDocumentWOptions.
@Test
public void testGetDesignDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"_attachments\": {\"mapKey\": {\"content_type\": \"contentType\", \"data\": \"VGhpcyBpcyBhbiBlbmNvZGVkIGJ5dGUgYXJyYXku\", \"digest\": \"digest\", \"encoded_length\": 0, \"encoding\": \"encoding\", \"follows\": false, \"length\": 0, \"revpos\": 1, \"stub\": true}}, \"_conflicts\": [\"conflicts\"], \"_deleted\": false, \"_deleted_conflicts\": [\"deletedConflicts\"], \"_id\": \"id\", \"_local_seq\": \"localSeq\", \"_rev\": \"rev\", \"_revisions\": {\"ids\": [\"ids\"], \"start\": 1}, \"_revs_info\": [{\"rev\": \"rev\", \"status\": \"available\"}], \"autoupdate\": true, \"filters\": {\"mapKey\": \"inner\"}, \"indexes\": {\"mapKey\": {\"analyzer\": {\"name\": \"classic\", \"stopwords\": [\"stopwords\"], \"fields\": {\"mapKey\": {\"name\": \"classic\", \"stopwords\": [\"stopwords\"]}}}, \"index\": \"index\"}}, \"language\": \"javascript\", \"options\": {\"partitioned\": false}, \"validate_doc_update\": \"validateDocUpdate\", \"views\": {\"mapKey\": {\"map\": \"map\", \"reduce\": \"reduce\"}}, \"st_indexes\": {\"mapKey\": {\"index\": \"index\"}}}";
String getDesignDocumentPath = "/testString/_design/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetDesignDocumentOptions model
GetDesignDocumentOptions getDesignDocumentOptionsModel = new GetDesignDocumentOptions.Builder().db("testString").ddoc("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
// Invoke operation with valid options model (positive test)
Response<DesignDocument> response = cloudantService.getDesignDocument(getDesignDocumentOptionsModel).execute();
assertNotNull(response);
DesignDocument 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);
assertNotNull(query);
// Get query params
assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("deleted_conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("local_seq")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("meta")), Boolean.valueOf(false));
assertEquals(query.get("rev"), "testString");
assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("revs_info")), Boolean.valueOf(false));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getDesignDocumentPath);
}
use of com.ibm.cloud.cloudant.v1.model.Analyzer in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostIndexWOptions.
@Test
public void testPostIndexWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"id\": \"id\", \"name\": \"name\", \"result\": \"created\"}";
String postIndexPath = "/testString/_index";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the Analyzer model
Analyzer analyzerModel = new Analyzer.Builder().name("classic").stopwords(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
// Construct an instance of the IndexTextOperatorDefaultField model
IndexTextOperatorDefaultField indexTextOperatorDefaultFieldModel = new IndexTextOperatorDefaultField.Builder().analyzer(analyzerModel).enabled(true).build();
// Construct an instance of the IndexField model
IndexField indexFieldModel = new IndexField.Builder().name("testString").type("boolean").add("foo", "asc").build();
// Construct an instance of the IndexDefinition model
IndexDefinition indexDefinitionModel = new IndexDefinition.Builder().defaultAnalyzer(analyzerModel).defaultField(indexTextOperatorDefaultFieldModel).fields(new java.util.ArrayList<IndexField>(java.util.Arrays.asList(indexFieldModel))).indexArrayLengths(true).partialFilterSelector(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).build();
// Construct an instance of the PostIndexOptions model
PostIndexOptions postIndexOptionsModel = new PostIndexOptions.Builder().db("testString").index(indexDefinitionModel).ddoc("testString").def(indexDefinitionModel).name("testString").partitioned(true).type("json").build();
// Invoke operation with valid options model (positive test)
Response<IndexResult> response = cloudantService.postIndex(postIndexOptionsModel).execute();
assertNotNull(response);
IndexResult 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, postIndexPath);
}
use of com.ibm.cloud.cloudant.v1.model.Analyzer in project cloudant-java-sdk by IBM.
the class Cloudant method postSearchAnalyze.
/**
* Query tokenization of sample text.
*
* Returns the results of analyzer tokenization of the provided sample text. This endpoint can be used for testing
* analyzer tokenization.
*
* @param postSearchAnalyzeOptions the {@link PostSearchAnalyzeOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link SearchAnalyzeResult}
*/
public ServiceCall<SearchAnalyzeResult> postSearchAnalyze(PostSearchAnalyzeOptions postSearchAnalyzeOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postSearchAnalyzeOptions, "postSearchAnalyzeOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_search_analyze"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postSearchAnalyze");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("analyzer", postSearchAnalyzeOptions.analyzer());
contentJson.addProperty("text", postSearchAnalyzeOptions.text());
builder.bodyJson(contentJson);
ResponseConverter<SearchAnalyzeResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SearchAnalyzeResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Analyzer in project cloudant-java-sdk by IBM.
the class DesignDocumentTest method testDesignDocument.
@Test
public void testDesignDocument() throws Throwable {
Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
assertEquals(attachmentModel.contentType(), "testString");
assertEquals(attachmentModel.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
assertEquals(attachmentModel.digest(), "testString");
assertEquals(attachmentModel.encodedLength(), Long.valueOf("0"));
assertEquals(attachmentModel.encoding(), "testString");
assertEquals(attachmentModel.follows(), Boolean.valueOf(true));
assertEquals(attachmentModel.length(), Long.valueOf("0"));
assertEquals(attachmentModel.revpos(), Long.valueOf("1"));
assertEquals(attachmentModel.stub(), Boolean.valueOf(true));
Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
assertEquals(revisionsModel.ids(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(revisionsModel.start(), Long.valueOf("1"));
DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
assertEquals(documentRevisionStatusModel.rev(), "testString");
assertEquals(documentRevisionStatusModel.status(), "available");
Analyzer analyzerModel = new Analyzer.Builder().name("classic").stopwords(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
assertEquals(analyzerModel.name(), "classic");
assertEquals(analyzerModel.stopwords(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
AnalyzerConfiguration analyzerConfigurationModel = new AnalyzerConfiguration.Builder().name("classic").stopwords(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).fields(new java.util.HashMap<String, Analyzer>() {
{
put("foo", analyzerModel);
}
}).build();
assertEquals(analyzerConfigurationModel.name(), "classic");
assertEquals(analyzerConfigurationModel.stopwords(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(analyzerConfigurationModel.fields(), new java.util.HashMap<String, Analyzer>() {
{
put("foo", analyzerModel);
}
});
SearchIndexDefinition searchIndexDefinitionModel = new SearchIndexDefinition.Builder().analyzer(analyzerConfigurationModel).index("testString").build();
assertEquals(searchIndexDefinitionModel.analyzer(), analyzerConfigurationModel);
assertEquals(searchIndexDefinitionModel.index(), "testString");
DesignDocumentOptions designDocumentOptionsModel = new DesignDocumentOptions.Builder().partitioned(true).build();
assertEquals(designDocumentOptionsModel.partitioned(), Boolean.valueOf(true));
DesignDocumentViewsMapReduce designDocumentViewsMapReduceModel = new DesignDocumentViewsMapReduce.Builder().map("testString").reduce("testString").build();
assertEquals(designDocumentViewsMapReduceModel.map(), "testString");
assertEquals(designDocumentViewsMapReduceModel.reduce(), "testString");
GeoIndexDefinition geoIndexDefinitionModel = new GeoIndexDefinition.Builder().index("testString").build();
assertEquals(geoIndexDefinitionModel.index(), "testString");
DesignDocument designDocumentModel = new DesignDocument.Builder().attachments(new java.util.HashMap<String, Attachment>() {
{
put("foo", attachmentModel);
}
}).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).autoupdate(true).filters(new java.util.HashMap<String, String>() {
{
put("foo", "testString");
}
}).indexes(new java.util.HashMap<String, SearchIndexDefinition>() {
{
put("foo", searchIndexDefinitionModel);
}
}).language("javascript").options(designDocumentOptionsModel).validateDocUpdate("testString").views(new java.util.HashMap<String, DesignDocumentViewsMapReduce>() {
{
put("foo", designDocumentViewsMapReduceModel);
}
}).stIndexes(new java.util.HashMap<String, GeoIndexDefinition>() {
{
put("foo", geoIndexDefinitionModel);
}
}).add("foo", "testString").build();
assertEquals(designDocumentModel.getAttachments(), new java.util.HashMap<String, Attachment>() {
{
put("foo", attachmentModel);
}
});
assertEquals(designDocumentModel.getConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(designDocumentModel.isDeleted(), Boolean.valueOf(true));
assertEquals(designDocumentModel.getDeletedConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(designDocumentModel.getId(), "testString");
assertEquals(designDocumentModel.getLocalSeq(), "testString");
assertEquals(designDocumentModel.getRev(), "testString");
assertEquals(designDocumentModel.getRevisions(), revisionsModel);
assertEquals(designDocumentModel.getRevsInfo(), new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel)));
assertEquals(designDocumentModel.isAutoupdate(), Boolean.valueOf(true));
assertEquals(designDocumentModel.getFilters(), new java.util.HashMap<String, String>() {
{
put("foo", "testString");
}
});
assertEquals(designDocumentModel.getIndexes(), new java.util.HashMap<String, SearchIndexDefinition>() {
{
put("foo", searchIndexDefinitionModel);
}
});
assertEquals(designDocumentModel.getLanguage(), "javascript");
assertEquals(designDocumentModel.getOptions(), designDocumentOptionsModel);
assertEquals(designDocumentModel.getValidateDocUpdate(), "testString");
assertEquals(designDocumentModel.getViews(), new java.util.HashMap<String, DesignDocumentViewsMapReduce>() {
{
put("foo", designDocumentViewsMapReduceModel);
}
});
assertEquals(designDocumentModel.getStIndexes(), new java.util.HashMap<String, GeoIndexDefinition>() {
{
put("foo", geoIndexDefinitionModel);
}
});
assertEquals(designDocumentModel.get("foo"), "testString");
String json = TestUtilities.serialize(designDocumentModel);
DesignDocument designDocumentModelNew = TestUtilities.deserialize(json, DesignDocument.class);
assertTrue(designDocumentModelNew instanceof DesignDocument);
assertEquals(designDocumentModelNew.isDeleted(), Boolean.valueOf(true));
assertEquals(designDocumentModelNew.getId(), "testString");
assertEquals(designDocumentModelNew.getLocalSeq(), "testString");
assertEquals(designDocumentModelNew.getRev(), "testString");
assertEquals(designDocumentModelNew.getRevisions().toString(), revisionsModel.toString());
assertEquals(designDocumentModelNew.isAutoupdate(), Boolean.valueOf(true));
assertEquals(designDocumentModelNew.getLanguage(), "javascript");
assertEquals(designDocumentModelNew.getOptions().toString(), designDocumentOptionsModel.toString());
assertEquals(designDocumentModelNew.getValidateDocUpdate(), "testString");
assertEquals(designDocumentModelNew.get("foo"), "testString");
}
Aggregations