1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.extensions.validator.test.propval.crossval;
20  
21  
22  import org.apache.myfaces.extensions.validator.test.propval.AbstractPropertyValidationTestCase;
23  import org.junit.Test;
24  
25  import javax.faces.component.UIViewRoot;
26  import javax.faces.component.html.HtmlForm;
27  import javax.faces.component.html.HtmlInputText;
28  
29  public class EqualsStringTestCase extends AbstractPropertyValidationTestCase
30  {
31  
32      HtmlInputText inputComponent1 = null;
33      HtmlInputText inputComponent2 = null;
34  
35      UIViewRoot rootComponent = null;
36  
37      public EqualsStringTestCase()
38      {
39          inputComponent1 = null;
40          inputComponent2 = null;
41          rootComponent = null;
42      }
43  
44  
45      @Override
46      protected void setUpTestCase()
47      {
48          super.setUpTestCase();
49          EqualsStringTestBean bean = new EqualsStringTestBean();
50          createValueBinding(null, "value", "#{testBean}");
51          facesContext.getExternalContext().getRequestMap().put("testBean", bean);
52  
53          rootComponent = new UIViewRoot();
54          HtmlForm form = new HtmlForm();
55          form.setId("form");
56          rootComponent.getChildren().add(form);
57          inputComponent1 = new HtmlInputText();
58          form.getChildren().add(inputComponent1);
59          inputComponent1.setId("input1");
60          inputComponent2 = new HtmlInputText();
61          form.getChildren().add(inputComponent2);
62          inputComponent2.setId("input2");
63      }
64  
65      @Test
66      public void testEqualsCaseSensitiveSame() throws Exception
67      {
68          createValueBinding(inputComponent1, "value", "#{testBean.property1}");
69          createValueBinding(inputComponent2, "value", "#{testBean.property2}");
70  
71          //decode
72          inputComponent1.setSubmittedValue("1d3");
73          inputComponent2.setSubmittedValue("1d3");
74  
75          //validate
76          inputComponent1.validate(facesContext);
77          inputComponent2.validate(facesContext);
78  
79          processCrossValidation();
80          checkMessageCount(0);
81      }
82  
83      @Test
84      public void testEqualsCaseSensitiveDifferent() throws Exception
85      {
86          createValueBinding(inputComponent1, "value", "#{testBean.property1}");
87          createValueBinding(inputComponent2, "value", "#{testBean.property2}");
88  
89          //decode
90          inputComponent1.setSubmittedValue("1d3");
91          inputComponent2.setSubmittedValue("1D3");
92  
93          //validate
94          inputComponent1.validate(facesContext);
95          inputComponent2.validate(facesContext);
96  
97          processCrossValidation();
98          checkMessageCount(2); // For each field a message
99      }
100 
101     @Test
102     public void testEqualsCaseInsensitiveSame() throws Exception
103     {
104         createValueBinding(inputComponent1, "value", "#{testBean.property1}");
105         createValueBinding(inputComponent2, "value", "#{testBean.property3}");
106 
107         //decode
108         inputComponent1.setSubmittedValue("1d3");
109         inputComponent2.setSubmittedValue("1d3");
110 
111         //validate
112         inputComponent1.validate(facesContext);
113         inputComponent2.validate(facesContext);
114 
115         processCrossValidation();
116         checkMessageCount(0);
117     }
118 
119     @Test
120     public void testEqualsCaseInsensitiveDifferent() throws Exception
121     {
122         createValueBinding(inputComponent1, "value", "#{testBean.property1}");
123         createValueBinding(inputComponent2, "value", "#{testBean.property3}");
124 
125         //decode
126         inputComponent1.setSubmittedValue("1d3");
127         inputComponent2.setSubmittedValue("1D3");
128 
129         //validate
130         inputComponent1.validate(facesContext);
131         inputComponent2.validate(facesContext);
132 
133         processCrossValidation();
134         checkMessageCount(0); // Due to extra parameter attribute, no longer an error.
135     }
136 }