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 String userPrefix = System.getProperty("test.xmlingester.user.prefix", ITUtil.DTS);
042 // group default values
043 private String groupId = System.getProperty("test.xmlingester.grp.id", "2203");
044 private String groupNamespace = System.getProperty("test.xmlingester.grp.namespace","KUALI");
045 private String groupName = System.getProperty("test.xmlingester.grp.name", "eDoc.Example1.IUPUI.Workgroup");
046 private String groupDesc = System.getProperty("test.xmlingester.grp.desc", "Edoclite Documentation workgroup");
047
048 @Rule
049 public TemporaryFolder folder= new TemporaryFolder();
050
051 @Ignore
052 @Override
053 public void testCreateNewCancel() throws Exception {}
054
055 @Ignore
056 @Override
057 public void testEditCancel() throws Exception {}
058
059
060 @Override
061 protected String getLinkLocator() {
062 return "XML Ingester";
063 }
064
065 @Override
066 public String getUserName() {
067 return "admin"; // xml ingestion requires admin permissions
068 }
069
070 @Override
071 public void setUp() throws Exception {
072 super.setUp();
073 // generated load users and group resources
074 buildFileUploadList();
075
076 }
077
078 private void buildFileUploadList() throws Exception {
079 fileUploadList = new ArrayList<File>();
080 fileUploadList.add(generateLoadUsersFile(userCnt, userPrefix));
081 fileUploadList.add(generateLoadGroupFile(userCnt, userPrefix));
082 }
083
084 /**
085 * Generates a temporary file for given number of users and prefix
086 *
087 * @param numberOfUsers
088 * @param prefix
089 * @throws Exception
090 */
091 private File generateLoadUsersFile(int numberOfUsers, String prefix) throws Exception {
092 File loadUsersFile = folder.newFile("loadtest-users.xml");
093
094 java.util.Date date= new java.util.Date();
095
096 FileWriter writer = new FileWriter(loadUsersFile);
097 writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
098 writer.write("<data xmlns=\"ns:workflow\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"ns:workflow resource:WorkflowData\">\n");
099 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 }