Skip to content

Commit

Permalink
original test remote transceiver
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavambastha committed Jun 8, 2024
1 parent 94705db commit 6dc19df
Showing 1 changed file with 4 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/address.hpp>
#include <boost/beast/http/status.hpp>
#include <boost/json.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <chrono>
#include <cstddef>
#include <cstdint>
Expand All @@ -21,7 +19,6 @@
#include "util_db.h"
#include "waypoint.pb.h"

using Polaris::GlobalPath;
using Polaris::Sensors;
using remote_transceiver::HTTPServer;
using remote_transceiver::Listener;
Expand Down Expand Up @@ -98,7 +95,11 @@ TEST_F(TestRemoteTransceiver, TestGet)
* @param params Params structure
* @return formatted request body
*/

std::string createPostBody(remote_transceiver::MOMsgParams::Params params);

std::string createSensorPostBody(remote_transceiver::MOMsgParams::Params params)

{
std::ostringstream s;
s << "imei=" << params.imei_ << "&serial=" << params.serial_ << "&momsn=" << params.momsn_
Expand All @@ -107,25 +108,6 @@ std::string createSensorPostBody(remote_transceiver::MOMsgParams::Params params)
return s.str();
}

std::string createGlobalPath(params) //std::string example = "{"field1": 0, "field2": 1.0}";
{
json globalPath;

json::array waypointsArr;

for (const auto & waypoint : params.waypoints) {
json waypoint;
waypoint["latitude"] = waypoint.latitude;
waypoint["longitude"] = waypoint.longitude;
waypointsArr.push_back(waypoint);
}

globalPath["waypoints"] = std::move(waypointsArray);
globalPath["timestamp"] = params.timestamp;

return json::serialize(globalPath);
}

/**
* @brief Test that we can POST sensor data to the server
*
Expand Down Expand Up @@ -221,38 +203,3 @@ TEST_F(TestRemoteTransceiver, TestPostSensorsMult)
// Check that DB is updated properly for all requests
EXPECT_TRUE(g_test_db.verifyDBWrite(expected_sensors, expected_info));
}

/**
* @brief Test that we can POST global path data to the server
*
*/
TEST_F(TestRemoteTransceiver, TestPostGlobalPath)
{
SCOPED_TRACE("Seed: " + std::to_string(g_rand_seed)); // Print seed on any failure
auto [rand_global_path, rand_timestamp] = g_test_db.genRandGlobalData(UtilDB::getTimestamp());

std::string rand_global_path_str;
ASSERT_TRUE(rand_global_path.SerializeToString(&rand_global_path_str));
Polaris::GlobalPath test;
test.ParseFromString(rand_global_path_str);
// This query is comprised entirely of arbitrary values exccept for .data_
std::string query = createGlobalPathPostBody(
{.imei_ = 0, //Change to JSON
.serial_ = 0,
.momsn_ = 1,
.transmit_time_ = rand_info.timestamp_,
.lat_ = rand_info.lat_,
.lon_ = rand_info.lon_,
.cep_ = rand_info.cep_,
.data_ = rand_sensors_str});
http::status status = http_client::post(
{TESTING_HOST, std::to_string(TESTING_PORT), remote_transceiver::targets::GLOBAL_PATH}, "application/json",
query);

EXPECT_EQ(status, http::status::ok);
std::this_thread::sleep_for(WAIT_AFTER_RES);

std::array<GlobalPath, 1> expected_global_path = {rand_global_path};
std::<std::string> expected_timestamp = {rand_timestamp};
EXPECT_TRUE(g_test_db.verifyDBWrite_GlobalPath(expected_global_path, expected_timestamp));
}

0 comments on commit 6dc19df

Please sign in to comment.