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  /***
25   * Validates the title in several different ways.
26   * When the title has whitespace leading or trailing whitespace it can get
27   * tricking, depending on whether they used the  
28   * character or not.
29   *
30   * @jameleon.function name="ie-validate-title" type="validation"
31   * @jameleon.step Verify that the document title equals the given text.
32   */
33  public class IEValidateTitleTag extends IEFunctionTag {
34  
35      /***
36       * The exact title of the page
37       * @jameleon.attribute contextName="ieValidateTitleTitle"
38       */
39      protected String title;
40      /***
41       * The text that the title should not match
42       * @jameleon.attribute
43       * contextName="ieValidateTitleTitleNotEquals"
44       */
45      protected String titleNotEquals;
46      /***
47       * The text that title should contain
48       * @jameleon.attribute
49       * contextName="ieValidateTitleTitleContains"
50       */
51      protected String titleContains;
52      /***
53       * The text that the title should begin with
54       * @jameleon.attribute
55       * contextName="ieValidateTitleTitleBeginsWith"
56       */
57      protected String titleBeginsWith;
58      /***
59       * The text that the title should end with
60       * @jameleon.attribute
61       * contextName="ieValidateTitleTitleEndsWith"
62       */
63      protected String titleEndsWith;
64  
65      public void testBlock() {
66          String actualTitle = getDocument().getTitle();
67          if (title != null) {
68              assertTitleEquals("title of page", title);
69          }else if (titleContains != null) {
70              assertTextContains("title, '"+actualTitle+"', does not contain '"+titleContains+"'", actualTitle, titleContains);
71          }else if (titleBeginsWith != null) {
72              assertTrue("title, '"+actualTitle+"', does not begin with '"+titleBeginsWith+"'", actualTitle.startsWith(titleBeginsWith));
73          }else if (titleEndsWith != null) {
74              assertTrue("title, '"+actualTitle+"', does not end with '"+titleEndsWith+"'", actualTitle.endsWith(titleEndsWith));
75          }else if (titleNotEquals != null) {
76              assertTitleNotEquals("title of page", titleNotEquals);
77          }else{
78              fail("No tests were run for this tag!");
79          }
80      }
81  }