Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *    Purpose: To test the MetaCatURL class by JUnit
6
 *    Authors: Jing Tao
7
 *
8
 *   '$Author: jones $'
9
 *     '$Date: 2006-11-10 11:30:36 -0800 (Fri, 10 Nov 2006) $'
10
 * '$Revision: 3080 $'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

    
27
package edu.ucsb.nceas.metacattest;
28

    
29
import edu.ucsb.nceas.metacat.*;
30

    
31
import junit.framework.Test;
32
import junit.framework.TestCase;
33
import junit.framework.TestResult;
34
import junit.framework.TestSuite;
35

    
36
/**
37
 * A JUnit test for testing Step class processing
38
 */
39
public class MetaCatURLTest extends TestCase
40
{
41
  private MetacatURL withProtocol =null;
42
  private String withHttp="http://dev.nceas.ucsb.edu/tao/test.txt";
43
  /**
44
   * Constructor to build the test
45
   *
46
   * @param name the name of the test method
47
   */
48
  public MetaCatURLTest(String name)
49
  {
50
    super(name);
51
  }
52

    
53
  /**
54
   * Establish a testing framework by initializing appropriate objects
55
   */
56
  public void setUp()
57
  {
58
    try 
59
    {
60
     
61
      withProtocol=new MetacatURL(withHttp);
62
        
63
    } 
64
    catch (Exception e) 
65
    {
66
      fail("Caught exception while setting up MetaCatURL test.");
67
    }
68
  }
69

    
70
  /**
71
   * Release any objects after tests are complete
72
   */
73
  public void tearDown()
74
  {
75
  }
76

    
77
  /**
78
   * Create a suite of tests to be run together
79
   */
80
  public static Test suite()
81
  {
82
    TestSuite suite = new TestSuite();
83
    suite.addTest(new MetaCatURLTest("initialize"));
84
    suite.addTest(new MetaCatURLTest("testGetProtocol"));
85
    suite.addTest(new MetaCatURLTest("testToString"));
86
    suite.addTest(new MetaCatURLTest("testGetParameter"));
87
    return suite;
88
  }
89

    
90
  /**
91
   * Run an initial test that always passes to check that the test
92
   * harness is working.
93
   */
94
  public void initialize()
95
  {
96
    assertTrue(1 == 1);
97
  }
98

    
99
  /**
100
   * Test if the getProtocol() function works given a url
101
   */
102
  public void testGetProtocol()
103
  {
104
    assertTrue( withProtocol.getProtocol().equals("http"));
105
  }
106
  
107
  /**
108
   * Test if the toString() function works given a url
109
   */
110
  public void testToString()
111
  {
112
    assertTrue((withProtocol.toString()).equals(withHttp));
113
  }
114
  
115
  /**
116
   * Test if the getParam() function works given a url
117
   */
118
  public void testGetParameter()
119
  {
120
    String [] str= new String[2];
121
    str=withProtocol.getParam(0);
122
    assertTrue(str[0].equals("httpurl"));
123
    assertTrue(str[1].equals("http://dev.nceas.ucsb.edu/tao/test.txt"));
124
    str=withProtocol.getParam(1);
125
    assertTrue(str[0].equals("filename"));
126
    assertTrue(str[1].equals("test.txt"));
127
  }
128
  
129

    
130
}
(8-8/20)