forked from aws/aws-sdk-cpp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCustomServicePetStoreTest.cpp
110 lines (93 loc) · 3.99 KB
/
CustomServicePetStoreTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <gtest/gtest.h>
#include <aws/core/utils/Outcome.h>
#include <aws/core/auth/AWSAuthSignerProvider.h>
#if STANDALONE
#include <aws/custom-service/PetStoreClient.h>
#include <aws/custom-service/model/CreatePetRequest.h>
#include <aws/custom-service/model/GetPetRequest.h>
#include <aws/custom-service/model/GetPetsRequest.h>
using namespace Custom::PetStore;
using namespace Custom::PetStore::Model;
#else
#include <aws/petstore/PetStoreClient.h>
#include <aws/petstore/model/CreatePetRequest.h>
#include <aws/petstore/model/GetPetRequest.h>
#include <aws/petstore/model/GetPetsRequest.h>
using namespace Aws::PetStore;
using namespace Aws::PetStore::Model;
#endif
using namespace Aws::Auth;
namespace
{
static const char ALLOCATION_TAG[] = "CustomServicePetStoreTest";
// This custom AuthSignerProvider always returns NullSigner.
class CustomAuthSignerProvider : public Aws::Auth::AWSAuthSignerProvider
{
public:
CustomAuthSignerProvider() : m_defaultSigner(Aws::MakeShared<Aws::Client::AWSNullSigner>(ALLOCATION_TAG)) {}
std::shared_ptr<Aws::Client::AWSAuthSigner> GetSigner(const Aws::String& signerName) const override
{
AWS_UNREFERENCED_PARAM(signerName);
return m_defaultSigner;
}
void AddSigner(std::shared_ptr<Aws::Client::AWSAuthSigner>&) override
{
// no-op
}
private:
std::shared_ptr<Aws::Client::AWSAuthSigner> m_defaultSigner;
};
class CustomServicePetStoreTest : public ::testing::Test
{
public:
PetStoreClient client;
};
// Test the PetStore specific operations, PetStore is an example provided by API Gateway:
// https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-from-example-console.html
// The resources of PetStore is constant and will not be changed even though we call CreatePet successfully:
// [{ "id": 1, "type": "dog", "price": 249.99 },
// { "id": 2, "type": "cat", "price": 124.99 },
// { "id": 3, "type": "fish", "price": 0.99 }]
TEST_F(CustomServicePetStoreTest, TestPetStoreOperations)
{
// Test CreatePetRequest
CreatePetRequest createPetRequest;
NewPet newPet;
newPet.SetType(PetType::bird);
newPet.SetPrice(9.99);
createPetRequest.SetNewPet(newPet);
auto createPetOutcome = client.CreatePet(createPetRequest);
ASSERT_TRUE(createPetOutcome.IsSuccess());
// Test GetPetRequest
GetPetRequest getPetRequest;
getPetRequest.SetPetId(1);
auto getPetOutcome = client.GetPet(getPetRequest);
ASSERT_TRUE(getPetOutcome.IsSuccess());
ASSERT_EQ("dog", getPetOutcome.GetResult().GetPet().GetType());
ASSERT_EQ(249.99, getPetOutcome.GetResult().GetPet().GetPrice());
// Test GetPetsRequest
GetPetsRequest getPetsRequest;
auto getPetsOutcome = client.GetPets(getPetsRequest);
ASSERT_TRUE(getPetsOutcome.IsSuccess());
auto pets = getPetsOutcome.GetResult().GetPets();
ASSERT_EQ(3u, pets.size());
auto pet = pets[1];
ASSERT_EQ(2 , pet.GetId());
ASSERT_EQ("cat", pet.GetType());
ASSERT_EQ(124.99, pet.GetPrice());
}
TEST_F(CustomServicePetStoreTest, TestCustomSignerProvider)
{
// GetPetsRequest doesn't need signer anyway, we just test the interface to make use of custom signer provider in class constructor here.
std::shared_ptr<Aws::Auth::AWSAuthSignerProvider> customSignerProvider = Aws::MakeShared<CustomAuthSignerProvider>(ALLOCATION_TAG);
auto clientWithCustomSigner = Aws::MakeShared<PetStoreClient>(ALLOCATION_TAG, customSignerProvider);
GetPetsRequest getPetsRequest;
auto getPetsOutcome = client.GetPets(getPetsRequest);
ASSERT_TRUE(getPetsOutcome.IsSuccess());
ASSERT_EQ(3u, getPetsOutcome.GetResult().GetPets().size());
}
}