Search in sources :

Example 51 with JsonObject

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

the class SubdocMutateIntegrationTest method replaceFullDocument.

@Test
void replaceFullDocument() {
    JsonObject content = JsonObject.create().put("foo", "bar");
    String docId = prepare(content);
    coll.mutateIn(docId, Arrays.asList(MutateInSpec.replace("", JsonObject.create().put("foo2", "bar2"))));
    assertEquals("bar2", getContent(docId).getString("foo2"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 52 with JsonObject

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

the class SubdocMutateIntegrationTest method arrayPrepend.

@Test
public void arrayPrepend() {
    JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create().put("foo", JsonArray.from("hello")), Arrays.asList(MutateInSpec.arrayPrepend("foo", Arrays.asList("world"))));
    assertEquals(JsonArray.from("world", "hello"), updatedContent.getArray("foo"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 53 with JsonObject

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

the class SubdocMutateIntegrationTest method arrayPrependMulti.

@Test
public void arrayPrependMulti() {
    JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create().put("foo", JsonArray.from("hello")), Arrays.asList(MutateInSpec.arrayPrepend("foo", Arrays.asList("world", "mars"))));
    assertEquals(JsonArray.from("world", "mars", "hello"), updatedContent.getArray("foo"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 54 with JsonObject

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

the class SubdocMutateIntegrationTest method reviveDocumentWithCAS3.

@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void reviveDocumentWithCAS3() {
    String docId = docId();
    JsonObject body = JsonObject.create().put("foo", "bar");
    MutateInResult mr = coll.mutateIn(docId, Collections.singletonList(upsert("txn", JsonObject.create().put("stgd", body).put("baz", "qux")).xattr().createPath()), MutateInOptions.mutateInOptions().createAsDeleted(true).accessDeleted(true).storeSemantics(StoreSemantics.INSERT));
    // Create a CAS mismatch
    coll.insert(docId, JsonObject.create());
    try {
        coll.mutateIn(docId, Arrays.asList(new ReplaceBodyWithXattr("txn.stgd"), MutateInSpec.remove("txn").xattr()), MutateInOptions.mutateInOptions().accessDeleted(true).cas(mr.cas()).storeSemantics(StoreSemantics.REVIVE));
        fail();
    } catch (CasMismatchException ignored) {
    // It hits this rather than CannotReviveAliveDocumentException
    }
}
Also used : MutateInResult(com.couchbase.client.java.kv.MutateInResult) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) JsonObject(com.couchbase.client.java.json.JsonObject) ReplaceBodyWithXattr(com.couchbase.client.java.kv.ReplaceBodyWithXattr) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 55 with JsonObject

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

the class SubdocMutateIntegrationTest method upsertStringDoesNotExist.

@Test
void upsertStringDoesNotExist() {
    JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create(), Arrays.asList(upsert("foo", "bar2")));
    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)

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