roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r395637 - in /incubator/roller/trunk/tests/org/roller/business: RefererManagerTest.java RefererTest.java
Date Thu, 20 Apr 2006 16:39:00 GMT
Author: agilliland
Date: Thu Apr 20 09:38:56 2006
New Revision: 395637

URL: http://svn.apache.org/viewcvs?rev=395637&view=rev
Log:
renaming referer unit test and fixing linefeed.


Added:
    incubator/roller/trunk/tests/org/roller/business/RefererTest.java
Removed:
    incubator/roller/trunk/tests/org/roller/business/RefererManagerTest.java

Added: incubator/roller/trunk/tests/org/roller/business/RefererTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/tests/org/roller/business/RefererTest.java?rev=395637&view=auto
==============================================================================
--- incubator/roller/trunk/tests/org/roller/business/RefererTest.java (added)
+++ incubator/roller/trunk/tests/org/roller/business/RefererTest.java Thu Apr 20 09:38:56
2006
@@ -0,0 +1,181 @@
+package org.roller.business;
+
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+import org.roller.TestUtils;
+import org.roller.model.PropertiesManager;
+import org.roller.model.RefererManager;
+import org.roller.model.RollerFactory;
+import org.roller.model.UserManager;
+import org.roller.pojos.RollerPropertyData;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WebsiteData;
+import org.roller.util.DateUtil;
+
+
+/**
+ * Test Roller Referer Management.
+ */
+public class RefererTest extends TestCase {
+    
+    public static Log log = LogFactory.getLog(RefererTest.class);
+    
+    UserData testUser = null;
+    WebsiteData testWeblog = null;
+    
+    int count = 20;
+    String testDay;
+    String origSpamWords;
+    
+    
+    public RefererTest(String name) {
+        super(name);
+    }
+    
+    
+    public static Test suite() {
+        return new TestSuite(RefererTest.class);
+    }
+    
+    
+    /**
+     * All tests in this suite require a user and a weblog.
+     */
+    public void setUp() throws Exception {
+        
+        try {
+            testUser = TestUtils.setupUser("referTestUser");
+            testWeblog = TestUtils.setupWeblog("referTestWeblog", testUser);
+            
+            // add "spamtest" to refererSpamWords
+            PropertiesManager pmgr = RollerFactory.getRoller().getPropertiesManager();
+            RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
+            this.origSpamWords = spamprop.getValue();
+            spamprop.setValue(spamprop.getValue() + ", spamtest");
+            pmgr.saveProperty(spamprop);
+            
+            // add a number of referers to play with
+            RefererManager rmgr = RollerFactory.getRoller().getRefererManager();
+            Calendar lCalendar = Calendar.getInstance();
+            lCalendar.setTime(new Date());
+            for (int i = 0; i < count; i++) {
+                lCalendar.add(Calendar.DATE, -1);
+                Timestamp day = new Timestamp(lCalendar.getTime().getTime());
+                testDay = DateUtil.format8chars(day);
+                
+                rmgr.processReferrer("http://test"+i, "http://test"+i,
+                        testWeblog.getHandle(), null, testDay);
+            }
+            
+            TestUtils.endSession(true);
+            
+        } catch (Exception ex){
+            log.error(ex);
+            throw new Exception("Test setup failed", ex);
+        }
+    }
+    
+    public void tearDown() throws Exception {
+        
+        try {
+            // reset refererSpamWords to original value
+            PropertiesManager pmgr = RollerFactory.getRoller().getPropertiesManager();
+            RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
+            spamprop.setValue(this.origSpamWords);
+            pmgr.saveProperty(spamprop);
+            
+            TestUtils.teardownWeblog(testWeblog.getId());
+            TestUtils.teardownUser(testUser.getId());
+            
+            TestUtils.endSession(true);
+        } catch (Exception ex) {
+            log.error(ex);
+            throw new Exception("Test teardown failed", ex);
+        }
+    }
+    
+    
+    public void testGetReferersToDate() throws Exception {
+        
+        RefererManager rmgr = RollerFactory.getRoller().getRefererManager();
+        
+        List referers = rmgr.getReferersToDate(testWeblog, testDay);
+        assertEquals("Should be one Referer.", referers.size(), 1);
+    }
+    
+    
+    public void testRefererProcessing() throws RollerException {
+        
+        RefererManager rmgr = RollerFactory.getRoller().getRefererManager();
+        
+        List refs = rmgr.getReferers(testWeblog);
+        assertEquals("number of referers should equal count", count, refs.size());
+        
+        int hits = rmgr.getDayHits(testWeblog);
+        assertEquals("There should be one fewer hits than referers", count, hits);
+    }
+    
+    
+    public void testApplyRefererFilters() throws Exception {
+        
+        log.info("Test apply referers (global)");
+        
+        RefererManager rmgr = RollerFactory.getRoller().getRefererManager();
+        
+        List refs = rmgr.getReferers(testWeblog);
+        assertEquals(count, refs.size());
+        
+        PropertiesManager pmgr = RollerFactory.getRoller().getPropertiesManager();
+        RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
+        String origWords = spamprop.getValue();
+        spamprop.setValue(spamprop.getValue() + ", test");
+        pmgr.saveProperty(spamprop);
+        TestUtils.endSession(true);
+        
+        rmgr.applyRefererFilters();
+        TestUtils.endSession(true);
+        
+        refs = rmgr.getReferers(testWeblog);
+        assertEquals(0, refs.size());
+        
+        spamprop = pmgr.getProperty("spam.blacklist");
+        spamprop.setValue(origWords);
+        pmgr.saveProperty(spamprop);
+        TestUtils.endSession(true);
+    }
+    
+    
+    public void testApplyRefererFiltersWebsite() throws Exception {
+        
+        log.info("Test apply referers (weblog)");
+        
+        RefererManager rmgr = RollerFactory.getRoller().getRefererManager();
+        
+        List refs = rmgr.getReferers(testWeblog);
+        assertEquals(count, refs.size());
+        String origWords = null;
+        
+        UserManager umgr = RollerFactory.getRoller().getUserManager();
+        testWeblog = umgr.getWebsite(testWeblog.getId());
+        origWords = testWeblog.getBlacklist();
+        testWeblog.setBlacklist("test");
+        umgr.saveWebsite(testWeblog);
+        TestUtils.endSession(true);
+        
+        rmgr.applyRefererFilters();
+        TestUtils.endSession(true);
+        
+        refs = rmgr.getReferers(testWeblog);
+        assertEquals(0, refs.size());
+    }
+    
+}
+



Mime
View raw message