001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kns.web.comparator; 017 018 import org.displaytag.model.Cell; 019 import org.junit.Test; 020 021 import static org.junit.Assert.assertEquals; 022 023 public class CellComparatorHelperTest { 024 025 @Test public void testExtractFromHref() { 026 027 String href = "<a style=\"color: red;\" href=\"inquiry.do?businessObjectClassName=org.kuali.rice.krad.bo.Options&universityFiscalYear=2004&methodToCall=start\" target=\"blank\">needle</a>"; 028 029 Cell cell = new Cell(href); 030 031 assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle"); 032 033 } 034 035 @Test public void testExtractFromHrefAndRemoveNbsp() { 036 037 String href = "<a href=\"haystack\">needle </a>"; 038 039 Cell cell = new Cell(href); 040 041 assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle"); 042 043 } 044 045 @Test public void testRemoveNbsp() { 046 047 String bad = "needle "; 048 049 Cell cell = new Cell(bad); 050 051 assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle"); 052 053 } 054 055 @Test public void testLeaveSimpleValueAlone() { 056 057 String good = "needle"; 058 Cell cell = new Cell(good); 059 assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle"); 060 061 } 062 063 @Test public void testMessyHref() { 064 065 String href = "<a onClick=\"foo();\" href=\"haystack\" class=\"my favorite class\" >needle</a> "; 066 067 Cell cell = new Cell(href); 068 069 assertEquals(CellComparatorHelper.getSanitizedStaticValue(cell), "needle"); 070 071 } 072 073 }