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