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.Ignore;
21  import org.junit.Rule;
22  import org.junit.Test;
23  import org.junit.rules.TemporaryFolder;
24  import org.openqa.selenium.By;
25  
26  import java.io.File;
27  import java.io.FileWriter;
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  /**
32   * tests uploads of new users and group
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class XMLIngesterLegacyIT extends AdminMenuLegacyITBase {
37  
38      // values set by default for repeatable testing; left as configurable for load tests
39      private List<File> fileUploadList;
40      private int userCnt = Integer.valueOf(System.getProperty("test.xmlingester.user.cnt", "10"));
41      private boolean userPadding = Boolean.valueOf(System.getProperty("test.xmlingester.user.padding", "true"));
42      private String userPrefix = System.getProperty("test.xmlingester.user.prefix", ITUtil.DTS);
43      private String emailDomain = System.getProperty("test.xmlingester.user.email.domain", "@kuali.org");
44      // group default values
45      private String groupId = System.getProperty("test.xmlingester.grp.id", "2203");
46      private String groupNamespace = System.getProperty("test.xmlingester.grp.namespace","KUALI");
47      private String groupName = System.getProperty("test.xmlingester.grp.name", "eDoc.Example1.IUPUI.Workgroup");
48      private String groupDesc = System.getProperty("test.xmlingester.grp.desc", "Edoclite Documentation workgroup");
49  
50      @Rule
51      public TemporaryFolder folder= new TemporaryFolder();
52  
53      @Ignore
54      @Override
55      public void testCreateNewCancel() throws Exception {}
56  
57      @Ignore
58      @Override
59      public void testEditCancel() throws Exception {}
60  
61  
62      @Override
63      protected String getLinkLocator() {
64          return "XML Ingester";
65      }
66  
67      @Override
68      public String getUserName() {
69          return "admin"; // xml ingestion requires admin permissions
70      }
71  
72      @Override
73      public void setUp() throws Exception {
74         super.setUp();
75          // generated load users and group resources
76         buildFileUploadList();
77  
78      }
79  
80      private void buildFileUploadList() throws Exception {
81          fileUploadList = new ArrayList<File>();
82          fileUploadList.add(generateLoadUsersFile(userCnt, userPrefix));
83          fileUploadList.add(generateLoadGroupFile(userCnt, userPrefix));
84      }
85  
86      /**
87       * Generates a temporary file for given number of users and prefix
88       * 
89       * @param numberOfUsers
90       * @param prefix
91       * @throws Exception
92       */
93      private File generateLoadUsersFile(int numberOfUsers, String prefix) throws Exception {
94          File loadUsersFile = folder.newFile("loadtest-users.xml");
95  
96          java.util.Date date= new java.util.Date();
97  
98          FileWriter writer = new FileWriter(loadUsersFile);
99          writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
100         writer.write("<data xmlns=\"ns:workflow\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"ns:workflow resource:WorkflowData\">\n");
101         writer.write("\t<users xmlns=\"ns:workflow/User\" xsi:schemaLocation=\"ns:workflow/User resource:User\">\n");
102         String count = "";
103         String format = "%0" + (numberOfUsers + "").length() + "d";
104         for(int i = 0; i < numberOfUsers; i++) {
105             if (userPadding) {
106                 count = prefix + String.format(format, i);
107             } else {
108                 count = prefix + i;
109             }
110             StringBuffer stringBuffer = new StringBuffer();
111             stringBuffer.append("\t\t<user><principalId>lt" + count + "</principalId>");
112             stringBuffer.append("<emplId>lt" + count + "emplid</emplId>");
113             stringBuffer.append("<principalName>loadtester" + count + "</principalName>");
114             stringBuffer.append("<givenName>Tester" + count + "</givenName>");
115             stringBuffer.append("<lastName>McLoady" + count + "</lastName>");
116             stringBuffer.append("<emailAddress>loadtester" + count + emailDomain + "</emailAddress>");
117             stringBuffer.append("</user>\n");
118             writer.write(stringBuffer.toString());
119         }
120         writer.write("\t</users>\n</data>\n");
121         writer.close();
122         return loadUsersFile;
123     }
124 
125     /**
126      *  Generates a temporary file for a group given number of users and principal name prefix
127      *
128      *
129      * @param numberOfUsers
130      * @param prefix
131      * @return
132      * @throws Exception
133      */
134     private File generateLoadGroupFile(int numberOfUsers, String prefix) throws Exception {
135         File loadGroupFile = folder.newFile("loadtest-group.xml");
136 
137         FileWriter writer = new FileWriter(loadGroupFile);
138         writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
139         writer.write("<data xmlns=\"ns:workflow\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"ns:workflow resource:WorkflowData\">\n");
140         writer.write("\t<groups xmlns=\"ns:workflow/Group\" xsi:schemaLocation=\"ns:workflow/Group resource:Group\">\n");
141         writer.write("\t\t<group><id>" + groupId + "</id><namespace>" + groupNamespace + "</namespace><description>" + groupDesc + "</description>");
142         writer.write("<name>" + groupName + "</name>");
143         writer.write("<members>");
144         writer.write("<principalName>admin</principalName>");
145         writer.write("<principalName>notsys</principalName>");
146         String count = "";
147         String format = "%0" + (numberOfUsers + "").length() + "d";
148         for(int i = 0; i < numberOfUsers; i++) {
149             if (userPadding) {
150                 count = prefix + String.format(format, i);
151             } else {
152                 count = prefix + i;
153             }
154             StringBuffer stringBuffer = new StringBuffer();
155             stringBuffer.append("<principalName>loadtester" + count + "</principalName>");
156             writer.write(stringBuffer.toString());
157         }
158         writer.write("\t\t</members>\n\t</group>\n</groups>\n</data>\n");
159         writer.close();
160         return loadGroupFile;
161     }
162 
163 
164     /**
165      * Based on load user and groups manual tests; load a dynamically generated user and group file into the xml ingester screen
166      *
167      */
168     @Test
169     public void testXMLIngesterSuccessfulFileUpload() throws Exception {
170         gotoMenuLinkLocator();
171         int cnt = 0;
172         for(File file : fileUploadList) {
173             String path = file.getAbsolutePath().toString();
174             driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
175             cnt++;
176         }
177         waitAndClickByXpath("//*[@id='imageField']");
178 
179         // confirm all files were uploaded successfully
180         for(File file: fileUploadList) {
181             assertTextPresent("Ingested xml doc: " + file.getName());
182         }
183         passed();
184     }
185 
186 }