RequestNotificationCommand extends AbstractMgcpCommand { @Override public MgcpCommandResult call() { RqntContext context = new RqntContext(); 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.warn("Unexpected error occurred during tx=" + this.transactionId + " execution. Reason:", e); context.code = MgcpResponseCode.PROTOCOL_ERROR.code(); context.message = MgcpResponseCode.PROTOCOL_ERROR.message(); } catch (MgcpCommandException e) { log.warn("Protocol error occurred during tx=" + this.transactionId + " execution. Reason:", e); context.code = e.getCode(); context.message = e.getMessage(); } return respond(context); } RequestNotificationCommand(int transactionId, Parameters<MgcpParameterType> parameters, MgcpEndpointManager endpointManager, MgcpPackageManager packageManager, MgcpSignalProvider signalProvider); @Override MgcpCommandResult call();  }
@Test @SuppressWarnings("unchecked") public void testNotificationRequest() throws MgcpParseException, UnrecognizedMgcpPackageException, UnsupportedMgcpSignalException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:AU/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final NotifiedEntity notifiedEntity = new NotifiedEntity("restcomm", "10.229.72.130", 2727); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEventType eventType = mock(MgcpEventType.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MediaGroup mediaGroup = mock(MediaGroup.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); when(endpoint.getMediaGroup()).thenReturn(mediaGroup); when(signalProvider.provide(eq("AU"), eq("pa"), eq(16), eq(notifiedEntity), any(Map.class), eq(endpoint))).thenReturn(mock(MgcpSignal.class)); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails(any(String.class))).thenReturn(eventType); when(eventType.parameterized()).thenReturn(false); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { NotificationRequest rqnt = invocation.getArgumentAt(0, NotificationRequest.class); int transactionId = rqnt.getTransactionId(); String requestId = rqnt.getRequestIdentifier(); NotifiedEntity entity = rqnt.getNotifiedEntity(); Assert.assertEquals(12345, transactionId); Assert.assertEquals("10", requestId); Assert.assertNotNull(notifiedEntity); Assert.assertEquals("restcomm@10.229.72.130:2727", entity.toString()); Assert.assertEquals("10", requestId); Assert.assertTrue(rqnt.isListening("AU/oc")); Assert.assertTrue(rqnt.isListening("AU/of")); Assert.assertEquals(1, rqnt.countSignals()); Assert.assertNotNull(rqnt.pollSignal()); Assert.assertNull(rqnt.pollSignal()); return null; } }).when(endpoint).requestNotification(any(NotificationRequest.class)); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code(), result.getCode()); verify(endpoint, times(1)).requestNotification(any(NotificationRequest.class)); }
@Test @SuppressWarnings("unchecked") public void testNotificationRequestWithoutNotifiedEntity() throws MgcpParseException, UnrecognizedMgcpPackageException, UnsupportedMgcpSignalException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:AU/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEventType eventType = mock(MgcpEventType.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MediaGroup mediaGroup = mock(MediaGroup.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); when(endpoint.getMediaGroup()).thenReturn(mediaGroup); when(signalProvider.provide(eq("AU"), eq("pa"), eq(16), isNull(NotifiedEntity.class), any(Map.class), eq(endpoint))).thenReturn(mock(MgcpSignal.class)); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails(any(String.class))).thenReturn(eventType); when(eventType.parameterized()).thenReturn(false); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { NotificationRequest rqnt = invocation.getArgumentAt(0, NotificationRequest.class); int transactionId = rqnt.getTransactionId(); String requestId = rqnt.getRequestIdentifier(); NotifiedEntity entity = rqnt.getNotifiedEntity(); Assert.assertEquals(12345, transactionId); Assert.assertEquals("10", requestId); Assert.assertNull(entity); Assert.assertEquals("10", requestId); Assert.assertTrue(rqnt.isListening("AU/oc")); Assert.assertTrue(rqnt.isListening("AU/of")); Assert.assertEquals(1, rqnt.countSignals()); Assert.assertNotNull(rqnt.pollSignal()); Assert.assertNull(rqnt.pollSignal()); return null; } }).when(endpoint).requestNotification(any(NotificationRequest.class)); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code(), result.getCode()); verify(endpoint, times(1)).requestNotification(any(NotificationRequest.class)); }
@Test @SuppressWarnings("unchecked") public void testNotificationRequestWithMultipleSignals() throws MgcpParseException, UnrecognizedMgcpPackageException, UnsupportedMgcpSignalException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("AU/pa(an=http: builder.append("R:AU/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final NotifiedEntity notifiedEntity = new NotifiedEntity("restcomm", "10.229.72.130", 2727); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEventType eventType = mock(MgcpEventType.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MediaGroup mediaGroup = mock(MediaGroup.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); when(endpoint.getMediaGroup()).thenReturn(mediaGroup); when(signalProvider.provide(eq("AU"), eq("pa"), eq(16), eq(notifiedEntity), any(Map.class), eq(endpoint))).thenReturn(mock(MgcpSignal.class)); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails(any(String.class))).thenReturn(eventType); when(eventType.parameterized()).thenReturn(false); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { NotificationRequest rqnt = invocation.getArgumentAt(0, NotificationRequest.class); int transactionId = rqnt.getTransactionId(); String requestId = rqnt.getRequestIdentifier(); NotifiedEntity notifiedEntity = rqnt.getNotifiedEntity(); Assert.assertEquals(12345, transactionId); Assert.assertEquals("10", requestId); Assert.assertNotNull(notifiedEntity); Assert.assertEquals("restcomm@10.229.72.130:2727", notifiedEntity.toString()); Assert.assertEquals("10", requestId); Assert.assertTrue(rqnt.isListening("AU/oc")); Assert.assertTrue(rqnt.isListening("AU/of")); Assert.assertEquals(2, rqnt.countSignals()); Assert.assertNotNull(rqnt.pollSignal()); Assert.assertNotNull(rqnt.pollSignal()); Assert.assertNull(rqnt.pollSignal()); return null; } }).when(endpoint).requestNotification(any(NotificationRequest.class)); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.TRANSACTION_WAS_EXECUTED.code(), result.getCode()); verify(endpoint, times(1)).requestNotification(any(NotificationRequest.class)); }
@Test public void testNotificationRequestWithAnyWildcard() throws MgcpParseException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/$@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:AU/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.WILDCARD_TOO_COMPLICATED.code(), result.getCode()); }
@Test public void testNotificationRequestMissingRequestIdentifier() throws MgcpParseException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:AU/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.PROTOCOL_ERROR.code(), result.getCode()); }
@Test public void testNotificationWithMissingEndpoint() throws MgcpParseException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:AU/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEventType eventType = mock(MgcpEventType.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(null); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails(any(String.class))).thenReturn(eventType); when(eventType.parameterized()).thenReturn(false); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.ENDPOINT_UNKNOWN.code(), result.getCode()); }
@Test @SuppressWarnings("unchecked") public void testNotificationRequestWithUnrecognizedSignalPackage() throws MgcpParseException, UnrecognizedMgcpPackageException, UnsupportedMgcpSignalException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AX/pa(an=http: builder.append("R:AX/oc(N),AX/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final NotifiedEntity notifiedEntity = new NotifiedEntity("restcomm", "10.229.72.130", 2727); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MediaGroup mediaGroup = mock(MediaGroup.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); when(endpoint.getMediaGroup()).thenReturn(mediaGroup); when(signalProvider.provide(eq("AX"), eq("pa"), eq(16), eq(notifiedEntity), any(Map.class), eq(endpoint))).thenThrow(new UnrecognizedMgcpPackageException("")); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.UNKNOWN_PACKAGE.code(), result.getCode()); }
@Test @SuppressWarnings("unchecked") public void testNotificationRequestWithUnrecognizedSignalType() throws MgcpParseException, UnrecognizedMgcpPackageException, UnsupportedMgcpSignalException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/xyz(an=http: builder.append("R:AU/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final NotifiedEntity notifiedEntity = new NotifiedEntity("restcomm", "10.229.72.130", 2727); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEventType eventType = mock(MgcpEventType.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MediaGroup mediaGroup = mock(MediaGroup.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); when(endpoint.getMediaGroup()).thenReturn(mediaGroup); when(signalProvider.provide(eq("AU"), eq("xyz"), eq(16), eq(notifiedEntity), any(Map.class), eq(endpoint))).thenThrow(new UnsupportedMgcpSignalException("")); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails(any(String.class))).thenReturn(eventType); when(eventType.parameterized()).thenReturn(false); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.NO_SUCH_EVENT_OR_SIGNAL.code(), result.getCode()); }
@Test public void testNotificationRequestWithUnrecognizedPackageOnEvent() throws MgcpParseException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:XYZ/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.UNKNOWN_PACKAGE.code(), result.getCode()); }
@Test public void testNotificationRequestWithUnrecognizedEvent() throws MgcpParseException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:AU/xyz(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails("xyz")).thenReturn(null); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.NO_SUCH_EVENT_OR_SIGNAL.code(), result.getCode()); }
@Test public void testNotificationRequestWithUnrecognizedAction() throws MgcpParseException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:AU/oc(XYZ),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEventType eventType = mock(MgcpEventType.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails(any(String.class))).thenReturn(eventType); when(eventType.parameterized()).thenReturn(false); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.EVENT_OR_SIGNAL_PARAMETER_ERROR.code(), result.getCode()); }
@Test public void testNotificationRequestWithMalformedRequestedEvents() throws MgcpParseException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/pa(an=http: builder.append("R:AU/oc(N),AU/of(N"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEventType eventType = mock(MgcpEventType.class); final MgcpEndpoint endpoint = mock(MgcpEndpoint.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenReturn(endpoint); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails(any(String.class))).thenReturn(eventType); when(eventType.parameterized()).thenReturn(false); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.PROTOCOL_ERROR.code(), result.getCode()); }
@Test public void testNotificationRequestWithUnexpectedError() throws MgcpParseException { final StringBuilder builder = new StringBuilder("RQNT 12345 mobicents/ivr/10@127.0.0.1:2427 MGCP 1.0").append("\n"); builder.append("N:restcomm@10.229.72.130:2727").append("\n"); builder.append("X:10").append("\n"); builder.append("S:AU/xyz(an=http: builder.append("R:AU/oc(N),AU/of(N)"); final MgcpMessageParser parser = new MgcpMessageParser(); final MgcpRequest request = parser.parseRequest(builder.toString()); final MgcpEndpointManager endpointManager = mock(MgcpEndpointManager.class); final MgcpPackageManager packageManager = mock(MgcpPackageManager.class); final MgcpPackage mgcpPackage = mock(MgcpPackage.class); final MgcpEventType eventType = mock(MgcpEventType.class); final MgcpSignalProvider signalProvider = mock(MgcpSignalProvider.class); final RequestNotificationCommand rqnt = new RequestNotificationCommand(request.getTransactionId(), request.getParameters(), endpointManager, packageManager, signalProvider); when(endpointManager.getEndpoint("mobicents/ivr/10@127.0.0.1:2427")).thenThrow(new RuntimeException()); when(packageManager.getPackage("AU")).thenReturn(mgcpPackage); when(mgcpPackage.getEventDetails(any(String.class))).thenReturn(eventType); when(eventType.parameterized()).thenReturn(false); MgcpCommandResult result = rqnt.call(); Assert.assertNotNull(result); Assert.assertEquals(MgcpResponseCode.PROTOCOL_ERROR.code(), result.getCode()); }