View Javadoc

1   /*
2    * Copyright 2006-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.web.comparator;
17  
18  import org.displaytag.model.Cell;
19  import org.junit.Test;
20  import org.kuali.rice.kns.web.comparator.CellComparatorHelper;
21  import org.kuali.test.KNSTestCase;
22  
23  public class CellComparatorHelperTest extends KNSTestCase {
24  
25      @Test public void testExtractFromHref() {
26  
27          String href = "<a style=\"color: red;\" href=\"inquiry.do?businessObjectClassName=org.kuali.rice.kns.bo.Options&amp;universityFiscalYear=2004&amp;methodToCall=start\" target=\"blank\">needle</a>";
28  
29          Cell cell = new Cell(href);
30  
31          assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle");
32  
33      }
34  
35      @Test public void testExtractFromHrefAndRemoveNbsp() {
36  
37          String href = "<a href=\"haystack\">needle&nbsp;</a>";
38  
39          Cell cell = new Cell(href);
40  
41          assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle");
42  
43      }
44  
45      @Test public void testRemoveNbsp() {
46  
47          String bad = "needle&nbsp;";
48  
49          Cell cell = new Cell(bad);
50  
51          assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle");
52  
53      }
54  
55      @Test public void testLeaveSimpleValueAlone() {
56  
57          String good = "needle";
58          Cell cell = new Cell(good);
59          assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle");
60  
61      }
62  
63      @Test public void testMessyHref() {
64  
65          String href = "<a onClick=\"foo();\" href=\"haystack\" class=\"my favorite class\" >needle</a>&nbsp;";
66  
67          Cell cell = new Cell(href);
68  
69          assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle");
70  
71      }
72  
73  }