001 /** 002 * Copyright 2005-2013 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.Failable; 019 import edu.samplu.common.FreemarkerSTBase; 020 import edu.samplu.common.ITUtil; 021 import org.openqa.selenium.By; 022 023 import java.io.File; 024 import java.io.IOException; 025 import java.util.ArrayList; 026 import java.util.List; 027 import java.util.Properties; 028 029 /** 030 * Tests uploads of new users and group. 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034 035 public abstract class XMLIngesterAbstractSmokeTestBase extends FreemarkerSTBase { 036 037 /** 038 * http://env12.rice.kuali.org/portal.do?channelTitle=XML%20Ingester&channelUrl=http://env12.rice.kuali.org/kew/../core/Ingester.do 039 */ 040 public static final String BOOKMARK_URL = ITUtil.PORTAL + "?channelTitle=XML%20Ingester&channelUrl=" 041 + ITUtil.getBaseUrlString() + "/kew/../core/Ingester.do"; 042 043 // File generation 044 private String PROPS_LOCATION = System.getProperty("xmlingester.props.location", null); 045 private static final String DEFAULT_PROPS_LOCATION = "XML/xmlingester.properties"; 046 047 // Templates for File Generation 048 private static final String DIR_TMPL = "/XML/"; 049 private static final String TMPL_USER_CONTENT = "SimpleUserContent.ftl"; 050 private static final String TMPL_GROUP_CONTENT = "SimpleGroupContent.ftl"; 051 052 /** 053 * 054 * @param name of temp file to create 055 * @return tempFile 056 * @throws IOException 057 */ 058 protected abstract File newTempFile(String name) throws IOException; 059 060 /** 061 * {@inheritDoc} 062 * {@link #DIR_TMPL} 063 * @return 064 */ 065 @Override 066 protected String getTemplateDir() { 067 return DIR_TMPL; 068 } 069 070 /** 071 * Nav tests start at {@link ITUtil#PORTAL}. Bookmark Tests should override and return {@link XMLIngesterAbstractSmokeTestBase#BOOKMARK_URL} 072 * {@inheritDoc} 073 * @return 074 */ 075 @Override 076 public String getTestUrl() { 077 return ITUtil.PORTAL; 078 } 079 080 /** 081 * "admin" xml ingestion requires admin permissions. 082 * {@inheritDoc} 083 * @return 084 */ 085 @Override 086 public String getUserName() { 087 return "admin"; 088 } 089 090 /** 091 * go to the getMenuLinkLocator() Menu and click the getLinkLocator() 092 */ 093 protected void navigate(Failable failable) throws Exception { 094 selectTopFrame(); 095 waitAndClickAdministration(failable); 096 waitForTitleToEqualKualiPortalIndex(); 097 waitAndClickXMLIngester(failable); 098 selectFrameIframePortlet(); 099 checkForIncidentReport("XML Ingester", failable, ""); 100 } 101 102 /** 103 * Navigate to the page under test and call {@link #testIngestion} 104 * 105 * @param failable {@link edu.samplu.common.Failable} 106 * @throws Exception 107 */ 108 protected void testIngestionNav(Failable failable) throws Exception { 109 navigate(failable); 110 testIngestion(failable); 111 passed(); 112 } 113 114 protected void testIngestionBookmark(Failable failable) throws Exception { 115 testIngestion(failable); 116 passed(); 117 } 118 119 /** 120 * Based on load user and groups manual tests; dynamically generates user and group file 121 * and loads into the xml ingester screen. 122 * This test should suffice for both KRAD and KNS versions of the ingester screen. 123 * 124 * 125 */ 126 protected void testIngestion(Failable failable) throws Exception { 127 selectFrameIframePortlet(); 128 List<File> fileUploadList = buildFileUploadList(); 129 int cnt = 0; 130 131 for(File file : fileUploadList) { 132 String path = file.getAbsolutePath().toString(); 133 if (isKrad()){ 134 driver.findElement(By.name("files[" + cnt + "]")).sendKeys(path); 135 } else { 136 driver.findElement(By.name("file[" + cnt + "]")).sendKeys(path); 137 } 138 cnt++; 139 } 140 141 // Click the Upload Button 142 if (isKrad()){ 143 waitAndClickByXpath("//button"); 144 } else { 145 waitAndClickByXpath("//*[@id='imageField']"); 146 } 147 148 // confirm all files were uploaded successfully 149 Thread.sleep(1000); 150 for(File file: fileUploadList) { 151 assertTextPresent("Ingested xml doc: " + file.getName()); 152 } 153 } 154 155 protected List<File> buildFileUploadList() throws Exception { 156 List<File> fileUploadList = new ArrayList<File>(); 157 try { 158 // update properties with timestamp value if includeDTSinPrefix is true 159 Properties props = loadProperties(PROPS_LOCATION, DEFAULT_PROPS_LOCATION); 160 if(props.get("userIncludeDTSinPrefix") != null 161 && "true".equalsIgnoreCase((String) props.get("userIncludeDTSinPrefix"))) { 162 props.setProperty("userPrefix", "" + props.get("userPrefix") + ITUtil.DTS); 163 } 164 systemPropertiesOverride(props, "XMLIngester"); 165 166 // build files and add to array 167 fileUploadList.add( 168 writeTemplateToFile(newTempFile("loadtest-users.xml"), cfg.getTemplate(TMPL_USER_CONTENT), props)); 169 fileUploadList.add( 170 writeTemplateToFile(newTempFile("loadtest-group.xml"), cfg.getTemplate(TMPL_GROUP_CONTENT), props)); 171 } catch( Exception e) { 172 throw new Exception("Unable to generate files for upload", e); 173 } 174 175 return fileUploadList; 176 } 177 }