1 37 package net.sourceforge.cruisecontrol.taglib; 38 39 import java.io.File ; 40 import java.io.IOException ; 41 import java.util.Locale ; 42 43 import javax.servlet.jsp.JspException ; 44 import javax.servlet.jsp.tagext.BodyTag ; 45 46 import junit.framework.TestCase; 47 import net.sourceforge.cruisecontrol.mock.MockBodyContent; 48 import net.sourceforge.cruisecontrol.mock.MockPageContext; 49 import net.sourceforge.cruisecontrol.mock.MockServletConfig; 50 import net.sourceforge.cruisecontrol.mock.MockServletRequest; 51 52 public class NavigationCountTagTest extends TestCase { 53 private NavigationCountTag tag; 54 private MockPageContext pageContext; 55 private File [] logFiles; 56 private File logDir; 57 58 public void setUp() throws IOException { 59 tag = new NavigationCountTag(); 60 pageContext = new MockPageContext(); 61 MockServletRequest request = new MockServletRequest("context", "servlet"); 62 request.setLocale(Locale.US); 63 pageContext.setHttpServletRequest(request); 64 65 tag.setPageContext(pageContext); 66 tag.setBodyContent(new MockBodyContent()); 67 68 logDir = new File ("testresults/NavigationTagTest"); 69 if (!logDir.exists()) { 70 assertTrue("Failed to create test result dir", logDir.mkdirs()); 71 } 72 final MockServletConfig servletConfig = (MockServletConfig) pageContext.getServletConfig(); 73 servletConfig.setInitParameter("logDir", logDir.getAbsolutePath()); 74 75 logFiles = new File [] { new File (logDir, "log20020222120000.xml"), new File (logDir, "log20020223120000.xml"), 76 new File (logDir, "log20020224120000.xml"), new File (logDir, "log20020225120000.xml") }; 77 for (int i = 0; i < logFiles.length; i++) { 78 File logFile = logFiles[i]; 79 logFile.createNewFile(); 80 } 81 } 82 83 protected void tearDown() throws Exception { 84 for (int i = 0; i < logFiles.length; i++) { 85 logFiles[i].delete(); 86 } 87 logDir.delete(); 88 } 89 90 91 public void testIncludeBody() throws Exception { 92 tag.setStartingBuildNumber(2); 93 assertEquals(BodyTag.EVAL_BODY_INCLUDE, tag.doStartTag()); 94 } 95 96 public void testDoNotIncludeBody() throws JspException { 97 tag.setStartingBuildNumber(5); 98 assertEquals(BodyTag.SKIP_BODY, tag.doStartTag()); 99 } 100 } 101 | Popular Tags |