use of com.gargoylesoftware.htmlunit.html.HtmlLink in project faces by jakartaee.
the class URLClient method outputStyleEncodeTest.
/*
* @class.setup_props: webServerHost; webServerPort; ts_home;
*/
/**
* @testName: outputStyleEncodeTest
* @assertion_ids: PENDING
* @test_Strategy: Validate the following test cases.
*
* case 1: Make sure that there is a given number of 'link'
* elements (2) tags rendered in the head of the response.
*
* case 2: Make sure that the correct attributes are rendered
* when we call for a style sheet with no Library.
*
* case 3: Make sure that the correct attributes are rendered
* when we call for a style sheet with library specified.
*
* case 4: Make sure that the correct value is set when we
* have a media attribute.
*
* @since 2.0
*/
public void outputStyleEncodeTest() throws Fault {
StringBuilder messages = new StringBuilder(128);
Formatter formatter = new Formatter(messages);
// ------------------------------------------------------------ case 1
HtmlPage pageOne = getPage(CONTEXT_ROOT + "/faces/encodetest_facelet.xhtml");
List<HtmlLink> links = pageOne.getDocumentElement().getHtmlElementsByTagName("link");
if (2 != links.size()) {
formatter.format("Wrong number of '%s' elements rendered. %n" + "Expected: %s %n" + "Received: " + links.size(), "link", "2");
}
// ------------------------------------------------------------ case 2
HtmlPage pageTwo = getPage(CONTEXT_ROOT + "/faces/encodetest_facelet_1.xhtml");
List<HtmlLink> linkTwo = pageTwo.getDocumentElement().getHtmlElementsByTagName("link");
String expected1 = "/jsf_render_outputstyle_web/faces/" + "jakarta.faces.resource/night.css";
this.testLink(linkTwo.get(0), expected1, formatter);
// ------------------------------------------------------------ case 3
HtmlPage pageThree = getPage(CONTEXT_ROOT + "/faces/encodetest_facelet_2.xhtml");
List<HtmlLink> linkThree = pageThree.getDocumentElement().getHtmlElementsByTagName("link");
String expected2 = "/jsf_render_outputstyle_web/faces/" + "jakarta.faces.resource/morning.css";
String expectedLib = "ln=cssLibrary";
this.testLink(linkThree.get(0), expected2, formatter);
this.testLink(linkThree.get(0), expectedLib, formatter);
// ------------------------------------------------------------ case 4
HtmlPage pageOneA = getPage(CONTEXT_ROOT + "/faces/encodetest_facelet.xhtml");
List<HtmlLink> link = pageOne.getDocumentElement().getHtmlElementsByTagName("link");
String mediaOne = link.get(0).getAttribute("media");
this.testAtts("screen", mediaOne, "media", formatter);
String mediaTwo = link.get(1).getAttribute("media");
this.testAtts("all", mediaTwo, "media", formatter);
handleTestStatus(messages);
}
use of com.gargoylesoftware.htmlunit.html.HtmlLink in project maven-doxia-sitetools by apache.
the class HeadVerifier method verify.
/**
* {@inheritDoc}
*/
public void verify(String file) throws Exception {
HtmlPage page = htmlPage(file);
assertNotNull(page);
HtmlElement html = page.getDocumentElement();
assertNotNull(html);
assertEquals("en", html.getAttribute("lang"));
List<HtmlElement> heads = html.getElementsByTagName("head");
assertEquals(1, heads.size());
HtmlElement head = heads.get(0);
assertNotNull(head);
Iterator<HtmlElement> elementIterator = head.getHtmlElementDescendants().iterator();
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
HtmlMeta meta = (HtmlMeta) elementIterator.next();
assertEquals("UTF-8", meta.getAttribute("charset"));
// Skip viewport
elementIterator.next();
meta = (HtmlMeta) elementIterator.next();
assertEquals("generator", meta.getAttribute("name"), "Unexpected meta entry found generated resource " + file);
String generator = meta.getAttribute("content");
assertEquals("Apache Maven Doxia Site Renderer", generator, "Unexpected value found for generator meta entry in generated resource " + file);
meta = (HtmlMeta) elementIterator.next();
assertEquals("author", meta.getAttribute("name"));
assertEquals("John Doe", meta.getAttribute("content").trim());
HtmlTitle title = (HtmlTitle) elementIterator.next();
assertNotNull(title);
HtmlLink link = (HtmlLink) elementIterator.next();
assertNotNull(link);
link = (HtmlLink) elementIterator.next();
assertNotNull(link);
link = (HtmlLink) elementIterator.next();
assertNotNull(link);
link = (HtmlLink) elementIterator.next();
assertNotNull(link);
meta = (HtmlMeta) elementIterator.next();
assertEquals("description", meta.getAttribute("name"));
assertEquals("Free Web tutorials", meta.getAttribute("content"));
meta = (HtmlMeta) elementIterator.next();
assertEquals("keywords", meta.getAttribute("name"));
assertEquals("HTML,CSS,XML,JavaScript", meta.getAttribute("content"));
HtmlBase base = (HtmlBase) elementIterator.next();
assertEquals("http://maven.apache.org/", base.getAttribute("href"));
}
use of com.gargoylesoftware.htmlunit.html.HtmlLink in project jenkins by jenkinsci.
the class AjaxTest method rejectedLinks.
@Issue("JENKINS-21254")
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
@Test
public void rejectedLinks() throws Exception {
JenkinsRule.WebClient wc = r.createWebClient();
String prefix = r.contextPath + '/';
for (DomElement e : wc.goTo("login").getElementsByTagName("link")) {
String href = ((HtmlLink) e).getHrefAttribute();
if (!href.startsWith(prefix)) {
System.err.println("ignoring " + href);
continue;
}
System.err.println("checking " + href);
wc.goTo(href.substring(prefix.length()), null);
}
}
Aggregations