@@ -318,39 +318,25 @@ void metricTotalsNonNegative() throws StreamException {
318318 }
319319
320320 @ Nested
321- @ DisplayName ("Data Correctness" )
322- class DataCorrectness {
321+ @ DisplayName ("Data Correctness - Date Range Query " )
322+ class DataCorrectnessDateRange {
323323
324324 /**
325- * Verifies exact metric values for sdk-test-team-1, sdk-test-team-2, sdk-test-team-3.
326- *
327- * <p>This test queries a fixed date range (2026-02-17 to 2026-02-18) and asserts exact values
328- * for all 16 metrics. This ensures the SDK correctly parses the API response and catches any
329- * API/SDK regressions.
325+ * Verifies exact metric values for sdk-test-team-1/2/3 using date range query.
330326 *
331327 * <p>Expected values for each sdk-test-team-N:
332328 * <ul>
333- * <li>users_daily: 0</li>
334- * <li>messages_daily: 100</li>
335- * <li>translations_daily: 0</li>
336- * <li>image_moderations_daily: 0</li>
337- * <li>concurrent_users: 0</li>
338- * <li>concurrent_connections: 0</li>
339- * <li>users_total: 5</li>
340- * <li>users_last_24_hours: 5</li>
341- * <li>users_last_30_days: 5</li>
342- * <li>users_month_to_date: 5</li>
343- * <li>users_engaged_last_30_days: 0</li>
344- * <li>users_engaged_month_to_date: 0</li>
345- * <li>messages_total: 100</li>
346- * <li>messages_last_24_hours: 100</li>
347- * <li>messages_last_30_days: 100</li>
348- * <li>messages_month_to_date: 100</li>
329+ * <li>users_daily: 0, messages_daily: 100</li>
330+ * <li>translations_daily: 0, image_moderations_daily: 0</li>
331+ * <li>concurrent_users: 0, concurrent_connections: 0</li>
332+ * <li>users_total: 5, users_last_24_hours: 5, users_last_30_days: 5, users_month_to_date: 5</li>
333+ * <li>users_engaged_last_30_days: 0, users_engaged_month_to_date: 0</li>
334+ * <li>messages_total: 100, messages_last_24_hours: 100, messages_last_30_days: 100, messages_month_to_date: 100</li>
349335 * </ul>
350336 */
351337 @ Test
352- @ DisplayName ("sdk-test-team-1 has exact expected values for all 16 metrics " )
353- void sdkTestTeam1HasExactValues () throws StreamException {
338+ @ DisplayName ("Date range: sdk-test-team-1 exact values" )
339+ void dateRangeSdkTestTeam1 () throws StreamException {
354340 QueryTeamUsageStatsResponse response =
355341 TeamUsageStats .queryTeamUsageStats ()
356342 .startDate ("2026-02-17" )
@@ -359,13 +345,12 @@ void sdkTestTeam1HasExactValues() throws StreamException {
359345
360346 TeamUsageStats team = findTeamByName (response , "sdk-test-team-1" );
361347 assertNotNull (team , "sdk-test-team-1 should exist" );
362-
363348 assertAllMetricsExact (team , "sdk-test-team-1" );
364349 }
365350
366351 @ Test
367- @ DisplayName ("sdk-test-team-2 has exact expected values for all 16 metrics " )
368- void sdkTestTeam2HasExactValues () throws StreamException {
352+ @ DisplayName ("Date range: sdk-test-team-2 exact values" )
353+ void dateRangeSdkTestTeam2 () throws StreamException {
369354 QueryTeamUsageStatsResponse response =
370355 TeamUsageStats .queryTeamUsageStats ()
371356 .startDate ("2026-02-17" )
@@ -374,13 +359,12 @@ void sdkTestTeam2HasExactValues() throws StreamException {
374359
375360 TeamUsageStats team = findTeamByName (response , "sdk-test-team-2" );
376361 assertNotNull (team , "sdk-test-team-2 should exist" );
377-
378362 assertAllMetricsExact (team , "sdk-test-team-2" );
379363 }
380364
381365 @ Test
382- @ DisplayName ("sdk-test-team-3 has exact expected values for all 16 metrics " )
383- void sdkTestTeam3HasExactValues () throws StreamException {
366+ @ DisplayName ("Date range: sdk-test-team-3 exact values" )
367+ void dateRangeSdkTestTeam3 () throws StreamException {
384368 QueryTeamUsageStatsResponse response =
385369 TeamUsageStats .queryTeamUsageStats ()
386370 .startDate ("2026-02-17" )
@@ -389,52 +373,179 @@ void sdkTestTeam3HasExactValues() throws StreamException {
389373
390374 TeamUsageStats team = findTeamByName (response , "sdk-test-team-3" );
391375 assertNotNull (team , "sdk-test-team-3 should exist" );
376+ assertAllMetricsExact (team , "sdk-test-team-3" );
377+ }
378+ }
379+
380+ @ Nested
381+ @ DisplayName ("Data Correctness - Month Query" )
382+ class DataCorrectnessMonth {
383+
384+ @ Test
385+ @ DisplayName ("Month query: sdk-test-team-1 exact values" )
386+ void monthQuerySdkTestTeam1 () throws StreamException {
387+ QueryTeamUsageStatsResponse response =
388+ TeamUsageStats .queryTeamUsageStats ().month ("2026-02" ).request ();
389+
390+ TeamUsageStats team = findTeamByName (response , "sdk-test-team-1" );
391+ assertNotNull (team , "sdk-test-team-1 should exist" );
392+ assertAllMetricsExact (team , "sdk-test-team-1" );
393+ }
394+
395+ @ Test
396+ @ DisplayName ("Month query: sdk-test-team-2 exact values" )
397+ void monthQuerySdkTestTeam2 () throws StreamException {
398+ QueryTeamUsageStatsResponse response =
399+ TeamUsageStats .queryTeamUsageStats ().month ("2026-02" ).request ();
400+
401+ TeamUsageStats team = findTeamByName (response , "sdk-test-team-2" );
402+ assertNotNull (team , "sdk-test-team-2 should exist" );
403+ assertAllMetricsExact (team , "sdk-test-team-2" );
404+ }
405+
406+ @ Test
407+ @ DisplayName ("Month query: sdk-test-team-3 exact values" )
408+ void monthQuerySdkTestTeam3 () throws StreamException {
409+ QueryTeamUsageStatsResponse response =
410+ TeamUsageStats .queryTeamUsageStats ().month ("2026-02" ).request ();
411+
412+ TeamUsageStats team = findTeamByName (response , "sdk-test-team-3" );
413+ assertNotNull (team , "sdk-test-team-3 should exist" );
414+ assertAllMetricsExact (team , "sdk-test-team-3" );
415+ }
416+ }
417+
418+ @ Nested
419+ @ DisplayName ("Data Correctness - No Parameters Query" )
420+ class DataCorrectnessNoParams {
421+
422+ @ Test
423+ @ DisplayName ("No params: sdk-test-team-1 exact values" )
424+ void noParamsSdkTestTeam1 () throws StreamException {
425+ QueryTeamUsageStatsResponse response = TeamUsageStats .queryTeamUsageStats ().request ();
426+
427+ TeamUsageStats team = findTeamByName (response , "sdk-test-team-1" );
428+ assertNotNull (team , "sdk-test-team-1 should exist" );
429+ assertAllMetricsExact (team , "sdk-test-team-1" );
430+ }
431+
432+ @ Test
433+ @ DisplayName ("No params: sdk-test-team-2 exact values" )
434+ void noParamsSdkTestTeam2 () throws StreamException {
435+ QueryTeamUsageStatsResponse response = TeamUsageStats .queryTeamUsageStats ().request ();
436+
437+ TeamUsageStats team = findTeamByName (response , "sdk-test-team-2" );
438+ assertNotNull (team , "sdk-test-team-2 should exist" );
439+ assertAllMetricsExact (team , "sdk-test-team-2" );
440+ }
441+
442+ @ Test
443+ @ DisplayName ("No params: sdk-test-team-3 exact values" )
444+ void noParamsSdkTestTeam3 () throws StreamException {
445+ QueryTeamUsageStatsResponse response = TeamUsageStats .queryTeamUsageStats ().request ();
446+
447+ TeamUsageStats team = findTeamByName (response , "sdk-test-team-3" );
448+ assertNotNull (team , "sdk-test-team-3 should exist" );
449+ assertAllMetricsExact (team , "sdk-test-team-3" );
450+ }
451+ }
452+
453+ @ Nested
454+ @ DisplayName ("Data Correctness - Pagination Query" )
455+ class DataCorrectnessPagination {
392456
457+ @ Test
458+ @ DisplayName ("Pagination: finds sdk-test-team-1 with exact values across pages" )
459+ void paginationFindsSdkTestTeam1 () throws StreamException {
460+ TeamUsageStats team = findTeamAcrossPages ("sdk-test-team-1" );
461+ assertNotNull (team , "sdk-test-team-1 should exist across paginated results" );
462+ assertAllMetricsExact (team , "sdk-test-team-1" );
463+ }
464+
465+ @ Test
466+ @ DisplayName ("Pagination: finds sdk-test-team-2 with exact values across pages" )
467+ void paginationFindsSdkTestTeam2 () throws StreamException {
468+ TeamUsageStats team = findTeamAcrossPages ("sdk-test-team-2" );
469+ assertNotNull (team , "sdk-test-team-2 should exist across paginated results" );
470+ assertAllMetricsExact (team , "sdk-test-team-2" );
471+ }
472+
473+ @ Test
474+ @ DisplayName ("Pagination: finds sdk-test-team-3 with exact values across pages" )
475+ void paginationFindsSdkTestTeam3 () throws StreamException {
476+ TeamUsageStats team = findTeamAcrossPages ("sdk-test-team-3" );
477+ assertNotNull (team , "sdk-test-team-3 should exist across paginated results" );
393478 assertAllMetricsExact (team , "sdk-test-team-3" );
394479 }
395480
396- private TeamUsageStats findTeamByName (QueryTeamUsageStatsResponse response , String teamName ) {
397- for (TeamUsageStats team : response .getTeams ()) {
398- if (teamName .equals (team .getTeam ())) {
399- return team ;
481+ private TeamUsageStats findTeamAcrossPages (String teamName ) throws StreamException {
482+ String nextCursor = null ;
483+ int maxPages = 10 ; // Safety limit
484+
485+ for (int page = 0 ; page < maxPages ; page ++) {
486+ var requestBuilder = TeamUsageStats .queryTeamUsageStats ().limit (5 );
487+ if (nextCursor != null ) {
488+ requestBuilder = requestBuilder .next (nextCursor );
489+ }
490+
491+ QueryTeamUsageStatsResponse response = requestBuilder .request ();
492+ TeamUsageStats found = findTeamByName (response , teamName );
493+ if (found != null ) {
494+ return found ;
495+ }
496+
497+ nextCursor = response .getNext ();
498+ if (nextCursor == null || nextCursor .isEmpty ()) {
499+ break ; // No more pages
400500 }
401501 }
402502 return null ;
403503 }
504+ }
404505
405- private void assertAllMetricsExact (TeamUsageStats team , String teamName ) {
406- // Daily activity metrics
407- assertEquals (0 , team .getUsersDaily ().getTotal (), teamName + " users_daily" );
408- assertEquals (100 , team .getMessagesDaily ().getTotal (), teamName + " messages_daily" );
409- assertEquals (0 , team .getTranslationsDaily ().getTotal (), teamName + " translations_daily" );
410- assertEquals (
411- 0 , team .getImageModerationDaily ().getTotal (), teamName + " image_moderations_daily" );
412-
413- // Peak metrics
414- assertEquals (0 , team .getConcurrentUsers ().getTotal (), teamName + " concurrent_users" );
415- assertEquals (
416- 0 , team .getConcurrentConnections ().getTotal (), teamName + " concurrent_connections" );
417-
418- // User rolling/cumulative metrics
419- assertEquals (5 , team .getUsersTotal ().getTotal (), teamName + " users_total" );
420- assertEquals (5 , team .getUsersLast24Hours ().getTotal (), teamName + " users_last_24_hours" );
421- assertEquals (5 , team .getUsersLast30Days ().getTotal (), teamName + " users_last_30_days" );
422- assertEquals (5 , team .getUsersMonthToDate ().getTotal (), teamName + " users_month_to_date" );
423- assertEquals (
424- 0 , team .getUsersEngagedLast30Days ().getTotal (), teamName + " users_engaged_last_30_days" );
425- assertEquals (
426- 0 ,
427- team .getUsersEngagedMonthToDate ().getTotal (),
428- teamName + " users_engaged_month_to_date" );
429-
430- // Message rolling/cumulative metrics
431- assertEquals (100 , team .getMessagesTotal ().getTotal (), teamName + " messages_total" );
432- assertEquals (
433- 100 , team .getMessagesLast24Hours ().getTotal (), teamName + " messages_last_24_hours" );
434- assertEquals (
435- 100 , team .getMessagesLast30Days ().getTotal (), teamName + " messages_last_30_days" );
436- assertEquals (
437- 100 , team .getMessagesMonthToDate ().getTotal (), teamName + " messages_month_to_date" );
506+ // Helper methods shared across nested classes
507+ private static TeamUsageStats findTeamByName (
508+ QueryTeamUsageStatsResponse response , String teamName ) {
509+ for (TeamUsageStats team : response .getTeams ()) {
510+ if (teamName .equals (team .getTeam ())) {
511+ return team ;
512+ }
438513 }
514+ return null ;
515+ }
516+
517+ private static void assertAllMetricsExact (TeamUsageStats team , String teamName ) {
518+ // Daily activity metrics
519+ assertEquals (0 , team .getUsersDaily ().getTotal (), teamName + " users_daily" );
520+ assertEquals (100 , team .getMessagesDaily ().getTotal (), teamName + " messages_daily" );
521+ assertEquals (0 , team .getTranslationsDaily ().getTotal (), teamName + " translations_daily" );
522+ assertEquals (
523+ 0 , team .getImageModerationDaily ().getTotal (), teamName + " image_moderations_daily" );
524+
525+ // Peak metrics
526+ assertEquals (0 , team .getConcurrentUsers ().getTotal (), teamName + " concurrent_users" );
527+ assertEquals (
528+ 0 , team .getConcurrentConnections ().getTotal (), teamName + " concurrent_connections" );
529+
530+ // User rolling/cumulative metrics
531+ assertEquals (5 , team .getUsersTotal ().getTotal (), teamName + " users_total" );
532+ assertEquals (5 , team .getUsersLast24Hours ().getTotal (), teamName + " users_last_24_hours" );
533+ assertEquals (5 , team .getUsersLast30Days ().getTotal (), teamName + " users_last_30_days" );
534+ assertEquals (5 , team .getUsersMonthToDate ().getTotal (), teamName + " users_month_to_date" );
535+ assertEquals (
536+ 0 , team .getUsersEngagedLast30Days ().getTotal (), teamName + " users_engaged_last_30_days" );
537+ assertEquals (
538+ 0 ,
539+ team .getUsersEngagedMonthToDate ().getTotal (),
540+ teamName + " users_engaged_month_to_date" );
541+
542+ // Message rolling/cumulative metrics
543+ assertEquals (100 , team .getMessagesTotal ().getTotal (), teamName + " messages_total" );
544+ assertEquals (
545+ 100 , team .getMessagesLast24Hours ().getTotal (), teamName + " messages_last_24_hours" );
546+ assertEquals (
547+ 100 , team .getMessagesLast30Days ().getTotal (), teamName + " messages_last_30_days" );
548+ assertEquals (
549+ 100 , team .getMessagesMonthToDate ().getTotal (), teamName + " messages_month_to_date" );
439550 }
440551}
0 commit comments