1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.qunit;
17
18 import java.io.File;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.apache.log4j.Logger;
24 import org.junit.Assert;
25 import org.junit.Ignore;
26 import org.junit.Test;
27 import org.kuali.hr.KPMEWebTestCase;
28 import org.kuali.hr.util.HtmlUnitUtil;
29 import org.kuali.kpme.core.FunctionalTest;
30
31 import com.gargoylesoftware.htmlunit.BrowserVersion;
32 import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
33 import com.gargoylesoftware.htmlunit.WebClient;
34 import com.gargoylesoftware.htmlunit.html.HtmlElement;
35 import com.gargoylesoftware.htmlunit.html.HtmlForm;
36 import com.gargoylesoftware.htmlunit.html.HtmlPage;
37 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
38
39 @Ignore
40 @FunctionalTest
41 public class QUnitTest extends KPMEWebTestCase {
42
43 private static final Logger LOG = Logger.getLogger(QUnitTest.class);
44 private List<String> failures;
45
46 @Test
47 public void testQUnit() throws Exception {
48 failures = new ArrayList<String>();
49
50 File qunitDir = new File("src/main/webapp/qunit");
51 if (!qunitDir.exists() || !qunitDir.isDirectory()) {
52 Assert.fail("Test dir does not exist or is not a directory: " + qunitDir);
53 }
54
55 for (File file : qunitDir.listFiles()) {
56 if (file.getName().endsWith(".jsp")) {
57 runTest(file);
58 }
59 }
60
61 if (failures.size() > 0) {
62 StringBuffer sb = new StringBuffer();
63 for (String failMsg : failures) {
64 if (sb.length() > 0)
65 sb.append("\n");
66 sb.append(failMsg);
67 }
68 LOG.debug("\n\n" + sb.toString() + "\n\n");
69
70 Assert.fail("Tests failed: " + sb.toString());
71 }
72 }
73
74 private void runTest(File file) throws Exception {
75 setWebClient(new WebClient(BrowserVersion.FIREFOX_10));
76 WebClient client = getWebClient();
77 client.setJavaScriptEnabled(true);
78 client.setThrowExceptionOnScriptError(false);
79 client.setAjaxController(new NicelyResynchronizingAjaxController());
80 client.waitForBackgroundJavaScript(1000);
81
82
83
84 HtmlPage page = client.getPage(new URL(getBaseURL() + "/TimeDetail.do"));
85 HtmlForm form = page.getFormByName("login-form");
86 HtmlSubmitInput button = form.getInputByName("login");
87 page = button.click();
88
89
90
91 page = client.getPage(new URL("http://localhost:8080/tk-dev/qunit/" + file.getName()));
92 synchronized (page) {
93 page.wait(5000);
94 }
95 HtmlUnitUtil.createTempFile(page);
96 HtmlElement element = page.getHtmlElementById("qunit-tests");
97 if (element.asText().indexOf("0 tests of 0") != -1)
98 failures.add(file.getName() + " - No tests were run - " + element.asText());
99 else if (element.asText().indexOf("0 failed") == -1)
100 failures.add(file.getName() + " - " + element.asText());
101 }
102
103 }