1 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 37 public class TestCastor extends JetspeedTestCase 38 { 39 public TestCastor(String name) 40 { 41 super(name); 42 } 43 44 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 } 86 | Popular Tags |