1 4 package org.roller.presentation.velocity; 5 6 import java.io.BufferedInputStream ; 7 import java.io.ByteArrayOutputStream ; 8 import java.io.IOException ; 9 import java.io.InputStream ; 10 import java.util.Date ; 11 import java.util.List ; 12 13 import junit.framework.Test; 14 import junit.framework.TestSuite; 15 16 import org.roller.model.WeblogManager; 17 import org.roller.pojos.UserData; 18 import org.roller.presentation.StrutsActionTestBase; 19 20 import com.mockrunner.mock.web.MockServletContext; 21 22 28 public class ExportRssTest extends StrutsActionTestBase 29 { 30 private String oldUploadPath; 31 32 36 public void testExportRecent() throws Exception 37 { 38 getRoller().begin(UserData.SYSTEM_USER); 39 ExportRss exporter = new ExportRss(mWebsite); 40 41 43 List entries = getRoller().getWeblogManager().getWeblogEntries( 44 null, null, new Date (), null, WeblogManager.ALL, new Integer (5)); 51 try 52 { 53 exporter.exportEntries(entries, "export-test.rss.xml"); 55 56 exporter.setExportAtom(true); 58 exporter.exportEntries(entries, "export-test.atom.xml"); 59 } 60 catch (Exception e) 61 { 62 mLogger.error(e); 63 fail("Find a better way to test than checking Exceptions, bozo!"); 66 } 67 finally 68 { 69 getRoller().begin(UserData.SYSTEM_USER); 70 } 71 } 72 73 77 public void setUp() throws Exception 78 { 79 super.setUp(); 80 81 getRoller().begin(UserData.SYSTEM_USER); 82 getRoller().commit(); 87 88 MockServletContext mContext = getMockFactory().getMockServletContext(); 89 mContext.setRealPath("build/junk", "./build/junk"); 90 91 setupVelocityProperties(mContext); 92 } 93 94 100 private void setupVelocityProperties(MockServletContext mContext) throws IOException 101 { 102 InputStream is = this.getClass().getClassLoader().getResourceAsStream("velocity.properties"); 103 if (is == null) fail("Unable to find velocity.properties"); 104 BufferedInputStream bis = new BufferedInputStream (is, 1); 105 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 106 int buf = bis.read(); 107 do 108 { 109 bos.write(buf); 110 buf = bis.read(); 111 } 112 while(buf != -1); 113 114 byte[] bytes = bos.toByteArray(); 115 mContext.setResourceAsStream("/WEB-INF/velocity.properties", bytes); 116 try 117 { 118 bos.close(); 119 bis.close(); 120 } 121 catch (IOException e) 122 { 123 e.printStackTrace(); 124 } 125 } 126 127 131 public void tearDown() throws Exception 132 { 133 139 super.tearDown(); 140 } 141 142 public static Test suite() 143 { 144 return new TestSuite(ExportRssTest.class); 145 } 146 } 147 | Popular Tags |