forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converters, Listeners and Validators (eugenp#1634)
* Converters, Listeners and Validators in Java EE 7 * Convertesrs, Listeners and validators Tests
- Loading branch information
Showing
5 changed files
with
186 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<faces-config | ||
xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | ||
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" | ||
version="2.0"> | ||
<managed-bean> | ||
<managed-bean-name>convListVal</managed-bean-name> | ||
<managed-bean-class>com.baeldung.convListVal.ConvListVal</managed-bean-class> | ||
<managed-bean-scope>session</managed-bean-scope> | ||
</managed-bean> | ||
</faces-config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> | ||
<!-- The bare minimum needed for JSF 2.2 is a servlet 2.5 or later | ||
declaration (this uses 3.0) and the mapping for the FacesServlet. | ||
Setting PROJECT_STAGE to Development is highly recommended | ||
during initial development so that you get more helpful | ||
error messages. Whether you want server-side state saving | ||
(default) or client-side is a more complicated question: | ||
client-side uses more bandwidth but fewer server resources. | ||
Client-side also helps to avoid the dreaded view expired exceptions. | ||
From JSF 2 and PrimeFaces tutorial | ||
at http://www.coreservlets.com/JSF-Tutorial/jsf2/ | ||
--> | ||
<servlet> | ||
<servlet-name>Faces Servlet</servlet-name> | ||
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>Faces Servlet</servlet-name> | ||
<url-pattern>*.jsf</url-pattern> | ||
</servlet-mapping> | ||
<context-param> | ||
<param-name>javax.faces.PROJECT_STAGE</param-name> | ||
<param-value>Development</param-value> | ||
</context-param> | ||
<context-param> | ||
<description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description> | ||
<param-name>javax.faces.STATE_SAVING_METHOD</param-name> | ||
<param-value>client</param-value> | ||
</context-param> | ||
<!-- If you go to http://host/project/ (with no file name), it will | ||
try index.jsf first, welcome.jsf next, and so forth. | ||
--> | ||
<welcome-file-list> | ||
<welcome-file>index.jsf</welcome-file> | ||
<welcome-file>welcome.jsf</welcome-file> | ||
<welcome-file>index.html</welcome-file> | ||
<welcome-file>index.jsp</welcome-file> | ||
</welcome-file-list> | ||
</web-app> |
101 changes: 101 additions & 0 deletions
101
jee7/src/test/java/com/baeldung/convListVal/ConvListValTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.baeldung.convListVal; | ||
|
||
import static org.jboss.arquillian.graphene.Graphene.guardHttp; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.drone.api.annotation.Drone; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.FindBy; | ||
|
||
@RunWith(Arquillian.class) | ||
public class ConvListValTest { | ||
|
||
@ArquillianResource | ||
private URL deploymentUrl; | ||
|
||
private static final String WEBAPP_SRC = "src/main/webapp"; | ||
|
||
@Deployment(testable = false) | ||
public static WebArchive createDeployment() { | ||
return ( ShrinkWrap.create( | ||
WebArchive.class, "jee7.war"). | ||
addClasses(ConvListVal.class, MyListener.class)). | ||
addAsWebResource(new File(WEBAPP_SRC, "ConvListVal.xhtml")). | ||
addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
} | ||
|
||
@Drone | ||
WebDriver browser; | ||
|
||
@ArquillianResource | ||
URL contextPath; | ||
|
||
@FindBy(id="myForm:age") | ||
private WebElement ageInput; | ||
|
||
@FindBy(id="myForm:average") | ||
private WebElement averageInput; | ||
|
||
@FindBy(id="myForm:send") | ||
private WebElement sendButton; | ||
|
||
@Test | ||
@RunAsClient | ||
public void givenAge_whenAgeInvalid_thenErrorMessage() throws Exception { | ||
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); | ||
ageInput.sendKeys("stringage"); | ||
guardHttp(sendButton).click(); | ||
Assert.assertTrue("Show Age error message", browser.findElements(By.id("myForm:ageError")).size() > 0); | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
public void givenAverage_whenAverageInvalid_thenErrorMessage() throws Exception { | ||
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); | ||
averageInput.sendKeys("stringaverage"); | ||
guardHttp(sendButton).click(); | ||
Assert.assertTrue("Show Average error message", browser.findElements(By.id("myForm:averageError")).size() > 0); | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
public void givenDate_whenDateInvalid_thenErrorMessage() throws Exception { | ||
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); | ||
averageInput.sendKeys("123"); | ||
guardHttp(sendButton).click(); | ||
Assert.assertTrue("Show Date error message", browser.findElements(By.id("myForm:myDateError")).size() > 0); | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
public void givenSurname_whenSurnameMinLenghtInvalid_thenErrorMessage() throws Exception { | ||
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); | ||
averageInput.sendKeys("aaa"); | ||
guardHttp(sendButton).click(); | ||
Assert.assertTrue("Show Surname error message", browser.findElements(By.id("myForm:surnameError")).size() > 0); | ||
} | ||
|
||
@Test | ||
@RunAsClient | ||
public void givenSurname_whenSurnameMaxLenghtInvalid_thenErrorMessage() throws Exception { | ||
browser.get(deploymentUrl.toExternalForm() + "ConvListVal.jsf"); | ||
averageInput.sendKeys("aaaaabbbbbc"); | ||
guardHttp(sendButton).click(); | ||
Assert.assertTrue("Show Surname error message", browser.findElements(By.id("myForm:surnameError")).size() > 0); | ||
} | ||
|
||
} |