1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.tika.utils;
18  
19  import java.util.List;
20  import junit.framework.TestCase;
21  
22  /**
23   * Test case for {@link RegexUtils}.
24   *
25   * @version $Revision$ $Date$
26   */
27  public class RegexUtilsTest extends TestCase {
28  
29      /** 
30       * Test {@link RegexUtils#extractLinks(String)} with no links.
31       */
32  
33      public void testExtractLinksNone() {
34          List<String> links = null;
35                  
36          links = RegexUtils.extractLinks(null);
37          assertNotNull(links);
38          assertEquals(0, links.size());
39          
40          links = RegexUtils.extractLinks("");
41          assertNotNull(links);
42          assertEquals(0, links.size());
43          
44          links = RegexUtils.extractLinks(
45                  "Test with no links " +
46                  "What about www.google.com");
47          assertNotNull(links);
48          assertEquals(0, links.size());
49      }
50        
51  
52      /** 
53       * Test {@link RegexUtils#extractLinks(String)} for http.
54       */
55      public void testExtractLinksHttp() {
56          List<String> links = RegexUtils.extractLinks(
57                  "Test with http://www.nutch.org/index.html is it found? " +
58                  "What about www.google.com at http://www.google.de " +
59                  "A longer URL could be http://www.sybit.com/solutions/portals.html");
60            
61          assertTrue("Url not found!", links.size() == 3);
62          assertEquals("Wrong URL", "http://www.nutch.org/index.html", links.get(0));
63          assertEquals("Wrong URL", "http://www.google.de", links.get(1));
64          assertEquals("Wrong URL", "http://www.sybit.com/solutions/portals.html", links.get(2));
65      }
66          
67      /** 
68       * Test {@link RegexUtils#extractLinks(String)} for ftp.
69       */
70      public void testExtractLinksFtp() {
71          List<String> links = RegexUtils.extractLinks(
72                  "Test with ftp://www.nutch.org is it found? " +
73                  "What about www.google.com at ftp://www.google.de");
74           
75          assertTrue("Url not found!", links.size() == 2);
76          assertEquals("Wrong URL", "ftp://www.nutch.org", links.get(0));
77          assertEquals("Wrong URL", "ftp://www.google.de", links.get(1));
78      }
79  }