AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
ArtifactUnderTest.h
Go to the documentation of this file.
1 /*
2  * Copyright 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 
16 #ifndef AVS_CAPABILITIES_ASSETMANAGER_ACSDKASSETMANAGER_TEST_ARTIFACTUNDERTEST_H_
17 #define AVS_CAPABILITIES_ASSETMANAGER_ACSDKASSETMANAGER_TEST_ARTIFACTUNDERTEST_H_
18 
20 #include <CurlWrapperMock.h>
21 #include <DavsServiceMock.h>
22 #include <TestUtil.h>
23 #include <gmock/gmock.h>
24 #include <gtest/gtest.h>
25 
26 #include <fstream>
27 #include <functional>
28 #include <memory>
29 #include <ostream>
30 
31 #include "RequestFactory.h"
38 
39 using namespace std;
40 using namespace chrono;
41 using namespace ::testing;
45 using namespace alexaClientSDK::acsdkAssets::davs;
48 
52  , public enable_shared_from_this<ArtifactUnderTest> {
53 public:
54  bool hasAllProps() {
55  return hasStateProp() && hasPriorityProp() && hasPathProp();
56  }
57 
58  bool hasStateProp() {
59  int value;
60  return commsHandler->readProperty(request->getSummary() + AMD::STATE_SUFFIX, value);
61  }
62 
63  bool hasPriorityProp() {
64  int value;
65  return commsHandler->readProperty(request->getSummary() + AMD::PRIORITY_SUFFIX, value);
66  }
67 
68  bool hasPathProp() {
69  return commsHandler->invoke(request->getSummary() + AMD::PATH_SUFFIX).isSucceeded();
70  }
71 
73  int value;
74  commsHandler->readProperty(request->getSummary() + AMD::STATE_SUFFIX, value);
75  return static_cast<State>(value);
76  }
77 
79  int temp;
80  commsHandler->readProperty(request->getSummary() + AMD::PRIORITY_SUFFIX, temp);
81  return static_cast<Priority>(temp);
82  }
83 
84  string getPathProp() {
85  return commsHandler->invoke(request->getSummary() + AMD::PATH_SUFFIX).value();
86  }
87 
89  commsHandler->writeProperty(request->getSummary() + AMD::PRIORITY_SUFFIX, static_cast<int>(p));
90  return p;
91  }
92 
93  bool waitUntilStateEquals(State expectedState, milliseconds timeout = milliseconds(500)) {
94  return waitUntil([this, expectedState] { return getStateProp() == expectedState; }, timeout);
95  }
96 
97  void onCommunicationPropertyChange(const std::string& PropertyName, int newValue) override {
98  if (PropertyName == request->getSummary() + AMD::STATE_SUFFIX) {
99  stateMap[static_cast<State>(newValue)] += 1;
100  }
101  }
102  void onCommunicationPropertyChange(const std::string& PropertyName, string) override {
103  if (PropertyName == request->getSummary() + AMD::UPDATE_SUFFIX) {
104  updateEventCount++;
105  }
106  }
107  void resetCounts() {
108  updateEventCount = 0;
109  stateMap.clear();
110  commsHandler->unsubscribeToPropertyChangeEvent(
111  request->getSummary() + AMD::STATE_SUFFIX,
112  static_pointer_cast<CommunicationPropertyChangeSubscriber<int>>(shared_from_this()));
113  commsHandler->unsubscribeToPropertyChangeEvent(
114  request->getSummary() + AMD::UPDATE_SUFFIX,
115  static_pointer_cast<CommunicationPropertyChangeSubscriber<string>>(shared_from_this()));
116  }
118  commsHandler->subscribeToPropertyChangeEvent(
119  request->getSummary() + AMD::STATE_SUFFIX,
120  static_pointer_cast<CommunicationPropertyChangeSubscriber<int>>(shared_from_this()));
121  commsHandler->subscribeToPropertyChangeEvent(
122  request->getSummary() + AMD::UPDATE_SUFFIX,
123  static_pointer_cast<CommunicationPropertyChangeSubscriber<string>>(shared_from_this()));
124  }
125  ArtifactUnderTest(std::shared_ptr<AmdCommunicationInterface> comm, shared_ptr<ArtifactRequest> request) :
126  commsHandler(comm),
127  request(request) {
128  }
129  std::shared_ptr<AmdCommunicationInterface> commsHandler;
130  shared_ptr<ArtifactRequest> request;
131  unordered_map<State, int, alexaClientSDK::avsCommon::utils::functional::EnumClassHash> stateMap;
132  int updateEventCount = 0;
133 };
134 
135 #endif // AVS_CAPABILITIES_ASSETMANAGER_ACSDKASSETMANAGER_TEST_ARTIFACTUNDERTEST_H_
string getPathProp()
Definition: ArtifactUnderTest.h:84
State getStateProp()
Definition: ArtifactUnderTest.h:72
Definition: gmock-actions.h:53
void resetCounts()
Definition: ArtifactUnderTest.h:107
Priority getPriorityProp()
Definition: ArtifactUnderTest.h:78
ArtifactUnderTest(std::shared_ptr< AmdCommunicationInterface > comm, shared_ptr< ArtifactRequest > request)
Definition: ArtifactUnderTest.h:125
unordered_map< State, int, alexaClientSDK::avsCommon::utils::functional::EnumClassHash > stateMap
Definition: ArtifactUnderTest.h:131
::std::string string
Definition: gtest-port.h:1097
Definition: CapabilityConfiguration.h:190
void onCommunicationPropertyChange(const std::string &PropertyName, int newValue) override
Definition: ArtifactUnderTest.h:97
std::shared_ptr< AmdCommunicationInterface > commsHandler
Definition: ArtifactUnderTest.h:129
shared_ptr< ArtifactRequest > request
Definition: ArtifactUnderTest.h:130
Definition: ArtifactRequest.h:27
Definition: CommunicationInvokeHandlerInterface.h:27
Definition: AmdMetricWrapper.h:31
Definition: DavsClient.h:28
bool hasAllProps()
Definition: ArtifactUnderTest.h:54
bool hasPathProp()
Definition: ArtifactUnderTest.h:68
bool waitUntil(const std::function< bool()> &validate, std::chrono::milliseconds timeout=std::chrono::seconds(5))
Priority setPriorityProp(Priority p)
Definition: ArtifactUnderTest.h:88
bool waitUntilStateEquals(State expectedState, milliseconds timeout=milliseconds(500))
Definition: ArtifactUnderTest.h:93
bool hasPriorityProp()
Definition: ArtifactUnderTest.h:63
void onCommunicationPropertyChange(const std::string &PropertyName, string) override
Definition: ArtifactUnderTest.h:102
Definition: ArtifactHandlerInterface.h:24
bool hasStateProp()
Definition: ArtifactUnderTest.h:58
Definition: ArtifactUnderTest.h:49
void subscribeToChangeEvents()
Definition: ArtifactUnderTest.h:117

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0