2929#include < olp/core/utils/Dir.h>
3030#include < olp/dataservice/read/VersionedLayerClient.h>
3131#include " ApiDefaultResponses.h"
32+ #include " PlatformUrlsGenerator.h"
3233#include " ReadDefaultResponses.h"
33- #include " UrlGenerators .h"
34+ #include " ResponseGenerator .h"
3435#include " VersionedLayerClientImpl.h"
3536#include " repositories/QuadTreeIndex.h"
3637// clang-format off
@@ -60,17 +61,6 @@ constexpr auto kOtherHereTile2 = "5904591";
6061constexpr auto kUrlLookup =
6162 R"( https://api-lookup.data.api.platform.here.com/lookup/v1/resources/hrn:here:data::olp-here-test:hereos-internal-test-v2/apis)" ;
6263
63- template <class T >
64- std::string serialize (std::vector<T> data) {
65- std::string str = " [" ;
66- for (const auto & el : data) {
67- str.append (olp::serializer::serialize (el));
68- str.append (" ," );
69- }
70- str[str.length () - 1 ] = ' ]' ;
71- return str;
72- }
73-
7464TEST (VersionedLayerClientTest, CanBeMoved) {
7565 read::VersionedLayerClient client_a (olp::client::HRN (), " " , boost::none, {});
7666 read::VersionedLayerClient client_b (std::move (client_a));
@@ -363,33 +353,22 @@ TEST(VersionedLayerClientTest, ProtectThanRelease) {
363353 settings.default_cache_expiration = std::chrono::seconds (2 );
364354 settings.network_request_handler = network_mock;
365355 auto version = 4u ;
366- auto api_response =
367- mockserver::ApiDefaultResponses::GenerateResourceApisResponse (kCatalog );
368- auto quad_path = mock::GeneratePath (
369- api_response, " query" ,
370- mock::GenerateGetQuadKeyPath (" 92259" , kLayerId , version, 4 ));
356+ auto api_response = ResponseGenerator::ResourceApis (kCatalog );
357+ PlatformUrlsGenerator generator (api_response, kLayerId );
358+ auto quad_path = generator.VersionedQuadTree (" 92259" , version, 4 );
371359 ASSERT_FALSE (quad_path.empty ());
372360 auto tile_key = olp::geo::TileKey::FromHereTile (kHereTile );
373361 auto responce_quad =
374362 mockserver::ReadDefaultResponses::GenerateQuadTreeResponse (
375363 tile_key.ChangedLevelBy (-4 ), 4 , {9 , 10 , 11 , 12 });
376- auto tile_path = mock::GeneratePath (
377- api_response, " blob" ,
378- mock::GenerateGetDataPath (
379- kLayerId ,
380- mockserver::ReadDefaultResponses::GenerateDataHandle (kHereTile )));
364+ auto tile_path = generator.DataBlob (
365+ mockserver::ReadDefaultResponses::GenerateDataHandle (kHereTile ));
381366 ASSERT_FALSE (tile_path.empty ());
382- auto tile2_path = mock::GeneratePath (
383- api_response, " blob" ,
384- mock::GenerateGetDataPath (
385- kLayerId , mockserver::ReadDefaultResponses::GenerateDataHandle (
386- kOtherHereTile2 )));
367+ auto tile2_path = generator.DataBlob (
368+ mockserver::ReadDefaultResponses::GenerateDataHandle (kOtherHereTile2 ));
387369 ASSERT_FALSE (tile2_path.empty ());
388- auto other_tile_path = mock::GeneratePath (
389- api_response, " blob" ,
390- mock::GenerateGetDataPath (
391- kLayerId , mockserver::ReadDefaultResponses::GenerateDataHandle (
392- kOtherHereTile )));
370+ auto other_tile_path = generator.DataBlob (
371+ mockserver::ReadDefaultResponses::GenerateDataHandle (kOtherHereTile ));
393372 ASSERT_FALSE (other_tile_path.empty ());
394373
395374 read::VersionedLayerClientImpl client (kHrn , kLayerId , boost::none, settings);
@@ -399,9 +378,8 @@ TEST(VersionedLayerClientTest, ProtectThanRelease) {
399378 EXPECT_CALL (*network_mock, Send (IsGetRequest (kUrlLookup ), _, _, _, _))
400379 .WillOnce (ReturnHttpResponse (olp::http::NetworkResponse ().WithStatus (
401380 olp::http::HttpStatusCode::OK),
402- serialize (api_response)));
403- auto version_path = mock::GeneratePath (
404- api_response, " metadata" , mock::GenerateGetLatestVersionPath ());
381+ api_response));
382+ auto version_path = generator.LatestVersion ();
405383 ASSERT_FALSE (version_path.empty ());
406384 EXPECT_CALL (*network_mock, Send (IsGetRequest (version_path), _, _, _, _))
407385 .WillOnce (ReturnHttpResponse (
@@ -574,8 +552,8 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsSplitted) {
574552 {
575553 SCOPED_TRACE (" Prefetch multiple partitions" );
576554
577- auto api_response =
578- mockserver::ApiDefaultResponses::GenerateResourceApisResponse ( kCatalog );
555+ auto api_response = ResponseGenerator::ResourceApis ( kCatalog );
556+ PlatformUrlsGenerator generator (api_response, kLayerId );
579557 auto partitions_response1 =
580558 mockserver::ReadDefaultResponses::GeneratePartitionsResponse (
581559 partitions_count / 2 );
@@ -586,10 +564,9 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsSplitted) {
586564 EXPECT_CALL (*network_mock, Send (IsGetRequest (kUrlLookup ), _, _, _, _))
587565 .WillOnce (ReturnHttpResponse (olp::http::NetworkResponse ().WithStatus (
588566 olp::http::HttpStatusCode::OK),
589- serialize ( api_response) ));
567+ api_response));
590568
591- auto version_path = mock::GeneratePath (
592- api_response, " metadata" , mock::GenerateGetLatestVersionPath ());
569+ auto version_path = generator.LatestVersion ();
593570 ASSERT_FALSE (version_path.empty ());
594571
595572 EXPECT_CALL (*network_mock, Send (IsGetRequest (version_path), _, _, _, _))
@@ -600,13 +577,9 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsSplitted) {
600577 mockserver::ReadDefaultResponses::GenerateVersionResponse (
601578 version))));
602579
603- auto partitions_path1 = mock::GeneratePath (
604- api_response, " query" ,
605- mock::GenerateGetPartitionsPath (kLayerId , partitions1, version));
580+ auto partitions_path1 = generator.PartitionsQuery (partitions1, version);
606581 ASSERT_FALSE (partitions_path1.empty ());
607- auto partitions_path2 = mock::GeneratePath (
608- api_response, " query" ,
609- mock::GenerateGetPartitionsPath (kLayerId , partitions2, version));
582+ auto partitions_path2 = generator.PartitionsQuery (partitions2, version);
610583 ASSERT_FALSE (partitions_path2.empty ());
611584
612585 EXPECT_CALL (*network_mock, Send (IsGetRequest (partitions_path1), _, _, _, _))
@@ -621,9 +594,7 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsSplitted) {
621594 olp::serializer::serialize (partitions_response2)));
622595
623596 for (const auto & partition : partitions_response1.GetPartitions ()) {
624- auto partition_path = mock::GeneratePath (
625- api_response, " blob" ,
626- mock::GenerateGetDataPath (kLayerId , partition.GetDataHandle ()));
597+ auto partition_path = generator.DataBlob (partition.GetDataHandle ());
627598 ASSERT_FALSE (partition_path.empty ());
628599
629600 EXPECT_CALL (*network_mock, Send (IsGetRequest (partition_path), _, _, _, _))
@@ -633,9 +604,7 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsSplitted) {
633604 }
634605
635606 for (const auto & partition : partitions_response2.GetPartitions ()) {
636- auto partition_path = mock::GeneratePath (
637- api_response, " blob" ,
638- mock::GenerateGetDataPath (kLayerId , partition.GetDataHandle ()));
607+ auto partition_path = generator.DataBlob (partition.GetDataHandle ());
639608 ASSERT_FALSE (partition_path.empty ());
640609
641610 EXPECT_CALL (*network_mock, Send (IsGetRequest (partition_path), _, _, _, _))
@@ -704,29 +673,26 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsSomeFail) {
704673 for (auto i = 0u ; i < partitions_count; i++) {
705674 partitions.emplace_back (std::to_string (i));
706675 }
707- auto api_response =
708- mockserver::ApiDefaultResponses::GenerateResourceApisResponse ( kCatalog );
676+ auto api_response = ResponseGenerator::ResourceApis ( kCatalog );
677+ PlatformUrlsGenerator generator (api_response, kLayerId );
709678 auto partitions_response =
710679 mockserver::ReadDefaultResponses::GeneratePartitionsResponse (
711680 partitions_count);
712681 const auto request =
713682 olp::dataservice::read::PrefetchPartitionsRequest ().WithPartitionIds (
714683 partitions);
715684 read::VersionedLayerClientImpl client (kHrn , kLayerId , boost::none, settings);
716- auto partitions_path = mock::GeneratePath (
717- api_response, " query" ,
718- mock::GenerateGetPartitionsPath (kLayerId , partitions, version));
685+ auto partitions_path = generator.PartitionsQuery (partitions, version);
719686 ASSERT_FALSE (partitions_path.empty ());
720687 {
721688 SCOPED_TRACE (" Prefetch partitions, some fails" );
722689
723690 EXPECT_CALL (*network_mock, Send (IsGetRequest (kUrlLookup ), _, _, _, _))
724691 .WillOnce (ReturnHttpResponse (olp::http::NetworkResponse ().WithStatus (
725692 olp::http::HttpStatusCode::OK),
726- serialize ( api_response) ));
693+ api_response));
727694
728- auto version_path = mock::GeneratePath (
729- api_response, " metadata" , mock::GenerateGetLatestVersionPath ());
695+ auto version_path = generator.LatestVersion ();
730696 ASSERT_FALSE (version_path.empty ());
731697
732698 EXPECT_CALL (*network_mock, Send (IsGetRequest (version_path), _, _, _, _))
@@ -746,9 +712,7 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsSomeFail) {
746712 olp::serializer::serialize (partitions_response)));
747713 for (auto i = 0u ; i < partitions_response.GetPartitions ().size (); i++) {
748714 const auto & partition = partitions_response.GetPartitions ().at (i);
749- auto partition_path = mock::GeneratePath (
750- api_response, " blob" ,
751- mock::GenerateGetDataPath (kLayerId , partition.GetDataHandle ()));
715+ auto partition_path = generator.DataBlob (partition.GetDataHandle ());
752716 ASSERT_FALSE (partition_path.empty ());
753717
754718 EXPECT_CALL (*network_mock, Send (IsGetRequest (partition_path), _, _, _, _))
@@ -800,9 +764,7 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsSomeFail) {
800764
801765 for (auto i = 0u ; i < partitions_response.GetPartitions ().size (); i++) {
802766 const auto & partition = partitions_response.GetPartitions ().at (i);
803- auto partition_path = mock::GeneratePath (
804- api_response, " blob" ,
805- mock::GenerateGetDataPath (kLayerId , partition.GetDataHandle ()));
767+ auto partition_path = generator.DataBlob (partition.GetDataHandle ());
806768 ASSERT_FALSE (partition_path.empty ());
807769
808770 EXPECT_CALL (*network_mock, Send (IsGetRequest (partition_path), _, _, _, _))
@@ -846,15 +808,13 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsFail) {
846808 for (auto i = 0u ; i < partitions_count; i++) {
847809 partitions.emplace_back (std::to_string (i));
848810 }
849- auto api_response =
850- mockserver::ApiDefaultResponses::GenerateResourceApisResponse ( kCatalog );
811+ auto api_response = ResponseGenerator::ResourceApis ( kCatalog );
812+ PlatformUrlsGenerator generator (api_response, kLayerId );
851813 const auto request =
852814 olp::dataservice::read::PrefetchPartitionsRequest ().WithPartitionIds (
853815 partitions);
854816 read::VersionedLayerClientImpl client (kHrn , kLayerId , boost::none, settings);
855- auto partitions_path = mock::GeneratePath (
856- api_response, " query" ,
857- mock::GenerateGetPartitionsPath (kLayerId , partitions, version));
817+ auto partitions_path = generator.PartitionsQuery (partitions, version);
858818 ASSERT_FALSE (partitions_path.empty ());
859819 {
860820 SCOPED_TRACE (" Prefetch partitions, empty request" );
@@ -881,10 +841,9 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsFail) {
881841 EXPECT_CALL (*network_mock, Send (IsGetRequest (kUrlLookup ), _, _, _, _))
882842 .WillOnce (ReturnHttpResponse (olp::http::NetworkResponse ().WithStatus (
883843 olp::http::HttpStatusCode::OK),
884- serialize ( api_response) ));
844+ api_response));
885845
886- auto version_path = mock::GeneratePath (
887- api_response, " metadata" , mock::GenerateGetLatestVersionPath ());
846+ auto version_path = generator.LatestVersion ();
888847 ASSERT_FALSE (version_path.empty ());
889848
890849 EXPECT_CALL (*network_mock, Send (IsGetRequest (version_path), _, _, _, _))
@@ -915,8 +874,7 @@ TEST(VersionedLayerClientTest, PrefetchPartitionsFail) {
915874 {
916875 SCOPED_TRACE (" Get data handles fails" );
917876
918- auto version_path = mock::GeneratePath (
919- api_response, " metadata" , mock::GenerateGetLatestVersionPath ());
877+ auto version_path = generator.LatestVersion ();
920878 ASSERT_FALSE (version_path.empty ());
921879 EXPECT_CALL (*network_mock, Send (IsGetRequest (version_path), _, _, _, _))
922880 .WillOnce (ReturnHttpResponse (
0 commit comments