Search in sources :

Example 31 with JsonObject

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

the class SubdocIntegrationTest method counterMulti.

@Test
void counterMulti() {
    JsonObject initial = JsonObject.create().put("mutated", 0).put("body", "").put("first_name", "James").put("age", 0);
    String id = UUID.randomUUID().toString();
    collection.upsert(id, initial);
    MutateInResult result = collection.mutateIn(id, Arrays.asList(MutateInSpec.upsert("addr", JsonObject.create().put("state", "NV").put("pincode", 7).put("city", "Chicago")), MutateInSpec.increment("mutated", 1), MutateInSpec.upsert("name", JsonObject.create().put("last", "").put("first", "James"))));
    assertEquals(1, result.contentAs(1, Integer.class));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 32 with JsonObject

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

the class SubdocMutateIntegrationTest method counterMinusXattrCreatePath.

@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void counterMinusXattrCreatePath() {
    JsonObject updatedContent = checkSingleOpSuccessXattr(JsonObject.create(), Arrays.asList(MutateInSpec.decrement("x.foo", 3).xattr().createPath()));
    assertEquals(-3, (int) updatedContent.getInt("foo"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 33 with JsonObject

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

the class SubdocMutateIntegrationTest method counterAddCreatePath.

// TODO failing with bad input server error
// @Test
// public void arrayInsertCreatePath() {
// JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create(),
// Arrays.asList(MutateInSpec.arrayInsert("foo[0]", "cruel", true));
// assertEquals(JsonArray.from("cruel"), updatedContent.getArray("foo"));
// }
// 
// @Test
// public void arrayInsertUniqueDoesNotExistCreatePath() {
// JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create(),
// Arrays.asList(MutateInSpec.arrayAddUnique("foo", "cruel", true));
// assertEquals(JsonArray.from("hello", "world", "cruel"), updatedContent.getArray("foo"));
// }
@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void counterAddCreatePath() {
    JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create(), Arrays.asList(MutateInSpec.increment("foo", 5).createPath()));
    assertEquals(5, (int) updatedContent.getInt("foo"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 34 with JsonObject

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

the class SubdocMutateIntegrationTest method upsertStringDoesNotExistXattr.

@Test
void upsertStringDoesNotExistXattr() {
    JsonObject updatedContent = checkSingleOpSuccessXattr(JsonObject.create(), Arrays.asList(upsert("x.foo", "bar2").xattr()));
    assertEquals("bar2", updatedContent.getString("foo"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 35 with JsonObject

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

the class SubdocMutateIntegrationTest method arrayAppendCreatePath.

@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void arrayAppendCreatePath() {
    JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create(), Arrays.asList(MutateInSpec.arrayAppend("foo", Arrays.asList("world")).createPath()));
    assertEquals(JsonArray.from("world"), updatedContent.getArray("foo"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) 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