|
| 1 | +package org.ocpsoft.prettyfaces.annotation.basic.validate; |
| 2 | + |
| 3 | +import static junit.framework.Assert.assertTrue; |
| 4 | +import static org.junit.Assert.assertEquals; |
| 5 | + |
| 6 | +import org.apache.http.HttpResponse; |
| 7 | +import org.apache.http.client.HttpClient; |
| 8 | +import org.apache.http.client.methods.HttpGet; |
| 9 | +import org.apache.http.impl.client.DefaultHttpClient; |
| 10 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 11 | +import org.jboss.arquillian.junit.Arquillian; |
| 12 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 13 | +import org.junit.Test; |
| 14 | +import org.junit.runner.RunWith; |
| 15 | +import org.ocpsoft.prettyfaces.test.PrettyFacesTestBase; |
| 16 | + |
| 17 | +@RunWith(Arquillian.class) |
| 18 | +public class JsfValidatorTest extends PrettyFacesTestBase |
| 19 | +{ |
| 20 | + |
| 21 | + @Deployment(testable = false) |
| 22 | + public static WebArchive getDeployment() |
| 23 | + { |
| 24 | + return getBaseDeployment() |
| 25 | + .addClass(JsfValidatorBean.class) |
| 26 | + .addClass(EvenLengthValidator.class) |
| 27 | + .addAsWebResource("basic/validate.xhtml", "validate.xhtml"); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testValidationSuccess() throws Exception |
| 32 | + { |
| 33 | + String page = getPageAsString("/validate/abcd"); |
| 34 | + assertTrue(page.contains("Parameter = [abcd]")); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testValidationFailed() throws Exception |
| 39 | + { |
| 40 | + HttpClient client = new DefaultHttpClient(); |
| 41 | + HttpGet get = new HttpGet(getFullUrl("/validate/abc")); |
| 42 | + HttpResponse response = client.execute(get); |
| 43 | + assertEquals(404, response.getStatusLine().getStatusCode()); |
| 44 | + } |
| 45 | + |
| 46 | +} |
0 commit comments