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.Rule;
021    import org.junit.Test;
022    import org.junit.rules.TemporaryFolder;
023    import org.openqa.selenium.By;
024    
025    import java.io.File;
026    import java.io.FileWriter;
027    
028    /**
029     * tests uploads of new users
030     * 
031     * @author Kuali Rice Team (rice.collab@kuali.org)
032     */
033    public class XMLIngesterLegacyIT extends AdminMenuLegacyITBase {
034    
035        private File loadUsersFile;
036    
037        @Rule
038        public TemporaryFolder folder= new TemporaryFolder();
039    
040        @Override
041        protected String getLinkLocator() {
042            return "XML Ingester";
043        }
044    
045        @Override
046        public String getUserName() {
047            return "admin"; // xml ingestion requires admin permissions
048        }
049    
050        @Override
051        public void setUp() throws Exception {
052           super.setUp();
053            // generated load users resource for repeated testing
054           generateLoadUsersFile(10, ITUtil.DTS);
055        }
056    
057        /**
058         * Generates a temporary file for given number of users and prefix
059         * 
060         * @param numberOfUsers
061         * @param prefix
062         * @throws Exception
063         */
064        private void generateLoadUsersFile(int numberOfUsers, String prefix) throws Exception {
065            loadUsersFile = folder.newFile("loadtest-users.xml");
066            java.util.Date date= new java.util.Date();
067    
068            FileWriter writer = new FileWriter(loadUsersFile);
069            writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
070            writer.write("<data xmlns=\"ns:workflow\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"ns:workflow resource:WorkflowData\">\n");
071            writer.write("\t<users xmlns=\"ns:workflow/User\" xsi:schemaLocation=\"ns:workflow/User resource:User\">\n");
072            for(int i = 0; i < numberOfUsers; i++) {
073                StringBuffer stringBuffer = new StringBuffer();
074                stringBuffer.append("\t\t<user><principalId>lt" + prefix + i + "</principalId>");
075                stringBuffer.append("<emplId>lt" + prefix + i + "emplid</emplId>");
076                stringBuffer.append("<principalName>loadtester" + prefix + i + "</principalName>");
077                stringBuffer.append("<givenName>Tester</givenName>");
078                stringBuffer.append("<lastName>McLoady" + prefix + i + "</lastName>");
079                stringBuffer.append("<emailAddress>loadtester" + prefix + i + "@kuali.org</emailAddress>");
080                stringBuffer.append("</user>\n");
081                writer.write(stringBuffer.toString());
082            }
083            writer.write("\t</users>\n</data>\n");
084            writer.close();
085        }
086    
087        @Test
088        public void testXMLIngesterUpload() throws Exception {
089            gotoMenuLinkLocator();
090            String path = loadUsersFile.getAbsolutePath().toString();
091            driver.findElement(By.name("file[0]")).sendKeys(path);
092            waitAndClickByXpath("//*[@id='imageField']");
093            assertTextPresent("Ingested xml doc");
094            passed();
095        }
096    
097    }