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 org.openqa.selenium.By;
22  
23  import java.io.File;
24  import java.io.IOException;
25  import java.util.ArrayList;
26  import java.util.List;
27  import java.util.Properties;
28  
29  /**
30   * Tests uploads of new users and group.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  
35  public abstract class XMLIngesterAbstractSmokeTestBase extends FreemarkerSTBase {
36  
37      /**
38       * http://env12.rice.kuali.org/portal.do?channelTitle=XML%20Ingester&channelUrl=http://env12.rice.kuali.org/kew/../core/Ingester.do
39       */
40      public static final String BOOKMARK_URL = ITUtil.PORTAL + "?channelTitle=XML%20Ingester&channelUrl="
41              + ITUtil.getBaseUrlString() + "/kew/../core/Ingester.do";
42  
43      // File generation
44      private String PROPS_LOCATION = System.getProperty("xmlingester.props.location", null);
45      private static final String DEFAULT_PROPS_LOCATION = "XML/xmlingester.properties";
46  
47      // Templates for File Generation
48      private static final String DIR_TMPL = "/XML/";
49      private static final String TMPL_USER_CONTENT = "SimpleUserContent.ftl";
50      private static final String TMPL_GROUP_CONTENT = "SimpleGroupContent.ftl";
51  
52      /**
53       *
54       * @param name of temp file to create
55       * @return tempFile
56       * @throws IOException
57       */
58      protected abstract File newTempFile(String name) throws IOException;
59  
60      /**
61       * {@inheritDoc}
62       * {@link #DIR_TMPL}
63       * @return
64       */
65      @Override
66      protected String getTemplateDir() {
67          return DIR_TMPL;
68      }
69  
70      /**
71       * Nav tests start at {@link ITUtil#PORTAL}.  Bookmark Tests should override and return {@link XMLIngesterAbstractSmokeTestBase#BOOKMARK_URL}
72       * {@inheritDoc}
73       * @return
74       */
75      @Override
76      public String getTestUrl() {
77          return ITUtil.PORTAL;
78      }
79  
80      /**
81       * "admin" xml ingestion requires admin permissions.
82       * {@inheritDoc}
83       * @return
84       */
85      @Override
86      public String getUserName() {
87          return "admin";
88      }
89  
90      /**
91       * go to the getMenuLinkLocator() Menu and click the getLinkLocator()
92       */
93      protected void navigate(Failable failable) throws Exception {
94          selectTopFrame();
95          waitAndClickAdministration(failable);
96          waitForTitleToEqualKualiPortalIndex();
97          waitAndClickXMLIngester(failable);
98          selectFrameIframePortlet();
99          checkForIncidentReport("XML Ingester", failable, "");
100     }
101 
102     /**
103      * Navigate to the page under test and call {@link #testIngestion}
104      *
105      * @param failable {@link edu.samplu.common.Failable}
106      * @throws Exception
107      */
108     protected void testIngestionNav(Failable failable) throws Exception {
109         navigate(failable);
110         testIngestion(failable);
111         passed();
112     }
113 
114     protected void testIngestionBookmark(Failable failable) throws Exception {
115         testIngestion(failable);
116         passed();
117     }
118 
119     /**
120      * Based on load user and groups manual tests; dynamically generates user and group file
121      * and loads into the xml ingester screen
122      *
123      */
124     protected void testIngestion(Failable failable) throws Exception {
125         selectFrameIframePortlet();
126         List<File> fileUploadList = buildFileUploadList();
127         int cnt = 0;
128 
129         for(File file : fileUploadList) {
130             String path = file.getAbsolutePath().toString();
131             driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
132             cnt++;
133         }
134 
135         waitAndClickByXpath("//*[@id='imageField']");
136 
137         // confirm all files were uploaded successfully
138         for(File file: fileUploadList) {
139             assertTextPresent("Ingested xml doc: " + file.getName());
140         }
141     }
142 
143     protected List<File> buildFileUploadList() throws Exception {
144         List<File> fileUploadList = new ArrayList<File>();
145         try {
146             // update properties with timestamp value if includeDTSinPrefix is true
147             Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION);
148             if(props.get("userIncludeDTSinPrefix") != null
149                     && "true".equalsIgnoreCase((String) props.get("userIncludeDTSinPrefix"))) {
150                 props.setProperty("userPrefix", "" + props.get("userPrefix") + ITUtil.DTS);
151             }
152             systemPropertiesOverride(props, "XMLIngester");
153 
154             // build files and add to array
155             fileUploadList.add(
156                     writeTemplateToFile(newTempFile("loadtest-users.xml"), cfg.getTemplate(TMPL_USER_CONTENT), props));
157             fileUploadList.add(
158                     writeTemplateToFile(newTempFile("loadtest-group.xml"), cfg.getTemplate(TMPL_GROUP_CONTENT), props));
159         } catch( Exception e) {
160             throw new Exception("Unable to generate files for upload", e);
161         }
162 
163         return fileUploadList;
164     }
165 }