|
19 | 19 | #include <unistd.h> |
20 | 20 | #include <cstring> |
21 | 21 | #include <string> |
| 22 | +#include <cassert> |
22 | 23 | #include "DiscoverySDKTest.h" |
23 | 24 |
|
24 | 25 | using namespace std; |
25 | 26 | bool DiscoverySDKTest::_connected; |
26 | 27 | DiscoverySDKTest::OnUserInterestNotification DiscoverySDKTest::_userInterestNotification; |
27 | 28 |
|
| 29 | + |
| 30 | + |
| 31 | +const nlohmann::json DiscoverySDKTest::userInterestEvent = { |
| 32 | + {"method", "content.onUserInterest"}, |
| 33 | + {"payload", { |
| 34 | + {"name", "interest"}, |
| 35 | + {"appId", "cool-app"}, |
| 36 | + {"type", "interest"}, |
| 37 | + {"reason", "playlist"}, |
| 38 | + {"entity", { |
| 39 | + {"identifiers", { |
| 40 | + {"entityId", "345"}, |
| 41 | + {"entityType", "program"}, |
| 42 | + {"programType", "movie"} |
| 43 | + }}, |
| 44 | + {"info", { |
| 45 | + {"title", "Cool Runnings"}, |
| 46 | + {"synopsis", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar sapien et ligula ullamcorper malesuada proin libero nunc."}, |
| 47 | + {"releaseDate", "1993-01-01T00:00:00.000Z"}, |
| 48 | + {"contentRatings", { |
| 49 | + { |
| 50 | + {"scheme", "US-Movie"}, |
| 51 | + {"rating", "PG"} |
| 52 | + }, |
| 53 | + { |
| 54 | + {"scheme", "CA-Movie"}, |
| 55 | + {"rating", "G"} |
| 56 | + } |
| 57 | + }} |
| 58 | + }} |
| 59 | + }} |
| 60 | + }} |
| 61 | +}; |
| 62 | + |
| 63 | +#ifdef GATEWAY_BIDIRECTIONAL |
| 64 | + |
| 65 | +std::string InterestTypeToString(Firebolt::Discovery::InterestType interestType) { |
| 66 | + switch (interestType) { |
| 67 | + case Firebolt::Discovery::InterestType::INTEREST: |
| 68 | + return "interest"; |
| 69 | + case Firebolt::Discovery::InterestType::DISINTEREST: |
| 70 | + return "disinterest"; |
| 71 | + default: |
| 72 | + return "unknown"; |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +std::string InterestReasonToString(Firebolt::Discovery::InterestReason interestReason) { |
| 77 | + switch (interestReason) { |
| 78 | + case Firebolt::Discovery::InterestReason::PLAYLIST: |
| 79 | + return "playlist"; |
| 80 | + case Firebolt::Discovery::InterestReason::REACTION: |
| 81 | + return "reaction"; |
| 82 | + case Firebolt::Discovery::InterestReason::RECORDING: |
| 83 | + return "recording"; |
| 84 | + default: |
| 85 | + return "unknown"; |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +std::string ContentRatingSchemeToString(Firebolt::Entertainment::ContentRatingScheme scheme) |
| 90 | +{ |
| 91 | + switch (scheme) |
| 92 | + { |
| 93 | + case Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE: |
| 94 | + return "CA-Movie"; |
| 95 | + case Firebolt::Entertainment::ContentRatingScheme::CA_TV: |
| 96 | + return "CA-TV"; |
| 97 | + case Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE_FR: |
| 98 | + return "CA-Movie_Fr"; |
| 99 | + case Firebolt::Entertainment::ContentRatingScheme::CA_TV_FR: |
| 100 | + return "CA-TV_Fr"; |
| 101 | + case Firebolt::Entertainment::ContentRatingScheme::US_MOVIE: |
| 102 | + return "US-Movie"; |
| 103 | + case Firebolt::Entertainment::ContentRatingScheme::US_TV: |
| 104 | + return "US-TV"; |
| 105 | + default: |
| 106 | + return "UNKNOWN"; |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +void DiscoverySDKTest::event_trigger(nlohmann::json event) |
| 111 | +{ |
| 112 | + std::cout << "Event triggered: " << event["method"].dump() << std::endl; |
| 113 | + std::string trigger_cmd = "curl --location --request POST http://localhost:3333/api/v1/bidirectionalEventPayload --header 'Content-Type: application/json' --data-raw '{ \"method\": " + event["method"].dump() + ", \"params\": " + event["payload"].dump() + "}'"; |
| 114 | + system(trigger_cmd.c_str()); |
| 115 | + std::cout << std::endl; |
| 116 | + std::cout << "[ADITYA] trigger_cmd: " << trigger_cmd << std::endl; |
| 117 | +} |
| 118 | + |
| 119 | +void DiscoverySDKTest::provider_trigger(nlohmann::json provider) |
| 120 | +{ |
| 121 | + std::cout << "Provider triggered: " << provider["method"].dump() << std::endl; |
| 122 | + std::string trigger_cmd = "curl --location --request POST http://localhost:3333/api/v1/bidirectionalPayload --header 'Content-Type: application/json' --data-raw '{ \"method\": " + provider["method"].dump() + ", \"params\": " + provider["payload"].dump() + "}'"; |
| 123 | + system(trigger_cmd.c_str()); |
| 124 | + std::cout << std::endl; |
| 125 | +} |
| 126 | + |
| 127 | +#else |
| 128 | + |
| 129 | +void DiscoverySDKTest::event_trigger(nlohmann::json event) |
| 130 | +{ |
| 131 | + std::cout << "Event triggered: " << event["method"].dump() << std::endl; |
| 132 | + std::string trigger_cmd = "curl --location --request POST http://localhost:3333/api/v1/event --header 'Content-Type: application/json' --data-raw '{ \"method\": " + event["method"].dump() + ", \"result\": " + event["payload"].dump() + "}'"; |
| 133 | + system(trigger_cmd.c_str()); |
| 134 | + std::cout << std::endl; |
| 135 | +} |
| 136 | + |
| 137 | +void DiscoverySDKTest::provider_trigger(nlohmann::json provider) |
| 138 | +{ |
| 139 | + std::cout << "Provider triggered: " << provider["method"].dump() << std::endl; |
| 140 | + std::string trigger_cmd = "curl --location --request POST http://localhost:3333/api/v1/event --header 'Content-Type: application/json' --data-raw '{ \"method\": " + provider["method"].dump() + ", \"params\": " + provider["payload"].dump() + "}'"; |
| 141 | + system(trigger_cmd.c_str()); |
| 142 | + std::cout << std::endl; |
| 143 | +} |
| 144 | + |
| 145 | +#endif |
| 146 | + |
28 | 147 | void DiscoverySDKTest::ConnectionChanged(const bool connected, const Firebolt::Error error) |
29 | 148 | { |
30 | 149 | cout << "Change in connection: connected: " << connected << " error: " << static_cast<int>(error) << endl; |
@@ -90,9 +209,33 @@ inline const T ConvertToEnum(EnumMap<T> enumMap, const string& str) |
90 | 209 | return value; |
91 | 210 | } |
92 | 211 |
|
93 | | -void DiscoverySDKTest::OnUserInterestNotification::onUserInterest( const Firebolt::Content::InterestEvent& interest) |
| 212 | + |
| 213 | + |
| 214 | +void DiscoverySDKTest::OnUserInterestNotification::onUserInterest(const Firebolt::Content::InterestEvent &interest) |
94 | 215 | { |
95 | | - cout << "User Interest changed notification" << endl; |
| 216 | + cout << "onUserInterest() notification \n"; |
| 217 | + |
| 218 | +#ifdef GATEWAY_BIDIRECTIONAL |
| 219 | + assert(interest.appId == userInterestEvent["payload"]["appId"]); |
| 220 | + assert(InterestTypeToString(interest.type) == userInterestEvent["payload"]["type"]); |
| 221 | + assert(InterestReasonToString(interest.reason) == userInterestEvent["payload"]["reason"]); |
| 222 | + // assert(interest.entity.identifiers == userInterestEvent["payload"]["entity"]["identifiers"]); |
| 223 | + assert(interest.entity.info->title.value() == userInterestEvent["payload"]["entity"]["info"]["title"]); |
| 224 | + assert(interest.entity.info->synopsis.value() == userInterestEvent["payload"]["entity"]["info"]["synopsis"]); |
| 225 | + assert(interest.entity.info->releaseDate.value() == userInterestEvent["payload"]["entity"]["info"]["releaseDate"]); |
| 226 | + size_t i = 0; |
| 227 | + for (const auto &rating : interest.entity.info->contentRatings.value()) |
| 228 | + { |
| 229 | + assert(ContentRatingSchemeToString(rating.scheme) == userInterestEvent["payload"]["entity"]["info"]["contentRatings"][i]["scheme"]); |
| 230 | + i++; |
| 231 | + } |
| 232 | + size_t j = 0; |
| 233 | + for (const auto &ratings : interest.entity.info->contentRatings.value()) |
| 234 | + { |
| 235 | + assert(ratings.rating == userInterestEvent["payload"]["entity"]["info"]["contentRatings"][j]["rating"]); |
| 236 | + j++; |
| 237 | + } |
| 238 | +#endif |
96 | 239 | } |
97 | 240 |
|
98 | 241 | void DiscoverySDKTest::SubscribeUserInterest() |
|
0 commit comments