1 package org.roller.business; 2 3 import java.io.InputStream ; 4 import java.util.HashMap ; 5 import java.util.Map ; 6 7 import junit.framework.Test; 8 import junit.framework.TestCase; 9 import junit.framework.TestSuite; 10 11 import org.roller.model.FileManager; 12 import org.roller.model.PropertiesManager; 13 import org.roller.model.Roller; 14 import org.roller.model.RollerFactory; 15 import org.roller.model.UserManager; 16 import org.roller.pojos.RollerPropertyData; 17 import org.roller.pojos.UserData; 18 import org.roller.pojos.WebsiteData; 19 import org.roller.util.RollerMessages; 20 21 24 public class FileManagerTest extends TestCase 25 { 26 29 public void setUp() throws Exception 30 { 31 32 } 33 34 public void tearDown() throws Exception 35 { 36 } 38 39 public void testCanSave() 40 { 41 try 42 { 43 Roller mRoller = RollerFactory.getRoller(); 45 46 UserManager umgr = mRoller.getUserManager(); 47 WebsiteData mWebsite = umgr.getWebsite("FileManagerTest_userName"); 48 49 if(mWebsite == null) 50 mWebsite = this.createTestUser(); 51 52 PropertiesManager pmgr = mRoller.getPropertiesManager(); 54 Map config = pmgr.getProperties(); 55 ((RollerPropertyData)config.get("uploads.enabled")).setValue("false"); 56 ((RollerPropertyData)config.get("uploads.types.forbid")).setValue("gif"); 57 ((RollerPropertyData)config.get("uploads.dir.maxsize")).setValue("1.00"); 58 pmgr.store(config); 59 mRoller.commit(); 60 61 FileManager fmgr = new FileManagerImpl(); 62 RollerMessages msgs = new RollerMessages(); 63 assertFalse(fmgr.canSave(mWebsite, "test.gif", 2500000, msgs)); 64 } 66 catch (Exception e) 67 { 68 e.printStackTrace(); 69 } 70 } 71 72 public void testSave() 73 { 74 try 75 { 76 Roller mRoller = RollerFactory.getRoller(); 78 79 UserManager umgr = mRoller.getUserManager(); 80 WebsiteData mWebsite = umgr.getWebsite("FileManagerTest_userName"); 81 82 if(mWebsite == null) 83 mWebsite = this.createTestUser(); 84 85 PropertiesManager pmgr = mRoller.getPropertiesManager(); 87 Map config = pmgr.getProperties(); 88 ((RollerPropertyData)config.get("uploads.enabled")).setValue("true"); 89 ((RollerPropertyData)config.get("uploads.types.allowed")).setValue("opml"); 90 ((RollerPropertyData)config.get("uploads.dir.maxsize")).setValue("1.00"); 91 pmgr.store(config); 92 mRoller.commit(); 93 94 96 FileManager fmgr = new FileManagerImpl(); 97 RollerMessages msgs = new RollerMessages(); 98 InputStream is = getClass().getResourceAsStream("/bookmarks.opml"); 99 fmgr.saveFile(mWebsite, "bookmarks.opml", 1545, is); 100 101 assertEquals(1, fmgr.getFiles(mWebsite).length); 102 103 fmgr.deleteFile(mWebsite, "bookmarks.opml"); 104 Thread.sleep(2000); 105 assertEquals(0, fmgr.getFiles(mWebsite).length); 106 } 107 catch (Exception e) 108 { 109 e.printStackTrace(); 110 } 111 } 112 113 private WebsiteData createTestUser() throws Exception { 114 Roller mRoller = RollerFactory.getRoller(); 116 117 UserManager umgr = mRoller.getUserManager(); 118 mRoller.begin(UserData.SYSTEM_USER); 119 UserData user = new UserData(null, 120 "FileManagerTest_userName", 121 "FileManagerTest_password", 122 "FileManagerTest_description", 123 "FileManagerTest@example.com", 124 new java.util.Date ()); 125 Map pages = new HashMap (); 126 pages.put("Weblog","Weblog page content"); 127 pages.put("_day","Day page content"); 128 pages.put("css","CSS page content"); 129 umgr.addUser(user, pages, "basic", "en_US_WIN", "America/Los_Angeles"); 130 mRoller.commit(); 131 WebsiteData mWebsite = umgr.getWebsite(user.getUserName()); 132 133 return mWebsite; 134 } 135 136 public static Test suite() 137 { 138 return new TestSuite(FileManagerTest.class); 139 } 140 } 141 | Popular Tags |