AWSGameLiftSearchSessionsActivityTest.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <AzFramework/Session/SessionConfig.h>
  13. #include <Activity/AWSGameLiftSearchSessionsActivity.h>
  14. #include <AWSGameLiftClientFixture.h>
  15. #include <AWSGameLiftSessionConstants.h>
  16. using namespace AWSGameLift;
  17. using AWSGameLiftSearchSessionsActivityTest = AWSGameLiftClientFixture;
  18. TEST_F(AWSGameLiftSearchSessionsActivityTest, BuildAWSGameLiftSearchGameSessionsRequest_Call_GetExpectedResult)
  19. {
  20. AWSGameLiftSearchSessionsRequest request;
  21. request.m_aliasId = "dummyAliasId";
  22. request.m_fleetId = "dummyFleetId";
  23. request.m_location = "dummyLocation";
  24. request.m_filterExpression = "dummyFilterExpression";
  25. request.m_sortExpression = "dummySortExpression";
  26. request.m_maxResult = 1;
  27. request.m_nextToken = "dummyNextToken";
  28. auto awsRequest = SearchSessionsActivity::BuildAWSGameLiftSearchGameSessionsRequest(request);
  29. EXPECT_TRUE(strcmp(awsRequest.GetFleetId().c_str(), request.m_fleetId.c_str()) == 0);
  30. EXPECT_TRUE(strcmp(awsRequest.GetAliasId().c_str(), request.m_aliasId.c_str()) == 0);
  31. EXPECT_TRUE(strcmp(awsRequest.GetFilterExpression().c_str(), request.m_filterExpression.c_str()) == 0);
  32. EXPECT_TRUE(strcmp(awsRequest.GetSortExpression().c_str(), request.m_sortExpression.c_str()) == 0);
  33. EXPECT_TRUE(awsRequest.GetLimit() == request.m_maxResult);
  34. EXPECT_TRUE(strcmp(awsRequest.GetNextToken().c_str(), request.m_nextToken.c_str()) == 0);
  35. // TODO: Update the AWS Native SDK to get the new request attributes.
  36. //EXPECT_TRUE(strcmp(awsRequest.GetLocation().c_str(), request.m_location.c_str()) == 0);
  37. }
  38. TEST_F(AWSGameLiftSearchSessionsActivityTest, ValidateSearchSessionsRequest_CallWithBaseType_GetFalseResult)
  39. {
  40. AZ_TEST_START_TRACE_SUPPRESSION;
  41. auto result = SearchSessionsActivity::ValidateSearchSessionsRequest(AzFramework::SearchSessionsRequest());
  42. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  43. EXPECT_FALSE(result);
  44. }
  45. TEST_F(AWSGameLiftSearchSessionsActivityTest, ValidateSearchSessionsRequest_CallWithoutAliasOrFleetId_GetFalseResult)
  46. {
  47. AWSGameLiftSearchSessionsRequest request;
  48. AZ_TEST_START_TRACE_SUPPRESSION;
  49. auto result = SearchSessionsActivity::ValidateSearchSessionsRequest(request);
  50. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  51. EXPECT_FALSE(result);
  52. }
  53. TEST_F(AWSGameLiftSearchSessionsActivityTest, ValidateSearchSessionsRequest_CallWithAliasId_GetTrueResult)
  54. {
  55. AWSGameLiftSearchSessionsRequest request;
  56. request.m_aliasId = "dummyAliasId";
  57. auto result = SearchSessionsActivity::ValidateSearchSessionsRequest(request);
  58. EXPECT_TRUE(result);
  59. }
  60. TEST_F(AWSGameLiftSearchSessionsActivityTest, ValidateSearchSessionsRequest_CallWithFleetId_GetTrueResult)
  61. {
  62. AWSGameLiftSearchSessionsRequest request;
  63. request.m_fleetId = "dummyFleetId";
  64. auto result = SearchSessionsActivity::ValidateSearchSessionsRequest(request);
  65. EXPECT_TRUE(result);
  66. }
  67. TEST_F(AWSGameLiftSearchSessionsActivityTest, ParseResponse_Call_GetExpectedResult)
  68. {
  69. Aws::GameLift::Model::GameProperty gameProperty;
  70. gameProperty.SetKey("dummyKey");
  71. gameProperty.SetValue("dummyValue");
  72. Aws::Vector<Aws::GameLift::Model::GameProperty> gameProperties = { gameProperty };
  73. Aws::GameLift::Model::GameSession gameSession;
  74. gameSession.SetCreationTime(Aws::Utils::DateTime(0.0));
  75. gameSession.SetTerminationTime(Aws::Utils::DateTime(0.0));
  76. gameSession.SetCreatorId("dummyCreatorId");
  77. gameSession.SetGameProperties(gameProperties);
  78. gameSession.SetGameSessionId("dummyGameSessionId");
  79. gameSession.SetName("dummyGameSessionName");
  80. gameSession.SetIpAddress("dummyIpAddress");
  81. gameSession.SetPort(0);
  82. gameSession.SetMaximumPlayerSessionCount(2);
  83. gameSession.SetCurrentPlayerSessionCount(1);
  84. gameSession.SetStatus(Aws::GameLift::Model::GameSessionStatus::TERMINATED);
  85. gameSession.SetStatusReason(Aws::GameLift::Model::GameSessionStatusReason::INTERRUPTED);
  86. // TODO: Update the AWS Native SDK to set the new game session attributes.
  87. //gameSession.SetDnsName("dummyDnsName");
  88. Aws::Vector<Aws::GameLift::Model::GameSession> gameSessions = { gameSession };
  89. Aws::GameLift::Model::SearchGameSessionsResult result;
  90. result.SetNextToken("dummyNextToken");
  91. result.SetGameSessions(gameSessions);
  92. auto response = SearchSessionsActivity::ParseResponse(result);
  93. EXPECT_TRUE(strcmp(response.m_nextToken.c_str(), result.GetNextToken().c_str()) == 0);
  94. EXPECT_EQ(response.m_sessionConfigs.size(), 1);
  95. const auto& sessionConfig = response.m_sessionConfigs[0];
  96. EXPECT_EQ(gameSession.GetCreationTime().Millis(), sessionConfig.m_creationTime);
  97. EXPECT_EQ(gameSession.GetTerminationTime().Millis(), sessionConfig.m_terminationTime);
  98. EXPECT_TRUE(strcmp(gameSession.GetCreatorId().c_str(), sessionConfig.m_creatorId.c_str()) == 0);
  99. EXPECT_TRUE(strcmp(gameSession.GetGameSessionId().c_str(), sessionConfig.m_sessionId.c_str()) == 0);
  100. EXPECT_TRUE(strcmp(gameSession.GetName().c_str(), sessionConfig.m_sessionName.c_str()) == 0);
  101. EXPECT_TRUE(strcmp(gameSession.GetIpAddress().c_str(), sessionConfig.m_ipAddress.c_str()) == 0);
  102. EXPECT_EQ(gameSession.GetPort(), 0);
  103. EXPECT_EQ(gameSession.GetMaximumPlayerSessionCount(), 2);
  104. EXPECT_EQ(gameSession.GetCurrentPlayerSessionCount(), 1);
  105. EXPECT_TRUE(strcmp(AWSGameLiftSessionStatusNames[(int)gameSession.GetStatus()], sessionConfig.m_status.c_str()) == 0);
  106. EXPECT_TRUE(strcmp(AWSGameLiftSessionStatusReasons[(int)gameSession.GetStatusReason()], sessionConfig.m_statusReason.c_str()) == 0);
  107. // TODO: Update the AWS Native SDK to get the new game session attributes.
  108. // EXPECT_TRUE(strcmp(gameSession.GetDnsName().c_str(), sessionConfig.m_dnsName.c_str()) == 0);
  109. }