001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package edu.samplu.admin.test;
017
018 import edu.samplu.common.AdminMenuLegacyITBase;
019 import edu.samplu.common.ITUtil;
020 import org.junit.Ignore;
021 import org.junit.Rule;
022 import org.junit.Test;
023 import org.junit.rules.TemporaryFolder;
024 import org.openqa.selenium.By;
025
026 import java.io.File;
027 import java.io.FileWriter;
028 import java.util.ArrayList;
029 import java.util.List;
030
031 /**
032 * tests uploads of new users and group
033 *
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036 public class XMLIngesterLegacyIT extends AdminMenuLegacyITBase {
037
038 // values set by default for repeatable testing; left as configurable for load tests
039 private List<File> fileUploadList;
040 private int userCnt = Integer.valueOf(System.getProperty("test.xmlingester.user.cnt", "10"));
041 private boolean userPadding = Boolean.valueOf(System.getProperty("test.xmlingester.user.padding", "true"));
042 private String userPrefix = System.getProperty("test.xmlingester.user.prefix", ITUtil.DTS);
043 private String emailDomain = System.getProperty("test.xmlingester.user.email.domain", "@kuali.org");
044 // group default values
045 private String groupId = System.getProperty("test.xmlingester.grp.id", "2203");
046 private String groupNamespace = System.getProperty("test.xmlingester.grp.namespace","KUALI");
047 private String groupName = System.getProperty("test.xmlingester.grp.name", "eDoc.Example1.IUPUI.Workgroup");
048 private String groupDesc = System.getProperty("test.xmlingester.grp.desc", "Edoclite Documentation workgroup");
049
050 @Rule
051 public TemporaryFolder folder= new TemporaryFolder();
052
053 @Ignore
054 @Override
055 public void testCreateNewCancel() throws Exception {}
056
057 @Ignore
058 @Override
059 public void testEditCancel() throws Exception {}
060
061
062 @Override
063 protected String getLinkLocator() {
064 return "XML Ingester";
065 }
066
067 @Override
068 public String getUserName() {
069 return "admin"; // xml ingestion requires admin permissions
070 }
071
072 @Override
073 public void setUp() throws Exception {
074 super.setUp();
075 // generated load users and group resources
076 buildFileUploadList();
077
078 }
079
080 private void buildFileUploadList() throws Exception {
081 fileUploadList = new ArrayList<File>();
082 fileUploadList.add(generateLoadUsersFile(userCnt, userPrefix));
083 fileUploadList.add(generateLoadGroupFile(userCnt, userPrefix));
084 }
085
086 /**
087 * Generates a temporary file for given number of users and prefix
088 *
089 * @param numberOfUsers
090 * @param prefix
091 * @throws Exception
092 */
093 private File generateLoadUsersFile(int numberOfUsers, String prefix) throws Exception {
094 File loadUsersFile = folder.newFile("loadtest-users.xml");
095
096 java.util.Date date= new java.util.Date();
097
098 FileWriter writer = new FileWriter(loadUsersFile);
099 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 }