5151import java .util .ArrayList ;
5252import java .util .Arrays ;
5353import java .util .Collections ;
54+ import java .util .HashMap ;
5455import java .util .List ;
5556import java .util .Locale ;
5657import java .util .Map ;
@@ -81,6 +82,23 @@ public class SampleTypeNameExpressionTest extends BaseWebDriverTest
8182 private static final String PARENT_SAMPLE_06 = "parent,06" ;
8283 private static final String PARENT_SAMPLE_07 = "\" parent07" ;
8384
85+ private static final String PARENT_FIELD_TRICKY01 = "Str01 \\ " ;
86+ private static final String PARENT_FIELD_TRICKY01_ESC = "Str01 \\ \\ " ;
87+ private static final String PARENT_FIELD_TRICKY02 = "Str02 $" ;
88+ private static final String PARENT_FIELD_TRICKY02_ESC = "Str02 \\ $" ;
89+ private static final String PARENT_FIELD_TRICKY03 = "Str03 /" ;
90+ private static final String PARENT_FIELD_TRICKY03_ESC = "Str03 \\ /" ;
91+ private static final String PARENT_FIELD_TRICKY04 = "Str04 ." ;
92+ private static final String PARENT_FIELD_TRICKY04_ESC = "Str04 \\ ." ;
93+ private static final String PARENT_FIELD_TRICKY05 = "Str05 &" ;
94+ private static final String PARENT_FIELD_TRICKY05_ESC = "Str05 \\ &" ;
95+ private static final String PARENT_FIELD_TRICKY06 = "Str06 {}" ;
96+ private static final String PARENT_FIELD_TRICKY06_ESC = "Str06 {\\ }" ;
97+ private static final String PARENT_FIELD_TRICKY07 = "Str07 ~" ;
98+ private static final String PARENT_FIELD_TRICKY07_ESC = "Str07 \\ ~" ;
99+ private static final String PARENT_FIELD_TRICKY08 = "Str08 ," ;
100+ private static final String PARENT_FIELD_TRICKY08_ESC = "Str08 \\ ," ;
101+
84102 private static final File PARENT_EXCEL = TestFileUtils .getSampleData ("samples/ParentSamples.xlsx" );
85103
86104 protected final AuditLogHelper _auditLogHelper = new AuditLogHelper (this );
@@ -107,11 +125,21 @@ public static void setupProject() throws IOException, CommandException
107125
108126 private void addDataRow (TestDataGenerator dataGenerator , String name , int intVal )
109127 {
110- Map <String , Object > sampleData = Map .of (
111- "name" , name ,
112- "Int" , intVal ,
113- "Str" , "Parent Sample " + ((char ) (intVal + 95 )),
114- "Date" , intVal + "/14/2020" );
128+ Map <String , Object > sampleData = new HashMap <>();
129+
130+ sampleData .put ("name" , name );
131+ sampleData .put ("Int" , intVal );
132+ sampleData .put ("Str" , "Parent Sample " + ((char ) (intVal + 95 )));
133+ sampleData .put ("Date" , intVal + "/14/2020" );
134+ sampleData .put (PARENT_FIELD_TRICKY01 , intVal + " tricky01" );
135+ sampleData .put (PARENT_FIELD_TRICKY02 , intVal + " tricky02" );
136+ sampleData .put (PARENT_FIELD_TRICKY03 , intVal + " tricky03" );
137+ sampleData .put (PARENT_FIELD_TRICKY04 , intVal + " tricky04" );
138+ sampleData .put (PARENT_FIELD_TRICKY05 , intVal + " tricky05" );
139+ sampleData .put (PARENT_FIELD_TRICKY06 , intVal + " tricky06" );
140+ sampleData .put (PARENT_FIELD_TRICKY07 , intVal + " tricky07" );
141+ sampleData .put (PARENT_FIELD_TRICKY08 , intVal + " tricky08" );
142+
115143 dataGenerator .addCustomRow (sampleData );
116144 }
117145
@@ -128,12 +156,19 @@ private void doSetup() throws IOException, CommandException
128156 definition = definition .setFields (List .of (
129157 new FieldDefinition ("Str" , FieldDefinition .ColumnType .String ),
130158 new FieldDefinition ("Int" , FieldDefinition .ColumnType .Integer ),
131- new FieldDefinition ("Date" , FieldDefinition .ColumnType .DateAndTime )));
159+ new FieldDefinition ("Date" , FieldDefinition .ColumnType .DateAndTime ),
160+ new FieldDefinition (PARENT_FIELD_TRICKY01 , FieldDefinition .ColumnType .String ),
161+ new FieldDefinition (PARENT_FIELD_TRICKY02 , FieldDefinition .ColumnType .String ),
162+ new FieldDefinition (PARENT_FIELD_TRICKY03 , FieldDefinition .ColumnType .String ),
163+ new FieldDefinition (PARENT_FIELD_TRICKY04 , FieldDefinition .ColumnType .String ),
164+ new FieldDefinition (PARENT_FIELD_TRICKY05 , FieldDefinition .ColumnType .String ),
165+ new FieldDefinition (PARENT_FIELD_TRICKY06 , FieldDefinition .ColumnType .String ),
166+ new FieldDefinition (PARENT_FIELD_TRICKY07 , FieldDefinition .ColumnType .String ),
167+ new FieldDefinition (PARENT_FIELD_TRICKY08 , FieldDefinition .ColumnType .String )));
132168
133169 TestDataGenerator dataGenerator = SampleTypeAPIHelper .createEmptySampleType (getCurrentContainerPath (), definition );
134170
135- log (String .format ("Give the parent sample type '%1$s' three samples named '%2$s', '%3$s' and '%4$s'." ,
136- PARENT_SAMPLE_TYPE , PARENT_SAMPLE_01 , PARENT_SAMPLE_02 , PARENT_SAMPLE_03 ));
171+ log ("Add some 'parent' samples." );
137172
138173 addDataRow (dataGenerator , PARENT_SAMPLE_01 , 1 );
139174 addDataRow (dataGenerator , PARENT_SAMPLE_02 , 2 );
@@ -388,6 +423,67 @@ public void testWithTrickyCharacters()
388423 checker ().screenShotIfNewError ("SampleCreationError" );
389424 }
390425
426+ /**
427+ * <p>
428+ * Automation to cover issue 52180. The name expression for the sample type will reference fields that contain
429+ * "special" characters.
430+ * </p>
431+ */
432+ @ Test
433+ public void testWithTrickyFieldNames () throws IOException , CommandException
434+ {
435+ goToProjectHome ();
436+
437+ SampleTypeHelper sampleHelper = new SampleTypeHelper (this );
438+
439+ final String sampleType = "Issue 52180 Sample Type" ;
440+
441+ StringBuilder sbNameExpression = new StringBuilder ();
442+
443+ // Covers Issue 52180
444+ String parentsampleTypeEncoded = PARENT_SAMPLE_TYPE .replace ("/" , "\\ /" );
445+ sbNameExpression .append ("Trick-Field ${genId} " );
446+ sbNameExpression .append (String .format ("${materialInputs/%s/%s} " , parentsampleTypeEncoded , PARENT_FIELD_TRICKY01_ESC ));
447+ sbNameExpression .append (String .format ("${materialInputs/%s/%s} " , parentsampleTypeEncoded , PARENT_FIELD_TRICKY02_ESC ));
448+ sbNameExpression .append (String .format ("${materialInputs/%s/%s} " , parentsampleTypeEncoded , PARENT_FIELD_TRICKY03_ESC ));
449+ sbNameExpression .append (String .format ("${materialInputs/%s/%s} " , parentsampleTypeEncoded , PARENT_FIELD_TRICKY04_ESC ));
450+ sbNameExpression .append (String .format ("${materialInputs/%s/%s} " , parentsampleTypeEncoded , PARENT_FIELD_TRICKY05_ESC ));
451+ sbNameExpression .append (String .format ("${materialInputs/%s/%s} " , parentsampleTypeEncoded , PARENT_FIELD_TRICKY06_ESC ));
452+ sbNameExpression .append (String .format ("${materialInputs/%s/%s} " , parentsampleTypeEncoded , PARENT_FIELD_TRICKY07_ESC ));
453+ sbNameExpression .append (String .format ("${materialInputs/%s/%s}" , parentsampleTypeEncoded , PARENT_FIELD_TRICKY08_ESC ));
454+
455+ log (String .format ("Create a sample type named '%s' with a name expression of '%s'." , sampleType , sbNameExpression ));
456+
457+ CreateSampleTypePage createPage = sampleHelper .goToCreateNewSampleType ();
458+
459+ createPage .setName (sampleType );
460+
461+ createPage .setNameExpression (sbNameExpression .toString ());
462+
463+ // Issue 53306 There is a problem with the derived sample form and field names that contain "special" characters.
464+ // String intField = TestDataGenerator.randomFieldName("Int");
465+ // String strField = TestDataGenerator.randomFieldName("Str");
466+ String intField = "Int" ;
467+ String strField = "Str" ;
468+ createPage .addFields (Arrays .asList (
469+ new FieldDefinition (intField , FieldDefinition .ColumnType .Integer ),
470+ new FieldDefinition (strField , FieldDefinition .ColumnType .String )));
471+
472+ createPage .clickSave ();
473+
474+ String flagString = "Hello, I'm a derived sample." ;
475+ String intVal = "678" ;
476+ String derivedSampleName = deriveSample (PARENT_SAMPLE_01 , PARENT_SAMPLE_TYPE , sampleType ,
477+ Map .of (intField , intVal ,
478+ strField , flagString ));
479+
480+ checker ().verifyTrue ("Name of derived sample doesn't look correct. Should start with 'Trick-Field '." ,
481+ derivedSampleName .startsWith ("Trick-Field " ));
482+ checker ().verifyTrue (String .format ("Doesn't look like there is a link to the parent sample '%s'." , PARENT_SAMPLE_01 ),
483+ isElementPresent (Locator .linkWithText (PARENT_SAMPLE_01 )));
484+
485+ }
486+
391487 @ Test
392488 public void testInputsExpression ()
393489 {
@@ -604,7 +700,9 @@ public void testDeriveSampleFromSampleDetailsPage() throws Exception
604700
605701 String flagString = "Hello, I'm a derived sample." ;
606702 String intVal = "987" ;
607- String derivedSampleName = deriveSample (PARENT_SAMPLE_01 , PARENT_SAMPLE_TYPE , sampleType , flagString , intVal );
703+ String derivedSampleName = deriveSample (PARENT_SAMPLE_01 , PARENT_SAMPLE_TYPE , sampleType ,
704+ Map .of ("Str" , flagString ,
705+ "Int" , intVal ));
608706
609707 checker ().verifyTrue ("Name of derived sample doesn't look correct. Should contain 'Parent Sample'." ,
610708 derivedSampleName .contains ("Parent Sample" ));
@@ -624,7 +722,9 @@ public void testDeriveSampleFromSampleDetailsPage() throws Exception
624722
625723 String flagStringGD = "grand child sample." ;
626724 String intValGD = "567" ;
627- String grandChildSampleName = deriveSample (derivedSampleName , sampleType , sampleType , flagStringGD , intValGD );
725+ String grandChildSampleName = deriveSample (derivedSampleName , sampleType , sampleType ,
726+ Map .of ("Str" , flagStringGD ,
727+ "Int" , intValGD ));
628728 checker ().verifyTrue (String .format ("Name of derived sample doesn't look correct. Should contain 'Parent Sample' and not contain '%s'." , flagString ),
629729 grandChildSampleName .contains ("Parent Sample" ) && !grandChildSampleName .contains (flagString ));
630730 checker ().verifyTrue (String .format ("Doesn't look like there is a link to the parent sample '%s'." , derivedSampleName ),
@@ -654,7 +754,7 @@ public void testDeriveSampleFromSampleDetailsPage() throws Exception
654754 isElementPresent (Locator .linkWithText (derivedSampleName )));
655755 }
656756
657- private String deriveSample (String parentSampleName , String parentSampleType , String targetSampleType , String strVal , String intVal ) throws IOException , CommandException
757+ private String deriveSample (String parentSampleName , String parentSampleType , String targetSampleType , Map < String , String > setField ) throws IOException , CommandException
658758 {
659759 log (String .format ("Go to the 'overview' page for sample '%s' in sample type '%s'" , parentSampleName , parentSampleType ));
660760 Integer sampleRowNum = SampleTypeAPIHelper .getRowIdsForSamples (getProjectName (), parentSampleType , Arrays .asList (parentSampleName )).get (parentSampleName );
@@ -671,11 +771,15 @@ private String deriveSample(String parentSampleName, String parentSampleType, St
671771 selectOptionByText (Locator .name ("targetSampleTypeId" ), String .format ("%s in /%s" , targetSampleType , getProjectName ()));
672772 clickButton ("Next" );
673773
674- setFormElement (Locator .name ("outputSample1_Int" ), intVal );
675- setFormElement (Locator .name ("outputSample1_Str" ), strVal );
774+ String flagString = "" ;
775+ for (Map .Entry <String , String > entry : setField .entrySet ())
776+ {
777+ setFormElement (Locator .name (String .format ("outputSample1_%s" , entry .getKey ())), entry .getValue ());
778+ flagString = entry .getValue ();
779+ }
676780 clickButton ("Submit" );
677781
678- waitForElement (Locator .tagWithText ("td" , strVal ));
782+ waitForElement (Locator .tagWithText ("td" , flagString ));
679783
680784 return Locator .tagWithText ("td" , "Name:" ).followingSibling ("td" ).findElement (getDriver ()).getText ();
681785 }
0 commit comments