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: daigle $'
9
 *     '$Date: 2008-09-24 11:28:29 -0700 (Wed, 24 Sep 2008) $'
10
 * '$Revision: 4384 $'
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.MCTestCase;
30
import edu.ucsb.nceas.metacat.*;
31
import edu.ucsb.nceas.metacat.service.PropertyService;
32
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
33

    
34
import junit.framework.Test;
35
import junit.framework.TestSuite;
36

    
37
import org.apache.commons.logging.Log;
38
import org.apache.commons.logging.LogFactory;
39

    
40
import java.util.*;
41

    
42

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

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

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

    
91
 }
92

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

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

    
120
    TestSuite suite = new TestSuite();
121

    
122
    try
123
    {
124

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

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

    
134

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

    
144

    
145

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

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

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