001    /*
002     * Copyright 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/ecl1.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 static org.junit.Assert.*;
019    
020    import java.io.File;
021    import java.util.ArrayList;
022    
023    import org.junit.Assert;
024    import org.junit.Test;
025    import org.openqa.selenium.By;
026    
027    import edu.samplu.common.AdminMenuLegacyITBase;
028    import java.io.File;
029    import java.io.FileWriter;
030    import java.io.InputStream;
031    import java.net.URISyntaxException;
032    import java.net.URL;
033    
034    import java.util.ArrayList;
035    import java.util.Collection;
036    import java.util.Collections;
037    import java.util.List;
038    import java.util.ResourceBundle;
039    
040    /**
041     * TODO vchauhan don't forget to fill this in.
042     * 
043     * @author Kuali Rice Team (rice.collab@kuali.org)
044     */
045    public class OAAeDocLiteXMLIngestLegacyIT extends AdminMenuLegacyITBase {
046        // values set by default for repeatable testing; left as configurable for load tests
047        private List<File> fileUploadList;
048    
049        private void setUpFiles() throws Exception {
050            fileUploadList = new ArrayList<File>();
051            // Load the directory as a resource
052            // Turn the resource into a File object
053    
054            File dir = new File("src/it/resources/OAA");
055    
056            if (dir != null && dir.listFiles().length > 0) {
057                Integer i = 1;
058                for (File file : dir.listFiles()) {
059                    if (file.getName().endsWith(".xml")) {
060                        if (!file.getName().equalsIgnoreCase("sample-app-config.xml"))
061                            fileUploadList.add(file);
062                    }
063                    i++;
064                }
065                Collections.sort(fileUploadList);
066            } else {
067                throw new Exception("----Resources not found----");
068            }
069    
070        }
071    
072        @Test
073        public void test() throws Exception {
074            try {
075                setUpFiles();
076            } catch (Exception e) {
077                Assert.fail("Resources not found. Test will be skipped");
078            }
079            testXMLIngesterSuccessfulFileUpload();
080    
081            Thread.sleep(2000);
082            driver.switchTo().defaultContent();
083            waitAndClickByLinkText("Main Menu");
084            waitAndClickByLinkText("eDoc Lite");
085    
086            driver.switchTo().frame("iframeportlet");
087            waitAndClick(By.cssSelector("td.infoline > input[name=\"methodToCall.search\"]"));
088            Thread.sleep(2000);
089    
090            /*
091            assertEquals("eDoc.Example1Doctype", driver.findElement(By.xpath("//table[@id='row']/tbody/tr/td[3]"))
092                    .getText());
093            assertEquals("InterviewRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[2]/td[3]")).getText());
094            assertEquals("OfferRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[3]/td[3]")).getText());
095            assertEquals("SearchStatus", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[4]/td[3]")).getText());
096            assertEquals("VacancyNotice", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[5]/td[3]")).getText());
097            assertEquals("WaiverRequest", driver.findElement(By.xpath("//table[@id='row']/tbody/tr[6]/td[3]")).getText());
098           */
099            driver.switchTo().defaultContent();
100    
101            waitAndClickByXpath("//input[@name='imageField' and @value='Logout']");
102            passed();
103    
104        }
105    
106        /**
107         * Uploads file available from fileUploadList through XML Ingester.
108         * Uploads each sublist from main fileUploadList if size greater than 10. 
109         * 
110         */
111    
112        public void testXMLIngesterSuccessfulFileUpload() throws Exception {
113            gotoMenuLinkLocator();
114            if (fileUploadList != null && !fileUploadList.isEmpty()) {
115    
116                if (fileUploadList.size() > 10) {
117                    List<List<File>> subLists = getSubListsForFile(fileUploadList, 10);
118                    for (List<File> fileSet : subLists) {
119                        fileIngester(fileSet);
120                    }
121                } else {
122                    fileIngester(fileUploadList);
123                }
124            }
125    
126        }
127    
128        /**
129         * This overridden method ...
130         * 
131         * @see edu.samplu.common.MenuLegacyITBase#getLinkLocator()
132         */
133        @Override
134        protected String getLinkLocator() {
135    
136            return "XML Ingester";
137        }
138    
139        /**
140         * Performs Ingesting files to fileupload component and asserts succesful ingestion.
141         * 
142         */
143        private void fileIngester(List<File> fileToUpload) throws Exception {
144            int cnt = 0;
145            for (File file : fileToUpload) {
146                String path = file.getAbsolutePath().toString();
147                driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path);
148                cnt++;
149            }
150            waitAndClickByXpath("//*[@id='imageField']");
151            Thread.sleep(2000);
152            // confirm all files were uploaded successfully
153            for (File file : fileToUpload) {
154                assertTextPresent("Ingested xml doc: " + file.getName());
155    
156            }
157        }
158    
159        /**
160         * Divides fileUploadList from resources into sublists to match the maximum number of file
161         * upload components available on XML Ingester Screen
162         * 
163         */
164        private List<List<File>> getSubListsForFile(List<File> fileList, final int L) {
165            List<List<File>> subLists = new ArrayList<List<File>>();
166            final int N = fileList.size();
167            for (int i = 0; i < N; i += L) {
168                subLists.add(new ArrayList<File>(fileList.subList(i, Math.min(N, i + L))));
169            }
170            return subLists;
171        }
172    
173    }