View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.samplu.admin.test;
17  
18  import edu.samplu.common.Failable;
19  import edu.samplu.common.FreemarkerSTBase;
20  import edu.samplu.common.ITUtil;
21  import edu.samplu.common.PropertiesUtils;
22  import org.openqa.selenium.By;
23  
24  import java.io.File;
25  import java.io.IOException;
26  import java.util.ArrayList;
27  import java.util.List;
28  import java.util.Properties;
29  
30  /**
31   * Tests uploads of new users and group.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  
36  public abstract class XMLIngesterAbstractSmokeTestBase extends FreemarkerSTBase {
37  
38      /**
39       * http://env12.rice.kuali.org/portal.do?channelTitle=XML%20Ingester&channelUrl=http://env12.rice.kuali.org/kew/../core/Ingester.do
40       */
41      public static final String BOOKMARK_URL = ITUtil.PORTAL + "?channelTitle=XML%20Ingester&channelUrl="
42              + ITUtil.getBaseUrlString() + "/kew/../core/Ingester.do";
43  
44      // File generation
45      private String PROPS_LOCATION = System.getProperty("xmlingester.props.location", null);
46      private static final String DEFAULT_PROPS_LOCATION = "XML/xmlingester.properties";
47  
48      // Templates for File Generation
49      private static final String DIR_TMPL = "/XML/";
50      private static final String TMPL_USER_CONTENT = "SimpleUserContent.ftl";
51      private static final String TMPL_GROUP_CONTENT = "SimpleGroupContent.ftl";
52  
53      /**
54       *
55       * @param name of temp file to create
56       * @return tempFile
57       * @throws IOException
58       */
59      protected abstract File newTempFile(String name) throws IOException;
60  
61      /**
62       * {@inheritDoc}
63       * {@link #DIR_TMPL}
64       * @return
65       */
66      @Override
67      protected String getTemplateDir() {
68          return DIR_TMPL;
69      }
70  
71      /**
72       * Nav tests start at {@link ITUtil#PORTAL}.  Bookmark Tests should override and return {@link XMLIngesterAbstractSmokeTestBase#BOOKMARK_URL}
73       * {@inheritDoc}
74       * @return
75       */
76      @Override
77      public String getTestUrl() {
78          return ITUtil.PORTAL;
79      }
80  
81      /**
82       * "admin" xml ingestion requires admin permissions.
83       * {@inheritDoc}
84       * @return
85       */
86      @Override
87      public String getUserName() {
88          return "admin";
89      }
90  
91      /**
92       * go to the getMenuLinkLocator() Menu and click the getLinkLocator()
93       */
94      protected void navigate(Failable failable) throws Exception {
95          selectTopFrame();
96          waitAndClickAdministration(failable);
97          waitForTitleToEqualKualiPortalIndex();
98          waitAndClickXMLIngester(failable);
99          selectFrameIframePortlet();
100         checkForIncidentReport("XML Ingester", failable, "");
101     }
102 
103     /**
104      * Navigate to the page under test and call {@link #testIngestion}
105      *
106      * @param failable {@link edu.samplu.common.Failable}
107      * @throws Exception
108      */
109     protected void testIngestionNav(Failable failable) throws Exception {
110         navigate(failable);
111         testIngestion(failable);
112         passed();
113     }
114 
115     protected void testIngestionBookmark(Failable failable) throws Exception {
116         testIngestion(failable);
117         passed();
118     }
119 
120     /**
121      * Based on load user and groups manual tests; dynamically generates user and group file
122      * and loads into the xml ingester screen.
123      * This test should suffice for both KRAD and KNS versions of the ingester screen.
124      *
125      *
126      */
127     protected void testIngestion(Failable failable) throws Exception {
128         selectFrameIframePortlet();
129         List<File> fileUploadList = buildFileUploadList();
130         int cnt = 0;
131 
132         for(File file : fileUploadList) {
133             String path = file.getAbsolutePath().toString();
134             if (isKrad()){
135                 driver.findElement(By.name("files[" + cnt + "]")).sendKeys(path);
136             } else {
137                 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
138             }
139             cnt++;
140         }
141 
142         // Click the Upload Button
143         if (isKrad()){
144             waitAndClickByXpath("//button");
145         } else {
146             waitAndClickByXpath("//*[@id='imageField']");
147         }
148 
149         // confirm all files were uploaded successfully
150         Thread.sleep(1000);
151         for(File file: fileUploadList) {
152             assertTextPresent("Ingested xml doc: " + file.getName());
153         }
154     }
155 
156     protected List<File> buildFileUploadList() throws Exception {
157         List<File> fileUploadList = new ArrayList<File>();
158         try {
159             // update properties with timestamp value if includeDTSinPrefix is true
160             Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
161             if(props.get("userIncludeDTSinPrefix") != null
162                     && "true".equalsIgnoreCase((String) props.get("userIncludeDTSinPrefix"))) {
163                 props.setProperty("userPrefix", "" + props.get("userPrefix") + ITUtil.DTS);
164             }
165             PropertiesUtils.systemPropertiesOverride(props, "XMLIngester");
166 
167             // build files and add to array
168             fileUploadList.add(
169                     writeTemplateToFile(newTempFile("loadtest-users.xml"), cfg.getTemplate(TMPL_USER_CONTENT), props));
170             fileUploadList.add(
171                     writeTemplateToFile(newTempFile("loadtest-group.xml"), cfg.getTemplate(TMPL_GROUP_CONTENT), props));
172         } catch( Exception e) {
173             throw new Exception("Unable to generate files for upload", e);
174         }
175 
176         return fileUploadList;
177     }
178 }