Search in sources :

Example 1 with IndexTextOperatorDefaultField

use of com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField 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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Analyzer(com.ibm.cloud.cloudant.v1.model.Analyzer) PostIndexOptions(com.ibm.cloud.cloudant.v1.model.PostIndexOptions) GeoIndexDefinition(com.ibm.cloud.cloudant.v1.model.GeoIndexDefinition) IndexDefinition(com.ibm.cloud.cloudant.v1.model.IndexDefinition) SearchIndexDefinition(com.ibm.cloud.cloudant.v1.model.SearchIndexDefinition) IndexResult(com.ibm.cloud.cloudant.v1.model.IndexResult) IndexTextOperatorDefaultField(com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField) IndexField(com.ibm.cloud.cloudant.v1.model.IndexField) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with IndexTextOperatorDefaultField

use of com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField 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");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Analyzer(com.ibm.cloud.cloudant.v1.model.Analyzer) PostIndexOptions(com.ibm.cloud.cloudant.v1.model.PostIndexOptions) IndexDefinition(com.ibm.cloud.cloudant.v1.model.IndexDefinition) IndexTextOperatorDefaultField(com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField) IndexField(com.ibm.cloud.cloudant.v1.model.IndexField) Test(org.testng.annotations.Test)

Example 3 with IndexTextOperatorDefaultField

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

the class IndexTextOperatorDefaultFieldTest method testIndexTextOperatorDefaultField.

@Test
public void testIndexTextOperatorDefaultField() 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));
    String json = TestUtilities.serialize(indexTextOperatorDefaultFieldModel);
    IndexTextOperatorDefaultField indexTextOperatorDefaultFieldModelNew = TestUtilities.deserialize(json, IndexTextOperatorDefaultField.class);
    assertTrue(indexTextOperatorDefaultFieldModelNew instanceof IndexTextOperatorDefaultField);
    assertEquals(indexTextOperatorDefaultFieldModelNew.analyzer().toString(), analyzerModel.toString());
    assertEquals(indexTextOperatorDefaultFieldModelNew.enabled(), Boolean.valueOf(true));
}
Also used : ArrayList(java.util.ArrayList) Analyzer(com.ibm.cloud.cloudant.v1.model.Analyzer) IndexTextOperatorDefaultField(com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField) Test(org.testng.annotations.Test)

Example 4 with IndexTextOperatorDefaultField

use of com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField 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));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Analyzer(com.ibm.cloud.cloudant.v1.model.Analyzer) IndexDefinition(com.ibm.cloud.cloudant.v1.model.IndexDefinition) IndexTextOperatorDefaultField(com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField) IndexField(com.ibm.cloud.cloudant.v1.model.IndexField) Test(org.testng.annotations.Test)

Aggregations

Analyzer (com.ibm.cloud.cloudant.v1.model.Analyzer)4 IndexTextOperatorDefaultField (com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField)4 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 IndexDefinition (com.ibm.cloud.cloudant.v1.model.IndexDefinition)3 IndexField (com.ibm.cloud.cloudant.v1.model.IndexField)3 HashMap (java.util.HashMap)3 PostIndexOptions (com.ibm.cloud.cloudant.v1.model.PostIndexOptions)2 GeoIndexDefinition (com.ibm.cloud.cloudant.v1.model.GeoIndexDefinition)1 IndexResult (com.ibm.cloud.cloudant.v1.model.IndexResult)1 SearchIndexDefinition (com.ibm.cloud.cloudant.v1.model.SearchIndexDefinition)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1