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: 2009-02-23 11:29:07 -0800 (Mon, 23 Feb 2009) $'
10
 * '$Revision: 4816 $'
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
		  PropertyService.getInstance();
56
	  }
57
	  catch(Exception e)
58
	  {
59
		  System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage());
60
	  }
61
  }
62
  /**
63
   * Constructor to build the test
64
   *
65
   * @param name the name of the test method
66
   */
67
  public SubTreeTest(String name)
68
  {
69
    super(name);
70
  }
71

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

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

    
90
 }
91

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

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

    
119
    TestSuite suite = new TestSuite();
120

    
121
    try
122
    {
123

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

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

    
133

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

    
143

    
144

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

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

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