1 18 19 package org.apache.roller.business; 20 21 import java.io.InputStream ; 22 import java.util.Map ; 23 import junit.framework.Test; 24 import junit.framework.TestCase; 25 import junit.framework.TestSuite; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.roller.TestUtils; 29 import org.apache.roller.model.FileManager; 30 import org.apache.roller.model.PropertiesManager; 31 import org.apache.roller.model.Roller; 32 import org.apache.roller.model.RollerFactory; 33 import org.apache.roller.model.UserManager; 34 import org.apache.roller.pojos.RollerPropertyData; 35 import org.apache.roller.pojos.UserData; 36 import org.apache.roller.pojos.WebsiteData; 37 import org.apache.roller.util.RollerMessages; 38 39 40 43 public class FileManagerTest extends TestCase { 44 45 public static Log log = LogFactory.getLog(FileManagerTest.class); 46 47 UserData testUser = null; 48 WebsiteData testWeblog = null; 49 50 51 public FileManagerTest(String name) { 52 super(name); 53 } 54 55 56 public static Test suite() { 57 return new TestSuite(FileManagerTest.class); 58 } 59 60 61 public void setUp() throws Exception { 62 63 try { 64 testUser = TestUtils.setupUser("FileManagerTest_userName"); 65 testWeblog = TestUtils.setupWeblog("FileManagerTest_handle", testUser); 66 TestUtils.endSession(true); 67 } catch (Exception ex) { 68 log.error(ex); 69 } 70 } 71 72 public void tearDown() throws Exception { 73 74 try { 75 TestUtils.teardownWeblog(testWeblog.getId()); 76 TestUtils.teardownUser(testUser.getId()); 77 TestUtils.endSession(true); 78 } catch (Exception ex) { 79 log.error(ex); 80 } 81 } 82 83 84 public void testCanSave() throws Exception { 85 86 PropertiesManager pmgr = RollerFactory.getRoller().getPropertiesManager(); 88 Map config = pmgr.getProperties(); 89 ((RollerPropertyData)config.get("uploads.enabled")).setValue("false"); 90 ((RollerPropertyData)config.get("uploads.types.forbid")).setValue("gif"); 91 ((RollerPropertyData)config.get("uploads.dir.maxsize")).setValue("1.00"); 92 pmgr.saveProperties(config); 93 TestUtils.endSession(true); 94 95 FileManager fmgr = RollerFactory.getRoller().getFileManager(); 97 RollerMessages msgs = new RollerMessages(); 98 assertFalse(fmgr.canSave(testWeblog.getHandle(), "test.gif", "text/plain", 2500000, msgs)); 99 } 100 101 102 public void testSave() throws Exception { 103 104 PropertiesManager pmgr = RollerFactory.getRoller().getPropertiesManager(); 106 Map config = pmgr.getProperties(); 107 ((RollerPropertyData)config.get("uploads.enabled")).setValue("true"); 108 ((RollerPropertyData)config.get("uploads.types.allowed")).setValue("opml"); 109 ((RollerPropertyData)config.get("uploads.dir.maxsize")).setValue("1.00"); 110 pmgr.saveProperties(config); 111 TestUtils.endSession(true); 112 113 115 FileManager fmgr = RollerFactory.getRoller().getFileManager(); 116 RollerMessages msgs = new RollerMessages(); 117 118 InputStream is = getClass().getResourceAsStream("/bookmarks.opml"); 120 fmgr.saveFile(testWeblog.getHandle(), "bookmarks.opml", "text/plain", 1545, is); 121 122 assertEquals(1, fmgr.getFiles(testWeblog.getHandle()).length); 124 125 fmgr.deleteFile(testWeblog.getHandle(), "bookmarks.opml"); 127 128 Thread.sleep(2000); 130 assertEquals(0, fmgr.getFiles(testWeblog.getHandle()).length); 131 } 132 133 } 134 | Popular Tags |