|
23 | 23 |
|
24 | 24 | #include <couchbase/cluster.hxx> |
25 | 25 | #include <couchbase/codec/raw_binary_transcoder.hxx> |
| 26 | +#include <couchbase/codec/raw_json_transcoder.hxx> |
| 27 | +#include <couchbase/codec/raw_string_transcoder.hxx> |
| 28 | +#include <couchbase/codec/tao_json_serializer.hxx> |
26 | 29 |
|
27 | 30 | #include <tao/json/contrib/vector_traits.hpp> |
28 | 31 |
|
@@ -594,3 +597,120 @@ TEST_CASE("integration: subdoc with public API", "[integration]") |
594 | 597 | REQUIRE(resp.content_as<std::string>(couchbase::subdoc::lookup_in_macro::cas) == fmt::format("0x{:016x}", cas.value())); |
595 | 598 | } |
596 | 599 | } |
| 600 | + |
| 601 | +TEST_CASE("integration: upsert with raw json transcoder, get with json and raw json transcoders", "[integration]") |
| 602 | +{ |
| 603 | + test::utils::integration_test_guard integration; |
| 604 | + |
| 605 | + test::utils::open_bucket(integration.cluster, integration.ctx.bucket); |
| 606 | + |
| 607 | + auto collection = couchbase::cluster(integration.cluster) |
| 608 | + .bucket(integration.ctx.bucket) |
| 609 | + .scope(couchbase::scope::default_name) |
| 610 | + .collection(couchbase::collection::default_name); |
| 611 | + auto id = test::utils::uniq_id("foo"); |
| 612 | + profile albert{ "this_guy_again", "Albert Einstein", 1879 }; |
| 613 | + auto data = couchbase::codec::tao_json_serializer::serialize(albert); |
| 614 | + |
| 615 | + // Upsert with raw_json_transcoder |
| 616 | + { |
| 617 | + auto [ctx, resp] = collection.upsert<couchbase::codec::raw_json_transcoder>(id, data, {}).get(); |
| 618 | + REQUIRE_SUCCESS(ctx.ec()); |
| 619 | + REQUIRE_FALSE(resp.cas().empty()); |
| 620 | + REQUIRE(resp.mutation_token().has_value()); |
| 621 | + } |
| 622 | + |
| 623 | + // Get with default_json_transcoder |
| 624 | + { |
| 625 | + auto [ctx, resp] = collection.get(id, {}).get(); |
| 626 | + REQUIRE_SUCCESS(ctx.ec()); |
| 627 | + REQUIRE_FALSE(resp.cas().empty()); |
| 628 | + REQUIRE(resp.content_as<profile>() == albert); |
| 629 | + } |
| 630 | + |
| 631 | + // Get with raw_json_transcoder |
| 632 | + { |
| 633 | + auto [ctx, resp] = collection.get(id, {}).get(); |
| 634 | + REQUIRE_SUCCESS(ctx.ec()); |
| 635 | + REQUIRE_FALSE(resp.cas().empty()); |
| 636 | + REQUIRE(resp.content_as<couchbase::codec::binary, couchbase::codec::raw_json_transcoder>() == data); |
| 637 | + } |
| 638 | +} |
| 639 | + |
| 640 | +TEST_CASE("integration: upsert and get string with raw json transcoder", "[integration]") |
| 641 | +{ |
| 642 | + test::utils::integration_test_guard integration; |
| 643 | + |
| 644 | + test::utils::open_bucket(integration.cluster, integration.ctx.bucket); |
| 645 | + |
| 646 | + auto collection = couchbase::cluster(integration.cluster) |
| 647 | + .bucket(integration.ctx.bucket) |
| 648 | + .scope(couchbase::scope::default_name) |
| 649 | + .collection(couchbase::collection::default_name); |
| 650 | + auto id = test::utils::uniq_id("foo"); |
| 651 | + std::string data{ R"({"foo": "bar"})" }; |
| 652 | + |
| 653 | + // Upsert with raw_json_transcoder |
| 654 | + { |
| 655 | + auto [ctx, resp] = collection.upsert<couchbase::codec::raw_json_transcoder>(id, data, {}).get(); |
| 656 | + REQUIRE_SUCCESS(ctx.ec()); |
| 657 | + REQUIRE_FALSE(resp.cas().empty()); |
| 658 | + REQUIRE(resp.mutation_token().has_value()); |
| 659 | + } |
| 660 | + |
| 661 | + // Get with default_json_transcoder |
| 662 | + { |
| 663 | + auto [ctx, resp] = collection.get(id, {}).get(); |
| 664 | + REQUIRE_SUCCESS(ctx.ec()); |
| 665 | + REQUIRE_FALSE(resp.cas().empty()); |
| 666 | + REQUIRE(resp.content_as<tao::json::value>() == tao::json::value{ { "foo", "bar" } }); |
| 667 | + } |
| 668 | + |
| 669 | + // Get with raw_json_transcoder |
| 670 | + { |
| 671 | + auto [ctx, resp] = collection.get(id, {}).get(); |
| 672 | + REQUIRE_SUCCESS(ctx.ec()); |
| 673 | + REQUIRE_FALSE(resp.cas().empty()); |
| 674 | + REQUIRE(resp.content_as<std::string, couchbase::codec::raw_json_transcoder>() == data); |
| 675 | + REQUIRE(resp.content_as<couchbase::codec::binary, couchbase::codec::raw_json_transcoder>() == |
| 676 | + couchbase::core::utils::to_binary(data)); |
| 677 | + } |
| 678 | +} |
| 679 | + |
| 680 | +TEST_CASE("integration: upsert and get with raw string transcoder, attempt to get with json transcoder", "[integration]") |
| 681 | +{ |
| 682 | + test::utils::integration_test_guard integration; |
| 683 | + |
| 684 | + test::utils::open_bucket(integration.cluster, integration.ctx.bucket); |
| 685 | + |
| 686 | + auto collection = couchbase::cluster(integration.cluster) |
| 687 | + .bucket(integration.ctx.bucket) |
| 688 | + .scope(couchbase::scope::default_name) |
| 689 | + .collection(couchbase::collection::default_name); |
| 690 | + auto id = test::utils::uniq_id("foo"); |
| 691 | + std::string document{ "lorem ipsum dolor sit amet" }; |
| 692 | + |
| 693 | + // Upsert with raw_string_transcoder |
| 694 | + { |
| 695 | + auto [ctx, resp] = collection.upsert<couchbase::codec::raw_string_transcoder>(id, document, {}).get(); |
| 696 | + REQUIRE_SUCCESS(ctx.ec()); |
| 697 | + REQUIRE_FALSE(resp.cas().empty()); |
| 698 | + REQUIRE(resp.mutation_token().has_value()); |
| 699 | + } |
| 700 | + |
| 701 | + // Get with raw_string_transcoder |
| 702 | + { |
| 703 | + auto [ctx, resp] = collection.get(id, {}).get(); |
| 704 | + REQUIRE_SUCCESS(ctx.ec()); |
| 705 | + REQUIRE_FALSE(resp.cas().empty()); |
| 706 | + REQUIRE(resp.content_as<std::string, couchbase::codec::raw_string_transcoder>() == document); |
| 707 | + } |
| 708 | + |
| 709 | + // Get with default_json_transcoder |
| 710 | + { |
| 711 | + auto [ctx, resp] = collection.get(id, {}).get(); |
| 712 | + REQUIRE_SUCCESS(ctx.ec()); |
| 713 | + REQUIRE_FALSE(resp.cas().empty()); |
| 714 | + REQUIRE_THROWS_WITH(resp.content_as<std::string>(), ContainsSubstring("document to have JSON common flags")); |
| 715 | + } |
| 716 | +} |
0 commit comments