use of com.ibm.cloud.cloudant.v1.model.IndexDefinition 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.IndexDefinition in project cloudant-java-sdk by IBM.
the class PostIndexOptionsTest method testPostIndexOptions.
@Test
public void testPostIndexOptions() throws Throwable {
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")));
IndexTextOperatorDefaultField indexTextOperatorDefaultFieldModel = new IndexTextOperatorDefaultField.Builder().analyzer(analyzerModel).enabled(true).build();
assertEquals(indexTextOperatorDefaultFieldModel.analyzer(), analyzerModel);
assertEquals(indexTextOperatorDefaultFieldModel.enabled(), Boolean.valueOf(true));
IndexField indexFieldModel = new IndexField.Builder().name("testString").type("boolean").add("foo", "asc").build();
assertEquals(indexFieldModel.getName(), "testString");
assertEquals(indexFieldModel.getType(), "boolean");
assertEquals(indexFieldModel.get("foo"), "asc");
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();
assertEquals(indexDefinitionModel.defaultAnalyzer(), analyzerModel);
assertEquals(indexDefinitionModel.defaultField(), indexTextOperatorDefaultFieldModel);
assertEquals(indexDefinitionModel.fields(), new java.util.ArrayList<IndexField>(java.util.Arrays.asList(indexFieldModel)));
assertEquals(indexDefinitionModel.indexArrayLengths(), Boolean.valueOf(true));
assertEquals(indexDefinitionModel.partialFilterSelector(), new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
PostIndexOptions postIndexOptionsModel = new PostIndexOptions.Builder().db("testString").index(indexDefinitionModel).ddoc("testString").def(indexDefinitionModel).name("testString").partitioned(true).type("json").build();
assertEquals(postIndexOptionsModel.db(), "testString");
assertEquals(postIndexOptionsModel.index(), indexDefinitionModel);
assertEquals(postIndexOptionsModel.ddoc(), "testString");
assertEquals(postIndexOptionsModel.def(), indexDefinitionModel);
assertEquals(postIndexOptionsModel.name(), "testString");
assertEquals(postIndexOptionsModel.partitioned(), Boolean.valueOf(true));
assertEquals(postIndexOptionsModel.type(), "json");
}
use of com.ibm.cloud.cloudant.v1.model.IndexDefinition in project cloudant-java-sdk by IBM.
the class IndexDefinitionTest method testIndexDefinition.
@Test
public void testIndexDefinition() throws Throwable {
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")));
IndexTextOperatorDefaultField indexTextOperatorDefaultFieldModel = new IndexTextOperatorDefaultField.Builder().analyzer(analyzerModel).enabled(true).build();
assertEquals(indexTextOperatorDefaultFieldModel.analyzer(), analyzerModel);
assertEquals(indexTextOperatorDefaultFieldModel.enabled(), Boolean.valueOf(true));
IndexField indexFieldModel = new IndexField.Builder().name("testString").type("boolean").add("foo", "asc").build();
assertEquals(indexFieldModel.getName(), "testString");
assertEquals(indexFieldModel.getType(), "boolean");
assertEquals(indexFieldModel.get("foo"), "asc");
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();
assertEquals(indexDefinitionModel.defaultAnalyzer(), analyzerModel);
assertEquals(indexDefinitionModel.defaultField(), indexTextOperatorDefaultFieldModel);
assertEquals(indexDefinitionModel.fields(), new java.util.ArrayList<IndexField>(java.util.Arrays.asList(indexFieldModel)));
assertEquals(indexDefinitionModel.indexArrayLengths(), Boolean.valueOf(true));
assertEquals(indexDefinitionModel.partialFilterSelector(), new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
String json = TestUtilities.serialize(indexDefinitionModel);
IndexDefinition indexDefinitionModelNew = TestUtilities.deserialize(json, IndexDefinition.class);
assertTrue(indexDefinitionModelNew instanceof IndexDefinition);
assertEquals(indexDefinitionModelNew.defaultAnalyzer().toString(), analyzerModel.toString());
assertEquals(indexDefinitionModelNew.defaultField().toString(), indexTextOperatorDefaultFieldModel.toString());
assertEquals(indexDefinitionModelNew.indexArrayLengths(), Boolean.valueOf(true));
}
Aggregations