1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.jsf.core.validation;
20
21 import javax.faces.application.StateManager;
22 import javax.faces.component.UIInput;
23 import javax.faces.validator.BeanValidator;
24 import javax.faces.validator.Validator;
25 import org.apache.myfaces.mc.test.core.AbstractMyFacesCDIRequestTestCase;
26 import org.apache.myfaces.shared.config.MyfacesConfig;
27 import org.junit.Assert;
28 import org.junit.Test;
29
30
31
32
33
34 public class BeanValidationCDIRequestTestCase extends AbstractMyFacesCDIRequestTestCase
35 {
36
37 @Override
38 protected boolean isScanAnnotations()
39 {
40 return true;
41 }
42
43 @Override
44 protected void setUpWebConfigParams() throws Exception
45 {
46 super.setUpWebConfigParams();
47 servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES",
48 "org.apache.myfaces.view.facelets.tag.jsf.core.validation");
49 servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
50 servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", "true");
51 servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS, "auto");
52 servletContext.addInitParameter("javax.faces.CLIENT_WINDOW_MODE", "url");
53 servletContext.addInitParameter("org.apache.myfaces.validator.BEAN_BEFORE_JSF_VALIDATION", "true");
54 }
55
56 @Test
57 public void testBeanValidation_1() throws Exception
58 {
59 startViewRequest("/testBeanValidation_1.xhtml");
60
61 processLifecycleExecute();
62 processLifecycleRender();
63 client.inputText("mainForm:username", "someusr");
64
65 client.submit("mainForm:submit");
66
67 processLifecycleExecute();
68
69 UIInput username = (UIInput) facesContext.getViewRoot().findComponent("mainForm:username");
70 Assert.assertNotNull(username);
71 Validator[] array = username.getValidators();
72 Assert.assertTrue(array[0] instanceof BeanValidator);
73 }
74
75 @Test
76 public void testBeanValidation_2() throws Exception
77 {
78 startViewRequest("/testBeanValidation_2.xhtml");
79
80 processLifecycleExecute();
81 processLifecycleRender();
82 client.inputText("mainForm:username", "someusr");
83
84 client.submit("mainForm:submit");
85
86 processLifecycleExecute();
87
88 UIInput username = (UIInput) facesContext.getViewRoot().findComponent("mainForm:username");
89 Assert.assertNotNull(username);
90 Validator[] array = username.getValidators();
91 Assert.assertTrue(array[0] instanceof BeanValidator);
92 }
93 }