Project

General

Profile

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
import edu.ucsb.nceas.MCTestCase;
10

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

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

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

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

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

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