1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.xml;
18
19 import junit.framework.TestCase;
20
21 import java.io.FileNotFoundException;
22 import java.io.InputStream;
23 import java.io.InputStreamReader;
24 import java.nio.CharBuffer;
25 import java.util.Vector;
26 import java.net.URL;
27
28
29
30
31
32 public class XMLDecoderTest extends TestCase {
33
34
35
36
37
38
39 public XMLDecoderTest(String arg0) {
40 super(arg0);
41 }
42
43 public String getStringFromResource(final String resourceName,
44 final int maxSize) throws Exception {
45 InputStream is = XMLDecoderTest.class.getResourceAsStream(resourceName);
46 if (is == null) {
47 throw new FileNotFoundException(resourceName);
48 }
49 InputStreamReader reader = new InputStreamReader(is, "UTF-8");
50 CharBuffer cb = CharBuffer.allocate(maxSize);
51 for(int chars = reader.read(cb);
52 chars != -1;
53 chars = reader.read(cb));
54 cb.flip();
55 return cb.toString();
56 }
57
58 public void testDecodeEventsString1() throws Exception {
59 String xmlStr = getStringFromResource("xmlLayout.1.xml", 10000);
60 XMLDecoder decoder = new XMLDecoder();
61 Vector events = decoder.decodeEvents(xmlStr);
62 assertEquals(17, events.size());
63 }
64
65 public void testDecodeEventsString2() throws Exception {
66 String xmlStr = getStringFromResource("xsltLayout.1.xml", 10000);
67 XMLDecoder decoder = new XMLDecoder();
68 Vector events = decoder.decodeEvents(xmlStr);
69 assertEquals(15, events.size());
70 }
71
72 public void testDecodeEventsURL1() throws Exception {
73 URL resource = XMLDecoderTest.class.getResource("xmlLayout.1.xml");
74 XMLDecoder decoder = new XMLDecoder();
75 Vector events = decoder.decode(resource);
76 assertEquals(17, events.size());
77 }
78
79 public void testDecodeEventsURL2() throws Exception {
80 URL resource = XMLDecoderTest.class.getResource("xsltLayout.1.xml");
81 XMLDecoder decoder = new XMLDecoder();
82 Vector events = decoder.decode(resource);
83 assertEquals(15, events.size());
84 }
85
86 }