1 16 package org.apache.roller.business; 17 18 import java.sql.Timestamp ; 19 import java.util.Date ; 20 import java.util.List ; 21 import junit.framework.Test; 22 import junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 import junit.textui.TestRunner; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.roller.TestUtils; 28 import org.apache.roller.model.PlanetManager; 29 import org.apache.roller.model.RollerFactory; 30 import org.apache.roller.pojos.UserData; 31 import org.apache.roller.pojos.WeblogEntryData; 32 import org.apache.roller.pojos.WebsiteData; 33 import org.apache.roller.ui.core.tasks.RefreshEntriesTask; 34 import org.apache.roller.ui.core.tasks.SyncWebsitesTask; 35 36 37 38 42 public class PlanetManagerLocalTest extends TestCase { 43 public static Log log = LogFactory.getLog(PlanetManagerLocalTest.class); 44 45 UserData testUser = null; 46 WebsiteData testWeblog = null; 47 48 public static void main(String [] args) { 49 TestRunner.run(PlanetManagerLocalTest.class); 50 } 51 52 55 public void setUp() throws Exception { 56 57 try { 58 testUser = TestUtils.setupUser("entryTestUser"); 59 testWeblog = TestUtils.setupWeblog("entryTestWeblog", testUser); 60 61 WeblogEntryData testEntry1 = new WeblogEntryData(); 62 testEntry1.setTitle("entryTestEntry1"); 63 testEntry1.setLink("testEntryLink1"); 64 testEntry1.setText("blah blah entry1"); 65 testEntry1.setAnchor("testEntryAnchor1"); 66 testEntry1.setPubTime(new Timestamp (new Date ().getTime())); 67 testEntry1.setUpdateTime(new Timestamp (new Date ().getTime())); 68 testEntry1.setWebsite(testWeblog); 69 testEntry1.setCreator(testUser); 70 testEntry1.setCategory(testWeblog.getDefaultCategory()); 71 RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1); 72 73 WeblogEntryData testEntry2 = new WeblogEntryData(); 74 testEntry2.setTitle("entryTestEntry2"); 75 testEntry2.setLink("testEntryLink2"); 76 testEntry2.setText("blah blah entry2"); 77 testEntry2.setAnchor("testEntryAnchor2"); 78 testEntry2.setPubTime(new Timestamp (new Date ().getTime())); 79 testEntry2.setUpdateTime(new Timestamp (new Date ().getTime())); 80 testEntry2.setWebsite(testWeblog); 81 testEntry2.setCreator(testUser); 82 testEntry2.setCategory(testWeblog.getDefaultCategory()); 83 RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1); 84 85 WeblogEntryData testEntry3 = new WeblogEntryData(); 86 testEntry3.setTitle("entryTestEntry3"); 87 testEntry3.setLink("testEntryLink3"); 88 testEntry3.setText("blah blah entry3"); 89 testEntry3.setAnchor("testEntryAnchor3"); 90 testEntry3.setPubTime(new Timestamp (new Date ().getTime())); 91 testEntry3.setUpdateTime(new Timestamp (new Date ().getTime())); 92 testEntry3.setWebsite(testWeblog); 93 testEntry3.setCreator(testUser); 94 testEntry3.setCategory(testWeblog.getDefaultCategory()); 95 RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1); 96 97 TestUtils.endSession(true); 98 99 } catch (Exception ex) { 100 log.error(ex); 101 throw new Exception ("Test setup failed", ex); 102 } 103 } 104 105 public void tearDown() throws Exception { 106 107 try { 108 TestUtils.teardownWeblog(testWeblog.getId()); 109 TestUtils.teardownUser(testUser.getId()); 110 TestUtils.endSession(true); 111 } catch (Exception ex) { 112 log.error(ex); 113 throw new Exception ("Test teardown failed", ex); 114 } 115 } 116 117 public void testRefreshEntries() { 118 try { 119 PlanetManager planet = RollerFactory.getRoller().getPlanetManager(); 120 121 SyncWebsitesTask syncTask = new SyncWebsitesTask(); 123 syncTask.init(RollerFactory.getRoller(), "dummy"); 124 syncTask.run(); 125 126 RefreshEntriesTask refreshTask = new RefreshEntriesTask(); 127 refreshTask.init(RollerFactory.getRoller(), "dummy"); 128 refreshTask.run(); 129 130 List agg = planet.getAggregation(null, null, 0, -1); 131 assertEquals(3, agg.size()); 132 } 133 catch (Exception e) { 134 e.printStackTrace(); 135 fail(); 136 } 137 } 138 139 public static Test suite() { 140 return new TestSuite(PlanetManagerLocalTest.class); 141 } 142 143 144 } 145 146 | Popular Tags |