1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.integration.spring;
21
22 import junit.framework.TestCase;
23
24 import org.apache.mina.common.ExecutorThreadModel;
25
26 import edu.emory.mathcs.backport.java.util.concurrent.Executor;
27 import edu.emory.mathcs.backport.java.util.concurrent.SynchronousQueue;
28 import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
29 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
30
31
32
33
34
35
36
37 public class ExecutorThreadModelFactoryBeanTest extends TestCase {
38 public void testSuccessfulCreationWithExecutor() throws Exception {
39 Executor executor = new ThreadPoolExecutor(1, 10, 3600,
40 TimeUnit.SECONDS, new SynchronousQueue());
41 ExecutorThreadModelFactoryBean factory = new ExecutorThreadModelFactoryBean();
42 factory.setServiceName("foo");
43 factory.setExecutor(executor);
44 factory.afterPropertiesSet();
45 ExecutorThreadModel threadModel = (ExecutorThreadModel) factory
46 .getObject();
47 assertSame(executor, threadModel.getExecutor());
48 }
49
50 public void testSuccessfulCreationWithoutExecutor() throws Exception {
51 ExecutorThreadModelFactoryBean factory = new ExecutorThreadModelFactoryBean();
52 factory.setServiceName("foo");
53 factory.afterPropertiesSet();
54 ExecutorThreadModel threadModel = (ExecutorThreadModel) factory
55 .getObject();
56 assertTrue(threadModel.getExecutor() instanceof ThreadPoolExecutor);
57 }
58
59 public void testUnsuccessfulCreation() throws Exception {
60 ExecutorThreadModelFactoryBean factory = new ExecutorThreadModelFactoryBean();
61 try {
62 factory.afterPropertiesSet();
63 fail("No serviceName set. IllegalArgumentException expected.");
64 } catch (IllegalArgumentException iae) {
65 }
66 }
67 }