1 37 package net.sourceforge.cruisecontrol.taglib; 38 39 import javax.servlet.jsp.tagext.Tag ; 40 import javax.servlet.jsp.JspException ; 41 42 import junit.framework.TestCase; 43 import net.sourceforge.cruisecontrol.mock.MockPageContext; 44 import net.sourceforge.cruisecontrol.mock.MockServletRequest; 45 46 50 public class TabTagTest extends TestCase { 51 private TabTag tabTag; 52 private MockServletRequest request; 53 54 public TabTagTest(String name) { 55 super(name); 56 } 57 58 public void setUp() { 59 tabTag = new TabTag(); 60 tabTag.setName("tab1"); 61 tabTag.setLabel("Tab 1"); 62 63 final MockPageContext pageContext = new MockPageContext(); 64 tabTag.setPageContext(pageContext); 65 request = new MockServletRequest(); 66 pageContext.setHttpServletRequest(request); 67 } 68 69 public void testTabsGetAdded() throws JspException { 70 setTabNameParam("tab1"); 71 72 TestTabSheetTag tabSheet = new TestTabSheetTag("tab1", "Tab 1", true); 73 tabTag.setParent(tabSheet); 74 assertEquals(Tag.EVAL_BODY_INCLUDE, tabTag.doStartTag()); 75 assertTrue(tabSheet.tabsWereAdded); 76 } 77 78 public void testTabsGetSkippedWhenDifferent() throws JspException { 79 setTabNameParam("tab2"); 80 81 TestTabSheetTag tabSheet = new TestTabSheetTag("tab1", "Tab 1", false); 82 tabTag.setParent(tabSheet); 83 assertEquals(Tag.SKIP_BODY, tabTag.doStartTag()); 84 assertTrue(tabSheet.tabsWereAdded); 85 } 86 87 public void testTabsGetAddedWhenNonePicked() throws JspException { 88 TestTabSheetTag tabSheet = new TestTabSheetTag("tab1", "Tab 1", true); 89 tabTag.setParent(tabSheet); 90 assertEquals(Tag.EVAL_BODY_INCLUDE, tabTag.doStartTag()); 91 assertTrue(tabSheet.tabsWereAdded); 92 } 93 94 private void setTabNameParam(final String tabName) { 95 request.addParameter("tab", tabName); 96 } 97 98 class TestTabSheetTag extends TabSheetTag { 99 private final String expectedName; 100 private final String expectedLabel; 101 private boolean tabsWereAdded; 102 private final boolean expectedSelected; 103 104 public TestTabSheetTag(String expectedName, String expectedLabel, boolean expectedSelected) { 105 this.expectedName = expectedName; 106 this.expectedLabel = expectedLabel; 107 this.expectedSelected = expectedSelected; 108 } 109 110 public void addTab(Tab tab) { 111 tabsWereAdded = true; 112 assertEquals(expectedName, tab.getName()); 113 assertEquals(expectedLabel, tab.getLabel()); 114 assertEquals(expectedSelected, tab.isSelected()); 115 } 116 } 117 118 } 119 | Popular Tags |