/
Spec1559IT.java
102 lines (82 loc) · 3.8 KB
/
Spec1559IT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 Contributors to Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.faces.test.servlet50.selectitemgroups;
import static java.lang.System.getProperty;
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.net.URL;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.importer.ZipImporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.HtmlOption;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;
@RunWith(Arquillian.class)
public class Spec1559IT {
@ArquillianResource
private URL webUrl;
private WebClient webClient;
@Deployment(testable = false)
public static WebArchive createDeployment() {
return create(ZipImporter.class, getProperty("finalName") + ".war")
.importFrom(new File("target/" + getProperty("finalName") + ".war"))
.as(WebArchive.class);
}
@Before
public void setUp() {
webClient = new WebClient();
}
@After
public void tearDown() {
webClient.close();
}
@Test
public void test() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "spec1559IT.xhtml");
HtmlSelect select = page.getHtmlElementById("form:input");
assertValidMarkup(select);
select.setSelectedAttribute(select.getOptionByValue("5"), true);
assertEquals("messages is empty before submit", "", page.getHtmlElementById("form:messages").asText());
assertEquals("output is empty before submit", "", page.getHtmlElementById("form:output").asText());
page = page.getHtmlElementById("form:submit").click();
assertValidMarkup(select);
assertEquals("messages is still empty after submit", "", page.getHtmlElementById("form:messages").asText());
assertEquals("output is '5' after submit", "5", page.getHtmlElementById("form:output").asText());
}
private static void assertValidMarkup(HtmlSelect select) {
assertEquals("select has 2 children", 2, select.getChildElementCount());
for (DomElement child : select.getChildElements()) {
assertEquals("child element is an optgroup", "optgroup", child.getNodeName());
assertEquals("child has in turn 3 grandchildren", 3, child.getChildElementCount());
for (DomElement grandchild : child.getChildElements()) {
assertEquals("grandchild element is an option", "option", grandchild.getNodeName());
}
}
assertEquals("select element has 6 options", 6, select.getOptions().size());
HtmlOption option = select.getOptionByValue("5");
assertEquals("5th option is 'Audi'", "Audi", option.getText());
}
}