@@ -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+
5157class StreamApiTest : public Test {
5258 protected:
5359 void SetUp () override {
@@ -77,19 +83,29 @@ const std::string kSubscriptionId{"test-subscription-id-123"};
7783const std::string kConsumerId {" test-consumer-id-987" };
7884const std::string kLayerId {" test-layer" };
7985const 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
8191constexpr 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
8494constexpr 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+
87100constexpr 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
90103constexpr 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+
93109constexpr 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