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-08-24 14:42:25 -0700 (Mon, 24 Aug 2009) $'
10
 * '$Revision: 5035 $'
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.database.*;
32
import edu.ucsb.nceas.metacat.replication.*;
33
import edu.ucsb.nceas.metacat.properties.PropertyService;
34
import edu.ucsb.nceas.metacat.util.MetacatUtil;
35

    
36
import junit.framework.Test;
37
import junit.framework.TestSuite;
38

    
39
import org.apache.commons.logging.Log;
40
import org.apache.commons.logging.LogFactory;
41

    
42
import java.util.*;
43

    
44

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

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

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

    
92
 }
93

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

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

    
121
    TestSuite suite = new TestSuite();
122

    
123
    try
124
    {
125

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

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

    
135

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

    
145

    
146

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

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

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