-
Notifications
You must be signed in to change notification settings - Fork 49
/
HttpClientManagerTests.cpp
76 lines (58 loc) · 2.17 KB
/
HttpClientManagerTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
#include "common/Common.hpp"
#include "common/MockIHttpClient.hpp"
#include "http/HttpClientManager.hpp"
#include "NullObjects.hpp"
#include "ILogManager.hpp"
using namespace testing;
using namespace MAT;
static NullLogManager dummyLogManager;
class HttpClientManager4Test : public HttpClientManager {
public:
HttpClientManager4Test(IHttpClient& httpClient)
: HttpClientManager(dummyLogManager, httpClient, *PAL::getDefaultTaskDispatcher())
{
}
virtual void scheduleOnHttpResponse(HttpCallback* callback) override
{
onHttpResponse(callback);
}
};
class HttpClientManagerTests : public StrictMock<Test> {
protected:
MockIHttpClient httpClientMock;
HttpClientManager4Test hcm;
RouteSink<HttpClientManagerTests, EventsUploadContextPtr const&> requestDone{this, &HttpClientManagerTests::resultRequestDone};
protected:
HttpClientManagerTests()
: hcm(httpClientMock)
{
hcm.requestDone >> requestDone;
}
MOCK_METHOD1(resultRequestDone, void(EventsUploadContextPtr const &));
};
TEST_F(HttpClientManagerTests, HandlesRequestFlow)
{
SimpleHttpRequest* req = new SimpleHttpRequest("HttpClientManagerTests");
auto ctx = std::make_shared<EventsUploadContext>();
ctx->httpRequestId = req->GetId();
ctx->httpRequest = req;
ctx->recordIdsAndTenantIds["r1"] = "t1"; ctx->recordIdsAndTenantIds["r2"] = "t1";
ctx->latency = EventLatency_Normal;
ctx->packageIds["tenant1-token"] = 0;
IHttpResponseCallback* callback = nullptr;
EXPECT_CALL(httpClientMock, SendRequestAsync(ctx->httpRequest, _))
.WillOnce(SaveArg<1>(&callback));
hcm.sendRequest(ctx);
ASSERT_THAT(callback, NotNull());
PAL::sleep(200);
std::unique_ptr<SimpleHttpResponse> rsp(new SimpleHttpResponse("HttpClientManagerTests"));
rsp->m_result = HttpResult_OK;
rsp->m_statusCode = 200;
EXPECT_CALL(*this, resultRequestDone(ctx))
.WillOnce(Return());
IHttpResponse* rspRef = rsp.get();
callback->OnHttpResponse(rsp.release());
EXPECT_THAT(ctx->httpResponse, rspRef);
EXPECT_THAT(ctx->durationMs, Gt(199));
}