Search in sources :

Example 11 with Analyzer

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

the class PostSearchAnalyzeOptionsTest method testPostSearchAnalyzeOptions.

@Test
public void testPostSearchAnalyzeOptions() throws Throwable {
    PostSearchAnalyzeOptions postSearchAnalyzeOptionsModel = new PostSearchAnalyzeOptions.Builder().analyzer("arabic").text("testString").build();
    assertEquals(postSearchAnalyzeOptionsModel.analyzer(), "arabic");
    assertEquals(postSearchAnalyzeOptionsModel.text(), "testString");
}
Also used : PostSearchAnalyzeOptions(com.ibm.cloud.cloudant.v1.model.PostSearchAnalyzeOptions) Test(org.testng.annotations.Test)

Example 12 with Analyzer

use of com.ibm.cloud.cloudant.v1.model.Analyzer 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 13 with Analyzer

use of com.ibm.cloud.cloudant.v1.model.Analyzer 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)

Example 14 with Analyzer

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

the class SearchIndexDefinitionTest method testSearchIndexDefinition.

@Test
public void testSearchIndexDefinition() 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")));
    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");
    String json = TestUtilities.serialize(searchIndexDefinitionModel);
    SearchIndexDefinition searchIndexDefinitionModelNew = TestUtilities.deserialize(json, SearchIndexDefinition.class);
    assertTrue(searchIndexDefinitionModelNew instanceof SearchIndexDefinition);
    assertEquals(searchIndexDefinitionModelNew.analyzer().toString(), analyzerConfigurationModel.toString());
    assertEquals(searchIndexDefinitionModelNew.index(), "testString");
}
Also used : HashMap(java.util.HashMap) SearchIndexDefinition(com.ibm.cloud.cloudant.v1.model.SearchIndexDefinition) ArrayList(java.util.ArrayList) Analyzer(com.ibm.cloud.cloudant.v1.model.Analyzer) AnalyzerConfiguration(com.ibm.cloud.cloudant.v1.model.AnalyzerConfiguration) Test(org.testng.annotations.Test)

Example 15 with Analyzer

use of com.ibm.cloud.cloudant.v1.model.Analyzer 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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SecurityObject(com.ibm.cloud.cloudant.v1.model.SecurityObject) GeoJsonGeometryObject(com.ibm.cloud.cloudant.v1.model.GeoJsonGeometryObject) PostExplainOptions(com.ibm.cloud.cloudant.v1.model.PostExplainOptions) ExplainResult(com.ibm.cloud.cloudant.v1.model.ExplainResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)11 Analyzer (com.ibm.cloud.cloudant.v1.model.Analyzer)10 HashMap (java.util.HashMap)9 MockResponse (okhttp3.mockwebserver.MockResponse)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 AnalyzerConfiguration (com.ibm.cloud.cloudant.v1.model.AnalyzerConfiguration)5 SearchIndexDefinition (com.ibm.cloud.cloudant.v1.model.SearchIndexDefinition)5 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)4 GeoIndexDefinition (com.ibm.cloud.cloudant.v1.model.GeoIndexDefinition)4 IndexTextOperatorDefaultField (com.ibm.cloud.cloudant.v1.model.IndexTextOperatorDefaultField)4 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)3 DesignDocumentOptions (com.ibm.cloud.cloudant.v1.model.DesignDocumentOptions)3 DesignDocumentViewsMapReduce (com.ibm.cloud.cloudant.v1.model.DesignDocumentViewsMapReduce)3 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)3 IndexDefinition (com.ibm.cloud.cloudant.v1.model.IndexDefinition)3 IndexField (com.ibm.cloud.cloudant.v1.model.IndexField)3 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)3 GetDesignDocumentOptions (com.ibm.cloud.cloudant.v1.model.GetDesignDocumentOptions)2