KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > mina > integration > spring > ExecutorThreadModelFactoryBeanTest


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 java.util.concurrent.Executor JavaDoc;
27 import java.util.concurrent.SynchronousQueue JavaDoc;
28 import java.util.concurrent.ThreadPoolExecutor JavaDoc;
29 import java.util.concurrent.TimeUnit JavaDoc;
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 JavaDoc {
39         Executor JavaDoc executor = new ThreadPoolExecutor JavaDoc(1, 10, 3600,
40                 TimeUnit.SECONDS, new SynchronousQueue JavaDoc<Runnable JavaDoc>());
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 JavaDoc {
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 JavaDoc);
57     }
58
59     public void testUnsuccessfulCreation() throws Exception JavaDoc {
60         ExecutorThreadModelFactoryBean factory = new ExecutorThreadModelFactoryBean();
61         try {
62             factory.afterPropertiesSet();
63             fail("No serviceName set. IllegalArgumentException expected.");
64         } catch (IllegalArgumentException JavaDoc iae) {
65         }
66     }
67 }
68
Popular Tags