1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.test;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
27
28 import javax.xml.parsers.SAXParser;
29 import javax.xml.parsers.SAXParserFactory;
30
31 import junit.framework.TestCase;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.apache.myfaces.shared_tomahawk.test.ClassElementHandler;
36 import org.xml.sax.EntityResolver;
37 import org.xml.sax.InputSource;
38 import org.xml.sax.SAXException;
39 import org.xml.sax.XMLReader;
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public abstract class AbstractClassElementTestCase extends TestCase
54 {
55
56 private Log log = LogFactory.getLog(AbstractClassElementTestCase.class);
57
58 protected List resource = new ArrayList();
59 private List className = new ArrayList();
60
61 public class DelegateEntityResolver extends ClassElementHandler
62 {
63 public DelegateEntityResolver()
64 {
65 super();
66 }
67
68 public InputSource resolveEntity(String publicId, String systemId)
69 throws SAXException, IOException
70 {
71 if (publicId.equals("-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"))
72 {
73 return new InputSource(Thread.currentThread()
74 .getContextClassLoader().getResourceAsStream(
75 "META-INF/dtd/web-jsptaglibrary_1_2.dtd"));
76 }
77 else if (publicId.equals("-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"))
78 {
79 return new InputSource(Thread.currentThread()
80 .getContextClassLoader().getResourceAsStream(
81 "org/apache/myfaces/resource/web-facesconfig_1_1.dtd"));
82 }
83 else
84 {
85 return super.resolveEntity(publicId, systemId);
86 }
87 }
88 }
89
90 protected void setUp() throws Exception
91 {
92 SAXParserFactory factory = SAXParserFactory.newInstance();
93 factory.setValidating(false);
94 factory.setNamespaceAware(false);
95
96 SAXParser parser = factory.newSAXParser();
97 ClassElementHandler handler = new DelegateEntityResolver();
98
99 Iterator iterator = resource.iterator();
100
101 while(iterator.hasNext()){
102
103 String resourceName = (String) iterator.next();
104
105 InputStream is = getClass().getClassLoader()
106 .getResourceAsStream(resourceName);
107
108 if(is == null)
109 is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
110
111 if(is == null)
112 throw new Exception("Could not locate resource :" + resourceName);
113
114 parser.parse(is, handler);
115
116 }
117
118 className.addAll(handler.getClassName());
119
120 }
121
122 public void testClassPath(){
123
124 int i = 0;
125 for( ; i < className.size() ; i++){
126
127 String clazz = (String) className.get(i);
128
129 try
130 {
131 getClass().getClassLoader().loadClass(clazz);
132
133 }
134 catch (ClassNotFoundException e)
135 {
136
137 try{
138
139 Thread.currentThread().getContextClassLoader().loadClass(clazz);
140
141 }catch(ClassNotFoundException e2){
142
143 assertFalse("Could not load " + clazz, true);
144
145 }
146
147 }
148
149 }
150
151 log.debug(( i + 1 ) + " class found ");
152
153 }
154
155 }