@Test public void testNoConnectionFoundWhenDeletingSingleConnection() throws MgcpException { final StringBuilder builder = new StringBuilder(); builder.append("DLCX 147483653 mobicents/bridge/1@127.0.0.1:2427 MGCP 1.0").append(System.lineSeparator()); builder.append("C:1").append(System.lineSeparator()); builder.append("I:1").append(System.lineSeparator()); final int transactionId = 147483653; final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpEndpoint bridgeEndpoint = mock(MgcpEndpoint.class); final DeleteConnectionCommand dlcx = new DeleteConnectionCommand(transactionId, request.getParameters(), endpointManager); when(endpointManager.getEndpoint("mobicents/bridge/1@127.0.0.1:2427")).thenReturn(bridgeEndpoint); when(bridgeEndpoint.deleteConnection(1, 1)).thenThrow(new MgcpConnectionNotFoundException("")); MgcpCommandResult result = dlcx.call(); verify(bridgeEndpoint, times(1)).deleteConnection(1, 1); assertNotNull(result); assertEquals(MgcpResponseCode.INCORRECT_CONNECTION_ID.code(), result.getCode()); Parameters<MgcpParameterType> parameters = result.getParameters(); assertEquals(0, parameters.size()); }
@Override public MgcpCommandResult call() { DlcxContext context = new DlcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.code = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code(); context.message = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message(); } catch (RuntimeException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Rolling back."); context.code = MgcpResponseCode.PROTOCOL_ERROR.code(); context.message = MgcpResponseCode.PROTOCOL_ERROR.message(); } catch (MgcpCallNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CALL_ID.code(); context.message = MgcpResponseCode.INCORRECT_CALL_ID.message(); } catch (MgcpConnectionNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CONNECTION_ID.code(); context.message = MgcpResponseCode.INCORRECT_CONNECTION_ID.message(); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = e.getCode(); context.message = e.getMessage(); } return respond(context); }
DeleteConnectionCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { DlcxContext context = new DlcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.code = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code(); context.message = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message(); } catch (RuntimeException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Rolling back."); context.code = MgcpResponseCode.PROTOCOL_ERROR.code(); context.message = MgcpResponseCode.PROTOCOL_ERROR.message(); } catch (MgcpCallNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CALL_ID.code(); context.message = MgcpResponseCode.INCORRECT_CALL_ID.message(); } catch (MgcpConnectionNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CONNECTION_ID.code(); context.message = MgcpResponseCode.INCORRECT_CONNECTION_ID.message(); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = e.getCode(); context.message = e.getMessage(); } return respond(context); } }
DeleteConnectionCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { DlcxContext context = new DlcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.code = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code(); context.message = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message(); } catch (RuntimeException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Rolling back."); context.code = MgcpResponseCode.PROTOCOL_ERROR.code(); context.message = MgcpResponseCode.PROTOCOL_ERROR.message(); } catch (MgcpCallNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CALL_ID.code(); context.message = MgcpResponseCode.INCORRECT_CALL_ID.message(); } catch (MgcpConnectionNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CONNECTION_ID.code(); context.message = MgcpResponseCode.INCORRECT_CONNECTION_ID.message(); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = e.getCode(); context.message = e.getMessage(); } return respond(context); } DeleteConnectionCommand(int transactionId, Parameters<MgcpParameterType> parameters, MgcpEndpointManager endpointManager); }
DeleteConnectionCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { DlcxContext context = new DlcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.code = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code(); context.message = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message(); } catch (RuntimeException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Rolling back."); context.code = MgcpResponseCode.PROTOCOL_ERROR.code(); context.message = MgcpResponseCode.PROTOCOL_ERROR.message(); } catch (MgcpCallNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CALL_ID.code(); context.message = MgcpResponseCode.INCORRECT_CALL_ID.message(); } catch (MgcpConnectionNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CONNECTION_ID.code(); context.message = MgcpResponseCode.INCORRECT_CONNECTION_ID.message(); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = e.getCode(); context.message = e.getMessage(); } return respond(context); } DeleteConnectionCommand(int transactionId, Parameters<MgcpParameterType> parameters, MgcpEndpointManager endpointManager); @Override MgcpCommandResult call(); }
DeleteConnectionCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { DlcxContext context = new DlcxContext(); try { validateParameters(this.requestParameters, context); executeCommand(context); context.code = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code(); context.message = MgcpResponseCode.TRANSACTION_WAS_EXECUTED.message(); } catch (RuntimeException e) { log.error("Unexpected error occurred during tx=" + this.transactionId + " execution. Rolling back."); context.code = MgcpResponseCode.PROTOCOL_ERROR.code(); context.message = MgcpResponseCode.PROTOCOL_ERROR.message(); } catch (MgcpCallNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CALL_ID.code(); context.message = MgcpResponseCode.INCORRECT_CALL_ID.message(); } catch (MgcpConnectionNotFoundException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = MgcpResponseCode.INCORRECT_CONNECTION_ID.code(); context.message = MgcpResponseCode.INCORRECT_CONNECTION_ID.message(); } catch (MgcpCommandException e) { log.error("Protocol error occurred during tx=" + this.transactionId + " execution: " + e.getMessage()); context.code = e.getCode(); context.message = e.getMessage(); } return respond(context); } DeleteConnectionCommand(int transactionId, Parameters<MgcpParameterType> parameters, MgcpEndpointManager endpointManager); @Override MgcpCommandResult call();  }