Status deserializeDistributedQueryResultJSON(const std::string& json, DistributedQueryResult& r) { pt::ptree tree; try { std::stringstream ss(json); pt::read_json(ss, tree); } catch (const pt::ptree_error& e) { return Status(1, "Error serializing JSON: " + std::string(e.what())); } return deserializeDistributedQueryResult(tree, r); }
TEST_F(DistributedTests, test_deserialize_distributed_query_result) { auto doc = JSON::newObject(); auto request_obj = doc.getObject(); doc.addRef("query", "bar", request_obj); doc.addRef("id", "foo", request_obj); auto row_obj = doc.getObject(); doc.addRef("foo", "bar", row_obj); auto results_arr = doc.getArray(); doc.push(row_obj, results_arr); doc.add("request", request_obj); doc.add("results", results_arr); DistributedQueryResult r; auto s = deserializeDistributedQueryResult(doc.doc(), r); EXPECT_EQ(r.request.id, "foo"); EXPECT_EQ(r.request.query, "bar"); EXPECT_EQ(r.results[0]["foo"], "bar"); }
TEST_F(DistributedTests, test_deserialize_distributed_query_result) { pt::ptree request; request.put<std::string>("id", "foo"); request.put<std::string>("query", "bar"); pt::ptree row; row.put<std::string>("foo", "bar"); pt::ptree results; results.push_back(std::make_pair("", row)); pt::ptree query_result; query_result.put_child("request", request); query_result.put_child("results", results); DistributedQueryResult r; auto s = deserializeDistributedQueryResult(query_result, r); EXPECT_TRUE(s.ok()); EXPECT_EQ(r.request.id, "foo"); EXPECT_EQ(r.request.query, "bar"); EXPECT_EQ(r.results[0]["foo"], "bar"); }