SubMgcpTransactionManager implements MgcpTransactionManager { @Override public void process(InetSocketAddress from, InetSocketAddress to, MgcpRequest request, MgcpCommand command, MessageDirection direction) throws DuplicateMgcpTransactionException { createTransaction(request); if (log.isDebugEnabled()) { String callAgent = MessageDirection.INCOMING.equals(direction) ? from.toString() : to.toString(); log.debug("Started transaction " + request.getTransactionId() + " for call agent " + callAgent); } if (command != null) { ListenableFuture<MgcpCommandResult> future = this.executor.submit(command); Futures.addCallback(future, new MgcpCommandCallback(from, to, request.getTransactionId())); } } SubMgcpTransactionManager(MgcpTransactionNumberspace numberspace, ListeningExecutorService executor); @Override void process(InetSocketAddress from, InetSocketAddress to, MgcpRequest request, MgcpCommand command, MessageDirection direction); @Override void process(InetSocketAddress from, InetSocketAddress to, MgcpResponse response, MessageDirection direction); @Override void observe(MgcpMessageObserver observer); @Override void forget(MgcpMessageObserver observer); @Override void notify(Object originator, InetSocketAddress from, InetSocketAddress to, MgcpMessage message, MessageDirection direction);  }
@SuppressWarnings("unchecked") @Test(expected = DuplicateMgcpTransactionException.class) public void testProcessRetransmission() throws DuplicateMgcpTransactionException, MgcpTransactionNotFoundException { final int transactionId = 147483653; final InetSocketAddress local = new InetSocketAddress("127.0.0.1", 2427); final InetSocketAddress remote = new InetSocketAddress("127.0.0.1", 2727); final MgcpRequest request = mock(MgcpRequest.class); final MgcpCommand command = mock(MgcpCommand.class); final MgcpTransactionNumberspace numberspace = mock(MgcpTransactionNumberspace.class); final ListeningExecutorService executor = mock(ListeningExecutorService.class); final SubMgcpTransactionManager txManager = new SubMgcpTransactionManager(numberspace, executor); when(executor.submit(command)).thenReturn(mock(ListenableFuture.class)); when(request.toString()).thenReturn(REQUEST); when(request.isRequest()).thenReturn(true); when(request.getRequestType()).thenReturn(MgcpRequestType.CRCX); when(request.getTransactionId()).thenReturn(transactionId); txManager.process(remote, local, request, command, MessageDirection.INCOMING); txManager.process(remote, local, request, command, MessageDirection.INCOMING); }
@SuppressWarnings("unchecked") @Test(expected = MgcpTransactionNotFoundException.class) public void testProcessIncomingResponseWithUnknownTransactionId() throws DuplicateMgcpTransactionException, MgcpTransactionNotFoundException { final int transactionId = 147483653; final InetSocketAddress local = new InetSocketAddress("127.0.0.1", 2427); final InetSocketAddress remote = new InetSocketAddress("127.0.0.1", 2727); final MgcpResponse response = mock(MgcpResponse.class); final MgcpCommand command = mock(MgcpCommand.class); final MgcpTransactionNumberspace numberspace = mock(MgcpTransactionNumberspace.class); final ListeningExecutorService executor = mock(ListeningExecutorService.class); final SubMgcpTransactionManager txManager = new SubMgcpTransactionManager(numberspace, executor); when(executor.submit(command)).thenReturn(mock(ListenableFuture.class)); when(response.toString()).thenReturn(REQUEST); when(response.isRequest()).thenReturn(true); when(response.getTransactionId()).thenReturn(transactionId); txManager.process(remote, local, response, MessageDirection.INCOMING); }