roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r395017 - in /incubator/roller/branches/roller-newbackend: src/org/roller/business/hibernate/HibernateRefererManagerImpl.java src/org/roller/model/RefererManager.java tests/org/roller/business/RefererManagerTest.java
Date Tue, 18 Apr 2006 19:58:51 GMT
Author: agilliland
Date: Tue Apr 18 12:58:49 2006
New Revision: 395017

URL: http://svn.apache.org/viewcvs?rev=395017&view=rev
Log:
adding method removeReferer().
removing private method removeReferers(list).


Modified:
    incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java
    incubator/roller/branches/roller-newbackend/src/org/roller/model/RefererManager.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java

Modified: incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java?rev=395017&r1=395016&r2=395017&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java
(original)
+++ incubator/roller/branches/roller-newbackend/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java
Tue Apr 18 12:58:49 2006
@@ -87,14 +87,8 @@
     }
     
     
-    // convenience method for removing a list of referers
-    private void removeReferers(List referers) throws RollerException {
-        
-        // just go through the list and remove each auto ping
-        Iterator referer = referers.iterator();
-        while (referer.hasNext()) {
-            this.strategy.remove((RefererData) referer.next());
-        }
+    public void removeReferer(RefererData referer) throws RollerException {
+        strategy.remove(referer);
     }
     
     
@@ -111,7 +105,12 @@
             Criteria criteria = session.createCriteria(RefererData.class);
             criteria.createAlias("weblogEntry","e");
             criteria.add(Expression.eq("e.id", entryid));
-            this.removeReferers(criteria.list());
+            
+            Iterator referer = criteria.list().iterator();
+            while (referer.hasNext()) {
+                this.strategy.remove((RefererData) referer.next());
+            }
+            
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
@@ -192,6 +191,7 @@
             Junction or = Expression.disjunction();
             for (int i=0; i<blacklist.length; i++) {
                 String ignoreWord = blacklist[i].trim();
+                //log.debug("including ignore word - "+ignoreWord);
                 or.add(Expression.ilike("refererUrl","%"+ignoreWord+"%"));
             }
             criteria.add(Expression.conjunction()
@@ -199,8 +199,13 @@
             .add(or)
             );
             
-            this.removeReferers(criteria.list());
+            log.debug("removing spam referers - "+criteria.list().size());
             
+            Iterator referer = criteria.list().iterator();
+            while (referer.hasNext()) {
+                this.strategy.remove((RefererData) referer.next());
+            }
+
         } catch (HibernateException e) {
             throw new RollerException(e);
         }
@@ -234,7 +239,11 @@
             .add(or)
             );
             
-            this.removeReferers(criteria.list());
+            Iterator referer = criteria.list().iterator();
+            while (referer.hasNext()) {
+                this.strategy.remove((RefererData) referer.next());
+            }
+            
         } catch (HibernateException e) {
             throw new RollerException(e);
         }

Modified: incubator/roller/branches/roller-newbackend/src/org/roller/model/RefererManager.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/src/org/roller/model/RefererManager.java?rev=395017&r1=395016&r2=395017&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/src/org/roller/model/RefererManager.java (original)
+++ incubator/roller/branches/roller-newbackend/src/org/roller/model/RefererManager.java Tue
Apr 18 12:58:49 2006
@@ -124,6 +124,10 @@
      */
     public void removeReferer( String id ) throws RollerException;
 
+    
+    public void removeReferer(RefererData referer) throws RollerException;
+    
+    
     /**
      * Store the referer.
      */

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java?rev=395017&r1=395016&r2=395017&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java
(original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java
Tue Apr 18 12:58:49 2006
@@ -1 +1 @@
-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.model.PropertiesManager;
import org.roller.model.RefererManager;
import
org.roller.pojos.RollerPropertyData;
import org.roller.pojos.UserData;
import org.roller.pojos.WebsiteData;
import
org.roller.util.DateUtil;
import org.roller.TestUtils;
import org.roller.model.RollerFactory;
import
org.roller.model.UserManager;


/**
 * Test Roller Referer Management.
 */
public class RefererManagerTest
extends TestCase {
    
    public static Log log = LogFactory.getLog(RefererManagerTest.class);
   
    UserData testUser = null;
    WebsiteData testWeblog = null;
    
    int count =
20;
    String testDay;
    String origSpa
 mWords;
    
    
    public RefererManagerTest(String name) {
        super(name);
    }
   
    
    public static Test suite() {
        return new TestSuite(RefererManagerTest.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.store(spamprop);
            
            // add a number of referers to play
with
            RefererManager rmgr = RollerFactory.getRoll
 er().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.getPro
 perty("spam.blacklist");
            spamprop.setValue(this.origSpamWords);
            pmgr.store(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
refer
 ers 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 {
        
        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.store(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.store(spamprop);
       TestUtils.endSession(true);
    }
    
    
    public void testApplyRefererFiltersWebsite()
throws Exception {
        
        RefererManager rmgr = RollerFactory.getRoller().getRefererManager();
       
        List refs = rmgr.getReferers(testWeblog);
        assertEquals(count, refs.size());
       String origWords = null;
        
        UserManager umgr = RollerFactory.getRoller().getUserManager();
       testWeblog = umgr.retrieveWebsite(testWeblog.getId());
        origWords = testWeblog.getBlacklist();
       testWeblog.setBlacklist("test");
        umgr.storeWebsite(testWeblog);
        TestUtils.endSession(true);
       
        rmgr.applyRefererFilters();
        TestUtils.endSession(true);
        
       refs = rmgr.getReferers(testWeblog);
        assertEquals(0, refs.size());
    }
 
  
}
\ No newline at end of file
+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.model.PropertiesManager;
import org.roller.model.RefererManager;
import
org.roller.pojos.RollerPropertyData;
import org.roller.pojos.UserData;
import org.roller.pojos.WebsiteData;
import
org.roller.util.DateUtil;
import org.roller.TestUtils;
import org.roller.model.RollerFactory;
import
org.roller.model.UserManager;


/**
 * Test Roller Referer Management.
 */
public class RefererManagerTest
extends TestCase {
    
    public static Log log = LogFactory.getLog(RefererManagerTest.class);
   
    UserData testUser = null;
    WebsiteData testWeblog = null;
    
    int count =
20;
    String testDay;
    String origSpa
 mWords;
    
    
    public RefererManagerTest(String name) {
        super(name);
    }
   
    
    public static Test suite() {
        return new TestSuite(RefererManagerTest.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.store(spamprop);
            
            // add a number of referers to play
with
            RefererManager rmgr = RollerFactory.getRoll
 er().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.getPro
 perty("spam.blacklist");
            spamprop.setValue(this.origSpamWords);
            pmgr.store(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
refer
 ers 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.store(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.store(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.retrieveWebsite(testWeblog.getId());
       origWords = testWeblog.getBlacklist();
        testWeblog.setBlacklist("test");
  
     umgr.storeWebsite(testWeblog);
        TestUtils.endSession(true);
        
        rmgr.applyRefererFilters();
       TestUtils.endSession(true);
        
        refs = rmgr.getReferer
 s(testWeblog);
        assertEquals(0, refs.size());
    }
    
}
\ No newline at end of file



Mime
View raw message