KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.net.InetSocketAddress JavaDoc;
23
24 import org.apache.mina.common.IoAcceptor;
25 import org.apache.mina.common.IoHandler;
26 import org.apache.mina.common.IoHandlerAdapter;
27 import org.apache.mina.common.IoServiceConfig;
28 import org.easymock.MockControl;
29
30 import junit.framework.TestCase;
31
32 /**
33  * Tests {@link IoAcceptorFactoryBean}.
34  *
35  * @author The Apache Directory Project (mina-dev@directory.apache.org)
36  * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (금, 13 7월 2007) $
37  */

38 public class IoAcceptorFactoryBeanTest extends TestCase {
39     public void testBindUnbind() throws Exception JavaDoc {
40         IoHandler handler1 = new IoHandlerAdapter();
41         IoHandler handler2 = new IoHandlerAdapter();
42         IoHandler handler3 = new IoHandlerAdapter();
43         IoServiceConfig config1 = (IoServiceConfig) MockControl.createControl(
44                 IoServiceConfig.class).getMock();
45         IoServiceConfig config2 = (IoServiceConfig) MockControl.createControl(
46                 IoServiceConfig.class).getMock();
47         MockControl mockIoAcceptor = MockControl
48                 .createControl(IoAcceptor.class);
49         IoAcceptor acceptor = (IoAcceptor) mockIoAcceptor.getMock();
50
51         acceptor.bind(new InetSocketAddress JavaDoc(80), handler1, config1);
52         acceptor.bind(new InetSocketAddress JavaDoc("192.168.0.1", 22), handler2,
53                 config2);
54         acceptor.bind(new InetSocketAddress JavaDoc("10.0.0.1", 9876), handler3);
55         acceptor.unbind(new InetSocketAddress JavaDoc(80));
56         acceptor.unbind(new InetSocketAddress JavaDoc("192.168.0.1", 22));
57         acceptor.unbind(new InetSocketAddress JavaDoc("10.0.0.1", 9876));
58
59         mockIoAcceptor.replay();
60
61         IoAcceptorFactoryBean factory = new IoAcceptorFactoryBean();
62         factory.setTarget(acceptor);
63         factory
64                 .setBindings(new Binding[] {
65                         new Binding(new InetSocketAddress JavaDoc(80), handler1,
66                                 config1),
67                         new Binding(new InetSocketAddress JavaDoc("192.168.0.1", 22),
68                                 handler2, config2),
69                         new Binding(new InetSocketAddress JavaDoc("10.0.0.1", 9876),
70                                 handler3) });
71         factory.afterPropertiesSet();
72         factory.destroy();
73
74         mockIoAcceptor.verify();
75     }
76
77     public void testIsSingleton() throws Exception JavaDoc {
78         assertTrue(new IoAcceptorFactoryBean().isSingleton());
79     }
80
81     public void testGetObjectType() throws Exception JavaDoc {
82         assertEquals(IoAcceptor.class, new IoAcceptorFactoryBean()
83                 .getObjectType());
84     }
85
86     public void testGetObject() throws Exception JavaDoc {
87         IoAcceptor acceptor = (IoAcceptor) MockControl.createControl(
88                 IoAcceptor.class).getMock();
89         IoAcceptorFactoryBean factory = new IoAcceptorFactoryBean();
90         factory.setTarget(acceptor);
91
92         assertEquals(acceptor, factory.getObject());
93     }
94
95 }
96
Popular Tags