Search in sources :

Example 46 with JsonObject

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

the class SubdocMutateIntegrationTest method removeFullDocAndSetSystemXattr.

@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
@Test
void removeFullDocAndSetSystemXattr() {
    JsonObject content = JsonObject.create().put("foo", "bar");
    String docId = prepare(content);
    // leading underscore lets it survive document deletion
    String systemXattrName = "_x";
    coll.mutateIn(docId, listOf(MutateInSpec.remove(""), MutateInSpec.insert(systemXattrName, "y").xattr()));
    LookupInResult result = coll.lookupIn(docId, listOf(LookupInSpec.get(systemXattrName).xattr()), LookupInOptions.lookupInOptions().accessDeleted(true));
    assertEquals("y", result.contentAs(0, String.class));
    assertTrue(result.isDeleted());
}
Also used : LookupInResult(com.couchbase.client.java.kv.LookupInResult) 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 47 with JsonObject

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

the class SubdocMutateIntegrationTest method reviveDocumentWithCAS2.

@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void reviveDocumentWithCAS2() {
    String docId = docId();
    JsonObject body = JsonObject.create().put("foo", "bar");
    coll.insert(docId, body);
    MutationResult mr = coll.remove(docId);
    coll.mutateIn(docId, Arrays.asList(// Do a dummy op as server complains if do nothing
    MutateInSpec.upsert("txn", JsonObject.create()).xattr()), MutateInOptions.mutateInOptions().accessDeleted(true).cas(mr.cas()).storeSemantics(StoreSemantics.REVIVE));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 48 with JsonObject

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

the class SubdocMutateIntegrationTest method insertCreatePath.

@Test
void insertCreatePath() {
    JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create(), Arrays.asList(MutateInSpec.insert("foo.baz", "bar2").createPath()));
    assertEquals("bar2", updatedContent.getObject("foo").getString("baz"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 49 with JsonObject

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

the class SubdocMutateIntegrationTest method insertExpandMacroXattrDoNotFlag.

@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void insertExpandMacroXattrDoNotFlag() {
    JsonObject updatedContent = checkSingleOpSuccessXattr(JsonObject.create(), Arrays.asList(MutateInSpec.insert("x.foo", "${Mutation.CAS}").xattr()));
    assertEquals("${Mutation.CAS}", updatedContent.getString("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 50 with JsonObject

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

the class SubdocMutateIntegrationTest method counterAdd.

@Test
void counterAdd() {
    JsonObject updatedContent = checkSingleOpSuccess(JsonObject.create().put("foo", 10), Arrays.asList(MutateInSpec.increment("foo", 5)));
    assertEquals(15, (int) updatedContent.getInt("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