1515 */
1616package org .labkey .test .tests ;
1717
18+ import org .assertj .core .api .Assertions ;
1819import org .jetbrains .annotations .Nullable ;
1920import org .junit .Assert ;
2021import org .junit .Before ;
2627import org .labkey .remoteapi .query .DeleteRowsCommand ;
2728import org .labkey .remoteapi .query .InsertRowsCommand ;
2829import org .labkey .remoteapi .query .BaseRowsCommand ;
30+ import org .labkey .remoteapi .query .MoveRowsCommand ;
2931import org .labkey .remoteapi .query .RowsResponse ;
3032import org .labkey .remoteapi .query .UpdateRowsCommand ;
3133import org .labkey .test .BaseWebDriverTest ;
4042import org .labkey .test .params .FieldDefinition .ColumnType ;
4143import org .labkey .test .params .experiment .DataClassDefinition ;
4244import org .labkey .test .params .experiment .SampleTypeDefinition ;
45+ import org .labkey .test .params .list .IntListDefinition ;
46+ import org .labkey .test .params .list .ListDefinition ;
4347import org .labkey .test .util .DataRegionTable ;
4448import org .labkey .test .util .Maps ;
4549import org .labkey .test .util .PortalHelper ;
6165@ BaseWebDriverTest .ClassTimeout (minutes = 8 )
6266public class TriggerScriptTest extends BaseWebDriverTest
6367{
68+ private static final String PROJECT_NAME = "Test Trigger Script Project" ;
69+ private static final String SUBFOLDER_NAME = "SubfolderA" ;
70+ private static final String SUBFOLDER_PATH = "/" + PROJECT_NAME + "/" + SUBFOLDER_NAME ;
71+
6472 //List constants
6573 private static final String TRIGGER_MODULE = "triggerTestModule" ;
6674 private static final String SIMPLE_MODULE = "simpletest" ;
@@ -90,6 +98,7 @@ public class TriggerScriptTest extends BaseWebDriverTest
9098 public static final String PEOPLE_LIST_NAME = "People" ;
9199
92100 protected final PortalHelper _portalHelper = new PortalHelper (this );
101+ private static ListDefinition EMPLOYEE_LIST ;
93102
94103 @ Override
95104 public List <String > getAssociatedModules ()
@@ -101,7 +110,7 @@ public List<String> getAssociatedModules()
101110 @ Override
102111 protected String getProjectName ()
103112 {
104- return "Test Trigger Script Project" ;
113+ return PROJECT_NAME ;
105114 }
106115
107116 @ Override
@@ -167,36 +176,42 @@ private interface GoToDataUI
167176 }
168177
169178 @ BeforeClass
170- public static void projectSetup ()
179+ public static void projectSetup () throws Exception
171180 {
172181 TriggerScriptTest init = getCurrentTest ();
173182 init .doSetup ();
174183 }
175184
176-
177- protected void doSetup ()
185+ protected void doSetup () throws Exception
178186 {
179187 _containerHelper .createProject (getProjectName (), null );
188+ _containerHelper .createSubfolder (getProjectName (), SUBFOLDER_NAME );
180189 _containerHelper .enableModule (getProjectName (), "Query" );
181190 _containerHelper .enableModule (getProjectName (), SIMPLE_MODULE );
182191 _containerHelper .enableModule (getProjectName (), TRIGGER_MODULE );
183192
184- //create List
185- FieldDefinition [] columns = new FieldDefinition [] {
193+ // Create lists
194+ {
195+ List <FieldDefinition > fields = List .of (
186196 new FieldDefinition ("name" , ColumnType .String ).setLabel ("Name" ),
187197 new FieldDefinition ("ssn" , ColumnType .String ).setLabel ("SSN" ),
188198 new FieldDefinition ("company" , ColumnType .String ).setLabel ("Company" )
199+ );
189200
190- };
191-
192- _listHelper .createList (getProjectName (), LIST_NAME , "Key" , columns );
201+ EMPLOYEE_LIST = new IntListDefinition (LIST_NAME , "Key" ).setFields (fields );
202+ EMPLOYEE_LIST .create (createDefaultConnection (), getProjectName ());
193203
194- log ("Create the People list" );
195- _listHelper .createList (getProjectName (), PEOPLE_LIST_NAME , "Key" ,
204+ fields = List .of (
196205 new FieldDefinition ("Name" , ColumnType .String ).setDescription ("Name" ),
197206 new FieldDefinition ("Age" , ColumnType .Integer ).setDescription ("Age" ),
198207 new FieldDefinition ("FavoriteDateTime" , ColumnType .DateAndTime ).setDescription ("Favorite date time. Who doesn't have one?" ),
199- new FieldDefinition ("Crazy" , ColumnType .Boolean ).setDescription ("Crazy?" ));
208+ new FieldDefinition ("Crazy" , ColumnType .Boolean ).setDescription ("Crazy?" )
209+ );
210+
211+ new IntListDefinition (PEOPLE_LIST_NAME , "Key" )
212+ .setFields (fields )
213+ .create (createDefaultConnection (), getProjectName ());
214+ }
200215
201216 importFolderFromZip (TestFileUtils .getSampleData ("studies/LabkeyDemoStudy.zip" ));
202217
@@ -217,6 +232,7 @@ public void goToProjectStart()
217232 @ Test
218233 public void testListIndividualTriggers ()
219234 {
235+ cleanUpListRows ();
220236 EmployeeRecord caughtAfter = new EmployeeRecord ("Emp 1" , "1112223333" , "Test" ),
221237 changedBefore = new EmployeeRecord ("Emp 2" , "2223334444" , "Some Other" );
222238
@@ -267,12 +283,12 @@ public void testListIndividualTriggers()
267283 clickButton ("Back" );
268284 //Verify validation error prevented delete
269285 waitForElement (Locator .tagWithText ("td" , "Emp 3" ));
270- cleanUpListRows ();
271286 }
272287
273288 @ Test
274289 public void testListImportTriggers ()
275290 {
291+ cleanUpListRows ();
276292 goToManagedList (LIST_NAME );
277293 _listHelper .clickImportData ();
278294
@@ -302,7 +318,27 @@ public void testListImportTriggers()
302318 importDataPage .submit ();
303319
304320 waitForElement (Locator .tagWithText ("td" ,"Importing TSV" ));
321+ }
322+
323+ @ Test
324+ public void testListMoveTriggers () throws Exception
325+ {
305326 cleanUpListRows ();
327+
328+ RowsResponse response = EMPLOYEE_LIST .getTestDataGenerator (getProjectName ())
329+ .addCustomRow (Map .of ("name" , "Emp 11" , "ssn" , "123-45-6789" , "company" , "LK" ))
330+ .insertRows ();
331+
332+ List <EmployeeRecord > records = response .getRows ().stream ().map (EmployeeRecord ::fromMap ).toList ();
333+
334+ openServerJavaScriptConsole ();
335+
336+ MoveRowsCommand command = new MoveRowsCommand (SUBFOLDER_PATH , LIST_SCHEMA , LIST_NAME );
337+ command .setRows (List .of (Map .of ("Key" , records .get (0 ).key )));
338+ command .execute (createDefaultConnection (), getProjectName ());
339+ waitForConsole ("init got triggered with event: move" , "complete got triggered with event: move" );
340+
341+ closeServerJavaScriptConsole ();
306342 }
307343
308344 /** Issue 52098 - ensure trigger scripts have a chance to do custom type conversion with the incoming row */
@@ -336,9 +372,10 @@ public void testListAPITriggerTypeConversion() throws Exception
336372 Assert .assertEquals (26 , updatedRow .get ("Age" ));
337373 }
338374
339- @ Test
375+ @ Test
340376 public void testListAPITriggers () throws Exception
341377 {
378+ cleanUpListRows ();
342379 String ssn1 = "111111112" ;
343380 String ssn2 = "222211111" ;
344381
@@ -408,8 +445,6 @@ public void testListAPITriggers() throws Exception
408445 delCmd = new DeleteRowsCommand (LIST_SCHEMA , LIST_NAME );
409446 delCmd .addRow (row3 .toMap ());
410447 assertAPIErrorMessage (delCmd , BEFORE_DELETE_ERROR , cn );
411-
412- cleanUpListRows ();
413448 }
414449
415450 /********************************
@@ -470,7 +505,7 @@ public void testDatasetImportTriggers()
470505 @ Test
471506 public void testDatasetAPITriggers () throws Exception
472507 {
473- doAPITriggerTest (STUDY_SCHEMA ,DATASET_NAME ,"ParticipantId" , true );
508+ doAPITriggerTest (STUDY_SCHEMA , DATASET_NAME , "ParticipantId" , true );
474509 }
475510
476511 /********************************
@@ -484,22 +519,14 @@ public void testDataClassIndividualTriggers() throws Exception
484519 GoToDataUI goToDataClass = () -> goTo ("Data Classes" , DATA_CLASSES_NAME );
485520
486521 setupDataClass ();
522+ openServerJavaScriptConsole ();
487523
488- // Go to the log view to start capturing messages
489- new SiteNavBar (getDriver ()).clickAdminMenuItem (false , "Developer Links" , "Server JavaScript Console" );
490- switchToWindow (1 );
491- waitForText ("Message" );
492-
493- switchToMainWindow ();
494524 doIndividualTriggerTest ("query" , goToDataClass , "Name" , false , "Yes, Delete" , false );
495525
496- // Go back to the console window
497- switchToWindow (1 );
498- waitForText ("init got triggered with event: delete" ,
526+ waitForConsole ("init got triggered with event: delete" ,
499527 "exp.data: this is from the shared function" ,
500528 "complete got triggered with event: delete" );
501- getDriver ().close ();
502- switchToMainWindow ();
529+ closeServerJavaScriptConsole ();
503530 }
504531
505532
@@ -728,7 +755,9 @@ private void assertAPIErrorMessage(BaseRowsCommand cmd, String expected, Connect
728755 }
729756 catch (CommandException e )
730757 {
731- Assert .assertTrue ("Trigger script error message was wrong" , e .getMessage ().contains (expected ));
758+ Assertions .assertThat (e .getMessage ())
759+ .as ("Trigger script error should contain expected text" )
760+ .contains (expected );
732761 }
733762 }
734763
@@ -834,7 +863,7 @@ private void goTo(String webPartName, String tableName)
834863 /**
835864 * Generate delimited string of keys from a map
836865 */
837- private String joinMapValues (Map <String ,String > data , String delimiter )
866+ private String joinMapValues (Map <String ,String > data , String delimiter )
838867 {
839868 StringBuilder sb = new StringBuilder ();
840869 data .values ().forEach (val -> sb .append (val ).append (delimiter ));
@@ -844,7 +873,7 @@ private String joinMapValues(Map<String,String> data, String delimiter )
844873 /**
845874 * Generate delimited string of keys from a map
846875 */
847- private String joinMapKeys (Map <String ,String > data , String delimiter )
876+ private String joinMapKeys (Map <String ,String > data , String delimiter )
848877 {
849878 StringBuilder sb = new StringBuilder ();
850879 data .keySet ().forEach (val -> sb .append (val ).append (delimiter ));
@@ -885,4 +914,27 @@ private void setupSampleType()
885914 new FieldDefinition (COUNTRY_FIELD , ColumnType .String )));
886915 SampleTypeAPIHelper .createEmptySampleType (getProjectName (), sampleType );
887916 }
917+
918+ private void closeServerJavaScriptConsole ()
919+ {
920+ switchToWindow (1 );
921+ getDriver ().close ();
922+ switchToMainWindow ();
923+ }
924+
925+ private void openServerJavaScriptConsole ()
926+ {
927+ // Go to the log view to start capturing messages
928+ new SiteNavBar (getDriver ()).clickAdminMenuItem (false , "Developer Links" , "Server JavaScript Console" );
929+ switchToWindow (1 );
930+ waitForText ("Message" );
931+ switchToMainWindow ();
932+ }
933+
934+ private void waitForConsole (String ... text )
935+ {
936+ switchToWindow (1 );
937+ waitForText (text );
938+ switchToMainWindow ();
939+ }
888940}
0 commit comments