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 2012/12/24 09:39:57 UTC
svn commit: r1425603 - in /mina/mina/trunk/core/src:
main/java/org/apache/mina/service/executor/
test/java/org/apache/mina/service/executor/
Author: jvermillard
Date: Mon Dec 24 08:39:57 2012
New Revision: 1425603
URL: http://svn.apache.org/viewvc?rev=1425603&view=rev
Log:
IoHandlerExecutor unit tests
Added:
mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/
mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/HandlerCallerTest.java
mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/InOrderHandlerExecutorTest.java
mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutorTest.java
Modified:
mina/mina/trunk/core/src/main/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutor.java
Modified: mina/mina/trunk/core/src/main/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutor.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/main/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutor.java?rev=1425603&r1=1425602&r2=1425603&view=diff
==============================================================================
--- mina/mina/trunk/core/src/main/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutor.java (original)
+++ mina/mina/trunk/core/src/main/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutor.java Mon Dec 24 08:39:57 2012
@@ -21,6 +21,8 @@ package org.apache.mina.service.executor
import java.util.concurrent.Executor;
+import org.apache.mina.util.Assert;
+
/**
* (in progress)
*
@@ -32,6 +34,7 @@ public class OutOfOrderHandlerExecutor i
private final Executor executor;
public OutOfOrderHandlerExecutor(Executor executor) {
+ Assert.assertNotNull(executor, "executor");
this.executor = executor;
}
Added: mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/HandlerCallerTest.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/HandlerCallerTest.java?rev=1425603&view=auto
==============================================================================
--- mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/HandlerCallerTest.java (added)
+++ mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/HandlerCallerTest.java Mon Dec 24 08:39:57 2012
@@ -0,0 +1,152 @@
+/*
+ * 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.service.executor;
+
+import static org.mockito.Mockito.*;
+
+import org.apache.mina.api.IdleStatus;
+import org.apache.mina.api.IoHandler;
+import org.apache.mina.api.IoService;
+import org.apache.mina.api.IoSession;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link HandlerCaller}
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class HandlerCallerTest {
+
+ private HandlerCaller caller = new HandlerCaller();
+
+ private IoSession session;
+ private IoService service;
+ private IoHandler handler;
+
+ @Before
+ public void setup() {
+ session = mock(IoSession.class);
+ service = mock(IoService.class);
+ handler = mock(IoHandler.class);
+ when(session.getService()).thenReturn(service);
+ when(service.getIoHandler()).thenReturn(handler);
+ }
+
+ @Test
+ public void call_open() {
+ // prepare
+ OpenEvent event = mock(OpenEvent.class);
+ when(event.getSession()).thenReturn(session);
+
+ // run
+ caller.visit(event);
+
+ // verify
+ verify(event).getSession();
+ verify(session).getService();
+ verify(service).getIoHandler();
+ verify(handler).sessionOpened(session);
+
+ verifyNoMoreInteractions(session, event, handler);
+ }
+
+ @Test
+ public void call_close() {
+ // prepare
+ CloseEvent event = mock(CloseEvent.class);
+ when(event.getSession()).thenReturn(session);
+
+ // run
+ caller.visit(event);
+
+ // verify
+ verify(event).getSession();
+ verify(session).getService();
+ verify(service).getIoHandler();
+ verify(handler).sessionClosed(session);
+
+ verifyNoMoreInteractions(session, event, handler);
+ }
+
+ @Test
+ public void call_idle() {
+ // prepare
+ IdleEvent event = mock(IdleEvent.class);
+ IdleStatus status = IdleStatus.READ_IDLE;
+ when(event.getIdleStatus()).thenReturn(status);
+ when(event.getSession()).thenReturn(session);
+
+ // run
+ caller.visit(event);
+
+ // verify
+ verify(event).getSession();
+ verify(event).getIdleStatus();
+ verify(session).getService();
+ verify(service).getIoHandler();
+ verify(handler).sessionIdle(session, status);
+
+ verifyNoMoreInteractions(session, event, handler);
+ }
+
+ @Test
+ public void call_receive() {
+ // prepare
+ ReceiveEvent event = mock(ReceiveEvent.class);
+ Object msg = mock(Object.class);
+ when(event.getMessage()).thenReturn(msg);
+ when(event.getSession()).thenReturn(session);
+
+ // run
+ caller.visit(event);
+
+ // verify
+ verify(event).getSession();
+ verify(event).getMessage();
+ verify(session).getService();
+ verify(service).getIoHandler();
+ verify(handler).messageReceived(session, msg);
+
+ verifyNoMoreInteractions(session, event, handler);
+ }
+
+ @Test
+ public void call_msg_sent() {
+ // prepare
+ SentEvent event = mock(SentEvent.class);
+ Object msg = mock(Object.class);
+ when(event.getMessage()).thenReturn(msg);
+ when(event.getSession()).thenReturn(session);
+
+ // run
+ caller.visit(event);
+
+ // verify
+ verify(event).getSession();
+ verify(event).getMessage();
+ verify(session).getService();
+ verify(service).getIoHandler();
+ verify(handler).messageSent(session, msg);
+
+ verifyNoMoreInteractions(session, event, handler);
+ }
+
+}
Added: mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/InOrderHandlerExecutorTest.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/InOrderHandlerExecutorTest.java?rev=1425603&view=auto
==============================================================================
--- mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/InOrderHandlerExecutorTest.java (added)
+++ mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/InOrderHandlerExecutorTest.java Mon Dec 24 08:39:57 2012
@@ -0,0 +1,58 @@
+/*
+ * 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.service.executor;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+import org.apache.mina.api.IoSession;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link InOrderHandlerExecutor}.
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class InOrderHandlerExecutorTest {
+
+ private InOrderHandlerExecutor executor;
+
+ @Test
+ public void execute_open_events() {
+ // prepare
+ executor = new InOrderHandlerExecutor(1, 1);
+ IoSession session = mock(IoSession.class);
+ when(session.getId()).thenReturn(12345L);
+
+ Event evt = mock(Event.class);
+ when(evt.getSession()).thenReturn(session);
+
+ // run
+
+ executor.execute(evt);
+
+ // verify
+ verify(session).getId();
+ verify(evt).getSession();
+
+ verify(evt).visit(any(EventVisitor.class));
+ verifyNoMoreInteractions(evt, session);
+ }
+}
Added: mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutorTest.java
URL: http://svn.apache.org/viewvc/mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutorTest.java?rev=1425603&view=auto
==============================================================================
--- mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutorTest.java (added)
+++ mina/mina/trunk/core/src/test/java/org/apache/mina/service/executor/OutOfOrderHandlerExecutorTest.java Mon Dec 24 08:39:57 2012
@@ -0,0 +1,75 @@
+/*
+ * 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.service.executor;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+import java.util.concurrent.Executor;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+/**
+ * Unit test for {@link OutOfOrderHandlerExecutor}
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class OutOfOrderHandlerExecutorTest {
+
+ private OutOfOrderHandlerExecutor handlerExecutor;
+
+ private Executor executor;
+
+ @Before
+ public void setup() {
+ executor = mock(Executor.class);
+ handlerExecutor = new OutOfOrderHandlerExecutor(executor);
+ }
+
+ @Test
+ public void null_param() {
+ try {
+ new OutOfOrderHandlerExecutor(null);
+ Assert.fail();
+ } catch (IllegalArgumentException ex) {
+ // happy
+ }
+ }
+
+ @Test
+ public void enqueu_event() {
+ // prepare
+ Event e = mock(Event.class);
+
+ // run
+ handlerExecutor.execute(e);
+
+ // verify
+ ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
+ verify(executor).execute(captor.capture());
+
+ captor.getValue().run();
+ verify(e).visit(any(EventVisitor.class));
+
+ }
+}