Skip to content

Commit 2ce5310

Browse files
authored
Add intergation tests for StreamApi::SeekToOffset method (#622)
Resolves: OLPEDGE-1474 Signed-off-by: Mykola Malik <[email protected]>
1 parent 93cfb8b commit 2ce5310

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ constexpr auto kUrlCommitOffsetsNoQueryParams =
112112
constexpr auto kUrlCommitOffsetsWithQueryParams =
113113
R"(https://some.node.base.url/stream/v2/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/test-layer/offsets?mode=parallel&subscriptionId=test-subscription-id-123)";
114114

115+
constexpr auto kUrlSeekToOffsetNoQueryParams =
116+
R"(https://some.node.base.url/stream/v2/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/test-layer/seek)";
117+
118+
constexpr auto kUrlSeekToOffsetWithQueryParams =
119+
R"(https://some.node.base.url/stream/v2/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/test-layer/seek?mode=serial&subscriptionId=test-subscription-id-123)";
120+
115121
constexpr auto kUrlUnsubscribe =
116122
R"(https://some.node.base.url/stream/v2/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/test-layer/subscribe?mode=parallel&subscriptionId=test-subscription-id-123)";
117123

@@ -124,6 +130,9 @@ constexpr auto kHttpResponseSubscribeFails =
124130
constexpr auto kHttpResponseCommitOffsetsFails =
125131
R"jsonString({ "title": "Unable to commit offset", "status": 409, "code": "E213028", "cause": "Unable to commit offset", "action": "Commit cannot be completed. Continue with reading and committing new messages", "correlationId": "4199533b-6290-41db-8d79-edf4f4019a74" })jsonString";
126132

133+
constexpr auto kHttpResponseSeekToOffsetFails =
134+
R"jsonString({ "title": "Realm not found", "status": 400, "code": "E213017", "cause": "App / user is not associated with a realm", "action": "Update access token and retry", "correlationId": "4199533b-6290-41db-8d79-edf4f4019a74" })jsonString";
135+
127136
constexpr auto kHttpResponseUnsubscribeFails =
128137
R"jsonString({ "error": "Unauthorized", "error_description": "Token Validation Failure - invalid time in token" })jsonString";
129138

@@ -296,6 +305,86 @@ TEST_F(StreamApiTest, CommitOffsets) {
296305
}
297306
}
298307

308+
TEST_F(StreamApiTest, SeekToOffset) {
309+
const auto stream_offsets = GetStreamOffsets();
310+
311+
{
312+
SCOPED_TRACE("SeekToOffset without optional input fields succeeds");
313+
314+
EXPECT_CALL(*network_mock_,
315+
Send(AllOf(IsPutRequest(kUrlSeekToOffsetNoQueryParams),
316+
HeadersContain(kCorrelationIdHeader),
317+
BodyEq(kHttpRequestBodyWithStreamOffsets)),
318+
_, _, _, _))
319+
.WillOnce(ReturnHttpResponse(
320+
http::NetworkResponse().WithStatus(http::HttpStatusCode::OK), ""));
321+
322+
olp_client_.SetBaseUrl(kNodeBaseUrl);
323+
std::string x_correlation_id = kCorrelationId;
324+
CancellationContext context;
325+
const auto seek_to_offset_response = StreamApi::SeekToOffset(
326+
olp_client_, kLayerId, stream_offsets, boost::none, boost::none,
327+
context, x_correlation_id);
328+
329+
EXPECT_TRUE(seek_to_offset_response.IsSuccessful())
330+
<< ApiErrorToString(seek_to_offset_response.GetError());
331+
EXPECT_EQ(seek_to_offset_response.GetResult(), http::HttpStatusCode::OK);
332+
333+
Mock::VerifyAndClearExpectations(network_mock_.get());
334+
}
335+
{
336+
SCOPED_TRACE("SeekToOffset with all optional input fields succeeds");
337+
338+
EXPECT_CALL(*network_mock_,
339+
Send(AllOf(IsPutRequest(kUrlSeekToOffsetWithQueryParams),
340+
HeadersContain(kCorrelationIdHeader),
341+
BodyEq(kHttpRequestBodyWithStreamOffsets)),
342+
_, _, _, _))
343+
.WillOnce(ReturnHttpResponse(
344+
http::NetworkResponse().WithStatus(http::HttpStatusCode::OK), ""));
345+
346+
olp_client_.SetBaseUrl(kNodeBaseUrl);
347+
std::string x_correlation_id = kCorrelationId;
348+
CancellationContext context;
349+
const auto commit_offsets_response = StreamApi::SeekToOffset(
350+
olp_client_, kLayerId, stream_offsets, kSubscriptionId, kSerialMode,
351+
context, x_correlation_id);
352+
353+
EXPECT_TRUE(commit_offsets_response.IsSuccessful())
354+
<< ApiErrorToString(commit_offsets_response.GetError());
355+
EXPECT_EQ(commit_offsets_response.GetResult(), http::HttpStatusCode::OK);
356+
357+
Mock::VerifyAndClearExpectations(network_mock_.get());
358+
}
359+
{
360+
SCOPED_TRACE("SeekToOffset fails");
361+
362+
EXPECT_CALL(*network_mock_,
363+
Send(AllOf(IsPutRequest(kUrlSeekToOffsetNoQueryParams),
364+
HeadersContain(kCorrelationIdHeader),
365+
BodyEq(kHttpRequestBodyWithStreamOffsets)),
366+
_, _, _, _))
367+
.WillOnce(ReturnHttpResponse(http::NetworkResponse().WithStatus(
368+
http::HttpStatusCode::BAD_REQUEST),
369+
kHttpResponseSeekToOffsetFails));
370+
371+
olp_client_.SetBaseUrl(kNodeBaseUrl);
372+
std::string x_correlation_id = kCorrelationId;
373+
CancellationContext context;
374+
const auto commit_offsets_response = StreamApi::SeekToOffset(
375+
olp_client_, kLayerId, stream_offsets, boost::none, boost::none,
376+
context, x_correlation_id);
377+
378+
EXPECT_FALSE(commit_offsets_response.IsSuccessful());
379+
EXPECT_EQ(commit_offsets_response.GetError().GetHttpStatusCode(),
380+
http::HttpStatusCode::BAD_REQUEST);
381+
EXPECT_EQ(commit_offsets_response.GetError().GetMessage(),
382+
kHttpResponseSeekToOffsetFails);
383+
384+
Mock::VerifyAndClearExpectations(network_mock_.get());
385+
}
386+
}
387+
299388
TEST_F(StreamApiTest, DeleteSubscription) {
300389
{
301390
SCOPED_TRACE("DeleteSubscription succeeds");

0 commit comments

Comments
 (0)