You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2008/11/11 19:39:46 UTC
svn commit: r713100 - in /mina/trunk/core/src/test/java/org/apache/mina:
core/DefaultIoFilterChainBuilderTest.java
filter/codec/CumulativeProtocolDecoderTest.java
filter/logging/MdcInjectionFilterTest.java
handler/chain/ChainedIoHandlerTest.java
Author: elecharny
Date: Tue Nov 11 10:39:46 2008
New Revision: 713100
URL: http://svn.apache.org/viewvc?rev=713100&view=rev
Log:
Doing some cleaning in tests :
o removing dead code
o using Junit 4 annotations
Modified:
mina/trunk/core/src/test/java/org/apache/mina/core/DefaultIoFilterChainBuilderTest.java
mina/trunk/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java
mina/trunk/core/src/test/java/org/apache/mina/filter/logging/MdcInjectionFilterTest.java
mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java
Modified: mina/trunk/core/src/test/java/org/apache/mina/core/DefaultIoFilterChainBuilderTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/core/DefaultIoFilterChainBuilderTest.java?rev=713100&r1=713099&r2=713100&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/core/DefaultIoFilterChainBuilderTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/core/DefaultIoFilterChainBuilderTest.java Tue Nov 11 10:39:46 2008
@@ -38,10 +38,6 @@
* @version $Rev$, $Date$
*/
public class DefaultIoFilterChainBuilderTest {
- /*public static void main(String[] args) {
- junit.textui.TestRunner.run(DefaultIoFilterChainBuilderTest.class);
- }*/
-
@Before
public void setUp() throws Exception {
}
Modified: mina/trunk/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java?rev=713100&r1=713099&r2=713100&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/filter/codec/CumulativeProtocolDecoderTest.java Tue Nov 11 10:39:46 2008
@@ -23,13 +23,18 @@
import java.util.ArrayList;
import java.util.List;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.service.DefaultTransportMetadata;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.session.IoSessionConfig;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
+
/**
* Tests {@link CumulativeProtocolDecoder}.
@@ -37,18 +42,14 @@
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*/
-public class CumulativeProtocolDecoderTest extends TestCase {
+public class CumulativeProtocolDecoderTest {
private final ProtocolCodecSession session = new ProtocolCodecSession();
private IoBuffer buf;
private IntegerDecoder decoder;
- public static void main(String[] args) {
- junit.textui.TestRunner.run(CumulativeProtocolDecoderTest.class);
- }
-
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
buf = IoBuffer.allocate(16);
decoder = new IntegerDecoder();
session.setTransportMetadata(
@@ -57,18 +58,19 @@
IoSessionConfig.class, IoBuffer.class));
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
decoder.dispose(session);
}
+ @Test
public void testCumulation() throws Exception {
buf.put((byte) 0);
buf.flip();
decoder.decode(session, buf, session.getDecoderOutput());
- Assert.assertEquals(0, session.getDecoderOutputQueue().size());
- Assert.assertEquals(buf.limit(), buf.position());
+ assertEquals(0, session.getDecoderOutputQueue().size());
+ assertEquals(buf.limit(), buf.position());
buf.clear();
buf.put((byte) 0);
@@ -77,11 +79,12 @@
buf.flip();
decoder.decode(session, buf, session.getDecoderOutput());
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals(new Integer(1), session.getDecoderOutputQueue().poll());
- Assert.assertEquals(buf.limit(), buf.position());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals(new Integer(1), session.getDecoderOutputQueue().poll());
+ assertEquals(buf.limit(), buf.position());
}
+ @Test
public void testRepeatitiveDecode() throws Exception {
for (int i = 0; i < 4; i++) {
buf.putInt(i);
@@ -89,25 +92,29 @@
buf.flip();
decoder.decode(session, buf, session.getDecoderOutput());
- Assert.assertEquals(4, session.getDecoderOutputQueue().size());
- Assert.assertEquals(buf.limit(), buf.position());
+ assertEquals(4, session.getDecoderOutputQueue().size());
+ assertEquals(buf.limit(), buf.position());
List<Object> expected = new ArrayList<Object>();
+
for (int i = 0; i < 4; i++) {
expected.add(new Integer(i));
}
- Assert.assertEquals(expected, session.getDecoderOutputQueue());
+
+ assertEquals(expected, session.getDecoderOutputQueue());
}
+ @Test
public void testWrongImplementationDetection() throws Exception {
try {
new WrongDecoder().decode(session, buf, session.getDecoderOutput());
- Assert.fail();
+ fail();
} catch (IllegalStateException e) {
// OK
}
}
+ @Test
public void testBufferDerivation() throws Exception {
decoder = new DuplicatingIntegerDecoder();
@@ -118,9 +125,9 @@
buf.flip();
decoder.decode(session, buf, session.getDecoderOutput());
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals(1, session.getDecoderOutputQueue().poll());
- Assert.assertEquals(buf.limit(), buf.position());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals(1, session.getDecoderOutputQueue().poll());
+ assertEquals(buf.limit(), buf.position());
// Keep appending to the internal buffer.
// DuplicatingIntegerDecoder will keep duplicating the internal
@@ -138,9 +145,9 @@
buf.position(1);
decoder.decode(session, buf, session.getDecoderOutput());
- Assert.assertEquals(1, session.getDecoderOutputQueue().size());
- Assert.assertEquals(i, session.getDecoderOutputQueue().poll());
- Assert.assertEquals(buf.limit(), buf.position());
+ assertEquals(1, session.getDecoderOutputQueue().size());
+ assertEquals(i, session.getDecoderOutputQueue().poll());
+ assertEquals(buf.limit(), buf.position());
}
}
@@ -149,7 +156,8 @@
@Override
protected boolean doDecode(IoSession session, IoBuffer in,
ProtocolDecoderOutput out) throws Exception {
- Assert.assertTrue(in.hasRemaining());
+ assertTrue(in.hasRemaining());
+
if (in.remaining() < 4) {
return false;
}
@@ -178,12 +186,11 @@
protected boolean doDecode(IoSession session, IoBuffer in,
ProtocolDecoderOutput out) throws Exception {
in.duplicate(); // Will disable auto-expansion.
- Assert.assertFalse(in.isAutoExpand());
+ assertFalse(in.isAutoExpand());
return super.doDecode(session, in, out);
}
public void dispose() throws Exception {
}
}
-
}
Modified: mina/trunk/core/src/test/java/org/apache/mina/filter/logging/MdcInjectionFilterTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/filter/logging/MdcInjectionFilterTest.java?rev=713100&r1=713099&r2=713100&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/filter/logging/MdcInjectionFilterTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/filter/logging/MdcInjectionFilterTest.java Tue Nov 11 10:39:46 2008
@@ -27,8 +27,6 @@
import java.util.List;
import java.util.concurrent.CountDownLatch;
-import junit.framework.TestCase;
-
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
@@ -51,6 +49,13 @@
import org.apache.mina.filter.statistic.ProfilerTimerFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,7 +65,7 @@
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*/
-public class MdcInjectionFilterTest extends TestCase {
+public class MdcInjectionFilterTest {
private static Logger logger = LoggerFactory.getLogger(MdcInjectionFilterTest.class);
private static final int TIMEOUT = 5000;
@@ -69,9 +74,8 @@
private int port;
private NioSocketAcceptor acceptor;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
// comment out next line if you want to see normal logging
org.apache.log4j.Logger.getRootLogger().removeAllAppenders();
org.apache.log4j.Logger.getRootLogger().setLevel(Level.DEBUG);
@@ -80,12 +84,12 @@
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
acceptor.dispose();
- super.tearDown();
}
+ @Test
public void testSimpleChain() throws IOException, InterruptedException {
DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
chain.addFirst("mdc-injector", new MdcInjectionFilter());
@@ -94,6 +98,7 @@
test(chain);
}
+ @Test
public void testExecutorFilterAtTheEnd() throws IOException, InterruptedException {
DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
@@ -105,6 +110,7 @@
test(chain);
}
+ @Test
public void testExecutorFilterAtBeginning() throws IOException, InterruptedException {
DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
@@ -115,6 +121,7 @@
test(chain);
}
+ @Test
public void testExecutorFilterBeforeProtocol() throws IOException, InterruptedException {
DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
@@ -125,6 +132,7 @@
test(chain);
}
+ @Test
public void testMultipleFilters() throws IOException, InterruptedException {
DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
@@ -138,6 +146,7 @@
}
+ @Test
public void testTwoExecutorFilters() throws IOException, InterruptedException {
DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
@@ -152,6 +161,7 @@
test(chain);
}
+ @Test
public void testOnlyRemoteAddress() throws IOException, InterruptedException {
DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
chain.addFirst("mdc-injector", new MdcInjectionFilter(
Modified: mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java?rev=713100&r1=713099&r2=713100&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java Tue Nov 11 10:39:46 2008
@@ -19,11 +19,10 @@
*/
package org.apache.mina.handler.chain;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import org.apache.mina.core.session.DummySession;
import org.apache.mina.core.session.IoSession;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
/**
* A test case for {@link ChainedIoHandler}.
@@ -31,11 +30,8 @@
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*/
-public class ChainedIoHandlerTest extends TestCase {
- public static void main(String[] args) {
- junit.textui.TestRunner.run(ChainedIoHandlerTest.class);
- }
-
+public class ChainedIoHandlerTest {
+ @Test
public void testChainedCommand() throws Exception {
IoHandlerChain chain = new IoHandlerChain();
StringBuilder buf = new StringBuilder();
@@ -45,7 +41,7 @@
new ChainedIoHandler(chain).messageReceived(new DummySession(), null);
- Assert.assertEquals("ABC", buf.toString());
+ assertEquals("ABC", buf.toString());
}
private class TestCommand implements IoHandlerCommand {