Search in sources :

Example 26 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class CouchbaseArrayListTest method SimpleRoundTripWithJsonObject.

@Test
void SimpleRoundTripWithJsonObject() {
    CouchbaseArrayList<JsonObject> list = new CouchbaseArrayList<>(uuid, collection, JsonObject.class, ArrayListOptions.arrayListOptions());
    JsonObject thing1 = JsonObject.fromJson("{\"string\":\"foo\", \"integer\":1}");
    JsonObject thing2 = JsonObject.fromJson("{\"string\":\"bar\", \"integer\":2}");
    list.add(0, thing1);
    list.add(0, thing2);
    assertEquals(2, list.size());
    assertEquals(thing2, list.get(0));
    assertEquals(thing1, list.get(1));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 27 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class QueryIntegrationTest method reactivePositionalParameterizedSelectQuery.

@Test
void reactivePositionalParameterizedSelectQuery() {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonArray.from(id));
    Mono<ReactiveQueryResult> result = cluster.reactive().query("select * from " + bucketName + " where meta().id=$1", options);
    List<JsonObject> rows = result.flux().flatMap(ReactiveQueryResult::rowsAsObject).collectList().block();
    assertNotNull(rows);
    assertEquals(1, rows.size());
}
Also used : ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) JsonObject(com.couchbase.client.java.json.JsonObject) QueryOptions(com.couchbase.client.java.query.QueryOptions) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 28 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class QueryIntegrationTest method asyncNamedParameterizedSelectQuery.

@Test
void asyncNamedParameterizedSelectQuery() throws Exception {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS).parameters(JsonObject.create().put("id", id));
    CompletableFuture<QueryResult> result = cluster.async().query("select * from " + bucketName + " where meta().id=$id", options);
    List<JsonObject> rows = result.get().rowsAs(JsonObject.class);
    assertEquals(1, rows.size());
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) JsonObject(com.couchbase.client.java.json.JsonObject) QueryOptions(com.couchbase.client.java.query.QueryOptions) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 29 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class QueryIntegrationTest method asyncSelect.

@Test
void asyncSelect() throws Exception {
    String id = insertDoc();
    QueryOptions options = queryOptions().scanConsistency(QueryScanConsistency.REQUEST_PLUS);
    CompletableFuture<QueryResult> result = cluster.async().query("select * from " + bucketName + " where meta().id=\"" + id + "\"", options);
    List<JsonObject> rows = result.get().rowsAs(JsonObject.class);
    assertEquals(1, rows.size());
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) JsonObject(com.couchbase.client.java.json.JsonObject) QueryOptions(com.couchbase.client.java.query.QueryOptions) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 30 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class SubdocIntegrationTest method upsertFullDocument.

@Test
void upsertFullDocument() {
    String id = UUID.randomUUID().toString();
    JsonObject content = JsonObject.create().put("foo", "bar");
    collection.mutateIn(id, Arrays.asList(// Server doesn't allow fullDocument to be only op here, get "key not found"
    MutateInSpec.upsert("qix", "qux"), MutateInSpec.replace("", content)), MutateInOptions.mutateInOptions().storeSemantics(StoreSemantics.UPSERT));
    GetResult doc = collection.get(id);
    assertEquals(content, doc.contentAsObject());
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

JsonObject (com.couchbase.client.java.json.JsonObject)189 Test (org.junit.jupiter.api.Test)145 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)119 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)39 JsonArray (com.couchbase.client.java.json.JsonArray)18 QueryResult (com.couchbase.client.java.query.QueryResult)16 GetResult (com.couchbase.client.java.kv.GetResult)15 MutationResult (com.couchbase.client.java.kv.MutationResult)15 QueryOptions (com.couchbase.client.java.query.QueryOptions)15 ReactiveQueryResult (com.couchbase.client.java.query.ReactiveQueryResult)15 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)6 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)6 Collection (com.couchbase.client.java.Collection)6 ReplaceBodyWithXattr (com.couchbase.client.java.kv.ReplaceBodyWithXattr)6 Duration (java.time.Duration)6 DisplayName (org.junit.jupiter.api.DisplayName)6 CouchbaseUtilTest (org.talend.components.couchbase.CouchbaseUtilTest)6 ArrayList (java.util.ArrayList)5 TestData (org.talend.components.couchbase.TestData)5 MutateInResult (com.couchbase.client.java.kv.MutateInResult)4