KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > registry > TestCastor


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 JavaDoc;
19 import java.io.FileReader JavaDoc;
20
21 import javax.xml.parsers.DocumentBuilder JavaDoc;
22 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
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 JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import org.xml.sax.InputSource JavaDoc;
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 JavaDoc 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 JavaDoc args[])
50     {
51         junit.awtui.TestRunner.main(new String JavaDoc[] { 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 JavaDoc mapFile = "test/conf/registry-mapping.xml";
58         String JavaDoc registryFile = "test/conf/test-registry.xreg";
59         
60         File JavaDoc map = new File JavaDoc(mapFile);
61         try
62         {
63             Mapping mapping = new Mapping();
64             InputSource JavaDoc is = new InputSource JavaDoc(new FileReader JavaDoc(map));
65             is.setSystemId(mapFile);
66             mapping.loadMapping(is);
67             
68             DocumentBuilderFactory JavaDoc dbfactory = DocumentBuilderFactory.newInstance();
69             DocumentBuilder JavaDoc builder = dbfactory.newDocumentBuilder();
70        
71             Document JavaDoc d = builder.parse(new File JavaDoc(registryFile));
72
73             Unmarshaller unmarshaller = new Unmarshaller(mapping);
74             RegistryFragment fragment = (RegistryFragment) unmarshaller.unmarshal((Node JavaDoc) d);
75             
76         }
77         catch (Exception JavaDoc e)
78         {
79             e.printStackTrace();
80             fail("Error in mapping creation");
81        }
82         
83     }
84             
85 }
86
Popular Tags