1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
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   * Tests {@link ExecutorThreadModelFactoryBean}.
33   * 
34   * @author The Apache Directory Project (mina-dev@directory.apache.org)
35   * @version $Rev$, $Date$
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  }