Skip to content

Commit 69d4acb

Browse files
authored
Add intergation tests for StreamApi::DeleteSubscription method (#613)
Resolves: OLPEDGE-1472 Signed-off-by: Mykola Malik <[email protected]>
1 parent 4ea880f commit 69d4acb

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ MATCHER_P(BodyEq, expected_body, "") {
4848
: expected_body_str.empty();
4949
}
5050

51+
MATCHER_P(HeadersContain, expected_header, "") {
52+
const auto& headers = arg.GetHeaders();
53+
return std::find(headers.begin(), headers.end(), expected_header) !=
54+
headers.end();
55+
}
56+
5157
class StreamApiTest : public Test {
5258
protected:
5359
void SetUp() override {
@@ -77,19 +83,29 @@ const std::string kSubscriptionId{"test-subscription-id-123"};
7783
const std::string kConsumerId{"test-consumer-id-987"};
7884
const std::string kLayerId{"test-layer"};
7985
const std::string kSerialMode{"serial"};
86+
const std::string kParallelMode{"parallel"};
87+
const std::string kCorrelationId{"test-correlation-id"};
88+
const std::pair<std::string, std::string> kCorrelationIdHeader{
89+
"X-Correlation-Id", kCorrelationId};
8090

8191
constexpr auto kUrlStreamSubscribeNoQueryParams =
8292
R"(https://some.base.url/stream/v2/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/test-layer/subscribe)";
8393

8494
constexpr auto kUrlStreamSubscribeWithQueryParams =
8595
R"(https://some.base.url/stream/v2/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/test-layer/subscribe?consumerId=test-consumer-id-987&mode=serial&subscriptionId=test-subscription-id-123)";
8696

97+
constexpr auto kUrlStreamUnsubscribe =
98+
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)";
99+
87100
constexpr auto kHttpResponseSubscribeSucceeds =
88101
R"jsonString({ "nodeBaseURL": "https://some.node.base.url/stream/v2/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2", "subscriptionId": "test-subscription-id-123" })jsonString";
89102

90103
constexpr auto kHttpResponseSubscribeFails =
91104
R"jsonString({ "title": "Subscription mode not supported", "status": 400, "code": "E213002", "cause": "Subscription mode 'singleton' not supported", "action": "Retry with valid subscription mode 'serial' or 'parallel'", "correlationId": "4199533b-6290-41db-8d79-edf4f4019a74" })jsonString";
92105

106+
constexpr auto kHttpResponseUnsubscribeFails =
107+
R"jsonString({ "error": "Unauthorized", "error_description": "Token Validation Failure - invalid time in token" })jsonString";
108+
93109
constexpr auto kHttpRequestBodyWithConsumerProperties =
94110
R"jsonString({"kafkaConsumerProperties":{"field_string":"abc","field_int":"456","field_bool":"1"}})jsonString";
95111

@@ -178,4 +194,53 @@ TEST_F(StreamApiTest, Subscribe) {
178194
}
179195
}
180196

197+
TEST_F(StreamApiTest, DeleteSubscription) {
198+
{
199+
SCOPED_TRACE("DeleteSubscription succeeds");
200+
201+
EXPECT_CALL(*network_mock_,
202+
Send(AllOf(IsDeleteRequest(kUrlStreamUnsubscribe),
203+
HeadersContain(kCorrelationIdHeader)),
204+
_, _, _, _))
205+
.WillOnce(ReturnHttpResponse(
206+
http::NetworkResponse().WithStatus(http::HttpStatusCode::OK), ""));
207+
208+
olp_client_.SetBaseUrl(kNodeBaseUrl);
209+
CancellationContext context;
210+
const auto unsubscribe_response =
211+
StreamApi::DeleteSubscription(olp_client_, kLayerId, kSubscriptionId,
212+
kParallelMode, kCorrelationId, context);
213+
214+
EXPECT_TRUE(unsubscribe_response.IsSuccessful())
215+
<< ApiErrorToString(unsubscribe_response.GetError());
216+
EXPECT_EQ(unsubscribe_response.GetResult(), http::HttpStatusCode::OK);
217+
218+
Mock::VerifyAndClearExpectations(network_mock_.get());
219+
}
220+
{
221+
SCOPED_TRACE("DeleteSubscription fails");
222+
223+
EXPECT_CALL(*network_mock_,
224+
Send(AllOf(IsDeleteRequest(kUrlStreamUnsubscribe),
225+
HeadersContain(kCorrelationIdHeader)),
226+
_, _, _, _))
227+
.WillOnce(ReturnHttpResponse(http::NetworkResponse().WithStatus(
228+
http::HttpStatusCode::UNAUTHORIZED),
229+
kHttpResponseUnsubscribeFails));
230+
231+
olp_client_.SetBaseUrl(kNodeBaseUrl);
232+
CancellationContext context;
233+
const auto unsubscribe_response =
234+
StreamApi::DeleteSubscription(olp_client_, kLayerId, kSubscriptionId,
235+
kParallelMode, kCorrelationId, context);
236+
237+
EXPECT_FALSE(unsubscribe_response.IsSuccessful());
238+
EXPECT_EQ(unsubscribe_response.GetError().GetHttpStatusCode(),
239+
http::HttpStatusCode::UNAUTHORIZED);
240+
EXPECT_EQ(unsubscribe_response.GetError().GetMessage(),
241+
kHttpResponseUnsubscribeFails);
242+
243+
Mock::VerifyAndClearExpectations(network_mock_.get());
244+
}
245+
}
181246
} // namespace

0 commit comments

Comments
 (0)