AWSGameLiftClientManagerTest.cpp 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Component/ComponentApplication.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/std/smart_ptr/make_shared.h>
  12. #include <Multiplayer/Session/SessionConfig.h>
  13. #include <Credential/AWSCredentialBus.h>
  14. #include <ResourceMapping/AWSResourceMappingBus.h>
  15. #include <AWSCoreBus.h>
  16. #include <AWSGameLiftClientFixture.h>
  17. #include <AWSGameLiftClientManager.h>
  18. #include <AWSGameLiftClientMocks.h>
  19. #include <Request/AWSGameLiftAcceptMatchRequest.h>
  20. #include <Request/AWSGameLiftCreateSessionOnQueueRequest.h>
  21. #include <Request/AWSGameLiftCreateSessionRequest.h>
  22. #include <Request/AWSGameLiftJoinSessionRequest.h>
  23. #include <Request/AWSGameLiftSearchSessionsRequest.h>
  24. #include <Request/IAWSGameLiftInternalRequests.h>
  25. #include <Request/AWSGameLiftStartMatchmakingRequest.h>
  26. #include <Request/AWSGameLiftStopMatchmakingRequest.h>
  27. using namespace AWSGameLift;
  28. MATCHER_P(SearchSessionsResponseMatcher, expectedResponse, "")
  29. {
  30. // Custome matcher for checking the SearchSessionsResponse type argument.
  31. AZ_UNUSED(result_listener);
  32. bool result = arg.m_nextToken == expectedResponse.m_nextToken;
  33. result &= arg.m_sessionConfigs.size() == expectedResponse.m_sessionConfigs.size();
  34. for (int index = 0; index < arg.m_sessionConfigs.size(); ++index)
  35. {
  36. result &= arg.m_sessionConfigs[index].m_creationTime == expectedResponse.m_sessionConfigs[index].m_creationTime;
  37. result &= arg.m_sessionConfigs[index].m_terminationTime == expectedResponse.m_sessionConfigs[index].m_terminationTime;
  38. result &= arg.m_sessionConfigs[index].m_creatorId == expectedResponse.m_sessionConfigs[index].m_creatorId;
  39. result &= arg.m_sessionConfigs[index].m_sessionProperties == expectedResponse.m_sessionConfigs[index].m_sessionProperties;
  40. result &= arg.m_sessionConfigs[index].m_sessionId == expectedResponse.m_sessionConfigs[index].m_sessionId;
  41. result &= arg.m_sessionConfigs[index].m_sessionName == expectedResponse.m_sessionConfigs[index].m_sessionName;
  42. result &= arg.m_sessionConfigs[index].m_dnsName == expectedResponse.m_sessionConfigs[index].m_dnsName;
  43. result &= arg.m_sessionConfigs[index].m_ipAddress == expectedResponse.m_sessionConfigs[index].m_ipAddress;
  44. result &= arg.m_sessionConfigs[index].m_port == expectedResponse.m_sessionConfigs[index].m_port;
  45. result &= arg.m_sessionConfigs[index].m_maxPlayer == expectedResponse.m_sessionConfigs[index].m_maxPlayer;
  46. result &= arg.m_sessionConfigs[index].m_currentPlayer == expectedResponse.m_sessionConfigs[index].m_currentPlayer;
  47. result &= arg.m_sessionConfigs[index].m_status == expectedResponse.m_sessionConfigs[index].m_status;
  48. result &= arg.m_sessionConfigs[index].m_statusReason == expectedResponse.m_sessionConfigs[index].m_statusReason;
  49. }
  50. return result;
  51. }
  52. class AWSResourceMappingRequestsHandlerMock
  53. : public AWSCore::AWSResourceMappingRequestBus::Handler
  54. {
  55. public:
  56. AWSResourceMappingRequestsHandlerMock()
  57. {
  58. AWSCore::AWSResourceMappingRequestBus::Handler::BusConnect();
  59. }
  60. ~ AWSResourceMappingRequestsHandlerMock()
  61. {
  62. AWSCore::AWSResourceMappingRequestBus::Handler::BusDisconnect();
  63. }
  64. MOCK_CONST_METHOD0(GetDefaultRegion, AZStd::string());
  65. MOCK_CONST_METHOD0(GetDefaultAccountId, AZStd::string());
  66. MOCK_CONST_METHOD1(HasResource, bool(const AZStd::string&));
  67. MOCK_CONST_METHOD1(GetResourceAccountId, AZStd::string(const AZStd::string&));
  68. MOCK_CONST_METHOD1(GetResourceNameId, AZStd::string(const AZStd::string&));
  69. MOCK_CONST_METHOD1(GetResourceRegion, AZStd::string(const AZStd::string&));
  70. MOCK_CONST_METHOD1(GetResourceType, AZStd::string(const AZStd::string&));
  71. MOCK_CONST_METHOD1(GetServiceUrlByServiceName, AZStd::string(const AZStd::string&));
  72. MOCK_CONST_METHOD2(GetServiceUrlByRESTApiIdAndStage, AZStd::string(const AZStd::string&, const AZStd::string&));
  73. MOCK_METHOD1(ReloadConfigFile, void(bool));
  74. };
  75. class AWSCredentialRequestsHandlerMock
  76. : public AWSCore::AWSCredentialRequestBus::Handler
  77. {
  78. public:
  79. AWSCredentialRequestsHandlerMock()
  80. {
  81. AWSCore::AWSCredentialRequestBus::Handler::BusConnect();
  82. }
  83. ~AWSCredentialRequestsHandlerMock()
  84. {
  85. AWSCore::AWSCredentialRequestBus::Handler::BusDisconnect();
  86. }
  87. MOCK_CONST_METHOD0(GetCredentialHandlerOrder, int());
  88. MOCK_METHOD0(GetCredentialsProvider, std::shared_ptr<Aws::Auth::AWSCredentialsProvider>());
  89. };
  90. class AWSCoreRequestsHandlerMock
  91. : public AWSCore::AWSCoreRequestBus::Handler
  92. {
  93. public:
  94. AWSCoreRequestsHandlerMock()
  95. {
  96. AWSCore::AWSCoreRequestBus::Handler::BusConnect();
  97. }
  98. ~AWSCoreRequestsHandlerMock()
  99. {
  100. AWSCore::AWSCoreRequestBus::Handler::BusDisconnect();
  101. }
  102. MOCK_METHOD0(GetDefaultJobContext, AZ::JobContext*());
  103. MOCK_METHOD0(GetDefaultConfig, AWSCore::AwsApiJobConfig*());
  104. };
  105. class AWSGameLiftClientManagerTest
  106. : public AWSGameLiftClientFixture
  107. , public IAWSGameLiftInternalRequests
  108. {
  109. protected:
  110. void SetUp() override
  111. {
  112. AWSGameLiftClientFixture::SetUp();
  113. AZ::Interface<IAWSGameLiftInternalRequests>::Register(this);
  114. m_gameliftClientMockPtr = AZStd::make_shared<GameLiftClientMock>();
  115. m_gameliftClientManager = AZStd::make_unique<AWSGameLiftClientManager>();
  116. m_gameliftClientManager->ActivateManager();
  117. }
  118. void TearDown() override
  119. {
  120. m_gameliftClientManager->DeactivateManager();
  121. m_gameliftClientManager.reset();
  122. m_gameliftClientMockPtr.reset();
  123. AZ::Interface<IAWSGameLiftInternalRequests>::Unregister(this);
  124. AWSGameLiftClientFixture::TearDown();
  125. }
  126. AZStd::shared_ptr<Aws::GameLift::GameLiftClient> GetGameLiftClient() const
  127. {
  128. return m_gameliftClientMockPtr;
  129. }
  130. void SetGameLiftClient(AZStd::shared_ptr<Aws::GameLift::GameLiftClient> gameliftClient)
  131. {
  132. AZ_UNUSED(gameliftClient);
  133. m_gameliftClientMockPtr.reset();
  134. }
  135. AWSGameLiftSearchSessionsRequest GetValidSearchSessionsRequest()
  136. {
  137. AWSGameLiftSearchSessionsRequest request;
  138. request.m_aliasId = "dummyAliasId";
  139. request.m_fleetId = "dummyFleetId";
  140. request.m_location = "dummyLocation";
  141. request.m_filterExpression = "dummyFilterExpression";
  142. request.m_sortExpression = "dummySortExpression";
  143. request.m_maxResult = 1;
  144. request.m_nextToken = "dummyNextToken";
  145. return request;
  146. }
  147. Aws::GameLift::Model::SearchGameSessionsOutcome GetValidSearchGameSessionsOutcome()
  148. {
  149. Aws::GameLift::Model::GameProperty gameProperty;
  150. gameProperty.SetKey("dummyKey");
  151. gameProperty.SetValue("dummyValue");
  152. Aws::Vector<Aws::GameLift::Model::GameProperty> gameProperties = { gameProperty };
  153. Aws::GameLift::Model::GameSession gameSession;
  154. gameSession.SetCreationTime(Aws::Utils::DateTime(0.0));
  155. gameSession.SetTerminationTime(Aws::Utils::DateTime(0.0));
  156. gameSession.SetCreatorId("dummyCreatorId");
  157. gameSession.SetGameProperties(gameProperties);
  158. gameSession.SetGameSessionId("dummyGameSessionId");
  159. gameSession.SetName("dummyGameSessionName");
  160. gameSession.SetIpAddress("dummyIpAddress");
  161. gameSession.SetPort(0);
  162. gameSession.SetMaximumPlayerSessionCount(2);
  163. gameSession.SetCurrentPlayerSessionCount(1);
  164. gameSession.SetStatus(Aws::GameLift::Model::GameSessionStatus::TERMINATED);
  165. gameSession.SetStatusReason(Aws::GameLift::Model::GameSessionStatusReason::INTERRUPTED);
  166. // TODO: Update the AWS Native SDK to set the new game session attributes.
  167. // gameSession.SetDnsName("dummyDnsName");
  168. Aws::GameLift::Model::SearchGameSessionsResult result;
  169. result.SetNextToken("dummyNextToken");
  170. result.SetGameSessions({ gameSession });
  171. return Aws::GameLift::Model::SearchGameSessionsOutcome(result);
  172. }
  173. Multiplayer::SearchSessionsResponse GetValidSearchSessionsResponse()
  174. {
  175. Multiplayer::SessionConfig sessionConfig;
  176. sessionConfig.m_creationTime = 0;
  177. sessionConfig.m_terminationTime = 0;
  178. sessionConfig.m_creatorId = "dummyCreatorId";
  179. sessionConfig.m_sessionProperties["dummyKey"] = "dummyValue";
  180. sessionConfig.m_matchmakingData = "dummyMatchmakingData";
  181. sessionConfig.m_sessionId = "dummyGameSessionId";
  182. sessionConfig.m_sessionName = "dummyGameSessionName";
  183. sessionConfig.m_ipAddress = "dummyIpAddress";
  184. sessionConfig.m_port = 0;
  185. sessionConfig.m_maxPlayer = 2;
  186. sessionConfig.m_currentPlayer = 1;
  187. sessionConfig.m_status = "Terminated";
  188. sessionConfig.m_statusReason = "Interrupted";
  189. // TODO: Update the AWS Native SDK to set the new game session attributes.
  190. // sessionConfig.m_dnsName = "dummyDnsName";
  191. Multiplayer::SearchSessionsResponse response;
  192. response.m_nextToken = "dummyNextToken";
  193. response.m_sessionConfigs = { sessionConfig };
  194. return response;
  195. }
  196. AWSGameLiftStartMatchmakingRequest GetValidStartMatchmakingRequest()
  197. {
  198. AWSGameLiftStartMatchmakingRequest request;
  199. request.m_configurationName = "dummyConfiguration";
  200. request.m_ticketId = DummyMatchmakingTicketId;
  201. AWSGameLiftPlayer player;
  202. player.m_playerAttributes["dummy"] = "{\"N\": \"1\"}";
  203. player.m_playerId = DummyPlayerId;
  204. player.m_latencyInMs["us-east-1"] = 10;
  205. request.m_players.emplace_back(player);
  206. return request;
  207. }
  208. Aws::GameLift::Model::StartMatchmakingOutcome GetValidStartMatchmakingResponse()
  209. {
  210. Aws::GameLift::Model::MatchmakingTicket ticket;
  211. ticket.SetTicketId(DummyMatchmakingTicketId);
  212. Aws::GameLift::Model::StartMatchmakingResult result;
  213. result.SetMatchmakingTicket(ticket);
  214. Aws::GameLift::Model::StartMatchmakingOutcome outcome(result);
  215. return outcome;
  216. }
  217. static const char* const DummyMatchmakingTicketId;
  218. static const char* const DummyPlayerId;
  219. public:
  220. AZStd::unique_ptr<AWSGameLiftClientManager> m_gameliftClientManager;
  221. AZStd::shared_ptr<GameLiftClientMock> m_gameliftClientMockPtr;
  222. };
  223. const char* const AWSGameLiftClientManagerTest::DummyMatchmakingTicketId = "dummyTicketId";
  224. const char* const AWSGameLiftClientManagerTest::DummyPlayerId = "dummyPlayerId";
  225. TEST_F(AWSGameLiftClientManagerTest, ConfigureGameLiftClient_CallWithoutRegion_GetFalseAsResult)
  226. {
  227. AWSCoreRequestsHandlerMock coreHandlerMock;
  228. EXPECT_CALL(coreHandlerMock, GetDefaultConfig()).Times(1).WillOnce(nullptr);
  229. AZ_TEST_START_TRACE_SUPPRESSION;
  230. auto result = m_gameliftClientManager->ConfigureGameLiftClient("");
  231. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  232. EXPECT_FALSE(result);
  233. }
  234. TEST_F(AWSGameLiftClientManagerTest, ConfigureGameLiftClient_CallWithoutCredential_GetFalseAsResult)
  235. {
  236. AWSCoreRequestsHandlerMock coreHandlerMock;
  237. EXPECT_CALL(coreHandlerMock, GetDefaultConfig()).Times(1).WillOnce(nullptr);
  238. AWSResourceMappingRequestsHandlerMock handlerMock;
  239. EXPECT_CALL(handlerMock, GetDefaultRegion()).Times(1).WillOnce(::testing::Return("us-west-2"));
  240. AZ_TEST_START_TRACE_SUPPRESSION;
  241. auto result = m_gameliftClientManager->ConfigureGameLiftClient("");
  242. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  243. EXPECT_FALSE(result);
  244. }
  245. TEST_F(AWSGameLiftClientManagerTest, ConfigureGameLiftClient_CallWithRegionAndCredential_GetTrueAsResult)
  246. {
  247. AWSCoreRequestsHandlerMock coreHandlerMock;
  248. EXPECT_CALL(coreHandlerMock, GetDefaultConfig()).Times(1).WillOnce(nullptr);
  249. AWSCredentialRequestsHandlerMock handlerMock;
  250. EXPECT_CALL(handlerMock, GetCredentialsProvider())
  251. .Times(1)
  252. .WillOnce(::testing::Return(std::make_shared<Aws::Auth::SimpleAWSCredentialsProvider>("dummyAccess", "dummySecret", "")));
  253. auto result = m_gameliftClientManager->ConfigureGameLiftClient("us-west-2");
  254. EXPECT_TRUE(result);
  255. }
  256. TEST_F(AWSGameLiftClientManagerTest, CreatePlayerId_CreateWithoutBracketsOrDashes_GetExpectedResult)
  257. {
  258. auto result = m_gameliftClientManager->CreatePlayerId(false, false);
  259. EXPECT_FALSE(result.starts_with("{"));
  260. EXPECT_FALSE(result.ends_with("}"));
  261. EXPECT_FALSE(result.contains("-"));
  262. }
  263. TEST_F(AWSGameLiftClientManagerTest, CreatePlayerId_CreateWithBrackets_GetExpectedResult)
  264. {
  265. auto result = m_gameliftClientManager->CreatePlayerId(true, false);
  266. EXPECT_TRUE(result.starts_with("{"));
  267. EXPECT_TRUE(result.ends_with("}"));
  268. EXPECT_FALSE(result.contains("-"));
  269. }
  270. TEST_F(AWSGameLiftClientManagerTest, CreatePlayerId_CreateWithDashes_GetExpectedResult)
  271. {
  272. auto result = m_gameliftClientManager->CreatePlayerId(false, true);
  273. EXPECT_FALSE(result.starts_with("{"));
  274. EXPECT_FALSE(result.ends_with("}"));
  275. EXPECT_TRUE(result.contains("-"));
  276. }
  277. TEST_F(AWSGameLiftClientManagerTest, CreatePlayerId_CreateWithBracketsAndDashes_GetExpectedResult)
  278. {
  279. auto result = m_gameliftClientManager->CreatePlayerId(true, true);
  280. EXPECT_TRUE(result.starts_with("{"));
  281. EXPECT_TRUE(result.ends_with("}"));
  282. EXPECT_TRUE(result.contains("-"));
  283. }
  284. TEST_F(AWSGameLiftClientManagerTest, CreateSession_CallWithoutClientSetup_GetEmptyResponse)
  285. {
  286. AZ_TEST_START_TRACE_SUPPRESSION;
  287. m_gameliftClientManager->ConfigureGameLiftClient("");
  288. AWSGameLiftCreateSessionRequest request;
  289. request.m_aliasId = "dummyAlias";
  290. auto response = m_gameliftClientManager->CreateSession(request);
  291. AZ_TEST_STOP_TRACE_SUPPRESSION(2); // capture 2 error message
  292. EXPECT_TRUE(response == "");
  293. }
  294. TEST_F(AWSGameLiftClientManagerTest, CreateSession_CallWithInvalidRequest_GetEmptyResponse)
  295. {
  296. AZ_TEST_START_TRACE_SUPPRESSION;
  297. auto response = m_gameliftClientManager->CreateSession(Multiplayer::CreateSessionRequest());
  298. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  299. EXPECT_TRUE(response == "");
  300. }
  301. TEST_F(AWSGameLiftClientManagerTest, CreateSession_CallWithValidRequest_GetSuccessOutcome)
  302. {
  303. AWSGameLiftCreateSessionRequest request;
  304. request.m_aliasId = "dummyAlias";
  305. Aws::GameLift::Model::CreateGameSessionResult result;
  306. result.SetGameSession(Aws::GameLift::Model::GameSession());
  307. Aws::GameLift::Model::CreateGameSessionOutcome outcome(result);
  308. EXPECT_CALL(*m_gameliftClientMockPtr, CreateGameSession(::testing::_))
  309. .Times(1)
  310. .WillOnce(::testing::Return(outcome));
  311. m_gameliftClientManager->CreateSession(request);
  312. }
  313. TEST_F(AWSGameLiftClientManagerTest, CreateSession_CallWithValidRequest_GetErrorOutcome)
  314. {
  315. AWSGameLiftCreateSessionRequest request;
  316. request.m_aliasId = "dummyAlias";
  317. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  318. Aws::GameLift::Model::CreateGameSessionOutcome outcome(error);
  319. EXPECT_CALL(*m_gameliftClientMockPtr, CreateGameSession(::testing::_))
  320. .Times(1)
  321. .WillOnce(::testing::Return(outcome));
  322. AZ_TEST_START_TRACE_SUPPRESSION;
  323. m_gameliftClientManager->CreateSession(request);
  324. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  325. }
  326. TEST_F(AWSGameLiftClientManagerTest, CreateSessionAsync_CallWithInvalidRequest_GetNotificationWithEmptyResponse)
  327. {
  328. AZ_TEST_START_TRACE_SUPPRESSION;
  329. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  330. EXPECT_CALL(sessionHandlerMock, OnCreateSessionAsyncComplete(AZStd::string())).Times(1);
  331. m_gameliftClientManager->CreateSessionAsync(Multiplayer::CreateSessionRequest());
  332. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  333. }
  334. TEST_F(AWSGameLiftClientManagerTest, CreateSessionAsync_CallWithValidRequest_GetNotificationWithSuccessOutcome)
  335. {
  336. AWSCoreRequestsHandlerMock handlerMock;
  337. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  338. AWSGameLiftCreateSessionRequest request;
  339. request.m_aliasId = "dummyAlias";
  340. Aws::GameLift::Model::CreateGameSessionResult result;
  341. result.SetGameSession(Aws::GameLift::Model::GameSession());
  342. Aws::GameLift::Model::CreateGameSessionOutcome outcome(result);
  343. EXPECT_CALL(*m_gameliftClientMockPtr, CreateGameSession(::testing::_))
  344. .Times(1)
  345. .WillOnce(::testing::Return(outcome));
  346. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  347. EXPECT_CALL(sessionHandlerMock, OnCreateSessionAsyncComplete(::testing::_)).Times(1);
  348. m_gameliftClientManager->CreateSessionAsync(request);
  349. }
  350. TEST_F(AWSGameLiftClientManagerTest, CreateSessionAsync_CallWithValidRequest_GetNotificationWithErrorOutcome)
  351. {
  352. AWSCoreRequestsHandlerMock handlerMock;
  353. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  354. AWSGameLiftCreateSessionRequest request;
  355. request.m_aliasId = "dummyAlias";
  356. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  357. Aws::GameLift::Model::CreateGameSessionOutcome outcome(error);
  358. EXPECT_CALL(*m_gameliftClientMockPtr, CreateGameSession(::testing::_))
  359. .Times(1)
  360. .WillOnce(::testing::Return(outcome));
  361. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  362. EXPECT_CALL(sessionHandlerMock, OnCreateSessionAsyncComplete(AZStd::string(""))).Times(1);
  363. AZ_TEST_START_TRACE_SUPPRESSION;
  364. m_gameliftClientManager->CreateSessionAsync(request);
  365. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  366. }
  367. TEST_F(AWSGameLiftClientManagerTest, CreateSessionOnQueue_CallWithoutClientSetup_GetEmptyResponse)
  368. {
  369. AZ_TEST_START_TRACE_SUPPRESSION;
  370. m_gameliftClientManager->ConfigureGameLiftClient("");
  371. AWSGameLiftCreateSessionOnQueueRequest request;
  372. request.m_queueName = "dummyQueue";
  373. request.m_placementId = "dummyPlacementId";
  374. auto response = m_gameliftClientManager->CreateSession(request);
  375. AZ_TEST_STOP_TRACE_SUPPRESSION(2); // capture 2 error message
  376. EXPECT_TRUE(response == "");
  377. }
  378. TEST_F(AWSGameLiftClientManagerTest, CreateSessionOnQueue_CallWithValidRequest_GetSuccessOutcome)
  379. {
  380. AWSGameLiftCreateSessionOnQueueRequest request;
  381. request.m_queueName = "dummyQueue";
  382. request.m_placementId = "dummyPlacementId";
  383. Aws::GameLift::Model::StartGameSessionPlacementResult result;
  384. result.SetGameSessionPlacement(Aws::GameLift::Model::GameSessionPlacement());
  385. Aws::GameLift::Model::StartGameSessionPlacementOutcome outcome(result);
  386. EXPECT_CALL(*m_gameliftClientMockPtr, StartGameSessionPlacement(::testing::_))
  387. .Times(1)
  388. .WillOnce(::testing::Return(outcome));
  389. m_gameliftClientManager->CreateSession(request);
  390. }
  391. TEST_F(AWSGameLiftClientManagerTest, CreateSessionOnQueue_CallWithValidRequest_GetErrorOutcome)
  392. {
  393. AWSGameLiftCreateSessionOnQueueRequest request;
  394. request.m_queueName = "dummyQueue";
  395. request.m_placementId = "dummyPlacementId";
  396. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  397. Aws::GameLift::Model::StartGameSessionPlacementOutcome outcome(error);
  398. EXPECT_CALL(*m_gameliftClientMockPtr, StartGameSessionPlacement(::testing::_))
  399. .Times(1)
  400. .WillOnce(::testing::Return(outcome));
  401. AZ_TEST_START_TRACE_SUPPRESSION;
  402. m_gameliftClientManager->CreateSession(request);
  403. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  404. }
  405. TEST_F(AWSGameLiftClientManagerTest, CreateSessionOnQueueAsync_CallWithValidRequest_GetNotificationWithSuccessOutcome)
  406. {
  407. AWSCoreRequestsHandlerMock handlerMock;
  408. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  409. AWSGameLiftCreateSessionOnQueueRequest request;
  410. request.m_queueName = "dummyQueue";
  411. request.m_placementId = "dummyPlacementId";
  412. Aws::GameLift::Model::StartGameSessionPlacementResult result;
  413. result.SetGameSessionPlacement(Aws::GameLift::Model::GameSessionPlacement());
  414. Aws::GameLift::Model::StartGameSessionPlacementOutcome outcome(result);
  415. EXPECT_CALL(*m_gameliftClientMockPtr, StartGameSessionPlacement(::testing::_))
  416. .Times(1)
  417. .WillOnce(::testing::Return(outcome));
  418. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  419. EXPECT_CALL(sessionHandlerMock, OnCreateSessionAsyncComplete(::testing::_)).Times(1);
  420. m_gameliftClientManager->CreateSessionAsync(request);
  421. }
  422. TEST_F(AWSGameLiftClientManagerTest, CreateSessionOnQueueAsync_CallWithValidRequest_GetNotificationWithErrorOutcome)
  423. {
  424. AWSCoreRequestsHandlerMock handlerMock;
  425. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  426. AWSGameLiftCreateSessionOnQueueRequest request;
  427. request.m_queueName = "dummyQueue";
  428. request.m_placementId = "dummyPlacementId";
  429. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  430. Aws::GameLift::Model::StartGameSessionPlacementOutcome outcome(error);
  431. EXPECT_CALL(*m_gameliftClientMockPtr, StartGameSessionPlacement(::testing::_))
  432. .Times(1)
  433. .WillOnce(::testing::Return(outcome));
  434. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  435. EXPECT_CALL(sessionHandlerMock, OnCreateSessionAsyncComplete(AZStd::string(""))).Times(1);
  436. AZ_TEST_START_TRACE_SUPPRESSION;
  437. m_gameliftClientManager->CreateSessionAsync(request);
  438. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  439. }
  440. TEST_F(AWSGameLiftClientManagerTest, JoinSession_CallWithoutClientSetup_GetFalseResponse)
  441. {
  442. AZ_TEST_START_TRACE_SUPPRESSION;
  443. m_gameliftClientManager->ConfigureGameLiftClient("");
  444. AWSGameLiftJoinSessionRequest request;
  445. request.m_playerId = "dummyPlayerId";
  446. request.m_sessionId = "dummySessionId";
  447. auto response = m_gameliftClientManager->JoinSession(request);
  448. AZ_TEST_STOP_TRACE_SUPPRESSION(2); // capture 2 error message
  449. EXPECT_FALSE(response);
  450. }
  451. TEST_F(AWSGameLiftClientManagerTest, JoinSession_CallWithInvalidRequest_GetFalseResponse)
  452. {
  453. AZ_TEST_START_TRACE_SUPPRESSION;
  454. auto response = m_gameliftClientManager->JoinSession(Multiplayer::JoinSessionRequest());
  455. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  456. EXPECT_FALSE(response);
  457. }
  458. TEST_F(AWSGameLiftClientManagerTest, JoinSession_CallWithValidRequestButNoRequestHandler_GetSuccessOutcomeButFalseResponse)
  459. {
  460. AWSGameLiftJoinSessionRequest request;
  461. request.m_sessionId = "dummySessionId";
  462. request.m_playerId = "dummyPlayerId";
  463. Aws::GameLift::Model::CreatePlayerSessionResult result;
  464. result.SetPlayerSession(Aws::GameLift::Model::PlayerSession());
  465. Aws::GameLift::Model::CreatePlayerSessionOutcome outcome(result);
  466. EXPECT_CALL(*m_gameliftClientMockPtr, CreatePlayerSession(::testing::_))
  467. .Times(1)
  468. .WillOnce(::testing::Return(outcome));
  469. AZ_TEST_START_TRACE_SUPPRESSION;
  470. auto response = m_gameliftClientManager->JoinSession(request);
  471. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  472. EXPECT_FALSE(response);
  473. }
  474. TEST_F(AWSGameLiftClientManagerTest, JoinSession_CallWithValidRequest_GetErrorOutcomeAndFalseResponse)
  475. {
  476. AWSGameLiftJoinSessionRequest request;
  477. request.m_sessionId = "dummySessionId";
  478. request.m_playerId = "dummyPlayerId";
  479. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  480. Aws::GameLift::Model::CreatePlayerSessionOutcome outcome(error);
  481. EXPECT_CALL(*m_gameliftClientMockPtr, CreatePlayerSession(::testing::_))
  482. .Times(1)
  483. .WillOnce(::testing::Return(outcome));
  484. AZ_TEST_START_TRACE_SUPPRESSION;
  485. auto response = m_gameliftClientManager->JoinSession(request);
  486. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  487. EXPECT_FALSE(response);
  488. }
  489. TEST_F(AWSGameLiftClientManagerTest, JoinSession_CallWithValidRequestAndRequestHandler_GetSuccessOutcomeButFalseResponse)
  490. {
  491. SessionHandlingClientRequestsMock handlerMock;
  492. EXPECT_CALL(handlerMock, RequestPlayerJoinSession(::testing::_)).Times(1).WillOnce(::testing::Return(false));
  493. AWSGameLiftJoinSessionRequest request;
  494. request.m_sessionId = "dummySessionId";
  495. request.m_playerId = "dummyPlayerId";
  496. Aws::GameLift::Model::CreatePlayerSessionResult result;
  497. result.SetPlayerSession(Aws::GameLift::Model::PlayerSession());
  498. Aws::GameLift::Model::CreatePlayerSessionOutcome outcome(result);
  499. EXPECT_CALL(*m_gameliftClientMockPtr, CreatePlayerSession(::testing::_))
  500. .Times(1)
  501. .WillOnce(::testing::Return(outcome));
  502. auto response = m_gameliftClientManager->JoinSession(request);
  503. EXPECT_FALSE(response);
  504. }
  505. TEST_F(AWSGameLiftClientManagerTest, JoinSession_CallWithValidRequestAndRequestHandler_GetSuccessOutcomeAndTrueResponse)
  506. {
  507. SessionHandlingClientRequestsMock handlerMock;
  508. EXPECT_CALL(handlerMock, RequestPlayerJoinSession(::testing::_)).Times(1).WillOnce(::testing::Return(true));
  509. AWSGameLiftJoinSessionRequest request;
  510. request.m_sessionId = "dummySessionId";
  511. request.m_playerId = "dummyPlayerId";
  512. Aws::GameLift::Model::CreatePlayerSessionResult result;
  513. result.SetPlayerSession(Aws::GameLift::Model::PlayerSession());
  514. Aws::GameLift::Model::CreatePlayerSessionOutcome outcome(result);
  515. EXPECT_CALL(*m_gameliftClientMockPtr, CreatePlayerSession(::testing::_))
  516. .Times(1)
  517. .WillOnce(::testing::Return(outcome));
  518. auto response = m_gameliftClientManager->JoinSession(request);
  519. EXPECT_TRUE(response);
  520. }
  521. TEST_F(AWSGameLiftClientManagerTest, JoinSessionAsync_CallWithInvalidRequest_GetNotificationWithFalseResponse)
  522. {
  523. AZ_TEST_START_TRACE_SUPPRESSION;
  524. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  525. EXPECT_CALL(sessionHandlerMock, OnJoinSessionAsyncComplete(false)).Times(1);
  526. m_gameliftClientManager->JoinSessionAsync(Multiplayer::JoinSessionRequest());
  527. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  528. }
  529. TEST_F(AWSGameLiftClientManagerTest, JoinSessionAsync_CallWithValidRequestButNoRequestHandler_GetSuccessOutcomeButNotificationWithFalseResponse)
  530. {
  531. AWSCoreRequestsHandlerMock handlerMock;
  532. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  533. AWSGameLiftJoinSessionRequest request;
  534. request.m_sessionId = "dummySessionId";
  535. request.m_playerId = "dummyPlayerId";
  536. Aws::GameLift::Model::CreatePlayerSessionResult result;
  537. result.SetPlayerSession(Aws::GameLift::Model::PlayerSession());
  538. Aws::GameLift::Model::CreatePlayerSessionOutcome outcome(result);
  539. EXPECT_CALL(*m_gameliftClientMockPtr, CreatePlayerSession(::testing::_))
  540. .Times(1)
  541. .WillOnce(::testing::Return(outcome));
  542. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  543. EXPECT_CALL(sessionHandlerMock, OnJoinSessionAsyncComplete(false)).Times(1);
  544. AZ_TEST_START_TRACE_SUPPRESSION;
  545. m_gameliftClientManager->JoinSessionAsync(request);
  546. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  547. }
  548. TEST_F(AWSGameLiftClientManagerTest, JoinSessionAsync_CallWithValidRequest_GetErrorOutcomeAndNotificationWithFalseResponse)
  549. {
  550. AWSCoreRequestsHandlerMock handlerMock;
  551. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  552. AWSGameLiftJoinSessionRequest request;
  553. request.m_sessionId = "dummySessionId";
  554. request.m_playerId = "dummyPlayerId";
  555. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  556. Aws::GameLift::Model::CreatePlayerSessionOutcome outcome(error);
  557. EXPECT_CALL(*m_gameliftClientMockPtr, CreatePlayerSession(::testing::_))
  558. .Times(1)
  559. .WillOnce(::testing::Return(outcome));
  560. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  561. EXPECT_CALL(sessionHandlerMock, OnJoinSessionAsyncComplete(false)).Times(1);
  562. AZ_TEST_START_TRACE_SUPPRESSION;
  563. m_gameliftClientManager->JoinSessionAsync(request);
  564. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  565. }
  566. TEST_F(AWSGameLiftClientManagerTest, JoinSessionAsync_CallWithValidRequestAndRequestHandler_GetSuccessOutcomeButNotificationWithFalseResponse)
  567. {
  568. AWSCoreRequestsHandlerMock coreHandlerMock;
  569. EXPECT_CALL(coreHandlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  570. SessionHandlingClientRequestsMock handlerMock;
  571. EXPECT_CALL(handlerMock, RequestPlayerJoinSession(::testing::_)).Times(1).WillOnce(::testing::Return(false));
  572. AWSGameLiftJoinSessionRequest request;
  573. request.m_sessionId = "dummySessionId";
  574. request.m_playerId = "dummyPlayerId";
  575. Aws::GameLift::Model::CreatePlayerSessionResult result;
  576. result.SetPlayerSession(Aws::GameLift::Model::PlayerSession());
  577. Aws::GameLift::Model::CreatePlayerSessionOutcome outcome(result);
  578. EXPECT_CALL(*m_gameliftClientMockPtr, CreatePlayerSession(::testing::_))
  579. .Times(1)
  580. .WillOnce(::testing::Return(outcome));
  581. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  582. EXPECT_CALL(sessionHandlerMock, OnJoinSessionAsyncComplete(false)).Times(1);
  583. m_gameliftClientManager->JoinSessionAsync(request);
  584. }
  585. TEST_F(AWSGameLiftClientManagerTest, JoinSessionAsync_CallWithValidRequestAndRequestHandler_GetSuccessOutcomeAndNotificationWithTrueResponse)
  586. {
  587. AWSCoreRequestsHandlerMock coreHandlerMock;
  588. EXPECT_CALL(coreHandlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  589. SessionHandlingClientRequestsMock handlerMock;
  590. EXPECT_CALL(handlerMock, RequestPlayerJoinSession(::testing::_)).Times(1).WillOnce(::testing::Return(true));
  591. AWSGameLiftJoinSessionRequest request;
  592. request.m_sessionId = "dummySessionId";
  593. request.m_playerId = "dummyPlayerId";
  594. Aws::GameLift::Model::CreatePlayerSessionResult result;
  595. result.SetPlayerSession(Aws::GameLift::Model::PlayerSession());
  596. Aws::GameLift::Model::CreatePlayerSessionOutcome outcome(result);
  597. EXPECT_CALL(*m_gameliftClientMockPtr, CreatePlayerSession(::testing::_))
  598. .Times(1)
  599. .WillOnce(::testing::Return(outcome));
  600. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  601. EXPECT_CALL(sessionHandlerMock, OnJoinSessionAsyncComplete(true)).Times(1);
  602. m_gameliftClientManager->JoinSessionAsync(request);
  603. }
  604. TEST_F(AWSGameLiftClientManagerTest, SearchSessions_CallWithValidRequestAndErrorOutcome_GetErrorWithEmptyResponse)
  605. {
  606. AWSGameLiftSearchSessionsRequest request = GetValidSearchSessionsRequest();
  607. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  608. Aws::GameLift::Model::SearchGameSessionsOutcome outcome(error);
  609. EXPECT_CALL(*m_gameliftClientMockPtr, SearchGameSessions(::testing::_))
  610. .Times(1)
  611. .WillOnce(::testing::Return(outcome));
  612. AZ_TEST_START_TRACE_SUPPRESSION;
  613. auto result = m_gameliftClientManager->SearchSessions(request);
  614. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  615. EXPECT_TRUE(result.m_sessionConfigs.size() == 0);
  616. }
  617. TEST_F(AWSGameLiftClientManagerTest, SearchSessions_CallWithValidRequestAndSuccessOutcome_GetNotificationWithValidResponse)
  618. {
  619. AWSGameLiftSearchSessionsRequest request = GetValidSearchSessionsRequest();
  620. Aws::GameLift::Model::SearchGameSessionsOutcome outcome = GetValidSearchGameSessionsOutcome();
  621. EXPECT_CALL(*m_gameliftClientMockPtr, SearchGameSessions(::testing::_))
  622. .Times(1)
  623. .WillOnce(::testing::Return(outcome));
  624. Multiplayer::SearchSessionsResponse expectedResponse = GetValidSearchSessionsResponse();
  625. auto result = m_gameliftClientManager->SearchSessions(request);
  626. EXPECT_TRUE(result.m_sessionConfigs.size() != 0);
  627. }
  628. TEST_F(AWSGameLiftClientManagerTest, SearchSessionsAsync_CallWithoutClientSetup_GetErrorWithEmptyResponse)
  629. {
  630. AZ_TEST_START_TRACE_SUPPRESSION;
  631. EXPECT_FALSE(m_gameliftClientManager->ConfigureGameLiftClient(""));
  632. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  633. AWSGameLiftSearchSessionsRequest request = GetValidSearchSessionsRequest();
  634. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  635. EXPECT_CALL(sessionHandlerMock,
  636. OnSearchSessionsAsyncComplete(SearchSessionsResponseMatcher(Multiplayer::SearchSessionsResponse()))).Times(1);
  637. AZ_TEST_START_TRACE_SUPPRESSION;
  638. m_gameliftClientManager->SearchSessionsAsync(request);
  639. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  640. }
  641. TEST_F(AWSGameLiftClientManagerTest, SearchSessionsAsync_CallWithInvalidRequest_GetErrorWithEmptyResponse)
  642. {
  643. AZ_TEST_START_TRACE_SUPPRESSION;
  644. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  645. EXPECT_CALL(sessionHandlerMock,
  646. OnSearchSessionsAsyncComplete(SearchSessionsResponseMatcher(Multiplayer::SearchSessionsResponse()))).Times(1);
  647. m_gameliftClientManager->SearchSessionsAsync(Multiplayer::SearchSessionsRequest());
  648. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  649. }
  650. TEST_F(AWSGameLiftClientManagerTest, SearchSessionsAsync_CallWithValidRequestAndErrorOutcome_GetErrorWithEmptyResponse)
  651. {
  652. AWSGameLiftSearchSessionsRequest request = GetValidSearchSessionsRequest();
  653. AWSCoreRequestsHandlerMock handlerMock;
  654. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  655. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  656. Aws::GameLift::Model::SearchGameSessionsOutcome outcome(error);
  657. EXPECT_CALL(*m_gameliftClientMockPtr, SearchGameSessions(::testing::_))
  658. .Times(1)
  659. .WillOnce(::testing::Return(outcome));
  660. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  661. EXPECT_CALL(sessionHandlerMock,
  662. OnSearchSessionsAsyncComplete(SearchSessionsResponseMatcher(Multiplayer::SearchSessionsResponse()))).Times(1);
  663. AZ_TEST_START_TRACE_SUPPRESSION;
  664. m_gameliftClientManager->SearchSessionsAsync(request);
  665. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  666. }
  667. TEST_F(AWSGameLiftClientManagerTest, SearchSessionsAsync_CallWithValidRequestAndSuccessOutcome_GetNotificationWithValidResponse)
  668. {
  669. AWSGameLiftSearchSessionsRequest request = GetValidSearchSessionsRequest();
  670. AWSCoreRequestsHandlerMock coreHandlerMock;
  671. EXPECT_CALL(coreHandlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  672. Aws::GameLift::Model::SearchGameSessionsOutcome outcome = GetValidSearchGameSessionsOutcome();
  673. EXPECT_CALL(*m_gameliftClientMockPtr, SearchGameSessions(::testing::_))
  674. .Times(1)
  675. .WillOnce(::testing::Return(outcome));
  676. Multiplayer::SearchSessionsResponse expectedResponse = GetValidSearchSessionsResponse();
  677. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  678. EXPECT_CALL(sessionHandlerMock,
  679. OnSearchSessionsAsyncComplete(SearchSessionsResponseMatcher(expectedResponse))).Times(1);
  680. m_gameliftClientManager->SearchSessionsAsync(request);
  681. }
  682. TEST_F(AWSGameLiftClientManagerTest, LeaveSession_CallWithInterfaceNotRegistered_GetExpectedError)
  683. {
  684. AZ_TEST_START_TRACE_SUPPRESSION;
  685. m_gameliftClientManager->LeaveSession();
  686. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  687. }
  688. TEST_F(AWSGameLiftClientManagerTest, LeaveSession_CallWithInterfaceRegistered_LeaveSessionRequestSent)
  689. {
  690. SessionHandlingClientRequestsMock handlerMock;
  691. EXPECT_CALL(handlerMock, RequestPlayerLeaveSession).Times(1);
  692. m_gameliftClientManager->LeaveSession();
  693. }
  694. TEST_F(AWSGameLiftClientManagerTest, LeaveSessionAsync_CallWithInterfaceNotRegistered_GetExpectedError)
  695. {
  696. AZ_TEST_START_TRACE_SUPPRESSION;
  697. m_gameliftClientManager->LeaveSessionAsync();
  698. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  699. }
  700. TEST_F(AWSGameLiftClientManagerTest, LeaveSessionAsync_CallWithInterfaceRegistered_LeaveSessionAsyncRequestSentAndGetNotification)
  701. {
  702. SessionHandlingClientRequestsMock handlerMock;
  703. EXPECT_CALL(handlerMock, RequestPlayerLeaveSession).Times(1);
  704. SessionAsyncRequestNotificationsHandlerMock sessionHandlerMock;
  705. EXPECT_CALL(sessionHandlerMock, OnLeaveSessionAsyncComplete()).Times(1);
  706. m_gameliftClientManager->LeaveSessionAsync();
  707. }
  708. TEST_F(AWSGameLiftClientManagerTest, StartMatchmaking_CallWithoutClientSetup_GetFalseResponse)
  709. {
  710. AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
  711. AZ_TEST_START_TRACE_SUPPRESSION;
  712. m_gameliftClientManager->ConfigureGameLiftClient("");
  713. AZStd::string response = m_gameliftClientManager->StartMatchmaking(request);
  714. AZ_TEST_STOP_TRACE_SUPPRESSION(2); // capture 2 error message
  715. EXPECT_TRUE(response.empty());
  716. }
  717. TEST_F(AWSGameLiftClientManagerTest, StartMatchmaking_CallWithInvalidRequest_GetErrorWithEmptyResponse)
  718. {
  719. AWSGameLiftStartMatchmakingRequest request;
  720. request.m_configurationName = "dummyConfiguration";
  721. AWSGameLiftPlayer player;
  722. player.m_playerAttributes["dummy"] = "{\"A\": \"1\"}";
  723. request.m_players.emplace_back(player);
  724. AZ_TEST_START_TRACE_SUPPRESSION;
  725. AZStd::string response = m_gameliftClientManager->StartMatchmaking(request);
  726. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  727. EXPECT_TRUE(response.empty());
  728. }
  729. TEST_F(AWSGameLiftClientManagerTest, StartMatchmaking_CallWithValidRequest_GetSuccessOutcome)
  730. {
  731. AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
  732. Aws::GameLift::Model::StartMatchmakingOutcome outcome = GetValidStartMatchmakingResponse();
  733. EXPECT_CALL(*m_gameliftClientMockPtr, StartMatchmaking(::testing::_))
  734. .Times(1)
  735. .WillOnce(::testing::Return(outcome));
  736. AZStd::string response = m_gameliftClientManager->StartMatchmaking(request);
  737. EXPECT_EQ(response, DummyMatchmakingTicketId);
  738. }
  739. TEST_F(AWSGameLiftClientManagerTest, StartMatchmaking_CallWithValidRequest_GetErrorOutcome)
  740. {
  741. AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
  742. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  743. Aws::GameLift::Model::StartMatchmakingOutcome outcome(error);
  744. EXPECT_CALL(*m_gameliftClientMockPtr, StartMatchmaking(::testing::_))
  745. .Times(1)
  746. .WillOnce(::testing::Return(outcome));
  747. AZ_TEST_START_TRACE_SUPPRESSION;
  748. m_gameliftClientManager->StartMatchmaking(request);
  749. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  750. }
  751. TEST_F(AWSGameLiftClientManagerTest, StartMatchmakingAsync_CallWithInvalidRequest_GetNotificationWithErrorOutcome)
  752. {
  753. AWSGameLiftStartMatchmakingRequest request;
  754. request.m_configurationName = "dummyConfiguration";
  755. AWSGameLiftPlayer player;
  756. player.m_playerAttributes["dummy"] = "{\"A\": \"1\"}";
  757. request.m_players.emplace_back(player);
  758. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  759. EXPECT_CALL(matchmakingHandlerMock, OnStartMatchmakingAsyncComplete(AZStd::string{})).Times(1);
  760. AZ_TEST_START_TRACE_SUPPRESSION;
  761. m_gameliftClientManager->StartMatchmakingAsync(request);
  762. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  763. }
  764. TEST_F(AWSGameLiftClientManagerTest, StartMatchmakingAsync_CallWithValidRequest_GetNotificationWithSuccessOutcome)
  765. {
  766. AWSCoreRequestsHandlerMock handlerMock;
  767. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  768. AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
  769. Aws::GameLift::Model::StartMatchmakingOutcome outcome = GetValidStartMatchmakingResponse();
  770. EXPECT_CALL(*m_gameliftClientMockPtr, StartMatchmaking(::testing::_))
  771. .Times(1)
  772. .WillOnce(::testing::Return(outcome));
  773. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  774. EXPECT_CALL(matchmakingHandlerMock, OnStartMatchmakingAsyncComplete(AZStd::string(DummyMatchmakingTicketId))).Times(1);
  775. m_gameliftClientManager->StartMatchmakingAsync(request);
  776. }
  777. TEST_F(AWSGameLiftClientManagerTest, StartMatchmakingAsync_CallWithValidRequest_GetNotificationWithErrorOutcome)
  778. {
  779. AWSCoreRequestsHandlerMock handlerMock;
  780. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  781. AWSGameLiftStartMatchmakingRequest request = GetValidStartMatchmakingRequest();
  782. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  783. Aws::GameLift::Model::StartMatchmakingOutcome outcome(error);
  784. EXPECT_CALL(*m_gameliftClientMockPtr, StartMatchmaking(::testing::_))
  785. .Times(1)
  786. .WillOnce(::testing::Return(outcome));
  787. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  788. EXPECT_CALL(matchmakingHandlerMock, OnStartMatchmakingAsyncComplete(AZStd::string{})).Times(1);
  789. AZ_TEST_START_TRACE_SUPPRESSION;
  790. m_gameliftClientManager->StartMatchmakingAsync(request);
  791. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  792. }
  793. TEST_F(AWSGameLiftClientManagerTest, StopMatchmaking_CallWithoutClientSetup_GetError)
  794. {
  795. AZ_TEST_START_TRACE_SUPPRESSION;
  796. m_gameliftClientManager->ConfigureGameLiftClient("");
  797. AWSGameLiftStopMatchmakingRequest request;
  798. request.m_ticketId = DummyMatchmakingTicketId;
  799. m_gameliftClientManager->StopMatchmaking(request);
  800. AZ_TEST_STOP_TRACE_SUPPRESSION(2); // capture 2 error message
  801. }
  802. TEST_F(AWSGameLiftClientManagerTest, StopMatchmaking_CallWithInvalidRequest_GetError)
  803. {
  804. AZ_TEST_START_TRACE_SUPPRESSION;
  805. m_gameliftClientManager->StopMatchmaking(Multiplayer::StopMatchmakingRequest());
  806. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  807. }
  808. TEST_F(AWSGameLiftClientManagerTest, StopMatchmaking_CallWithValidRequest_Success)
  809. {
  810. AWSGameLiftStopMatchmakingRequest request;
  811. request.m_ticketId = DummyMatchmakingTicketId;
  812. Aws::GameLift::Model::StopMatchmakingResult result;
  813. Aws::GameLift::Model::StopMatchmakingResult outcome(result);
  814. EXPECT_CALL(*m_gameliftClientMockPtr, StopMatchmaking(::testing::_))
  815. .Times(1)
  816. .WillOnce(::testing::Return(outcome));
  817. m_gameliftClientManager->StopMatchmaking(request);
  818. }
  819. TEST_F(AWSGameLiftClientManagerTest, StopMatchmaking_CallWithValidRequest_GetError)
  820. {
  821. AWSGameLiftStopMatchmakingRequest request;
  822. request.m_ticketId = DummyMatchmakingTicketId;
  823. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  824. Aws::GameLift::Model::StopMatchmakingOutcome outcome(error);
  825. EXPECT_CALL(*m_gameliftClientMockPtr, StopMatchmaking(::testing::_))
  826. .Times(1)
  827. .WillOnce(::testing::Return(outcome));
  828. AZ_TEST_START_TRACE_SUPPRESSION;
  829. m_gameliftClientManager->StopMatchmaking(request);
  830. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  831. }
  832. TEST_F(AWSGameLiftClientManagerTest, StopMatchmakingAsync_CallWithInvalidRequest_GetNotificationWithError)
  833. {
  834. AWSGameLiftStopMatchmakingRequest request;
  835. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  836. EXPECT_CALL(matchmakingHandlerMock, OnStopMatchmakingAsyncComplete()).Times(1);
  837. AZ_TEST_START_TRACE_SUPPRESSION;
  838. m_gameliftClientManager->StopMatchmakingAsync(request);
  839. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  840. }
  841. TEST_F(AWSGameLiftClientManagerTest, StopMatchmakingAsync_CallWithValidRequest_GetNotification)
  842. {
  843. AWSCoreRequestsHandlerMock handlerMock;
  844. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  845. AWSGameLiftStopMatchmakingRequest request;
  846. request.m_ticketId = DummyMatchmakingTicketId;
  847. Aws::GameLift::Model::StopMatchmakingResult result;
  848. Aws::GameLift::Model::StopMatchmakingOutcome outcome(result);
  849. EXPECT_CALL(*m_gameliftClientMockPtr, StopMatchmaking(::testing::_))
  850. .Times(1)
  851. .WillOnce(::testing::Return(outcome));
  852. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  853. EXPECT_CALL(matchmakingHandlerMock, OnStopMatchmakingAsyncComplete()).Times(1);
  854. m_gameliftClientManager->StopMatchmakingAsync(request);
  855. }
  856. TEST_F(AWSGameLiftClientManagerTest, StopMatchmakingAsync_CallWithValidRequest_GetNotificationWithError)
  857. {
  858. AWSCoreRequestsHandlerMock handlerMock;
  859. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  860. AWSGameLiftStopMatchmakingRequest request;
  861. request.m_ticketId = DummyMatchmakingTicketId;
  862. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  863. Aws::GameLift::Model::StopMatchmakingOutcome outcome(error);
  864. EXPECT_CALL(*m_gameliftClientMockPtr, StopMatchmaking(::testing::_))
  865. .Times(1)
  866. .WillOnce(::testing::Return(outcome));
  867. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  868. EXPECT_CALL(matchmakingHandlerMock, OnStopMatchmakingAsyncComplete()).Times(1);
  869. AZ_TEST_START_TRACE_SUPPRESSION;
  870. m_gameliftClientManager->StopMatchmakingAsync(request);
  871. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  872. }
  873. TEST_F(AWSGameLiftClientManagerTest, AcceptMatch_CallWithoutClientSetup_GetError)
  874. {
  875. AZ_TEST_START_TRACE_SUPPRESSION;
  876. m_gameliftClientManager->ConfigureGameLiftClient("");
  877. AWSGameLiftAcceptMatchRequest request;
  878. request.m_acceptMatch = true;
  879. request.m_playerIds = { DummyPlayerId };
  880. request.m_ticketId = DummyMatchmakingTicketId;
  881. m_gameliftClientManager->AcceptMatch(request);
  882. AZ_TEST_STOP_TRACE_SUPPRESSION(2); // capture 2 error message
  883. }
  884. TEST_F(AWSGameLiftClientManagerTest, AcceptMatch_CallWithInvalidRequest_GetError)
  885. {
  886. AZ_TEST_START_TRACE_SUPPRESSION;
  887. m_gameliftClientManager->AcceptMatch(Multiplayer::AcceptMatchRequest());
  888. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  889. }
  890. TEST_F(AWSGameLiftClientManagerTest, AcceptMatch_CallWithValidRequest_Success)
  891. {
  892. AWSGameLiftAcceptMatchRequest request;
  893. request.m_acceptMatch = true;
  894. request.m_playerIds = { DummyPlayerId };
  895. request.m_ticketId = DummyMatchmakingTicketId;
  896. Aws::GameLift::Model::AcceptMatchResult result;
  897. Aws::GameLift::Model::AcceptMatchResult outcome(result);
  898. EXPECT_CALL(*m_gameliftClientMockPtr, AcceptMatch(::testing::_)).Times(1).WillOnce(::testing::Return(outcome));
  899. m_gameliftClientManager->AcceptMatch(request);
  900. }
  901. TEST_F(AWSGameLiftClientManagerTest, AcceptMatch_CallWithValidRequest_GetError)
  902. {
  903. AWSGameLiftAcceptMatchRequest request;
  904. request.m_acceptMatch = true;
  905. request.m_playerIds = { DummyPlayerId };
  906. request.m_ticketId = DummyMatchmakingTicketId;
  907. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  908. Aws::GameLift::Model::AcceptMatchOutcome outcome(error);
  909. EXPECT_CALL(*m_gameliftClientMockPtr, AcceptMatch(::testing::_)).Times(1).WillOnce(::testing::Return(outcome));
  910. AZ_TEST_START_TRACE_SUPPRESSION;
  911. m_gameliftClientManager->AcceptMatch(request);
  912. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  913. }
  914. TEST_F(AWSGameLiftClientManagerTest, AcceptMatchAsync_CallWithInvalidRequest_GetNotificationWithError)
  915. {
  916. AWSGameLiftAcceptMatchRequest request;
  917. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  918. EXPECT_CALL(matchmakingHandlerMock, OnAcceptMatchAsyncComplete()).Times(1);
  919. AZ_TEST_START_TRACE_SUPPRESSION;
  920. m_gameliftClientManager->AcceptMatchAsync(request);
  921. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  922. }
  923. TEST_F(AWSGameLiftClientManagerTest, AcceptMatchAsync_CallWithValidRequest_GetNotification)
  924. {
  925. AWSCoreRequestsHandlerMock handlerMock;
  926. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  927. AWSGameLiftAcceptMatchRequest request;
  928. request.m_acceptMatch = true;
  929. request.m_playerIds = { DummyPlayerId };
  930. request.m_ticketId = DummyMatchmakingTicketId;
  931. Aws::GameLift::Model::AcceptMatchResult result;
  932. Aws::GameLift::Model::AcceptMatchOutcome outcome(result);
  933. EXPECT_CALL(*m_gameliftClientMockPtr, AcceptMatch(::testing::_)).Times(1).WillOnce(::testing::Return(outcome));
  934. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  935. EXPECT_CALL(matchmakingHandlerMock, OnAcceptMatchAsyncComplete()).Times(1);
  936. m_gameliftClientManager->AcceptMatchAsync(request);
  937. }
  938. TEST_F(AWSGameLiftClientManagerTest, AcceptMatchAsync_CallWithValidRequest_GetNotificationWithError)
  939. {
  940. AWSCoreRequestsHandlerMock handlerMock;
  941. EXPECT_CALL(handlerMock, GetDefaultJobContext()).Times(1).WillOnce(::testing::Return(m_jobContext.get()));
  942. AWSGameLiftAcceptMatchRequest request;
  943. request.m_acceptMatch = true;
  944. request.m_playerIds = { DummyPlayerId };
  945. request.m_ticketId = DummyMatchmakingTicketId;
  946. Aws::Client::AWSError<Aws::GameLift::GameLiftErrors> error;
  947. Aws::GameLift::Model::AcceptMatchOutcome outcome(error);
  948. EXPECT_CALL(*m_gameliftClientMockPtr, AcceptMatch(::testing::_)).Times(1).WillOnce(::testing::Return(outcome));
  949. MatchmakingAsyncRequestNotificationsHandlerMock matchmakingHandlerMock;
  950. EXPECT_CALL(matchmakingHandlerMock, OnAcceptMatchAsyncComplete()).Times(1);
  951. AZ_TEST_START_TRACE_SUPPRESSION;
  952. m_gameliftClientManager->AcceptMatchAsync(request);
  953. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  954. }