2727
2828import net .luckperms .rest .LuckPermsRestClient ;
2929import net .luckperms .rest .model .Action ;
30+ import net .luckperms .rest .model .ActionPage ;
3031import org .junit .jupiter .api .Test ;
32+ import org .testcontainers .shaded .com .google .common .collect .ImmutableList ;
3133import retrofit2 .Response ;
3234
3335import java .io .IOException ;
36+ import java .util .ArrayList ;
37+ import java .util .List ;
3438import java .util .UUID ;
39+ import java .util .stream .Collectors ;
3540
41+ import static org .junit .jupiter .api .Assertions .assertEquals ;
42+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
3643import static org .junit .jupiter .api .Assertions .assertTrue ;
3744
3845public class ActionServiceTest extends AbstractIntegrationTest {
@@ -50,4 +57,65 @@ public void testSubmit() throws IOException {
5057 assertTrue (resp .isSuccessful ());
5158 }
5259
60+ @ Test
61+ public void testQuery () throws IOException {
62+ LuckPermsRestClient client = createClient ();
63+
64+ long time = System .currentTimeMillis () / 1000L ;
65+ Action .Source source = new Action .Source (UUID .randomUUID (), randomName ());
66+
67+ Action testUserAction = new Action (time , source ,
68+ new Action .Target (UUID .randomUUID (), randomName (), Action .Target .Type .USER ),
69+ "test user action"
70+ );
71+ Action testGroupAction = new Action (time + 1 , source ,
72+ new Action .Target (null , randomName (), Action .Target .Type .GROUP ),
73+ "test group action"
74+ );
75+ Action testTrackAction = new Action (time + 2 , source ,
76+ new Action .Target (null , randomName (), Action .Target .Type .TRACK ),
77+ "test track action"
78+ );
79+
80+ client .actions ().submit (testUserAction ).execute ();
81+ client .actions ().submit (testGroupAction ).execute ();
82+ client .actions ().submit (testTrackAction ).execute ();
83+
84+ // test simple query all
85+ Response <ActionPage > resp1 = client .actions ().query ().execute ();
86+ assertTrue (resp1 .isSuccessful ());
87+ ActionPage body1 = resp1 .body ();
88+ assertNotNull (body1 );
89+ assertEquals (3 , body1 .overallSize ());
90+ assertEquals (ImmutableList .of (testTrackAction , testGroupAction , testUserAction ), body1 .entries ());
91+
92+ for (int i = 0 ; i < 20 ; i ++) {
93+ Action testAction = new Action (
94+ time + 100 - i ,
95+ new Action .Source (UUID .randomUUID (), randomName ()),
96+ new Action .Target (null , randomName (), Action .Target .Type .GROUP ),
97+ "test " + i
98+ );
99+ client .actions ().submit (testAction ).execute ();
100+ }
101+
102+ // test pagination
103+ Response <ActionPage > resp2 = client .actions ().query (5 , 2 ).execute ();
104+ assertTrue (resp2 .isSuccessful ());
105+ ActionPage body2 = resp2 .body ();
106+ assertNotNull (body2 );
107+ assertEquals (23 , body2 .overallSize ());
108+ assertEquals (
109+ ImmutableList .of ("test 5" , "test 6" , "test 7" , "test 8" , "test 9" ),
110+ body2 .entries ().stream ().map (Action ::description ).collect (Collectors .toList ())
111+ );
112+
113+ // test query by source
114+ Response <ActionPage > resp3 = client .actions ().querySource (source .uniqueId (), 5 , 1 ).execute ();
115+ assertTrue (resp3 .isSuccessful ());
116+ ActionPage body3 = resp3 .body ();
117+ assertNotNull (body3 );
118+ assertEquals (3 , body3 .overallSize ());
119+ }
120+
53121}
0 commit comments