use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project security by jakartaee.
the class OpenId2DefaultIT method testOpenIdConnect.
@Test
@RunAsClient
public void testOpenIdConnect() throws IOException {
// 1. Public servlet should be accessible for an unauthenticated user
assertDefaultNotAuthenticated(readFromServer("/publicServlet"));
// 2. Access to secured web page redirects us to OpenID Connect Provider's login page
// Look at redirect:
getWebClient().getOptions().setRedirectEnabled(false);
WebResponse response = responseFromServer("/protectedServlet");
for (NameValuePair header : response.getResponseHeaders()) {
System.out.println("name: " + header.getName() + " : " + header.getValue());
}
// Automatically follow redirects and request secured page again
getWebClient().getOptions().setRedirectEnabled(true);
// 3. We should now see the login page from the OpenId Provider
HtmlPage providerLoginPage = pageFromServer("/protectedServlet");
printPage(providerLoginPage);
// Authenticate with the OpenId Provider using the username and password for a default user
providerLoginPage.getElementById("j_username").setAttribute("value", "user");
providerLoginPage.getElementById("j_password").setAttribute("value", "password");
// 4. We should now get a confirmation page, which we acknowledge.
HtmlPage confirmationPage = providerLoginPage.getElementByName("submit").click();
printPage(confirmationPage);
// Set to "remember-not" to make tests easily repeatable. If we don't set this without restarting the OpenID Provider
// we would not get the confirmation page next time.
HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) confirmationPage.getElementById("remember-not");
radioButton.setChecked(true);
// 5. After authenticating and confirmation, we are now redirected back to our application.
// A servlet on the /callBack URI is called.
TextPage callbackPage = confirmationPage.getElementByName("authorize").click();
printPage(callbackPage);
assertTrue(callbackPage.getContent().contains("This is the callback servlet"));
// 6. Access protected servlet as an authenticated user
assertAuthenticated("web", "user", readFromServer("/protectedServlet"), "foo", "bar");
// 7. Finally, access should still be allowed to a public web page when already logged in
assertAuthenticated("web", "user", readFromServer("/publicServlet"), "foo", "bar");
}
use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project faces by jakartaee.
the class Issue2408IT method getRadios.
private List<HtmlRadioButtonInput> getRadios(final HtmlPage page) {
final List<HtmlRadioButtonInput> radios = new ArrayList<>();
final DomNodeList<DomElement> elements = page.getElementsByTagName("input");
for (DomElement elem : elements) {
if (elem instanceof HtmlRadioButtonInput) {
radios.add((HtmlRadioButtonInput) elem);
}
}
return radios;
}
use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project faces by jakartaee.
the class Spec329IT method testSpec329.
/**
* @see HtmlSelectOneRadio#getGroup()
* @see https://github.com/jakartaee/faces/issues/329
*/
@Test
public void testSpec329() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "spec329.xhtml");
assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
assertTrue(page.getHtmlElementById("inDataTableWithEntityList:selectedItem").asNormalizedText().isEmpty());
assertTrue(page.getHtmlElementById("inRepeatWithSelectItemList:selectedItem").asNormalizedText().isEmpty());
assertTrue(page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:selectedItem").asNormalizedText().isEmpty());
assertTrue(page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:selectedItem").asNormalizedText().isEmpty());
assertTrue(page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:selectedItem").asNormalizedText().isEmpty());
page = ((HtmlSubmitInput) page.getHtmlElementById("inDataTableWithEntityList:button")).click();
// It should appear only once!
assertEquals("required", page.getHtmlElementById("messages").asNormalizedText());
HtmlRadioButtonInput inDataTableWithEntityListRadio = (HtmlRadioButtonInput) page.getHtmlElementById("inDataTableWithEntityList:table:1:radio");
inDataTableWithEntityListRadio.setChecked(true);
page = ((HtmlSubmitInput) page.getHtmlElementById("inDataTableWithEntityList:button")).click();
System.out.println("\n\n***** " + page.getHtmlElementById("messages").asNormalizedText() + "\n\n\n");
assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
assertEquals("two", page.getHtmlElementById("inDataTableWithEntityList:selectedItem").asNormalizedText());
page = ((HtmlSubmitInput) page.getHtmlElementById("inRepeatWithSelectItemList:button")).click();
// It should appear only once!
assertEquals("required", page.getHtmlElementById("messages").asNormalizedText());
HtmlRadioButtonInput inRepeatWithSelectItemListRadio = (HtmlRadioButtonInput) page.getHtmlElementById("inRepeatWithSelectItemList:repeat:1:radio");
inRepeatWithSelectItemListRadio.setChecked(true);
page = ((HtmlSubmitInput) page.getHtmlElementById("inRepeatWithSelectItemList:button")).click();
assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
assertEquals("value2", page.getHtmlElementById("inRepeatWithSelectItemList:selectedItem").asNormalizedText());
page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:button")).click();
// It should appear only once for first component!
assertEquals("required1", page.getHtmlElementById("messages").asNormalizedText());
HtmlRadioButtonInput multipleRadioButtonsWithStaticItemsInFirstRadio = (HtmlRadioButtonInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:radio2");
multipleRadioButtonsWithStaticItemsInFirstRadio.setChecked(true);
page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:button")).click();
assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
assertEquals("two", page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:selectedItem").asNormalizedText());
page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:button")).click();
// It should appear only once for first component!
assertEquals("required1", page.getHtmlElementById("messages").asNormalizedText());
HtmlRadioButtonInput multipleRadioButtonsWithStaticItemsInEachRadio = (HtmlRadioButtonInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:radio2");
multipleRadioButtonsWithStaticItemsInEachRadio.setChecked(true);
page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:button")).click();
assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
assertEquals("two", page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:selectedItem").asNormalizedText());
page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:button")).click();
// It should appear only once for first component!
assertEquals("required1", page.getHtmlElementById("messages").asNormalizedText());
HtmlRadioButtonInput multipleRadioButtonsWithSelectItemListRadio = (HtmlRadioButtonInput) page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:radio2");
multipleRadioButtonsWithSelectItemListRadio.setChecked(true);
page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:button")).click();
assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
assertEquals("value2", page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:selectedItem").asNormalizedText());
}
use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project security by jakartaee.
the class OpenId3DefaultIT method testOpenIdConnect.
@Test
@RunAsClient
public void testOpenIdConnect() throws IOException {
// 1. Public servlet should be accessible for an unauthenticated user
assertDefaultNotAuthenticated(readFromServer("/publicServlet"));
// 2. Access to secured web page redirects us to OpenID Connect Provider's login page
HtmlPage providerLoginPage = pageFromServer("/protectedServlet");
printPage(providerLoginPage);
// Authenticate with the OpenId Provider using the username and password for a default user
providerLoginPage.getElementById("j_username").setAttribute("value", "user");
providerLoginPage.getElementById("j_password").setAttribute("value", "password");
// 3. We should now get a confirmation page, which we acknowledge.
HtmlPage confirmationPage = providerLoginPage.getElementByName("submit").click();
printPage(confirmationPage);
// Set to "remember-not" to make tests easily repeatable. If we don't set this without restarting the OpenID Provider
// we would not get the confirmation page next time.
HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) confirmationPage.getElementById("remember-not");
radioButton.setChecked(true);
// 4. After authenticating and confirmation, we are now redirected back to our original resource
TextPage originalPage = confirmationPage.getElementByName("authorize").click();
assertAuthenticated("web", "user", originalPage.getContent(), "foo", "bar");
// 5. Finally, access should still be allowed to a public web page when already logged in
assertAuthenticated("web", "user", readFromServer("/publicServlet"), "foo", "bar");
}
use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project faces by jakartaee.
the class Issue2340IT method testCommandLinkRadio.
/**
* @see AjaxBehavior
* @see HtmlCommandLink
* @see HtmlSelectOneRadio
* @see https://github.com/eclipse-ee4j/mojarra/issues/2344
*/
@Test
public void testCommandLinkRadio() throws Exception {
HtmlPage page = getPage("commandLinkRadio.xhtml");
HtmlAnchor anchor = (HtmlAnchor) page.getElementById("testLink");
// This will ensure JavaScript finishes before evaluating the page.
webClient.waitForBackgroundJavaScript(3000);
anchor.click();
webClient.waitForBackgroundJavaScript(3000);
assertTrue(page.asXml().contains("LINK ACTION"));
HtmlRadioButtonInput radio1 = (HtmlRadioButtonInput) page.getElementById("testRadio:0");
HtmlRadioButtonInput radio2 = (HtmlRadioButtonInput) page.getElementById("testRadio:1");
HtmlRadioButtonInput radio3 = (HtmlRadioButtonInput) page.getElementById("testRadio:2");
page = radio1.click();
webClient.waitForBackgroundJavaScript(3000);
assertTrue(page.asXml().contains("RADIO:red"));
page = radio2.click();
webClient.waitForBackgroundJavaScript(3000);
assertTrue(page.asXml().contains("RADIO:blue"));
page = radio3.click();
webClient.waitForBackgroundJavaScript(3000);
assertTrue(page.asXml().contains("RADIO:white"));
}
Aggregations