1 5 package org.exoplatform.services.xml.resolving.impl.simple; 6 7 import org.exoplatform.container.PortalContainer; 8 import org.exoplatform.services.xml.resolving.SimpleResolvingService; 9 import junit.framework.TestCase; 10 11 14 public class TestSimpleResolver extends TestCase { 15 16 private SimpleResolvingService service; 17 18 public void setUp() throws Exception 19 { 20 if(service == null) { 21 PortalContainer manager = PortalContainer.getInstance(); 22 service = (SimpleResolvingService) manager. 23 getComponentInstanceOfType(SimpleResolvingService.class); 24 } 25 } 26 27 public void testLookupFailed() throws Exception 28 { 29 try { 30 31 javax.xml.parsers.SAXParserFactory factory=javax.xml.parsers.SAXParserFactory.newInstance(); 32 factory.setNamespaceAware( true ); 33 javax.xml.parsers.SAXParser jaxpParser=factory.newSAXParser(); 34 org.xml.sax.XMLReader reader=jaxpParser.getXMLReader(); 35 36 reader.setEntityResolver(service.getEntityResolver()); 37 try { 38 reader.parse("tmp/dtd-not-found.xml"); 39 } catch (Exception e) { 40 return; 41 } 42 throw new Exception ("Lookup should be Failed as there is not such local DTD."); 43 44 } catch ( Exception e) { 45 46 fail( "LookupFailed() ERROR: "+e.toString()); 47 } 48 49 } 50 51 52 public void testWebXmlResolving() throws Exception 53 { 54 try { 55 59 javax.xml.parsers.SAXParserFactory factory=javax.xml.parsers.SAXParserFactory.newInstance(); 60 factory.setNamespaceAware( true ); 61 javax.xml.parsers.SAXParser jaxpParser=factory.newSAXParser(); 62 org.xml.sax.XMLReader reader=jaxpParser.getXMLReader(); 63 64 reader.setEntityResolver(service.getEntityResolver()); 65 reader.parse("tmp/web.xml"); 66 67 } catch ( Exception e) { 68 69 fail( "testWebXmlResolving() ERROR: "+e.toString()); 70 } 71 72 } 73 74 } 75 | Popular Tags |