KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > resolving > impl > simple > TestSimpleResolver


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

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 /**
12  * Created by the Exo Development team.
13  */

14 public class TestSimpleResolver extends TestCase {
15
16    private SimpleResolvingService service;
17
18    public void setUp() throws Exception JavaDoc
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 JavaDoc
28    {
29        try {
30
31       javax.xml.parsers.SAXParserFactory JavaDoc factory=javax.xml.parsers.SAXParserFactory.newInstance();
32       factory.setNamespaceAware( true );
33       javax.xml.parsers.SAXParser JavaDoc jaxpParser=factory.newSAXParser();
34       org.xml.sax.XMLReader JavaDoc reader=jaxpParser.getXMLReader();
35
36           reader.setEntityResolver(service.getEntityResolver());
37           try {
38              reader.parse("tmp/dtd-not-found.xml");
39           } catch (Exception JavaDoc e) {
40              return;
41           }
42           throw new Exception JavaDoc("Lookup should be Failed as there is not such local DTD.");
43              
44        } catch ( Exception JavaDoc e) {
45
46             fail( "LookupFailed() ERROR: "+e.toString());
47        }
48
49    }
50
51
52    public void testWebXmlResolving() throws Exception JavaDoc
53    {
54        try {
55 // PortalContainer manager = PortalContainer.getInstance();
56
// SimpleResolvingService service = (SimpleResolvingService) manager.
57
// getComponentInstanceOfType(SimpleResolvingService.class);
58

59       javax.xml.parsers.SAXParserFactory JavaDoc factory=javax.xml.parsers.SAXParserFactory.newInstance();
60       factory.setNamespaceAware( true );
61       javax.xml.parsers.SAXParser JavaDoc jaxpParser=factory.newSAXParser();
62       org.xml.sax.XMLReader JavaDoc reader=jaxpParser.getXMLReader();
63
64           reader.setEntityResolver(service.getEntityResolver());
65           reader.parse("tmp/web.xml");
66
67        } catch ( Exception JavaDoc e) {
68
69             fail( "testWebXmlResolving() ERROR: "+e.toString());
70         }
71
72    }
73
74 }
75
Popular Tags