1616
1717package org .labkey .test .tests .snd ;
1818
19+ import org .junit .Assert ;
1920import org .junit .Before ;
2021import org .junit .BeforeClass ;
2122import org .junit .Ignore ;
5657import org .labkey .test .util .ApiPermissionsHelper ;
5758import org .labkey .test .util .DataRegionTable ;
5859import org .labkey .test .util .Maps ;
60+ import org .labkey .test .util .OptionalFeatureHelper ;
61+ import org .labkey .test .util .PortalHelper ;
5962import org .labkey .test .util .SqlserverOnlyTest ;
63+ import org .labkey .test .util .StudyHelper ;
6064import org .labkey .test .util .core .webdav .WebDavUploadHelper ;
6165import org .openqa .selenium .WebElement ;
6266
@@ -107,6 +111,7 @@ public class SNDTest extends BaseWebDriverTest implements SqlserverOnlyTest
107111 private static final int TEST_CATEGORY_ID2 = 51 ;
108112 private static final int TEST_CATEGORY_ID3 = 52 ;
109113 private static final int TEST_CATEGORY_ID4 = 53 ;
114+ private static final int TEST_CATEGORY_ID5 = 54 ;
110115 private static final int TEST_SUPER_PKG_START_ID1 = 130 ;
111116 private static final int TEST_SUPER_PKG_START_ID2 = 140 ;
112117 private static final int TEST_SUPER_PKG_START_ID3 = 150 ;
@@ -141,6 +146,8 @@ public class SNDTest extends BaseWebDriverTest implements SqlserverOnlyTest
141146 private static final String UITEST_PROJECT_SUBPKG2 = "Vet Comment" ;
142147 private static final String UITEST_PROJECT_SUBPKG3 = "Ketamine Sedation" ;
143148
149+ private static final String STUDY_NAME = "Query provisioned snapshot test" ;
150+
144151 private static final String CREATEDOMAINSAPI ="LABKEY.Domain.create({\n " +
145152 " domainGroup: 'test', \n " +
146153 " domainKind: 'SND', \n " +
@@ -553,7 +560,12 @@ private static String getPackageWithId(String packageId)
553560 " 'Description': 'Weight', \n " +
554561 " 'Active': true, \n " +
555562 " 'Comment': 'This is a weight' \n " +
556- " },{ \n " +
563+ " },{ \n " +
564+ " 'CategoryId': " + TEST_CATEGORY_ID5 + " ,\n " +
565+ " 'Description': 'Sodium', \n " +
566+ " 'Active': true, \n " +
567+ " 'Comment': 'This is Sodium' \n " +
568+ " },{ \n " +
557569 " 'CategoryId': " + TEST_CATEGORY_ID4 + ",\n " +
558570 " 'Description': 'Vitals', \n " +
559571 " 'Active': true, \n " +
@@ -870,16 +882,16 @@ public void checkLinks()
870882 @ BeforeClass
871883 public static void setupProject ()
872884 {
873- SNDTest init = (SNDTest ) getCurrentTest ();
874-
885+ SNDTest init = getCurrentTest ();
875886 init .doSetup ();
876887 }
877888
878889 private void doSetup ()
879890 {
880891 _containerHelper .createProject (getProjectName (), "Collaboration" );
881892 goToProjectHome ();
882- _containerHelper .enableModules (Arrays .asList ("SND" ));
893+ _containerHelper .enableModules (Arrays .asList ("SND" , "Study" ));
894+
883895 _containerHelper .createSubfolder (getProjectName (), getProjectName (), TEST1SUBFOLDER , "Collaboration" , new String []{"SND" });
884896 setupTest1Project ();
885897
@@ -2089,8 +2101,7 @@ public void reviseProjectViaUI() throws Exception
20892101 assertFalse ("Unassigned package found assigned." , viewPage .isAssignedPackagePresent (UITEST_PROJECT_SUBPKG2 ));
20902102 }
20912103
2092- @ Test
2093- public void verifyTestFrameworkAPITests ()
2104+ private boolean runTestsInAPIFrameWork ()
20942105 {
20952106 log ("Launching the Testing framework" );
20962107 goToProjectHome ();
@@ -2101,11 +2112,10 @@ public void verifyTestFrameworkAPITests()
21012112 clickButton ("Run tests" , 0 );
21022113 waitForText ("Total tests:" , 1 , WAIT_FOR_PAGE );
21032114
2104- log ("Verifying no test failed" );
2105- assertTextPresent ("Complete" ,"Failed tests: 0" );
2115+ return isTextPresent ("Complete" ,"Failed tests: 0" );
21062116 }
21072117
2108- private String getPerimissionTableValue (int row , int col )
2118+ private String getPermissionTableValue (int row , int col )
21092119 {
21102120 List <WebElement > els = ((Locator .XPathLocator )getSimpleTableCell (Locator .id ("category-security" ), row , col )).child ("div" ).child ("a" ).child ("input" ).findElements (getDriver ());
21112121 if (els .size () > 0 )
@@ -2157,7 +2167,7 @@ public void categoryPermissionsUI() throws Exception
21572167 {
21582168 if (categories .contains (getTableCellText (Locator .id ("category-security" ), i , 0 )))
21592169 {
2160- value = getPerimissionTableValue (i , 1 );
2170+ value = getPermissionTableValue (i , 1 );
21612171 assertNotNull (value );
21622172 assertTrue (value .equals ("None" ));
21632173 categoryRows .add (i );
@@ -2169,7 +2179,7 @@ public void categoryPermissionsUI() throws Exception
21692179
21702180 for (Integer r : categoryRows )
21712181 {
2172- value = getPerimissionTableValue (r , 1 );
2182+ value = getPermissionTableValue (r , 1 );
21732183 assertNotNull (value );
21742184 assertTrue (value .equals ("SND Reader" ));
21752185 }
@@ -2179,7 +2189,7 @@ public void categoryPermissionsUI() throws Exception
21792189
21802190 for (int k = 0 ; k < categoryRows .size (); k ++)
21812191 {
2182- value = getPerimissionTableValue (categoryRows .get (k ), 1 );
2192+ value = getPermissionTableValue (categoryRows .get (k ), 1 );
21832193 assertNotNull (value );
21842194 assertTrue (value .equals ("None" ));
21852195 click (getSimpleTableCell (Locator .id ("category-security" ), categoryRows .get (k ), 1 ));
@@ -2190,13 +2200,96 @@ public void categoryPermissionsUI() throws Exception
21902200
21912201 for (int j = 0 ; j < categoryRows .size (); j ++)
21922202 {
2193- value = getPerimissionTableValue (categoryRows .get (j ), 1 );
2203+ value = getPermissionTableValue (categoryRows .get (j ), 1 );
21942204 assertNotNull (value );
21952205 assertTrue (value .equals (permissions .get (j )));
21962206 }
21972207
21982208 }
21992209
2210+ @ Test
2211+ public void testQueryProvisionedSnapshot ()
2212+ {
2213+ String SOURCE_QUERY_NAME = "SND: Source query" ;
2214+ String SNAPSHOT_NAME = SOURCE_QUERY_NAME + " Snapshot" ;
2215+ String SOURCE_QUERY = "SELECT\n " +
2216+ "lsid AS _key,\n " +
2217+ "SubjectId AS participantid,\n " +
2218+ "date,\n " +
2219+ "qcstate,\n " +
2220+ "lsid,\n " +
2221+ "amount,\n " +
2222+ "units,\n " +
2223+ "kit_type\n " +
2224+ "FROM SND.Categories.Sodium\n " ;
2225+
2226+ String UPDATED_SOURCE_QUERY = "SELECT\n " +
2227+ "lsid AS _key,\n " +
2228+ "SubjectId AS participantid,\n " +
2229+ "date,\n " +
2230+ "qcstate,\n " +
2231+ "lsid,\n " +
2232+ "'8976' AS amount,\n " +
2233+ "units,\n " +
2234+ "kit_type\n " +
2235+ "FROM SND.Categories.Sodium" ;
2236+
2237+ log ("Run the tests from the framework for set up" );
2238+ if (!runTestsInAPIFrameWork ())
2239+ Assert .fail ("Tests failed in the framework" );
2240+
2241+ log ("Enable Allow query based dataset snapshots" );
2242+ OptionalFeatureHelper .enableOptionalFeature (createDefaultConnection (), "queryBasedDatasets" );
2243+
2244+ log ("Enable study module and create continuous study" );
2245+ goToProjectHome ();
2246+ goToManageStudy ();
2247+ _studyHelper .startCreateStudy ()
2248+ .setTimepointType (StudyHelper .TimepointType .CONTINUOUS )
2249+ .createStudy ();
2250+
2251+ log ("Adding dataset webpart" );
2252+ goToProjectHome ();
2253+ PortalHelper _portalHelper = new PortalHelper (getDriver ());
2254+ _portalHelper .addBodyWebPart ("Datasets" );
2255+
2256+ log ("Create source query from study" );
2257+ goToSchemaBrowser ();
2258+ createNewQuery ("study" );
2259+ setFormElement (Locator .id ("ff_newQueryName" ), SOURCE_QUERY_NAME );
2260+ selectOptionByText (Locator .name ("ff_baseTableName" ), "DataSets" );
2261+ clickButton ("Create and Edit Source" );
2262+ setCodeEditorValue ("queryText" , SOURCE_QUERY );
2263+ clickButton ("Save & Finish" );
2264+
2265+ log ("Create the snapshot" );
2266+ DataRegionTable queryTable = new DataRegionTable .DataRegionFinder (getDriver ()).withName ("query" ).waitFor ();
2267+ queryTable .goToReport ("Create Query Snapshot" );
2268+ checkCheckbox (Locator .name ("queryDataset" ));
2269+ clickButton ("Create Snapshot" );
2270+
2271+ log ("Verify the dataset snapshot" );
2272+ goToProjectHome ();
2273+ clickAndWait (Locator .linkWithText (SNAPSHOT_NAME ));
2274+ DataRegionTable dataRegionTable = new DataRegionTable .DataRegionFinder (getDriver ()).withName ("Dataset" ).waitFor ();
2275+ Assert .assertEquals ("Incorrect number of rows" , 3 , dataRegionTable .getDataRowCount ());
2276+ Assert .assertEquals ("Incorrect column titles" , Arrays .asList ("ParticipantId" , "_key" , "date" , "amount" , "units" , "kit_type" ),
2277+ dataRegionTable .getColumnNames ());
2278+ Assert .assertEquals ("Incorrect value in amount column" , Arrays .asList ("100" , "100" , " " ), dataRegionTable .getColumnDataAsText ("amount" ));
2279+
2280+ log ("Edit the source query and verify snapshot is updated" );
2281+ goToSchemaBrowser ();
2282+ selectQuery ("study" , SOURCE_QUERY_NAME );
2283+ clickAndWait (Locator .linkContainingText ("edit source" ));
2284+ setCodeEditorValue ("queryText" , UPDATED_SOURCE_QUERY );
2285+ clickButton ("Save & Finish" );
2286+
2287+ goToProjectHome ();
2288+ clickAndWait (Locator .linkWithText (SNAPSHOT_NAME ));
2289+ dataRegionTable = new DataRegionTable .DataRegionFinder (getDriver ()).withName ("Dataset" ).waitFor ();
2290+ Assert .assertEquals ("Incorrect value in amount column" , Arrays .asList ("8976" , "8976" , "8976" ), dataRegionTable .getColumnDataAsText ("amount" ));
2291+ }
2292+
22002293 private void truncateSndPkg () throws Exception
22012294 {
22022295 //cleanup - truncate snd.pkgs
0 commit comments