View Javadoc

1   /*
2       Jiffie Plugin for Jameleon - An Internet Explorer plug-in for Jameleon
3       Copyright (C) 2004-2006 Christian W. Hargraves (engrean@hotmail.com) and
4                          Matthias Marschall (matthias@marschalls.de)
5   
6       This program is free software; you can redistribute it and/or modify
7       it under the terms of the GNU General Public License as published by
8       the Free Software Foundation; either version 2 of the License, or
9       (at your option) any later version.
10  
11      This program is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14      GNU General Public License for more details.
15  
16      You should have received a copy of the GNU General Public License
17      along with this program; if not, write to the Free Software
18      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  package net.sf.jameleon.plugin.jiffie.tags;
21  
22  import net.sf.jameleon.plugin.jiffie.IEFunctionTag;
23  
24  import java.util.Iterator;
25  import java.util.List;
26  
27  /***
28   * Validates the title, text and links on the page.
29   * 
30   * If no checks occur, then this tag will fail.
31   *
32   * Some example uses might be:
33   * 
34   * To validate the title is 'Jameleon':
35   * 
36   * <pre><source>
37   *  &lt;ie-validate functionId="Verify the title is 'Jameleon'" 
38   *       title="Jameleon"/&gt;
39   * </source></pre>
40   * 
41   * To validate the title is <b>not</b> 'Jameleon':
42   * 
43   * <pre><source>
44   *  &lt;ie-validate functionId="Verify the title is NOT 'Jameleon'" 
45   *       titleNoEquals="Jameleon"/&gt;
46   * </source></pre>
47   * 
48   * To check that 'automated testing tool' is on the page:
49   * 
50   * <pre><source>
51   *  &lt;ie-validate functionId="check that 'automated testing tool' is on the page" 
52   *       textPresent="automated testing tool"/&gt;
53   * </source></pre>
54   * 
55   * To check that a link with the given text 'some link' is on the page:
56   * 
57   * <pre><source>
58   *  &lt;ie-validate functionId="Validate that 'some link' is on the current page." 
59   *       linkPresent="some link"/&gt;
60   * </source></pre>
61   * 
62   * Most of the attributes can support multiple values.
63   * 
64   * For example, to check that 'automated testing tool' and 'book' are on the page:
65   * 
66   * <pre><source>
67   *  &lt;map-variable toVariable="textPresent" variableType="list"&gt;
68   *      &lt;variable-value&gt;automated testing tool&lt;/variable-value&gt;
69   *      &lt;variable-value&gt;book&lt;/variable-value&gt;
70   *  &lt;/map-variable&gt;
71   *  &lt;ie-validate functionId="check that 'automated testing tool' is on the page" 
72   *       textPresent="${textPresent}"/&gt;
73   * </source></pre>
74   * 
75   * @jameleon.function name="ie-validate" type="validation"
76   * @jameleon.step Validate that the title is what is expected, if provided
77   * @jameleon.step Check that the given text, if provided, appears on the page.
78   */
79  public class IEValidationTag extends IEFunctionTag {
80  
81      /***
82       * Expected title
83       *
84       * @jameleon.attribute required="false" contextName="ieValidationTitle"
85       */
86      protected String title;
87  
88      /***
89       * Title that is NOT expected. If multiple titles are passed, then ALL titles are compared.
90       *
91       * @jameleon.attribute required="false" contextName="ieValidationTitleNotEquals"
92       */
93      protected List titleNotEquals;
94  
95      /***
96       * Text that should exist on the resulting page
97       *
98       * @jameleon.attribute required="false" contextName="ieValidationTextPresent"
99       */
100     protected List textPresent;
101 
102     /***
103      * Text that should NOT exist on the resulting page
104      *
105      * @jameleon.attribute required="false" contextName="ieValidationTextNotPresent"
106      */
107     protected List textNotPresent;
108 
109     /***
110      * Link that should exist on the resulting page
111      *
112      * @jameleon.attribute required="false" contextName="ieValidationLinkPresent"
113      */
114     protected List linkPresent;
115 
116     public void testBlock() {
117 
118         boolean assertOccurred = false;
119 
120         if (title != null && title.trim().length() > 0) {
121             assertOccurred = true;
122             assertTitleEquals(title);
123         }
124         Iterator it = null;
125         if (titleNotEquals != null && titleNotEquals.size() > 0) {
126             assertOccurred = true;
127             it = titleNotEquals.iterator();
128             String titleS;
129             while (it.hasNext()) {
130                 titleS = (String)it.next();
131                 assertTitleNotEquals(titleS);
132             }
133         }
134         if (textPresent != null && textPresent.size() > 0) {
135             assertOccurred = true;
136             it = textPresent.iterator();
137             String text = null;
138             while (it.hasNext()) {
139                 text = (String) it.next();
140                 assertTextPresent(text);
141             }
142         }
143         if (textNotPresent != null && textNotPresent.size() > 0) {
144             assertOccurred = true;
145             it = textNotPresent.iterator();
146             String text = null;
147             while (it.hasNext()) {
148                 text = (String) it.next();
149                 assertTextNotPresent(text);
150             }
151         }
152         if (linkPresent != null && linkPresent.size() > 0) {
153             assertOccurred = true;
154             it = linkPresent.iterator();
155             String link = null;
156             while (it.hasNext()) {
157                 link = (String) it.next();
158                 assertLinkPresent(link);
159             }
160         }
161 
162         if (!assertOccurred) {
163             fail("No test occurred on ie-validate tag.  You must define a title or textPresent");
164         }
165     }
166 }
167