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 ReplicationServerList class by JUnit
6
 *    Authors: Jing Tao
7
 *
8
 *   '$Author: tao $'
9
 *     '$Date: 2007-11-03 22:16:17 -0700 (Sat, 03 Nov 2007) $'
10
 * '$Revision: 3567 $'
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
import edu.ucsb.nceas.utilities.Options;
31
//import edu.ucsb.nceas.morpho.framework.*;
32
import junit.framework.Test;
33
import junit.framework.TestCase;
34
import junit.framework.TestResult;
35
import junit.framework.TestSuite;
36
import org.apache.commons.logging.Log;
37
import org.apache.commons.logging.LogFactory;
38

    
39
import java.io.*;
40
import java.net.*;
41
import java.util.*;
42

    
43

    
44
/**
45
 * A JUnit test for testing Step class processing
46
 */
47
public class SubTreeTest extends TestCase
48
{
49
  private SubTree tree = null;
50
  private static final Log log = LogFactory.getLog("edu.ucsb.nceas.metacattest.ReplicationServerListTest");
51
  /* Initialize Options*/
52
  static
53
  {
54
	  try
55
	  {
56
		  Options.initialize(new File("build/tests/metacat.properties"));
57
		  MetaCatUtil.pathsForIndexing 
58
		         = MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexPaths"));
59
	  }
60
	  catch(Exception e)
61
	  {
62
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
63
	  }
64
  }
65
  /**
66
   * Constructor to build the test
67
   *
68
   * @param name the name of the test method
69
   */
70
  public SubTreeTest(String name)
71
  {
72
    super(name);
73
  }
74

    
75
  /**
76
   * Constructor to build the test
77
   *
78
   * @param name the name of the test method
79
   * @param tree the subtree
80
   */
81
  public SubTreeTest(String name, SubTree myTree)
82
  {
83
    super(name);
84
    this.tree = myTree;
85
  }
86

    
87
  /**
88
   * Establish a testing framework by initializing appropriate objects
89
   */
90
  public void setUp()
91
 {
92

    
93
 }
94

    
95
  /**
96
   * Release any objects after tests are complete
97
   */
98
  public void tearDown()
99
  {
100
    //DBConnectionPool will be release
101
    DBConnectionPool.release();
102
  }
103

    
104
  /**
105
   * Create a suite of tests to be run together
106
   */
107
  public static Test suite()
108
  {
109
     //Get DBConnection pool, this is only for junit test.
110
    //Because DBConnection is singleton class. So there is only one DBConnection
111
    //pool in the program
112
    try
113
    {
114
      DBConnectionPool pool = DBConnectionPool.getInstance();
115
    }//try
116
    catch (Exception e)
117
    {
118
        log.debug("Error in ReplicationServerList() to get" +
119
                        " DBConnection pool"+e.getMessage());
120
    }//catch
121

    
122
    TestSuite suite = new TestSuite();
123

    
124
    try
125
    {
126

    
127
      //create a new subtree
128
      SubTree subTree = new SubTree("eml.349", "distribution1", 118214, 118223);
129

    
130
      //Doing test test cases
131
      suite.addTest(new SubTreeTest("initialize"));
132
      System.out.println("before adding testGetSubTreeNodeStack() into suite");
133
      suite.addTest(new SubTreeTest("testGetSubTreeNodeStack", subTree));
134
      System.out.println("here!!");
135

    
136

    
137
    }//try
138
    catch (Exception e)
139
    {
140
        log.debug("Error in SubTreeTest.suite: "+
141
                                e.getMessage());
142
    }//catch
143
    return suite;
144
 }
145

    
146

    
147

    
148
  /**
149
   * Run an initial test that always passes to check that the test
150
   * harness is working.
151
   */
152
  public void initialize()
153
  {
154
    System.out.println("in initialize");
155
    assertTrue(1 == 1);
156
  }
157

    
158
  /**
159
   * Test the method getSubTreeNodeStack
160
   */
161
  public void testGetSubTreeNodeStack()
162
  {
163
    Stack nodeStack = null;
164
    try{
165
      nodeStack = tree.getSubTreeNodeStack();
166
    }//try
167
    catch (Exception e)
168
    {
169
        log.debug("Error in SubTreeTest.suite: "+ e.getMessage());
170
    }//catch
171

    
172
    while (nodeStack != null && !nodeStack.empty())
173
    {
174
      NodeRecord node =(NodeRecord)nodeStack.pop();
175
      String nodeType = node.getNodeType();
176
      if ( nodeType != null && nodeType.equals("ELEMENT"))
177
      {
178
          log.debug("Elment: "+ node.getNodeName());
179
      }
180
      else if (nodeType != null && nodeType.equals("ATTRIBUTE"))
181
      {
182
          log.debug("Attribute: "  +node.getNodeName() +
183
                                 " = " + node.getNodeData());
184
      }
185
      else
186
      {
187
          log.debug("text: " + node.getNodeData());
188
      }
189
    }
190
   
191
  }
192
}
(16-16/18)