4444/**
4545 * A model for interacting with the BrokerHost app during UI Test.
4646 * <p>
47- * By default all the {@link ITestBroker} operations are performed using the {@link SingleWpjApiFragment } class.
47+ * By default all the {@link ITestBroker} operations are performed using the {@link MultipleWpjApiFragment } class.
4848 * if you want to perform specif broker host operations, you need to call the corresponding fragment class
4949 * and then call the corresponding method.
5050 * <p>
51- * Legacy WPJ operations are contained in the {@link SingleWpjApiFragment} class.
5251 * Multiple WPJ operations are contained in the {@link MultipleWpjApiFragment} class.
5352 * Broker API operations are contained in the {@link BrokerApiFragment} class.
5453 * Broker Flights operations are contained in the {@link BrokerFlightsFragment} class.
@@ -71,11 +70,8 @@ public class BrokerHost extends AbstractTestBroker {
7170 public final BrokerFlightsFragment brokerFlightsFragment ;
7271 public final BrokerApiFragment brokerApiFragment ;
7372 @ Getter
74- public final SingleWpjApiFragment singleWpjApiFragment ;
75- // If you're writing test specifically for MWPJ, use this fragment
76- // the default behavior for brokerHost app is to use the SingleWpjApiFragment
77- @ Getter
78- public final MultipleWpjApiFragment multipleWpjApiFragment ;
73+ private final MultipleWpjApiFragment multipleWpjApiFragment ;
74+
7975
8076 public BrokerHost () {
8177 this (BROKER_HOST_APK , BROKER_HOST_APK );
@@ -97,53 +93,49 @@ public BrokerHost(@NonNull final String brokerHostApkName,
9793 localUpdateApkFileName = updateBrokerHostApkName ;
9894 brokerFlightsFragment = new BrokerFlightsFragment ();
9995 brokerApiFragment = new BrokerApiFragment ();
100- singleWpjApiFragment = new SingleWpjApiFragment ();
10196 multipleWpjApiFragment = new MultipleWpjApiFragment (this );
10297 }
10398
10499 @ Override
105100 public void performDeviceRegistration (@ NonNull final String username ,
106101 @ NonNull final String password ) {
107- singleWpjApiFragment .launch ();
108- singleWpjApiFragment .performDeviceRegistration (
102+ multipleWpjApiFragment .launch ();
103+ multipleWpjApiFragment .performDeviceRegistration (
109104 username ,
110- password ,
111- false ,
112- false ,
113- getDefaultBrokerPromptHandlerParameters (username )
105+ password
114106 );
115- final String joinedUpn = singleWpjApiFragment .getWpjAccount ();
116- Assert .assertTrue ("Assert that the joined account is the expected account" , username .equalsIgnoreCase (joinedUpn ));
117107 }
118108
119109 @ Override
120110 public void performDeviceRegistration (@ NonNull String username ,
121111 @ NonNull String password ,
122112 boolean isFederatedUser ) {
123- singleWpjApiFragment .launch ();
124- singleWpjApiFragment .performDeviceRegistration (
113+ multipleWpjApiFragment .launch ();
114+ multipleWpjApiFragment .performDeviceRegistration (
125115 username ,
126116 password ,
127- isFederatedUser ,
128117 false ,
129- getDefaultBrokerPromptHandlerParameters (username )
118+ false ,
119+ getDefaultBrokerPromptHandlerParameters (username ),
120+ isFederatedUser
130121 );
131- final String joinedUpn = singleWpjApiFragment . getWpjAccount ( );
122+ final String joinedUpn = multipleWpjApiFragment . getRecordByUpn ( username ). get ( "Upn" );
132123 Assert .assertTrue ("Assert that the joined account is the expected account" , username .equalsIgnoreCase (joinedUpn ));
133124 }
134125
135126 @ Override
136127 public void performSharedDeviceRegistration (String username , String password ) {
137128 Logger .i (TAG , "Performing Shared Device Registration for the given account.." );
138- singleWpjApiFragment .launch ();
139- singleWpjApiFragment .performDeviceRegistration (
129+ multipleWpjApiFragment .launch ();
130+ multipleWpjApiFragment .performDeviceRegistration (
140131 username ,
141132 password ,
142- false ,
143133 true ,
144- getDefaultBrokerPromptHandlerParameters (username )
134+ true ,
135+ getDefaultBrokerPromptHandlerParameters (username ),
136+ false
145137 );
146- final String joinedUpn = singleWpjApiFragment . getWpjAccount ( );
138+ final String joinedUpn = multipleWpjApiFragment . getRecordByUpn ( username ). get ( "Upn" );
147139 Assert .assertTrue ("Assert that the joined account is the expected account" , username .equalsIgnoreCase (joinedUpn ));
148140 }
149141
@@ -156,15 +148,27 @@ public void performSharedDeviceRegistrationDontValidate(@NonNull final String us
156148 @ Nullable
157149 @ Override
158150 public String obtainDeviceId () {
159- singleWpjApiFragment .launch ();
160- return singleWpjApiFragment .getDeviceId ();
151+ multipleWpjApiFragment .launch ();
152+ final List <?> records = multipleWpjApiFragment .getAllRecords ();
153+ if (records == null || records .isEmpty ()) {
154+ // No WPJ records are available; honor the @Nullable contract.
155+ return null ;
156+ }
157+
158+ Assert .assertTrue (
159+ "Expected exactly one WPJ record when obtaining device id, but found: " + records .size (),
160+ records .size () == 1
161+ );
162+
163+ // Safe to access the first record now that we have asserted the size.
164+ return (String ) ((java .util .Map <?, ?>) records .get (0 )).get ("DeviceId" );
161165 }
162166
163167 @ Override
164168 public void enableBrowserAccess (@ NonNull final String username ) {
165169 Logger .i (TAG , "Enable Browser Access.." );
166- singleWpjApiFragment .launch ();
167- singleWpjApiFragment .installCertificate ();
170+ multipleWpjApiFragment .launch ();
171+ multipleWpjApiFragment .installCertificate (username );
168172 }
169173
170174 @ Override
@@ -183,31 +187,6 @@ public void initialiseAppImpl() {
183187 // nothing needed here
184188 }
185189
186- @ Nullable
187- public String getAccountUpn () {
188- singleWpjApiFragment .launch ();
189- return singleWpjApiFragment .getWpjAccount ();
190- }
191-
192- @ Nullable
193- public String getDeviceState () {
194- singleWpjApiFragment .launch ();
195- return singleWpjApiFragment .getDeviceState ();
196- }
197-
198- @ Nullable
199- public String getBlob (@ NonNull final String tenantId ) {
200- Logger .i (TAG , "Get Blob.." );
201- singleWpjApiFragment .launch ();
202- return singleWpjApiFragment .getBlob (tenantId );
203- }
204-
205- @ NonNull
206- public String getDeviceToken () {
207- Logger .i (TAG , "Get Device Token.." );
208- singleWpjApiFragment .launch ();
209- return singleWpjApiFragment .getDeviceToken ();
210- }
211190
212191 @ Override
213192 public void overwriteFlights (@ NonNull final String flightsJson ) {
@@ -233,15 +212,16 @@ public String getFlights() {
233212 public void performDeviceRegistration (@ NonNull final String username ,
234213 @ NonNull final String password ,
235214 @ NonNull final PromptHandlerParameters promptHandlerParameters ) {
236- singleWpjApiFragment .launch ();
237- singleWpjApiFragment .performDeviceRegistration (
215+ multipleWpjApiFragment .launch ();
216+ multipleWpjApiFragment .performDeviceRegistration (
238217 username ,
239218 password ,
240219 false ,
241220 false ,
242- promptHandlerParameters
221+ promptHandlerParameters ,
222+ false
243223 );
244- final String joinedUpn = singleWpjApiFragment . getWpjAccount ( );
224+ final String joinedUpn = multipleWpjApiFragment . getRecordByUpn ( username ). get ( "Upn" );
245225 Assert .assertTrue ("Assert that the joined account is the expected account" , username .equalsIgnoreCase (joinedUpn ));
246226 }
247227
@@ -277,15 +257,11 @@ public String obtainDeviceIdLegacyApp() {
277257 }
278258
279259
280- public void wpjLeave () {
281- singleWpjApiFragment .launch ();
282- singleWpjApiFragment . wpjLeave ( );
260+ public void wpjLeave (@ NonNull final String username ) {
261+ multipleWpjApiFragment .launch ();
262+ multipleWpjApiFragment . unregister ( username );
283263 }
284264
285- public void clickJoinTenant (@ NonNull final String tenantId ) {
286- singleWpjApiFragment .launch ();
287- singleWpjApiFragment .clickJoinTenant (tenantId );
288- }
289265
290266 /**
291267 * Gets all the accounts added
0 commit comments