Project

General

Profile

« Previous | Next » 

Revision 5940

Added by Jing Tao almost 14 years ago

Add a junit test file for testing the XMLSchemaParser class.

View differences:

test/edu/ucsb/nceas/metacattest/service/XMLSchemaParserTest.java
1
package edu.ucsb.nceas.metacattest.service;
2

  
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.util.Vector;
6

  
7
import edu.ucsb.nceas.metacat.properties.PropertyService;
8
import edu.ucsb.nceas.metacat.service.XMLSchemaParser;
9

  
10
import junit.framework.Test;
11
import junit.framework.TestCase;
12
import junit.framework.TestResult;
13
import junit.framework.TestSuite;
14

  
15
/**
16
 * Junit test for xml schema parser
17
 * @author tao
18
 *
19
 */
20
public class XMLSchemaParserTest extends TestCase
21
{
22
  private static String schemaLocation = "./test/servertestfiles/product.xsd";
23
  private static String INCLUDEDPATH = "./item.xsd";
24
  private static final String CONFIG_DIR_TEST = "./lib";
25
  /**
26
   * Constructor to build the test
27
   *
28
   * @param name the name of the test method
29
   */
30
  public XMLSchemaParserTest(String name)
31
  {
32
    super(name);
33
  }
34

  
35
  /**
36
   * Establish a testing framework by initializing appropriate objects
37
   */
38
  public void setUp()
39
  {
40
    
41
  }
42

  
43
  /**
44
   * Release any objects after tests are complete
45
   */
46
  public void tearDown()
47
  {
48
  }
49

  
50
  /**
51
   * Create a suite of tests to be run together
52
   */
53
  public static Test suite()
54
  {
55
    TestSuite suite = new TestSuite();
56
    suite.addTest(new XMLSchemaParserTest("initialize"));
57
    suite.addTest(new XMLSchemaParserTest("testGetIncludedSchemaFilePaths"));
58
    return suite;
59
  }
60

  
61
  /**
62
   * Run an initial test that always passes to check that the test
63
   * harness is working.
64
   */
65
  public void initialize()
66
  {
67
    assertTrue(1 == 1);
68
  }
69
  
70
  public void testGetIncludedSchemaFilePaths()
71
  {
72
     
73
     try
74
     {
75
       PropertyService.getInstance(CONFIG_DIR_TEST);
76
       FileInputStream schemaInputStream =
77
                                     new FileInputStream(new File(schemaLocation));
78
       
79
       XMLSchemaParser  parser =  new XMLSchemaParser(schemaInputStream);
80
       parser.parse();
81
       Vector<String>includedPaths = parser.getIncludedSchemaFilePathes();
82
       assertTrue("The length of the paths should be one.", includedPaths.size()==1);
83
       assertTrue("The path should be "+INCLUDEDPATH, 
84
                                includedPaths.elementAt(0).equals(INCLUDEDPATH));
85
     }
86
     catch(Exception e)
87
     {
88
       e.printStackTrace();
89
       fail("Error: "+e.getMessage());
90
     }
91
     
92
  }
93
}

Also available in: Unified diff