AWSScriptBehaviorDynamoDBTest.cpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/RTTI/BehaviorContext.h>
  9. #include <ScriptCanvas/AWSScriptBehaviorDynamoDB.h>
  10. #include <TestFramework/AWSCoreFixture.h>
  11. using namespace AWSCore;
  12. class AWSScriptBehaviorDynamoDBNotificationBusHandlerMock
  13. : public AWSScriptBehaviorDynamoDBNotificationBusHandler
  14. {
  15. public:
  16. AZ_CLASS_ALLOCATOR(AWSScriptBehaviorDynamoDBNotificationBusHandlerMock, AZ::SystemAllocator)
  17. AWSScriptBehaviorDynamoDBNotificationBusHandlerMock()
  18. {
  19. AWSScriptBehaviorDynamoDBNotificationBus::Handler::BusConnect();
  20. }
  21. ~AWSScriptBehaviorDynamoDBNotificationBusHandlerMock() override
  22. {
  23. AWSScriptBehaviorDynamoDBNotificationBus::Handler::BusDisconnect();
  24. }
  25. MOCK_METHOD1(OnGetItemSuccess, void(const DynamoDBAttributeValueMap&));
  26. MOCK_METHOD1(OnGetItemError, void(const AZStd::string&));
  27. };
  28. using AWSScriptBehaviorDynamoDBTest = AWSCoreFixture;
  29. TEST_F(AWSScriptBehaviorDynamoDBTest, GetItemRaw_CallWithEmptyTableName_InvokeOnError)
  30. {
  31. AWSScriptBehaviorDynamoDBNotificationBusHandlerMock dynamodbHandlerMock;
  32. EXPECT_CALL(dynamodbHandlerMock, OnGetItemError(::testing::_)).Times(1);
  33. DynamoDBAttributeValueMap dummyMap;
  34. AWSScriptBehaviorDynamoDB::GetItemRaw("", dummyMap, "dummyRegion");
  35. }
  36. TEST_F(AWSScriptBehaviorDynamoDBTest, GetItemRaw_CallWithEmptyKeyMap_InvokeOnError)
  37. {
  38. AWSScriptBehaviorDynamoDBNotificationBusHandlerMock dynamodbHandlerMock;
  39. EXPECT_CALL(dynamodbHandlerMock, OnGetItemError(::testing::_)).Times(1);
  40. DynamoDBAttributeValueMap dummyMap;
  41. AWSScriptBehaviorDynamoDB::GetItemRaw("dummyTable", dummyMap, "dummyRegion");
  42. }
  43. TEST_F(AWSScriptBehaviorDynamoDBTest, GetItemRaw_CallWithInvalidKeyMap_InvokeOnError)
  44. {
  45. AWSScriptBehaviorDynamoDBNotificationBusHandlerMock dynamodbHandlerMock;
  46. EXPECT_CALL(dynamodbHandlerMock, OnGetItemError(::testing::_)).Times(1);
  47. DynamoDBAttributeValueMap dummyMap;
  48. dummyMap.emplace("dummyKey", "{invalidJsonFormat}");
  49. AWSScriptBehaviorDynamoDB::GetItemRaw("dummyTable", dummyMap, "dummyRegion");
  50. }
  51. TEST_F(AWSScriptBehaviorDynamoDBTest, GetItemRaw_CallWithEmptyRegionName_InvokeOnError)
  52. {
  53. AWSScriptBehaviorDynamoDBNotificationBusHandlerMock dynamodbHandlerMock;
  54. EXPECT_CALL(dynamodbHandlerMock, OnGetItemError(::testing::_)).Times(1);
  55. DynamoDBAttributeValueMap dummyMap;
  56. dummyMap.emplace("dummyKey", "{}");
  57. AWSScriptBehaviorDynamoDB::GetItemRaw("dummyTable", dummyMap, "");
  58. }
  59. TEST_F(AWSScriptBehaviorDynamoDBTest, GetItem_NoTableNameInResourceMappingFound_InvokeOnError)
  60. {
  61. AWSScriptBehaviorDynamoDBNotificationBusHandlerMock dynamodbHandlerMock;
  62. EXPECT_CALL(dynamodbHandlerMock, OnGetItemError(::testing::_)).Times(1);
  63. DynamoDBAttributeValueMap dummyMap;
  64. AWSScriptBehaviorDynamoDB::GetItem("dummyTable", dummyMap);
  65. }
  66. TEST_F(AWSScriptBehaviorDynamoDBTest, OnSuccessOnError_Call_GetExpectedNumOfInvoke)
  67. {
  68. AWSScriptBehaviorDynamoDBNotificationBusHandlerMock dynamodbHandlerMock;
  69. EXPECT_CALL(dynamodbHandlerMock, OnGetItemSuccess(::testing::_)).Times(1);
  70. EXPECT_CALL(dynamodbHandlerMock, OnGetItemError(::testing::_)).Times(1);
  71. DynamoDBAttributeValueMap dummyMap;
  72. AWSScriptBehaviorDynamoDBNotificationBus::Broadcast(&AWSScriptBehaviorDynamoDBNotificationBus::Events::OnGetItemSuccess, dummyMap);
  73. AWSScriptBehaviorDynamoDBNotificationBus::Broadcast(&AWSScriptBehaviorDynamoDBNotificationBus::Events::OnGetItemError, "dummy success message");
  74. }