1 20 package org.apache.mina.integration.spring; 21 22 import java.net.InetSocketAddress ; 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 38 public class IoAcceptorFactoryBeanTest extends TestCase { 39 public void testBindUnbind() throws Exception { 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 (80), handler1, config1); 52 acceptor.bind(new InetSocketAddress ("192.168.0.1", 22), handler2, 53 config2); 54 acceptor.bind(new InetSocketAddress ("10.0.0.1", 9876), handler3); 55 acceptor.unbind(new InetSocketAddress (80)); 56 acceptor.unbind(new InetSocketAddress ("192.168.0.1", 22)); 57 acceptor.unbind(new InetSocketAddress ("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 (80), handler1, 66 config1), 67 new Binding(new InetSocketAddress ("192.168.0.1", 22), 68 handler2, config2), 69 new Binding(new InetSocketAddress ("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 { 78 assertTrue(new IoAcceptorFactoryBean().isSingleton()); 79 } 80 81 public void testGetObjectType() throws Exception { 82 assertEquals(IoAcceptor.class, new IoAcceptorFactoryBean() 83 .getObjectType()); 84 } 85 86 public void testGetObject() throws Exception { 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 |