View Javadoc

1   /**
2    * Copyright 2005-2011 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.AdminMenuLegacyITBase;
19  import edu.samplu.common.ITUtil;
20  import org.junit.Rule;
21  import org.junit.Test;
22  import org.junit.rules.TemporaryFolder;
23  import org.openqa.selenium.By;
24  
25  import java.io.File;
26  import java.io.FileWriter;
27  
28  /**
29   * tests uploads of new users
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class XMLIngesterLegacyIT extends AdminMenuLegacyITBase {
34  
35      private File loadUsersFile;
36  
37      @Rule
38      public TemporaryFolder folder= new TemporaryFolder();
39  
40      @Override
41      protected String getLinkLocator() {
42          return "XML Ingester";
43      }
44  
45      @Override
46      public String getUserName() {
47          return "admin"; // xml ingestion requires admin permissions
48      }
49  
50      @Override
51      public void setUp() throws Exception {
52         super.setUp();
53          // generated load users resource for repeated testing
54         generateLoadUsersFile(10, ITUtil.DTS);
55      }
56  
57      /**
58       * Generates a temporary file for given number of users and prefix
59       * 
60       * @param numberOfUsers
61       * @param prefix
62       * @throws Exception
63       */
64      private void generateLoadUsersFile(int numberOfUsers, String prefix) throws Exception {
65          loadUsersFile = folder.newFile("loadtest-users.xml");
66          java.util.Date date= new java.util.Date();
67  
68          FileWriter writer = new FileWriter(loadUsersFile);
69          writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
70          writer.write("<data xmlns=\"ns:workflow\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"ns:workflow resource:WorkflowData\">\n");
71          writer.write("\t<users xmlns=\"ns:workflow/User\" xsi:schemaLocation=\"ns:workflow/User resource:User\">\n");
72          for(int i = 0; i < numberOfUsers; i++) {
73              StringBuffer stringBuffer = new StringBuffer();
74              stringBuffer.append("\t\t<user><principalId>lt" + prefix + i + "</principalId>");
75              stringBuffer.append("<emplId>lt" + prefix + i + "emplid</emplId>");
76              stringBuffer.append("<principalName>loadtester" + prefix + i + "</principalName>");
77              stringBuffer.append("<givenName>Tester</givenName>");
78              stringBuffer.append("<lastName>McLoady" + prefix + i + "</lastName>");
79              stringBuffer.append("<emailAddress>loadtester" + prefix + i + "@kuali.org</emailAddress>");
80              stringBuffer.append("</user>\n");
81              writer.write(stringBuffer.toString());
82          }
83          writer.write("\t</users>\n</data>\n");
84          writer.close();
85      }
86  
87      @Test
88      public void testXMLIngesterUpload() throws Exception {
89          gotoMenuLinkLocator();
90          String path = loadUsersFile.getAbsolutePath().toString();
91          driver.findElement(By.name("file[0]")).sendKeys(path);
92          waitAndClickByXpath("//*[@id='imageField']");
93          assertTextPresent("Ingested xml doc");
94          passed();
95      }
96  
97  }