1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.jetspeed.services.registry;
17  
18  import java.io.File;
19  import java.io.FileReader;
20  
21  import javax.xml.parsers.DocumentBuilder;
22  import javax.xml.parsers.DocumentBuilderFactory;
23  
24  import org.apache.jetspeed.test.JetspeedTestCase;
25  import org.exolab.castor.mapping.Mapping;
26  import org.exolab.castor.xml.Unmarshaller;
27  import org.w3c.dom.Document;
28  import org.w3c.dom.Node;
29  import org.xml.sax.InputSource;
30  
31  /***
32   * TestCastor
33   *
34   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
35   * @version $Id: TestCastor.java,v 1.1 2004/04/07 22:02:42 jford Exp $
36   */
37  public class TestCastor extends JetspeedTestCase
38  {
39      public TestCastor(String name)
40      {
41          super(name);
42      }
43              
44      /***
45       * Start the tests.
46       *
47       * @param args the arguments. Not used
48       */
49      public static void main(String args[])
50      {
51          junit.awtui.TestRunner.main(new String[] { TestCastor.class.getName() });
52      }
53      
54      public void testUnMarshall()
55      {
56          System.out.println("This Test is for testing compatibility with new versions of Castor as they are released.");
57          String mapFile = "test/conf/registry-mapping.xml";
58          String registryFile = "test/conf/test-registry.xreg";
59          
60          File map = new File(mapFile);
61          try
62          {
63              Mapping mapping = new Mapping();
64              InputSource is = new InputSource(new FileReader(map));
65              is.setSystemId(mapFile);
66              mapping.loadMapping(is);
67              
68              DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
69              DocumentBuilder builder = dbfactory.newDocumentBuilder();
70         
71              Document d = builder.parse(new File(registryFile));
72  
73              Unmarshaller unmarshaller = new Unmarshaller(mapping);
74              RegistryFragment fragment = (RegistryFragment) unmarshaller.unmarshal((Node) d);
75              
76          }
77          catch (Exception e)
78          {
79              e.printStackTrace();
80              fail("Error in mapping creation");            
81         }
82          
83      }
84              
85  }