directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r344069 [2/2] - in /directory/network/trunk: ./ src/java/org/apache/mina/integration/ src/java/org/apache/mina/integration/spring/ src/java/org/apache/mina/integration/spring/support/ src/java/org/apache/mina/transport/socket/nio/ src/test/...
Date Mon, 14 Nov 2005 07:38:00 GMT
Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBeanTest.java
(added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBeanTest.java
Sun Nov 13 23:37:37 2005
@@ -0,0 +1,147 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.integration.spring.support;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoSessionManager;
+import org.easymock.MockControl;
+import org.easymock.classextension.MockClassControl;
+
+/**
+ * Tests
+ * {@link org.apache.mina.integration.spring.support.AbstractIoConnectorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class AbstractIoConnectorFactoryBeanTest extends TestCase
+{
+    MockControl mockFactory;
+
+    AbstractIoConnectorFactoryBean factory;
+
+    MockControl mockIoConnector;
+
+    IoConnector ioConnector;
+
+    protected void setUp() throws Exception
+    {
+        /*
+         * Create the object to be tested. We're using EasyMock to mock some of
+         * the methods in the super class since we're already testing those in
+         * AbstractIoSessionManagerFactoryBeanTest and we don't want to test
+         * them in this test again.
+         */
+        mockFactory = MockClassControl
+                .createControl(
+                        TestIoConnectorFactoryBean.class,
+                        new Method[] {
+                                TestIoConnectorFactoryBean.class
+                                        .getDeclaredMethod(
+                                                "createIoConnector",
+                                                new Class[ 0 ] ),
+                                AbstractIoSessionManagerFactoryBean.class
+                                        .getDeclaredMethod(
+                                                "initIoSessionManager",
+                                                new Class[] { IoSessionManager.class } ),
+                                AbstractIoSessionManagerFactoryBean.class
+                                        .getDeclaredMethod(
+                                                "destroyIoSessionManager",
+                                                new Class[] { IoSessionManager.class } )
} );
+
+        factory = ( AbstractIoConnectorFactoryBean ) mockFactory.getMock();
+
+        /*
+         * Create other EasyMock mocks.
+         */
+        mockIoConnector = MockControl.createControl( IoConnector.class );
+        ioConnector = ( IoConnector ) mockIoConnector.getMock();
+    }
+
+    public void testCreateInstance() throws Exception
+    {
+        /*
+         * Record expectations.
+         */
+        factory.createIoConnector();
+        mockFactory.setReturnValue( ioConnector );
+        factory.initIoSessionManager( ioConnector );
+        ioConnector.setConnectTimeout( 30 );
+
+        /*
+         * Replay.
+         */
+        mockIoConnector.replay();
+        mockFactory.replay();
+
+        factory.setConnectTimeout( 30 );
+        Object o = factory.createInstance();
+
+        /*
+         * Verify.
+         */
+        mockIoConnector.verify();
+        mockFactory.verify();
+
+        assertSame( ioConnector, o );
+    }
+
+    public void testDestroyInstance() throws Exception
+    {
+        /*
+         * Record expectations.
+         */
+        factory.destroyIoSessionManager( ioConnector );
+
+        /*
+         * Replay.
+         */
+        mockFactory.replay();
+
+        factory.destroyInstance( ioConnector );
+
+        /*
+         * Verify.
+         */
+        mockFactory.verify();
+    }
+
+    public void testGetObjectType() throws Exception
+    {
+        AbstractIoConnectorFactoryBean factory = new TestIoConnectorFactoryBean();
+        assertSame( IoConnector.class, factory.getObjectType() );
+    }
+
+    /*
+     * We need a concrete class to test.
+     */
+    public static class TestIoConnectorFactoryBean extends
+            AbstractIoConnectorFactoryBean
+    {
+        protected IoConnector createIoConnector()
+        {
+            // Don't care. This method will be mocked.
+            return null;
+        }
+    }
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBeanTest.java
(added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBeanTest.java
Sun Nov 13 23:37:37 2005
@@ -0,0 +1,306 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.integration.spring.support;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoSessionManager;
+import org.apache.mina.integration.spring.IoFilterMapping;
+import org.easymock.MockControl;
+
+/**
+ * Tests
+ * {@link org.apache.mina.integration.spring.support.AbstractIoSessionManagerFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class AbstractIoSessionManagerFactoryBeanTest extends TestCase
+{
+    AbstractIoSessionManagerFactoryBean factory;
+
+    protected void setUp() throws Exception
+    {
+        /*
+         * Create the object under test.
+         */
+        factory = new AbstractIoSessionManagerFactoryBean()
+        {
+            public Class getObjectType()
+            {
+                // Don't care
+                return null;
+            }
+
+            protected Object createInstance() throws Exception
+            {
+                // Don't care
+                return null;
+            }
+        };
+    }
+
+    /**
+     * Tests that
+     * {@link AbstractIoSessionManagerFactoryBean#initIoSessionManager(IoSessionManager)}
+     * initializes the filter chain in the expected order and using auto
+     * generated names.
+     */
+    public void testInitNoExceptionMonitorUnamedFilters() throws Exception
+    {
+        /*
+         * Create EasyMock mocks.
+         */
+        MockControl mockIoFilterChain = MockControl
+                .createStrictControl( IoFilterChain.class );
+        MockControl mockIoSessionManager = MockControl
+                .createControl( IoSessionManager.class );
+
+        IoFilter[] filters = new IoFilter[] {
+                ( IoFilter ) MockControl.createControl( IoFilter.class )
+                        .getMock(),
+                ( IoFilter ) MockControl.createControl( IoFilter.class )
+                        .getMock(),
+                ( IoFilter ) MockControl.createControl( IoFilter.class )
+                        .getMock() };
+
+        IoSessionManager ioSessionManager = ( IoSessionManager ) mockIoSessionManager
+                .getMock();
+        IoFilterChain ioFilterChain = ( IoFilterChain ) mockIoFilterChain
+                .getMock();
+
+        /*
+         * Record expectations.
+         */
+        ioFilterChain.addLast( "filter0", filters[ 0 ] );
+        ioFilterChain.addLast( "filter1", filters[ 1 ] );
+        ioFilterChain.addLast( "filter2", filters[ 2 ] );
+
+        ioSessionManager.getFilterChain();
+        mockIoSessionManager.setReturnValue( mockIoFilterChain.getMock() );
+
+        /*
+         * Replay.
+         */
+        mockIoFilterChain.replay();
+        mockIoSessionManager.replay();
+
+        factory.setFilters( filters );
+        factory.initIoSessionManager( ioSessionManager );
+
+        /*
+         * Verify.
+         */
+        mockIoFilterChain.verify();
+        mockIoSessionManager.verify();
+    }
+
+    /**
+     * Tests that
+     * {@link AbstractIoSessionManagerFactoryBean#initIoSessionManager(IoSessionManager)}
+     * initializes the filter chain in the expected order and using the
+     * specified names.
+     */
+    public void testInitNoExceptionMonitorNamedFilters() throws Exception
+    {
+        /*
+         * Create EasyMock mocks.
+         */
+        MockControl mockIoFilterChain = MockControl
+                .createStrictControl( IoFilterChain.class );
+        MockControl mockIoSessionManager = MockControl
+                .createControl( IoSessionManager.class );
+
+        IoFilterMapping[] mappings = new IoFilterMapping[] {
+                new IoFilterMapping( "first", ( IoFilter ) MockControl
+                        .createControl( IoFilter.class ).getMock() ),
+                new IoFilterMapping( "second", ( IoFilter ) MockControl
+                        .createControl( IoFilter.class ).getMock() ),
+                new IoFilterMapping( "third", ( IoFilter ) MockControl
+                        .createControl( IoFilter.class ).getMock() ) };
+
+        IoSessionManager ioSessionManager = ( IoSessionManager ) mockIoSessionManager
+                .getMock();
+        IoFilterChain ioFilterChain = ( IoFilterChain ) mockIoFilterChain
+                .getMock();
+
+        /*
+         * Record expectations.
+         */
+        ioFilterChain.addLast( "first", mappings[ 0 ].getFilter() );
+        ioFilterChain.addLast( "second", mappings[ 1 ].getFilter() );
+        ioFilterChain.addLast( "third", mappings[ 2 ].getFilter() );
+
+        ioSessionManager.getFilterChain();
+        mockIoSessionManager.setReturnValue( mockIoFilterChain.getMock() );
+
+        /*
+         * Replay.
+         */
+        mockIoFilterChain.replay();
+        mockIoSessionManager.replay();
+
+        factory.setFilterMappings( mappings );
+        factory.initIoSessionManager( ioSessionManager );
+
+        /*
+         * Verify.
+         */
+        mockIoFilterChain.verify();
+        mockIoSessionManager.verify();
+    }
+
+    /**
+     * Tests that
+     * {@link AbstractIoSessionManagerFactoryBean#initIoSessionManager(IoSessionManager)}
+     * sets the configured ExceptionManager on the IoSessionManager.
+     */
+    public void testInitWithExceptionMonitor() throws Exception
+    {
+        /*
+         * Create EasyMock mocks.
+         */
+        MockControl mockIoSessionManager = MockControl
+                .createControl( IoSessionManager.class );
+
+        IoSessionManager ioSessionManager = ( IoSessionManager ) mockIoSessionManager
+                .getMock();
+        IoFilterChain ioFilterChain = ( IoFilterChain ) MockControl
+                .createControl( IoFilterChain.class ).getMock();
+        ExceptionMonitor exceptionMonitor = ( ExceptionMonitor ) MockControl
+                .createControl( ExceptionMonitor.class ).getMock();
+
+        /*
+         * Record expectations.
+         */
+        ioSessionManager.getFilterChain();
+        mockIoSessionManager.setReturnValue( ioFilterChain );
+        ioSessionManager.setExceptionMonitor( exceptionMonitor );
+
+        /*
+         * Replay.
+         */
+        mockIoSessionManager.replay();
+
+        factory.setExceptionMonitor( exceptionMonitor );
+        factory.initIoSessionManager( ioSessionManager );
+
+        /*
+         * Verify.
+         */
+        mockIoSessionManager.verify();
+    }
+
+    /**
+     * Tests that
+     * {@link AbstractIoSessionManagerFactoryBean#destroyIoSessionManager(IoSessionManager)}
+     * clears the filter chain of the IoSessionManager.
+     */
+    public void testDestroyIoSessionManager() throws Exception
+    {
+        /*
+         * Create EasyMock mocks.
+         */
+        MockControl mockIoFilterChain = MockControl
+                .createStrictControl( IoFilterChain.class );
+        MockControl mockIoSessionManager = MockControl
+                .createControl( IoSessionManager.class );
+
+        IoSessionManager ioSessionManager = ( IoSessionManager ) mockIoSessionManager
+                .getMock();
+        IoFilterChain ioFilterChain = ( IoFilterChain ) mockIoFilterChain
+                .getMock();
+
+        /*
+         * Record expectations.
+         */
+        ioSessionManager.getFilterChain();
+        mockIoSessionManager.setReturnValue( ioFilterChain );
+        ioFilterChain.clear();
+
+        /*
+         * Replay.
+         */
+        mockIoFilterChain.replay();
+        mockIoSessionManager.replay();
+
+        factory.destroyIoSessionManager( ioSessionManager );
+
+        /*
+         * Verify.
+         */
+        mockIoFilterChain.verify();
+        mockIoSessionManager.verify();
+    }
+
+    /**
+     * Tests that
+     * {@link AbstractIoSessionManagerFactoryBean#setFilters(IoFilter[])}
+     * validates the method arguments.
+     */
+    public void testSetIoFilters()
+    {
+        try
+        {
+            factory.setFilters( null );
+            fail( "null filters array set. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link AbstractIoSessionManagerFactoryBean#setFilterMappings(IoFilterMapping[])}
+     * validates the method arguments.
+     */
+    public void testSetIoFilterMappings()
+    {
+        try
+        {
+            factory.setFilterMappings( null );
+            fail( "null filter mappings array set. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link AbstractIoSessionManagerFactoryBean#setExceptionMonitor(ExceptionMonitor)}
+     * validates the method arguments.
+     */
+    public void testSetExceptionMonitor()
+    {
+        try
+        {
+            factory.setExceptionMonitor( null );
+            fail( "null exceptionMonitor set. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message