1 package org.apache.commons.digester3;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static java.lang.System.getProperty;
23 import static java.util.concurrent.Executors.newFixedThreadPool;
24 import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
25 import static org.junit.Assert.assertNotNull;
26
27 import java.io.File;
28 import java.io.InputStreamReader;
29 import java.util.concurrent.Future;
30
31 import org.apache.commons.digester3.binder.AbstractRulesModule;
32 import org.apache.commons.digester3.binder.DigesterLoader;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.xml.sax.InputSource;
37
38 public final class AsyncReaderTestCase
39 {
40
41 private final DigesterLoader digesterLoader = newLoader( new AbstractRulesModule()
42 {
43
44 @Override
45 protected void configure()
46 {
47 forPattern( "employee" ).createObject().ofType( Employee.class );
48 }
49
50 } ).setExecutorService( newFixedThreadPool( 1 ) );
51
52 private Digester digester;
53
54 @Before
55 public void setUp()
56 {
57 digester = digesterLoader.newDigester();
58 }
59
60 @After
61 public void tearDown()
62 {
63 digester = null;
64 }
65
66 @Test
67 public void parseFromFile()
68 throws Exception
69 {
70 Future<Employee> future = digester.asyncParse( new File( getProperty( "user.dir" ),
71 "src/test/resources/org/apache/commons/digester3/Test9.xml" ) );
72 verify( future );
73 }
74
75 @Test
76 public void parseFromClasspathURL()
77 throws Exception
78 {
79 Future<Employee> future = digester.asyncParse( getClass().getResource( "Test9.xml" ) );
80 verify( future );
81 }
82
83 @Test
84 public void parseFromInputStream()
85 throws Exception
86 {
87 Future<Employee> future = digester.asyncParse( getClass().getResource( "Test9.xml" ).openStream() );
88 verify( future );
89 }
90
91 @Test
92 public void parseFromInputSource()
93 throws Exception
94 {
95 Future<Employee> future =
96 digester.asyncParse( new InputSource( getClass().getResource( "Test9.xml" ).openStream() ) );
97 verify( future );
98 }
99
100 @Test
101 public void parseFromReader()
102 throws Exception
103 {
104 Future<Employee> future =
105 digester.asyncParse( new InputStreamReader( getClass().getResource( "Test9.xml" ).openStream() ) );
106 verify( future );
107 }
108
109 @Test
110 public void parseFromUri()
111 throws Exception
112 {
113 Future<Employee> future = digester.asyncParse( getClass().getResource( "Test9.xml" ).toExternalForm() );
114 verify( future );
115 }
116
117 private void verify( Future<Employee> result )
118 throws Exception
119 {
120 Employee employee = result.get();
121 assertNotNull( employee );
122 }
123
124 }