You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2011/11/07 23:16:15 UTC
svn commit: r1198977 - in
/mina/trunk/core/src/test/java/org/apache/mina/transport: socket/ tcp/
tcp/ProxySocketSessionConfigTest.java
Author: jvermillard
Date: Mon Nov 7 22:16:15 2011
New Revision: 1198977
URL: http://svn.apache.org/viewvc?rev=1198977&view=rev
Log:
DIRMINA-863 unit test for socket configuration proxy
Added:
mina/trunk/core/src/test/java/org/apache/mina/transport/tcp/
mina/trunk/core/src/test/java/org/apache/mina/transport/tcp/ProxySocketSessionConfigTest.java (with props)
Removed:
mina/trunk/core/src/test/java/org/apache/mina/transport/socket/
Added: mina/trunk/core/src/test/java/org/apache/mina/transport/tcp/ProxySocketSessionConfigTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/transport/tcp/ProxySocketSessionConfigTest.java?rev=1198977&view=auto
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/transport/tcp/ProxySocketSessionConfigTest.java (added)
+++ mina/trunk/core/src/test/java/org/apache/mina/transport/tcp/ProxySocketSessionConfigTest.java Mon Nov 7 22:16:15 2011
@@ -0,0 +1,319 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.transport.tcp;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
+
+import java.net.Socket;
+import java.net.SocketException;
+
+import org.apache.mina.api.ConfigurationException;
+import org.apache.mina.api.IdleStatus;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Unit test for {@link ProxySocketSessionConfig}
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class ProxySocketSessionConfigTest {
+
+ private ProxySocketSessionConfig config;
+
+ private Socket socket;
+
+ @Before
+ public void setup() throws Exception {
+ socket = Mockito.mock(Socket.class);
+ config = new ProxySocketSessionConfig(socket);
+ }
+
+ @Test
+ public void idle() {
+ assertEquals(-1, config.getIdleTimeInMillis(IdleStatus.READ_IDLE));
+ assertEquals(-1, config.getIdleTimeInMillis(IdleStatus.READ_WRITE_IDLE));
+ assertEquals(-1, config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));
+
+ config.setIdleTimeInMillis(IdleStatus.READ_IDLE, 1);
+ assertEquals(1, config.getIdleTimeInMillis(IdleStatus.READ_IDLE));
+ assertEquals(-1, config.getIdleTimeInMillis(IdleStatus.READ_WRITE_IDLE));
+ assertEquals(-1, config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));
+
+ config.setIdleTimeInMillis(IdleStatus.READ_WRITE_IDLE, 2);
+ assertEquals(1, config.getIdleTimeInMillis(IdleStatus.READ_IDLE));
+ assertEquals(2, config.getIdleTimeInMillis(IdleStatus.READ_WRITE_IDLE));
+ assertEquals(-1, config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));
+
+ config.setIdleTimeInMillis(IdleStatus.WRITE_IDLE, 3);
+ assertEquals(1, config.getIdleTimeInMillis(IdleStatus.READ_IDLE));
+ assertEquals(2, config.getIdleTimeInMillis(IdleStatus.READ_WRITE_IDLE));
+ assertEquals(3, config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));
+ }
+
+ @Test
+ public void tcpNoDelay() throws SocketException {
+ when(socket.getTcpNoDelay()).thenReturn(true);
+ assertTrue(config.isTcpNoDelay());
+ verify(socket).getTcpNoDelay();
+ verifyNoMoreInteractions(socket);
+
+ config.setTcpNoDelay(true);
+ verify(socket).setTcpNoDelay(eq(true));
+ verifyNoMoreInteractions(socket);
+
+ // handle error
+ when(socket.getTcpNoDelay()).thenThrow(new SocketException("test"));
+ try {
+ config.isTcpNoDelay();
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ // handle error
+ doThrow(new SocketException("test")).when(socket).setTcpNoDelay(eq(true));
+ try {
+ config.setTcpNoDelay(true);
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ }
+
+ @Test
+ public void reuseAddress() throws SocketException {
+ when(socket.getReuseAddress()).thenReturn(true);
+ assertTrue(config.isReuseAddress());
+ verify(socket).getReuseAddress();
+ verifyNoMoreInteractions(socket);
+
+ config.setReuseAddress(true);
+ verify(socket).setReuseAddress(eq(true));
+ verifyNoMoreInteractions(socket);
+
+ // handle error
+ when(socket.getReuseAddress()).thenThrow(new SocketException("test"));
+ try {
+ config.isReuseAddress();
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ // handle error
+ doThrow(new SocketException("test")).when(socket).setReuseAddress(eq(true));
+ try {
+ config.setReuseAddress(true);
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+ }
+
+ @Test
+ public void receiveBufferSize() throws SocketException {
+ when(socket.getReceiveBufferSize()).thenReturn(1234);
+ assertEquals(1234, config.getReceiveBufferSize().intValue());
+ verify(socket).getReceiveBufferSize();
+ verifyNoMoreInteractions(socket);
+
+ config.setReceiveBufferSize(1234);
+ verify(socket).setReceiveBufferSize(eq(1234));
+ verifyNoMoreInteractions(socket);
+
+ // handle error
+ when(socket.getReceiveBufferSize()).thenThrow(new SocketException("test"));
+ try {
+ config.getReceiveBufferSize();
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ // handle error
+ doThrow(new SocketException("test")).when(socket).setReceiveBufferSize(eq(1234));
+ try {
+ config.setReceiveBufferSize(1234);
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ }
+
+ @Test
+ public void sendBufferSize() throws SocketException {
+ when(socket.getSendBufferSize()).thenReturn(1234);
+ assertEquals(1234, config.getSendBufferSize().intValue());
+ verify(socket).getSendBufferSize();
+ verifyNoMoreInteractions(socket);
+
+ config.setSendBufferSize(1234);
+ verify(socket).setSendBufferSize(eq(1234));
+ verifyNoMoreInteractions(socket);
+
+ // handle error
+ when(socket.getSendBufferSize()).thenThrow(new SocketException("test"));
+ try {
+ config.getSendBufferSize();
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ // handle error
+ doThrow(new SocketException("test")).when(socket).setSendBufferSize(eq(1234));
+ try {
+ config.setSendBufferSize(1234);
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+ }
+
+ @Test
+ public void trafficClass() throws SocketException {
+ when(socket.getTrafficClass()).thenReturn(1234);
+ assertEquals(1234, config.getTrafficClass().intValue());
+ verify(socket).getTrafficClass();
+ verifyNoMoreInteractions(socket);
+
+ config.setTrafficClass(1234);
+ verify(socket).setTrafficClass(eq(1234));
+ verifyNoMoreInteractions(socket);
+
+ // handle error
+ when(socket.getTrafficClass()).thenThrow(new SocketException("test"));
+ try {
+ config.getTrafficClass();
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ // handle error
+ doThrow(new SocketException("test")).when(socket).setTrafficClass(eq(1234));
+ try {
+ config.setTrafficClass(1234);
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+ }
+
+ @Test
+ public void keepAlive() throws SocketException {
+ when(socket.getKeepAlive()).thenReturn(true);
+ assertTrue(config.isKeepAlive());
+ verify(socket).getKeepAlive();
+ verifyNoMoreInteractions(socket);
+
+ config.setKeepAlive(true);
+ verify(socket).setKeepAlive(eq(true));
+ verifyNoMoreInteractions(socket);
+
+ // handle error
+ when(socket.getKeepAlive()).thenThrow(new SocketException("test"));
+ try {
+ config.isKeepAlive();
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ // handle error
+ doThrow(new SocketException("test")).when(socket).setKeepAlive(eq(true));
+ try {
+ config.setKeepAlive(true);
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+ }
+
+ @Test
+ public void oobInline() throws SocketException {
+ when(socket.getOOBInline()).thenReturn(true);
+ assertTrue(config.isOobInline());
+ verify(socket).getOOBInline();
+ verifyNoMoreInteractions(socket);
+
+ config.setOobInline(true);
+ verify(socket).setOOBInline(eq(true));
+ verifyNoMoreInteractions(socket);
+
+ // handle error
+ when(socket.getOOBInline()).thenThrow(new SocketException("test"));
+ try {
+ config.isOobInline();
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ // handle error
+ doThrow(new SocketException("test")).when(socket).setOOBInline(eq(true));
+ try {
+ config.setOobInline(true);
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+ }
+
+ @Test
+ public void soLinger() throws SocketException {
+ when(socket.getSoLinger()).thenReturn(1234);
+ assertEquals(1234, config.getSoLinger().intValue());
+ verify(socket).getSoLinger();
+ verifyNoMoreInteractions(socket);
+
+ config.setSoLinger(1234);
+ verify(socket).setSoLinger(eq(true), eq(1234));
+ verifyNoMoreInteractions(socket);
+
+ config.setSoLinger(-1234);
+ verify(socket).setSoLinger(eq(false), anyInt());
+ verifyNoMoreInteractions(socket);
+
+ // handle error
+ when(socket.getSoLinger()).thenThrow(new SocketException("test"));
+ try {
+ config.getSoLinger();
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+
+ // handle error
+ doThrow(new SocketException("test")).when(socket).setSoLinger(eq(true), eq(1234));
+ try {
+ config.setSoLinger(1234);
+ fail();
+ } catch (ConfigurationException e) {
+ assertEquals("test", e.getCause().getMessage());
+ }
+ }
+
+}
\ No newline at end of file
Propchange: mina/trunk/core/src/test/java/org/apache/mina/transport/tcp/ProxySocketSessionConfigTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain