Update of /cvsroot/roller/roller/tests/org/roller/presentation/velocity
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8677/tests/org/roller/presentation/velocity
Added Files:
ExportRssTest.java VelocityTest.java
Log Message:
Forgot to checkin unit tests.
--- NEW FILE: ExportRssTest.java ---
/*
* Created on Mar 25, 2004
*/
package org.roller.presentation.velocity;
import com.mockrunner.mock.web.MockServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.roller.pojos.RollerConfig;
import org.roller.presentation.ServletTestBase;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
/**
* Not really a servlet test, the ExportRss class does require
* that RollerContext has been loaded and initialized.
*
* @author lance.lavandowska
*/
public class ExportRssTest extends ServletTestBase
{
public static Log mLogger =
LogFactory.getFactory().getInstance(ExportRssTest.class);
private String oldUploadPath;
/**
* Not sure how to test that the file was generated, so if
* there was no Exception we passed.
*/
public void testExportRecent() throws Exception
{
ExportRss exporter = new ExportRss(mWebsite);
List entries =
getRoller().getWeblogManager().getAllRecentWeblogEntries(new Date(), 5);
try
{
// test RSS output
exporter.exportEntries(entries, "export-test.rss.xml");
// test Atom output
exporter.setExportAtom(true);
exporter.exportEntries(entries, "export-test.atom.xml");
}
catch (Exception e)
{
mLogger.error(e);
// I'm not sure how best to test the output!
// I guess no exceptions will have to do.
fail("Find a better way to test than checking Exceptions, bozo!");
}
}
/*
* Need to change the UploadPath location for testing.
* @see junit.framework.TestCase#setUp()
*/
public void setUp() throws Exception
{
super.setUp();
getRoller().begin();
RollerConfig rollerConfig = rollerContext.getRollerConfig();
oldUploadPath = rollerConfig.getUploadPath();
rollerConfig.setUploadPath("build/junk");
rollerConfig.save();
getRoller().commit();
MockServletContext mContext = mockFactory.getMockServletContext();
mContext.setRealPath("build/junk", "./build/junk");
setupVelocityProperties(mContext);
}
/**
* ExportRss needs to load velocity.properties from ServletContext.
* For the mock implementation we need to set the 'resource stream'.
* @param mContext
* @throws IOException
*/
private void setupVelocityProperties(MockServletContext mContext) throws
IOException
{
InputStream is =
this.getClass().getClassLoader().getResourceAsStream("velocity.properties");
if (is == null) fail("Unable to find velocity.properties");
BufferedInputStream bis = new BufferedInputStream(is, 1);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int buf = bis.read();
do
{
bos.write(buf);
buf = bis.read();
}
while(buf != -1);
byte[] bytes = bos.toByteArray();
mContext.setResourceAsStream("/WEB-INF/velocity.properties", bytes);
try
{
bos.close();
bis.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
/*
* Need to reset the UploadPath after testing.
* @see junit.framework.TestCase#tearDown()
*/
public void tearDown() throws Exception
{
getRoller().begin();
RollerConfig rollerConfig = rollerContext.getRollerConfig();
rollerConfig.setUploadPath(oldUploadPath);
rollerConfig.save();
getRoller().commit();
super.tearDown();
}
}
--- NEW FILE: VelocityTest.java ---
/*
* Created on Oct 31, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.roller.presentation.velocity;
import junit.framework.TestCase;
import org.roller.presentation.velocity.plugins.textile.TextilePlugin;
/**
* We really need to solve webtesting to adequately test our Presentation
classes.
*
* @author lance
*/
public class VelocityTest extends TestCase
{
String textileStr = "*strong* plain _emphasis_ * _emphaticStrong_ * ";
String expected = "<p><strong>strong</strong>plain <em>emphasis</em>
<strong> <em>emphaticStrong</em> </strong></p>";
/* this is failing, but I think it is due to a problem in Textile4J:
* for instance, it is stripping a space after closing a "strong" tag.
*/
public void testTextile()
{
PagePlugin textile = new TextilePlugin();
String result = textile.render(textileStr);
assertEquals("this will fail until Textile4J is fixed.", expected,
result);
}
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
}
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception
{
super.tearDown();
}
}
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
|
Try Searching:
servers, voip, java, networking, microsoft ...
|
|
|
|