18 #include <gtest/gtest.h> 19 #include <gmock/gmock.h> 21 #include <aws/core/utils/Outcome.h> 22 #include <aws/lex/LexRuntimeServiceClient.h> 23 #include <aws/core/utils/memory/AWSMemory.h> 24 #include <aws/lex/model/PostContentResult.h> 44 : object(std::move(object)),
47 Mover(
const Mover<T> & other)
48 : object(const_cast<T &&>(other.object)),
55 Mover & operator=(
const Mover & other)
58 object =
const_cast<T &&
>(other.object);
81 inline Mover<T> Movable(T &&
object)
83 return Mover<T>(std::move(
object));
92 using Aws::LexRuntimeService::Model::PostContentOutcome;
93 using Aws::LexRuntimeService::Model::PostContentRequest;
94 using Aws::LexRuntimeService::Model::PostContentResult;
95 using Aws::LexRuntimeService::LexRuntimeServiceErrors;
96 using testing::Return;
101 std::string user_id =
"user_id";
102 std::string bot_alias =
"bot_alias";
103 std::string bot_name =
"bot_name";
107 lex_configuration.
user_id = user_id;
109 lex_configuration.
bot_name = bot_name;
114 :
public Aws::LexRuntimeService::LexRuntimeServiceClient
119 MOCK_CONST_METHOD1(PostContent_, Mover<PostContentOutcome>(
const PostContentRequest & request));
121 PostContentOutcome
PostContent(
const PostContentRequest & request)
const 123 return std::move(PostContent_(request).
get());
136 Aws::LexRuntimeService::Model::PostContentResult
result;
140 lex_runtime_client = std::make_shared<LexRuntimeServiceClientMock>();
141 lex_configuration = std::make_shared<LexConfiguration>();
149 default_expected_request
150 .WithBotAlias(lex_configuration->bot_alias.c_str())
151 .WithBotName(lex_configuration->bot_name.c_str())
153 .WithUserId(lex_configuration->user_id.c_str());
154 default_expected_request.SetBotAlias(lex_configuration->bot_alias.c_str());
155 default_expected_request.SetContentType(default_request.
content_type.c_str());
162 lex_interactor.ConfigureAwsLex(
nullptr,
nullptr));
164 lex_interactor.ConfigureAwsLex(lex_configuration,
nullptr));
166 lex_interactor.ConfigureAwsLex(
nullptr, lex_runtime_client));
171 lex_runtime_client));
172 default_request.audio_request = std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7};
173 auto lex_configuration = std::make_shared<LexConfiguration>();
174 auto io_stream = std::make_shared<StringStream>();
175 std::copy(default_request.audio_request.begin(),
176 default_request.audio_request.end(), std::ostream_iterator<unsigned char>(*io_stream));
177 default_expected_request.SetBody(io_stream);
178 EXPECT_CALL(*lex_runtime_client, PostContent_(default_expected_request))
179 .WillOnce(testing::Return(Movable(PostContentOutcome(std::move(result)))));
183 test_data.ExpectEq(response);
187 default_request.audio_request = std::vector<uint8_t>{1, 2, 3, 4, 5, 6, 7};
188 auto io_stream = std::make_shared<StringStream>();
189 std::copy(default_request.audio_request.begin(),
190 default_request.audio_request.end(), std::ostream_iterator<unsigned char>(*io_stream));
191 default_expected_request.SetBody(io_stream);
194 lex_runtime_client));
196 PostContentResult result;
198 EXPECT_CALL(*lex_runtime_client, PostContent_(default_expected_request))
199 .WillOnce(testing::Return(Movable(PostContentOutcome(std::move(result)))));
203 test_data.ExpectEq(response);
208 lex_runtime_client));
210 EXPECT_CALL(*lex_runtime_client, PostContent_(testing::_))
211 .WillOnce(testing::Return(Movable(PostContentOutcome(
212 Aws::Client::AWSError<LexRuntimeServiceErrors>(LexRuntimeServiceErrors::ACCESS_DENIED,
220 lex_runtime_client));
222 EXPECT_CALL(*lex_runtime_client, PostContent_(testing::_))
223 .WillOnce(testing::Return(Movable(PostContentOutcome(
224 Aws::Client::AWSError<LexRuntimeServiceErrors>(LexRuntimeServiceErrors::REQUEST_TIMEOUT,
LexRequest default_request
std::shared_ptr< LexRuntimeServiceClientMock > lex_runtime_client
TEST_F(TestLexInteractor, TestLexInteractorPostContentRetry)
Aws::LexRuntimeService::Model::PostContentResult result
std::shared_ptr< LexConfiguration > lex_configuration
PostContentRequest default_expected_request
PostContentOutcome PostContent(const PostContentRequest &request) const
LexInteractor lex_interactor
void ConfigureExampleResult(Aws::LexRuntimeService::Model::PostContentResult &example_result)
void ConfigureLexConfiguration(LexConfiguration &lex_configuration)