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      /**
45       * Represents an attribute of a component that is expected to be
46       * rendered into html
47       * @param name  The name of the attribute.
48       * @param value The value of the attribute.
49       * @param expectedHtml The expected html output for this attribute.  
50       *     E.g. name="value".
51       */
52      public HtmlRenderedAttr(String name, String value, String expectedHtml) {
53          this.name = name;
54          this.value = value;
55          this.expectedHtml = expectedHtml;
56          
57          renderSuccessful = false;
58          expectedOccurrences = 1;
59      }
60      
61      public HtmlRenderedAttr(String name, String value, String expectedHtml, int occurances) {
62          this(name, value, expectedHtml);
63          this.expectedOccurrences = occurances;
64      }
65  
66      public String getName()
67      {
68          return name;
69      }
70  
71      public void setName(String name)
72      {
73          this.name = name;
74      }
75  
76      public String getValue()
77      {
78          return value;
79      }
80  
81      public void setValue(String value)
82      {
83          this.value = value;
84      }
85  
86      public String getExpectedHtml()
87      {
88          return expectedHtml;
89      }
90  
91      public void setExpectedHtml(String expectedHtml)
92      {
93          this.expectedHtml = expectedHtml;
94      }
95  
96      /**
97       * This returns the result of the rendering of the attribute.
98       * @return True if the rendered html output of this attribute is
99       * the same as expectedHtml.  False if either the attribute was not
100      * rendered, it was rendered multiple times, or the rendered html
101      * is different from expectedHtml.
102      */
103     public boolean isRenderSuccessful()
104     {
105         return renderSuccessful;
106     }
107 
108     public void setRenderSuccessful(boolean renderSuccessful)
109     {
110         this.renderSuccessful = renderSuccessful;
111     }
112 
113     public int getErrorCode()
114     {
115         return errorCode;
116     }
117 
118     public void setErrorCode(int errorCode)
119     {
120         this.errorCode = errorCode;
121         setRenderSuccessful(false);
122     }
123     
124     public void increaseActualOccurrences() {
125         actualOccurrences++;
126     }
127     
128     public int getActualOccurrences() {
129         return this.actualOccurrences;
130     }
131     
132     public int getExpectedOccurrences() {
133         return this.expectedOccurrences;
134     }
135 }