lex_param_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #include <gtest/gtest.h>
16 #include <gmock/gmock.h>
17 
20 
22 
23 #include <aws/core/config/AWSProfileConfigLoader.h>
24 #include <aws/core/Aws.h>
25 #include <aws/core/utils/logging/LogMacros.h>
26 #include <aws/core/utils/logging/AWSLogging.h>
27 #include <aws/core/utils/logging/LogLevel.h>
28 
29 #include <string>
30 #include <memory>
31 
34 using testing::_;
35 using testing::Eq;
38 using Aws::AwsError;
39 
40 TEST(ParameterTest, LoadLexParamsUserIdFail) {
41  ParameterReaderMock mock_reader;
42  SetupMockReader(AwsError::AWS_ERR_NOT_FOUND, AwsError::AWS_ERR_OK, AwsError::AWS_ERR_OK,
43  mock_reader);
44  LexConfiguration lex_config;
45  ASSERT_EQ(ErrorCode::INVALID_LEX_CONFIGURATION, LoadLexParameters(mock_reader, lex_config));
46 }
47 
48 TEST(ParameterTest, LoadLexParamsBotNameFail) {
49  ParameterReaderMock mock_reader;
50  SetupMockReader(AwsError::AWS_ERR_OK, AwsError::AWS_ERR_NOT_FOUND, AwsError::AWS_ERR_OK,
51  mock_reader);
52  LexConfiguration lex_config;
53  ASSERT_EQ(ErrorCode::INVALID_LEX_CONFIGURATION, LoadLexParameters(mock_reader, lex_config));
54 }
55 
56 TEST(ParameterTest, LoadLexParamsBotAliasFail) {
57  ParameterReaderMock mock_reader;
58  SetupMockReader(AwsError::AWS_ERR_OK, AwsError::AWS_ERR_OK, AwsError::AWS_ERR_NOT_FOUND,
59  mock_reader);
60  LexConfiguration lex_config;
61  ASSERT_EQ(ErrorCode::INVALID_LEX_CONFIGURATION, LoadLexParameters(mock_reader, lex_config));
62 }
63 
67 TEST(ParameterTest, LoadLexParamsSuccess) {
68  ParameterReaderMock mock_reader;
69  const std::string user_id = "user_id";
70  const std::string bot_name = "bot_name";
71  const std::string bot_alias = "bot_alias";
72 
73  auto read_std_str =
74  [](std::string expected, const ParameterPath & name, std::string & out) -> AwsError {
75  out = expected;
76  return AwsError::AWS_ERR_OK;
77  };
78  using namespace std::placeholders;
79  using testing::Invoke;
80  EXPECT_CALL(mock_reader, ReadParam(Eq(Aws::Client::user_id_key), testing::A<std::string&>()))
81  .WillOnce(Invoke(std::bind(read_std_str, user_id, _1, _2)));
82  EXPECT_CALL(mock_reader, ReadParam(Eq(Aws::Client::bot_name_key), testing::A<std::string&>()))
83  .WillOnce(Invoke(std::bind(read_std_str, bot_name, _1, _2)));
84  EXPECT_CALL(mock_reader, ReadParam(Eq(Aws::Client::bot_alias_key), testing::A<std::string&>()))
85  .WillOnce(Invoke(std::bind(read_std_str, bot_alias, _1, _2)));
86  LexConfiguration lex_config;
87  ASSERT_EQ(ErrorCode::SUCCESS, LoadLexParameters(mock_reader, lex_config));
88  EXPECT_EQ(user_id, lex_config.user_id);
89  EXPECT_EQ(bot_name, lex_config.bot_name);
90  EXPECT_EQ(bot_alias, lex_config.bot_alias);
91 }
92 
93 int main(int argc, char ** argv)
94 {
95  Aws::Utils::Logging::InitializeAWSLogging(
96  std::make_shared<Aws::Utils::Logging::TestLogSystem>(Aws::Utils::Logging::LogLevel::Trace));
97  Aws::SDKOptions options;
98  Aws::InitAPI(options);
99  // The following line must be executed to initialize Google Mock
100  // (and Google Test) before running the tests.
101  ::testing::InitGoogleMock(&argc, argv);
102  auto result = RUN_ALL_TESTS();
103  Aws::Utils::Logging::ShutdownAWSLogging();
104  Aws::ShutdownAPI(options);
105  return result;
106 }
int main(int argc, char **argv)
void SetupMockReader(AwsError user_id_error, AwsError bot_name_error, AwsError bot_alias_error, ParameterReaderMock &mock_reader)
TEST(ParameterTest, LoadLexParamsUserIdFail)
const ParameterPath bot_alias_key
const ParameterPath user_id_key
const ParameterPath bot_name_key
ErrorCode LoadLexParameters(const Client::ParameterReaderInterface &parameter_interface, LexConfiguration &lex_configuration)


lex_common
Author(s): AWS RoboMaker
autogenerated on Sat Mar 6 2021 03:43:24