001: package net.javacoding.jspider.core.util.html;
002:
003: import junit.framework.TestCase;
004:
005: import java.net.URL;
006:
007: /**
008: * $Id: RobotsTXTLineTest.java,v 1.1 2003/02/11 17:33:04 vanrogu Exp $
009: */
010: public class RobotsTXTLineTest extends TestCase {
011:
012: public RobotsTXTLineTest() {
013: super ("RobotsTXTLineTest");
014: }
015:
016: public void testSimpleAllow() {
017: RobotsTXTLine l = RobotsTXTLine.parse("allow: index.html");
018:
019: assertNotNull("line returned for correct info is null", l);
020:
021: String resource = l.getResourceURI();
022: int type = l.getType();
023:
024: assertEquals("type parsed incorrect",
025: RobotsTXTLine.ROBOTSTXT_RULE_ALLOW, type);
026: assertEquals("resourceURI parsed incorrect", "index.html",
027: resource);
028:
029: }
030:
031: public void testSimpleAllowCaseSensitivity() {
032: RobotsTXTLine l = RobotsTXTLine.parse("AlLoW: index.html");
033:
034: assertNotNull("line returned for correct info is null", l);
035:
036: String resource = l.getResourceURI();
037: int type = l.getType();
038:
039: assertEquals("type parsed incorrect",
040: RobotsTXTLine.ROBOTSTXT_RULE_ALLOW, type);
041: assertEquals("resourceURI parsed incorrect", "index.html",
042: resource);
043:
044: }
045:
046: public void testSimpleDisallow() {
047: RobotsTXTLine l = RobotsTXTLine.parse("disallow: index.html");
048:
049: assertNotNull("line returned for correct info is null", l);
050:
051: String resource = l.getResourceURI();
052: int type = l.getType();
053:
054: assertEquals("type parsed incorrect",
055: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW, type);
056: assertEquals("resourceURI parsed incorrect", "index.html",
057: resource);
058:
059: }
060:
061: public void testSimpleDisallowCaseSensitivity() {
062: RobotsTXTLine l = RobotsTXTLine.parse("dIsAlLoW: index.html");
063:
064: assertNotNull("line returned for correct info is null", l);
065:
066: String resource = l.getResourceURI();
067: int type = l.getType();
068:
069: assertEquals("type parsed incorrect",
070: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW, type);
071: assertEquals("resourceURI parsed incorrect", "index.html",
072: resource);
073:
074: }
075:
076: public void testSimpleAllowWithoutSpace() {
077: RobotsTXTLine l = RobotsTXTLine.parse("allow:index.html");
078:
079: assertNotNull("line returned for correct info is null", l);
080:
081: String resource = l.getResourceURI();
082: int type = l.getType();
083:
084: assertEquals("type parsed incorrect",
085: RobotsTXTLine.ROBOTSTXT_RULE_ALLOW, type);
086: assertEquals("resourceURI parsed incorrect", "index.html",
087: resource);
088:
089: }
090:
091: public void testSimpleDisallowWithoutSpace() {
092: RobotsTXTLine l = RobotsTXTLine.parse("disallow:index.html");
093:
094: assertNotNull("line returned for correct info is null", l);
095:
096: String resource = l.getResourceURI();
097: int type = l.getType();
098:
099: assertEquals("type parsed incorrect",
100: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW, type);
101: assertEquals("resourceURI parsed incorrect", "index.html",
102: resource);
103:
104: }
105:
106: public void testErroneousAllowDisallow() {
107: RobotsTXTLine l = RobotsTXTLine.parse("alow:index.html");
108: assertNull("line returned for incorrect info is not null", l);
109: }
110:
111: public void testEmptyString() {
112: RobotsTXTLine l = RobotsTXTLine.parse("");
113: assertNull("line returned for empty string is not null", l);
114: }
115:
116: public void testOnlyAllow() {
117: RobotsTXTLine l = RobotsTXTLine.parse("allow:");
118: assertNull("line returned for 'allow:' string is not null", l);
119: }
120:
121: public void testOnlyDisAllow() {
122: RobotsTXTLine l = RobotsTXTLine.parse("disallow:");
123: assertNull("line returned for 'disallow:' string is not null",
124: l);
125: }
126:
127: public void testNullString() {
128: RobotsTXTLine l = RobotsTXTLine.parse(null);
129: assertNull("line returned for null string is not null", l);
130: }
131:
132: public void testSimpleMatch() throws Exception {
133: URL url = new URL("http://j-spider.sourceforge.net/index.html");
134: RobotsTXTLine line = new RobotsTXTLine("/index.html",
135: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW);
136: boolean matches = line.matches(url);
137:
138: assertTrue("simple match didn't work", matches);
139: }
140:
141: public void testSimpleMatchWithFolder() throws Exception {
142: URL url = new URL(
143: "http://j-spider.sourceforge.net/manual/index.html");
144: RobotsTXTLine line = new RobotsTXTLine("/manual",
145: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW);
146: boolean matches = line.matches(url);
147:
148: assertTrue("simple match didn't work", matches);
149: }
150:
151: public void testSimpleMatchCaseSensitivity() throws Exception {
152: URL url = new URL("http://j-spider.sourceforge.net/index.HTML");
153: RobotsTXTLine line = new RobotsTXTLine("/index.html",
154: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW);
155: boolean matches = line.matches(url);
156:
157: assertFalse("cases were different, yet a match was given",
158: matches);
159: }
160:
161: public void testSimpleNoMatch() throws Exception {
162: URL url = new URL("http://j-spider.sourceforge.net/index.htm");
163: RobotsTXTLine line = new RobotsTXTLine("/index.html",
164: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW);
165: boolean matches = line.matches(url);
166:
167: assertFalse("simple nomatch didn't work", matches);
168: }
169:
170: public void testRootMatch() throws Exception {
171: URL url = new URL("http://j-spider.sourceforge.net");
172: RobotsTXTLine line = new RobotsTXTLine("/",
173: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW);
174: boolean matches = line.matches(url);
175:
176: assertTrue("root match didn't work", matches);
177: }
178:
179: public void testRootMatchWithTrailingSlash() throws Exception {
180: URL url = new URL("http://j-spider.sourceforge.net/");
181: RobotsTXTLine line = new RobotsTXTLine("/",
182: RobotsTXTLine.ROBOTSTXT_RULE_DISALLOW);
183: boolean matches = line.matches(url);
184:
185: assertTrue("root match didn't work", matches);
186: }
187:
188: }
|