1919#include < unistd.h>
2020#include < cstring>
2121#include < string>
22+ #include < cassert>
2223#include " DiscoverySDKTest.h"
2324
2425using namespace std ;
2526bool DiscoverySDKTest::_connected;
2627DiscoverySDKTest::OnUserInterestNotification DiscoverySDKTest::_userInterestNotification;
2728
29+ #ifdef GATEWAY_BIDIRECTIONAL
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+
64+ void DiscoverySDKTest::event_trigger (nlohmann::json event)
65+ {
66+ std::cout << " Event triggered: " << event[" method" ].dump () << std::endl;
67+ 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 () + " }'" ;
68+ system (trigger_cmd.c_str ());
69+ std::cout << std::endl;
70+ std::cout << " [ADITYA] trigger_cmd: " << trigger_cmd << std::endl;
71+ }
72+
73+ void DiscoverySDKTest::provider_trigger (nlohmann::json provider)
74+ {
75+ std::cout << " Provider triggered: " << provider[" method" ].dump () << std::endl;
76+ 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 () + " }'" ;
77+ system (trigger_cmd.c_str ());
78+ std::cout << std::endl;
79+ }
80+
81+ std::string InterestTypeToString (Firebolt::Discovery::InterestType interestType) {
82+ switch (interestType) {
83+ case Firebolt::Discovery::InterestType::INTEREST:
84+ return " interest" ;
85+ case Firebolt::Discovery::InterestType::DISINTEREST:
86+ return " disinterest" ;
87+ default :
88+ return " unknown" ;
89+ }
90+ }
91+
92+ std::string InterestReasonToString (Firebolt::Discovery::InterestReason interestReason) {
93+ switch (interestReason) {
94+ case Firebolt::Discovery::InterestReason::PLAYLIST:
95+ return " playlist" ;
96+ case Firebolt::Discovery::InterestReason::REACTION:
97+ return " reaction" ;
98+ case Firebolt::Discovery::InterestReason::RECORDING:
99+ return " recording" ;
100+ default :
101+ return " unknown" ;
102+ }
103+ }
104+
105+
106+ #endif
107+
28108void DiscoverySDKTest::ConnectionChanged (const bool connected, const Firebolt::Error error)
29109{
30- cout << " Change in connection: connected: " << connected << " error: " << static_cast <int >(error) << endl;
31- _connected = connected;
110+ if (!_connected) {
111+ cout << " Change in connection: connected: " << connected << " error: " << static_cast <int >(error) << endl;
112+ _connected = connected;
113+ }
32114}
33115
34116void DiscoverySDKTest::CreateFireboltInstance (const std::string& url)
@@ -67,6 +149,7 @@ bool DiscoverySDKTest::WaitOnConnectionReady()
67149 usleep (sleepSlot);
68150 waiting -= sleepSlot;
69151 }
152+ usleep (5000 );
70153 return _connected;
71154}
72155
@@ -90,9 +173,51 @@ inline const T ConvertToEnum(EnumMap<T> enumMap, const string& str)
90173 return value;
91174}
92175
93- void DiscoverySDKTest::OnUserInterestNotification::onUserInterest ( const Firebolt::Content::InterestEvent& interest)
176+ std::string ContentRatingSchemeToString (Firebolt::Entertainment::ContentRatingScheme scheme)
177+ {
178+ switch (scheme)
179+ {
180+ case Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE:
181+ return " CA-Movie" ;
182+ case Firebolt::Entertainment::ContentRatingScheme::CA_TV:
183+ return " CA-TV" ;
184+ case Firebolt::Entertainment::ContentRatingScheme::CA_MOVIE_FR:
185+ return " CA-Movie_Fr" ;
186+ case Firebolt::Entertainment::ContentRatingScheme::CA_TV_FR:
187+ return " CA-TV_Fr" ;
188+ case Firebolt::Entertainment::ContentRatingScheme::US_MOVIE:
189+ return " US-Movie" ;
190+ case Firebolt::Entertainment::ContentRatingScheme::US_TV:
191+ return " US-TV" ;
192+ default :
193+ return " UNKNOWN" ;
194+ }
195+ }
196+
197+ void DiscoverySDKTest::OnUserInterestNotification::onUserInterest (const Firebolt::Content::InterestEvent &interest)
94198{
95- cout << " User Interest changed notification" << endl;
199+ cout << " onUserInterest() notification \n " ;
200+
201+ #ifdef GATEWAY_BIDIRECTIONAL
202+ assert (interest.appId == userInterestEvent[" payload" ][" appId" ]);
203+ assert (InterestTypeToString (interest.type ) == userInterestEvent[" payload" ][" type" ]);
204+ assert (InterestReasonToString (interest.reason ) == userInterestEvent[" payload" ][" reason" ]);
205+ assert (interest.entity .info ->title .value () == userInterestEvent[" payload" ][" entity" ][" info" ][" title" ]);
206+ assert (interest.entity .info ->synopsis .value () == userInterestEvent[" payload" ][" entity" ][" info" ][" synopsis" ]);
207+ assert (interest.entity .info ->releaseDate .value () == userInterestEvent[" payload" ][" entity" ][" info" ][" releaseDate" ]);
208+ size_t i = 0 ;
209+ for (const auto &rating : interest.entity .info ->contentRatings .value ())
210+ {
211+ assert (ContentRatingSchemeToString (rating.scheme ) == userInterestEvent[" payload" ][" entity" ][" info" ][" contentRatings" ][i][" scheme" ]);
212+ i++;
213+ }
214+ size_t j = 0 ;
215+ for (const auto &ratings : interest.entity .info ->contentRatings .value ())
216+ {
217+ assert (ratings.rating == userInterestEvent[" payload" ][" entity" ][" info" ][" contentRatings" ][j][" rating" ]);
218+ j++;
219+ }
220+ #endif
96221}
97222
98223void DiscoverySDKTest::SubscribeUserInterest ()
0 commit comments