001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.util;
020:
021: import java.io.File;
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025:
026: /**
027: * Test blacklist functionality.
028: */
029: public class BlacklistTest extends TestCase {
030:
031: private Blacklist blacklist;
032:
033: public BlacklistTest() {
034: super ();
035: }
036:
037: /**
038: * @param arg0
039: */
040: public BlacklistTest(String arg0) {
041: super (arg0);
042: }
043:
044: /**
045: * @see TestCase#setUp()
046: */
047: protected void setUp() throws Exception {
048: super .setUp();
049: blacklist = Blacklist.getBlacklist();
050: String FS = File.separator;
051: blacklist.loadBlacklistFromFile(".." + FS + "WEB-INF" + FS
052: + "classes" + FS + "blacklist.txt");
053: }
054:
055: /**
056: * @see TestCase#tearDown()
057: */
058: protected void tearDown() throws Exception {
059: super .tearDown();
060: //System.out.println(blacklist);
061: }
062:
063: public void testIsBlacklisted0() {
064: assertFalse(blacklist
065: .isBlacklisted("four score and seven years ago.com"));
066: }
067:
068: // test non-regex
069: public void testIsBlacklisted1() {
070: assertTrue(blacklist.isBlacklisted("00000-online-casino.com"));
071: }
072:
073: // test the regex patterns
074: public void testIsBlacklisted2() {
075: assertTrue(blacklist.isBlacklisted("www.lsotr.com"));
076: }
077:
078: // test the regex patterns
079: public void testIsBlacklisted3() {
080: assertTrue(blacklist.isBlacklisted("www.lsotr.com"));
081: }
082:
083: // test the regex patterns
084: public void testIsBlacklisted4() {
085: assertTrue(blacklist.isBlacklisted("blow-job.com"));
086: }
087:
088: // test the regex patterns
089: public void testIsBlacklisted5() {
090: assertTrue(blacklist.isBlacklisted("buymoreonline.com"));
091: }
092:
093: // test the regex patterns
094: public void testIsBlacklisted6() {
095: assertTrue(blacklist.isBlacklisted("diet-enlargement.com"));
096: }
097:
098: // test the regex patterns
099: public void testIsBlacklisted7() {
100: assertTrue(blacklist.isBlacklisted("viagra.com"));
101: }
102:
103: // test the regex patterns
104: public void testIsBlacklisted8() {
105: assertTrue(blacklist.isBlacklisted("ragazze-something.com"));
106: }
107:
108: public static Test suite() {
109: return new TestSuite(BlacklistTest.class);
110: }
111:
112: }
|