View Javadoc

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.test.utils;
20  
21  public class HtmlRenderedAttr
22  {
23      public static final int RENDERED_MORE_TIMES_THAN_EXPECTED = 1;
24      public static final int RENDERED_LESS_TIMES_THAN_EXPECTED = 2;
25      
26      private String name;
27      private String value;
28      private String expectedHtml;
29      private boolean renderSuccessful;
30      private int errorCode;
31      private int expectedOccurrences;
32      private int actualOccurrences;
33      
34      public HtmlRenderedAttr(String name) {
35          this(name, name, name + "=\"" + name + "\"");
36          expectedOccurrences = 1;
37      }
38      
39      public HtmlRenderedAttr(String name, int expectedOccurences) {
40          this(name);
41          this.expectedOccurrences = expectedOccurences;
42      }
43      
44      public HtmlRenderedAttr(String name, String value)
45      {
46          this.name = name;
47          this.value = value;
48          this.expectedHtml = " "+name+"=\""+value+"\"";
49          
50          renderSuccessful = false;
51          expectedOccurrences = 1;
52      }
53      
54      /**
55       * Represents an attribute of a component that is expected to be
56       * rendered into html
57       * @param name  The name of the attribute.
58       * @param value The value of the attribute.
59       * @param expectedHtml The expected html output for this attribute.  
60       *     E.g. name="value".
61       */
62      public HtmlRenderedAttr(String name, String value, String expectedHtml) {
63          this.name = name;
64          this.value = value;
65          this.expectedHtml = expectedHtml;
66          
67          renderSuccessful = false;
68          expectedOccurrences = 1;
69      }
70      
71      public HtmlRenderedAttr(String name, String value, String expectedHtml, int occurances) {
72          this(name, value, expectedHtml);
73          this.expectedOccurrences = occurances;
74      }
75  
76      public String getName()
77      {
78          return name;
79      }
80  
81      public void setName(String name)
82      {
83          this.name = name;
84      }
85  
86      public String getValue()
87      {
88          return value;
89      }
90  
91      public void setValue(String value)
92      {
93          this.value = value;
94      }
95  
96      public String getExpectedHtml()
97      {
98          return expectedHtml;
99      }
100 
101     public void setExpectedHtml(String expectedHtml)
102     {
103         this.expectedHtml = expectedHtml;
104     }
105 
106     /**
107      * This returns the result of the rendering of the attribute.
108      * @return True if the rendered html output of this attribute is
109      * the same as expectedHtml.  False if either the attribute was not
110      * rendered, it was rendered multiple times, or the rendered html
111      * is different from expectedHtml.
112      */
113     public boolean isRenderSuccessful()
114     {
115         return renderSuccessful;
116     }
117 
118     public void setRenderSuccessful(boolean renderSuccessful)
119     {
120         this.renderSuccessful = renderSuccessful;
121     }
122 
123     public int getErrorCode()
124     {
125         return errorCode;
126     }
127 
128     public void setErrorCode(int errorCode)
129     {
130         this.errorCode = errorCode;
131         setRenderSuccessful(false);
132     }
133     
134     public void increaseActualOccurrences() {
135         actualOccurrences++;
136     }
137     
138     public int getActualOccurrences() {
139         return this.actualOccurrences;
140     }
141     
142     public int getExpectedOccurrences() {
143         return this.expectedOccurrences;
144     }
145 }