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