1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
33
34
35
36 public class XMLIngesterLegacyIT extends AdminMenuLegacyITBase {
37
38
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
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";
70 }
71
72 @Override
73 public void setUp() throws Exception {
74 super.setUp();
75
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
88
89
90
91
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
127
128
129
130
131
132
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
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
180 for(File file: fileUploadList) {
181 assertTextPresent("Ingested xml doc: " + file.getName());
182 }
183 passed();
184 }
185
186 }