1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.test.impl;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.ByteArrayOutputStream;
20
21 import org.apache.commons.jelly.impl.Embedded;
22
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26 import junit.textui.TestRunner;
27
28 /***
29 * Unit case of Embedded
30 *
31 * @author <a href="mailto:vinayc@apache.org">Vinay Chandran</a>
32 */
33 public class TestEmbedded extends TestCase
34 {
35
36 public static void main(String[] args)
37 {
38 TestRunner.run(suite());
39 }
40
41 public static Test suite()
42 {
43 return new TestSuite(TestEmbedded.class);
44 }
45
46 public TestEmbedded(String testName)
47 {
48 super(testName);
49 }
50
51 /***
52 * test Script input as a java.lang.String object
53 */
54 public void testStringAsScript()
55 {
56 Embedded embedded = new Embedded();
57 String jellyScript =
58 "<?xml version=\"1.0\"?>"
59 + " <j:jelly xmlns:j=\"jelly:core\">"
60 + "jelly-test-case"
61 + " </j:jelly>";
62 embedded.setScript(jellyScript);
63 ByteArrayOutputStream baos = new ByteArrayOutputStream();
64 embedded.setOutputStream(baos);
65 boolean status = embedded.execute();
66
67 assertEquals(status, true);
68
69 assertEquals("jelly-test-case", new String(baos.toByteArray()));
70
71 embedded.setScript(jellyScript + "obnoxious-part");
72 status = embedded.execute();
73
74 assertEquals(false, status);
75
76 assertNotNull(embedded.getErrorMsg());
77 }
78
79 /***
80 * test Script input as a InputStream
81 */
82 public void testInputStreamAsScript()
83 {
84 Embedded embedded = new Embedded();
85 String jellyScript =
86 "<?xml version=\"1.0\"?>"
87 + " <j:jelly xmlns:j=\"jelly:core\">"
88 + "jelly-test-case"
89 + " </j:jelly>";
90 embedded.setScript(new ByteArrayInputStream(jellyScript.getBytes()));
91 ByteArrayOutputStream baos = new ByteArrayOutputStream();
92 embedded.setOutputStream(baos);
93 boolean status = embedded.execute();
94
95 assertEquals(status, true);
96
97 assertEquals("jelly-test-case", new String(baos.toByteArray()));
98
99 }
100 }