Skip to content

Commit ea781c5

Browse files
author
Liubov Didkivska
authored
Add ListVersions serialize functionality (#913)
Add serialize to json. Add tests for VersionInfos. Relates-To: OLPEDGE-1606 Signed-off-by: Liubov Didkivska <[email protected]>
1 parent 4b420e5 commit ea781c5

File tree

3 files changed

+139
-3
lines changed

3 files changed

+139
-3
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2020 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
#include "VersionInfosSerializer.h"
21+
22+
#include <olp/core/generated/serializer/SerializerWrapper.h>
23+
24+
namespace olp {
25+
namespace serializer {
26+
27+
void to_json(const dataservice::read::model::VersionDependency& x,
28+
rapidjson::Value& value,
29+
rapidjson::Document::AllocatorType& allocator) {
30+
value.SetObject();
31+
serialize("hrn", x.GetHrn(), value, allocator);
32+
serialize("version", x.GetVersion(), value, allocator);
33+
serialize("direct", x.GetDirect(), value, allocator);
34+
}
35+
36+
void to_json(const dataservice::read::model::VersionInfo& x,
37+
rapidjson::Value& value,
38+
rapidjson::Document::AllocatorType& allocator) {
39+
value.SetObject();
40+
serialize("dependencies", x.GetDependencies(), value, allocator);
41+
serialize("timestamp", x.GetTimestamp(), value, allocator);
42+
serialize("version", x.GetVersion(), value, allocator);
43+
serialize("partitionCounts", x.GetPartitionCounts(), value, allocator);
44+
}
45+
46+
void to_json(const dataservice::read::model::VersionInfos& x,
47+
rapidjson::Value& value,
48+
rapidjson::Document::AllocatorType& allocator) {
49+
value.SetObject();
50+
serialize("versions", x.GetVersions(), value, allocator);
51+
}
52+
} // namespace serializer
53+
} // namespace olp
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2020 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
#pragma once
21+
22+
#include <rapidjson/document.h>
23+
#include "olp/dataservice/read/model/VersionInfos.h"
24+
25+
namespace olp {
26+
namespace serializer {
27+
28+
void to_json(const dataservice::read::model::VersionDependency& x,
29+
rapidjson::Value& value,
30+
rapidjson::Document::AllocatorType& allocator);
31+
32+
void to_json(const dataservice::read::model::VersionInfo& x,
33+
rapidjson::Value& value,
34+
rapidjson::Document::AllocatorType& allocator);
35+
36+
void to_json(const dataservice::read::model::VersionInfos& x,
37+
rapidjson::Value& value,
38+
rapidjson::Document::AllocatorType& allocator);
39+
} // namespace serializer
40+
} // namespace olp

olp-cpp-sdk-dataservice-read/tests/ParserTest.cpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
#include "generated/parser/IndexParser.h"
3232
#include "generated/parser/MessagesParser.h"
3333
#include "generated/parser/SubscribeResponseParser.h"
34+
#include "generated/parser/VersionInfosParser.h"
3435
#include <olp/core/generated/parser/JsonParser.h>
36+
#include "generated/serializer/VersionInfosSerializer.h"
37+
#include "generated/serializer/JsonSerializer.h"
3538
// clang-format on
3639

37-
namespace {
38-
3940
TEST(ParserTest, Api) {
4041
std::string json_input =
4142
"[\
@@ -608,4 +609,46 @@ TEST(ParserTest, SubscribeResponse) {
608609
EXPECT_TRUE(response.GetSubscriptionId().empty());
609610
}
610611
}
611-
} // namespace
612+
613+
TEST(ParserTest, VersionInfos) {
614+
{
615+
SCOPED_TRACE("Parse valid VersionInfosResponse");
616+
olp::dataservice::read::model::VersionInfos infos;
617+
auto size = 1;
618+
auto start = 1;
619+
std::vector<olp::dataservice::read::model::VersionInfo> versions_vect(size);
620+
for (size_t i = 0; i < versions_vect.size(); i++) {
621+
versions_vect[i].SetVersion(++start);
622+
versions_vect[i].SetTimestamp(1000 * start);
623+
std::vector<olp::dataservice::read::model::VersionDependency>
624+
dependencyes(1);
625+
dependencyes.front().SetHrn("hrn::some-value");
626+
versions_vect[i].SetDependencies(std::move(dependencyes));
627+
versions_vect[i].SetPartitionCounts({{"partition", 1}});
628+
}
629+
630+
infos.SetVersions(versions_vect);
631+
auto str = olp::serializer::serialize(infos);
632+
auto version_infos_response =
633+
"{\"versions\":[{\"dependencies\":[{\"hrn\":\"hrn::some-value\","
634+
"\"version\":0,\"direct\":false}],\"timestamp\":2000,\"version\":2,"
635+
"\"partitionCounts\":{\"partition\":1}}]}";
636+
const auto response =
637+
olp::parser::parse<olp::dataservice::read::model::VersionInfos>(
638+
version_infos_response);
639+
640+
EXPECT_EQ(str.compare(version_infos_response), 0);
641+
}
642+
643+
{
644+
SCOPED_TRACE("Parse invalid VersionInfosResponse");
645+
auto version_infos_response =
646+
"{\"invalid_versions\":[{\"timestamp\":2000,\"version\":2,"
647+
"\"partitionCounts\":{\"partition\":1}}]}";
648+
const auto response =
649+
olp::parser::parse<olp::dataservice::read::model::VersionInfos>(
650+
version_infos_response);
651+
652+
EXPECT_TRUE(response.GetVersions().empty());
653+
}
654+
}

0 commit comments

Comments
 (0)