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