MgcpMessageParser { public MgcpRequest parseRequest(byte[] data, int offset, int length) throws MgcpParseException { return parseRequest(new String(data, offset, length)); } MgcpMessageParser(); MgcpRequest parseRequest(byte[] data, int offset, int length); MgcpRequest parseRequest(String message); MgcpResponse parseResponse(byte[] data, int offset, int length); MgcpResponse parseResponse(String message);  }
@Test public void testParseCrcxRequest() throws MgcpParseException { StringBuilder builder = new StringBuilder(); builder.append("CRCX 147483653 mobicents/bridge/$@127.0.0.1:2427 MGCP 1.0").append(System.lineSeparator()); builder.append("C:1").append(System.lineSeparator()); builder.append("M:sendrecv").append(System.lineSeparator()); builder.append("N:restcomm@127.0.0.1:2727").append(System.lineSeparator()); builder.append("Z2:mobicents/ivr/$@127.0.0.1:2427"); MgcpMessageParser parser = new MgcpMessageParser(); MgcpRequest request = parser.parseRequest(builder.toString()); assertEquals(MgcpRequestType.CRCX, request.getRequestType()); assertEquals(147483653, request.getTransactionId()); assertEquals("mobicents/bridge/$@127.0.0.1:2427", request.getEndpointId()); assertEquals("1", request.getParameter(MgcpParameterType.CALL_ID)); assertEquals("sendrecv", request.getParameter(MgcpParameterType.MODE)); assertEquals("restcomm@127.0.0.1:2727", request.getParameter(MgcpParameterType.NOTIFIED_ENTITY)); assertEquals("mobicents/ivr/$@127.0.0.1:2427", request.getParameter(MgcpParameterType.SECOND_ENDPOINT)); }
@Test public void testParseCrcxRequestWithWhitespaceBetweenParameters() throws MgcpParseException { StringBuilder builder = new StringBuilder(); builder.append("CRCX 147483653 mobicents/bridge/$@127.0.0.1:2427 MGCP 1.0").append(System.lineSeparator()); builder.append("C: 1").append(System.lineSeparator()); builder.append("M: sendrecv").append(System.lineSeparator()); builder.append("N: restcomm@127.0.0.1:2727").append(System.lineSeparator()); builder.append("Z2: mobicents/ivr/$@127.0.0.1:2427"); MgcpMessageParser parser = new MgcpMessageParser(); MgcpRequest request = parser.parseRequest(builder.toString()); assertEquals(MgcpRequestType.CRCX, request.getRequestType()); assertEquals(147483653, request.getTransactionId()); assertEquals("mobicents/bridge/$@127.0.0.1:2427", request.getEndpointId()); assertEquals("1", request.getParameter(MgcpParameterType.CALL_ID)); assertEquals("sendrecv", request.getParameter(MgcpParameterType.MODE)); assertEquals("restcomm@127.0.0.1:2727", request.getParameter(MgcpParameterType.NOTIFIED_ENTITY)); assertEquals("mobicents/ivr/$@127.0.0.1:2427", request.getParameter(MgcpParameterType.SECOND_ENDPOINT)); }
@Test public void testParseCrcxRequestWithSdp() throws MgcpParseException { StringBuilder builder = new StringBuilder(); builder.append("CRCX 147483655 mobicents/bridge/1@127.0.0.1:2427 MGCP 1.0").append(System.lineSeparator()); builder.append("C:1").append(System.lineSeparator()); builder.append("M:sendrecv").append(System.lineSeparator()); builder.append("N:restcomm@127.0.0.1:2727").append(System.lineSeparator()); builder.append("L:webrtc:false").append(System.lineSeparator()); builder.append(System.lineSeparator()); StringBuilder builderSdp = new StringBuilder(); builderSdp.append("v=0").append(System.lineSeparator()); builderSdp.append("o=hrosa 3616 1899 IN IP4 127.0.0.1").append(System.lineSeparator()); builderSdp.append("s=Talk").append(System.lineSeparator()); builderSdp.append("c=IN IP4 127.0.0.1").append(System.lineSeparator()); builderSdp.append("t=0 0").append(System.lineSeparator()); builderSdp.append("a=rtcp-xr:rcvr-rtt=all:10000 stat-summary=loss,dup,jitt,TTL voip-metrics") .append(System.lineSeparator()); builderSdp.append("m=audio 7070 RTP/AVP 8 0 101").append(System.lineSeparator()); builderSdp.append("a=rtpmap:101 telephone-event/8000"); builder.append(builderSdp.toString()); MgcpMessageParser parser = new MgcpMessageParser(); MgcpRequest request = parser.parseRequest(builder.toString()); assertEquals(MgcpRequestType.CRCX, request.getRequestType()); assertEquals(147483655, request.getTransactionId()); assertEquals("mobicents/bridge/1@127.0.0.1:2427", request.getEndpointId()); assertEquals("1", request.getParameter(MgcpParameterType.CALL_ID)); assertEquals("sendrecv", request.getParameter(MgcpParameterType.MODE)); assertEquals("restcomm@127.0.0.1:2727", request.getParameter(MgcpParameterType.NOTIFIED_ENTITY)); assertEquals("webrtc:false", request.getParameter(MgcpParameterType.LOCAL_CONNECTION_OPTIONS)); assertTrue(request.isSdpDetected()); assertEquals(builderSdp.toString(), request.getParameter(MgcpParameterType.SDP)); }
@Test public void testParseMdcxRequest() throws MgcpParseException { StringBuilder builder = new StringBuilder(); builder.append("MDCX 147483654 mobicents/ivr/1@127.0.0.1:2427 MGCP 1.0").append(System.lineSeparator()); builder.append("C:1").append(System.lineSeparator()); builder.append("I:10").append(System.lineSeparator()); builder.append("M:sendrecv").append(System.lineSeparator()); MgcpMessageParser parser = new MgcpMessageParser(); MgcpRequest request = parser.parseRequest(builder.toString()); assertEquals(MgcpRequestType.MDCX, request.getRequestType()); assertEquals(147483654, request.getTransactionId()); assertEquals("mobicents/ivr/1@127.0.0.1:2427", request.getEndpointId()); assertEquals("1", request.getParameter(MgcpParameterType.CALL_ID)); assertEquals("sendrecv", request.getParameter(MgcpParameterType.MODE)); assertEquals("10", request.getParameter(MgcpParameterType.CONNECTION_ID)); }
@Test public void testParseRqntRequest() throws MgcpParseException { StringBuilder builder = new StringBuilder(); builder.append("RQNT 147483656 mobicents/ivr/1@127.0.0.1:2427 MGCP 1.0").append(System.lineSeparator()); builder.append("N:restcomm@127.0.0.1:2727").append(System.lineSeparator()); builder.append("X:1").append(System.lineSeparator()); builder.append("S:AU/pa(an=http: builder.append("R:AU/oc(N),AU/of(N)").append(System.lineSeparator()); MgcpMessageParser parser = new MgcpMessageParser(); MgcpRequest request = parser.parseRequest(builder.toString()); assertEquals(MgcpRequestType.RQNT, request.getRequestType()); assertEquals(147483656, request.getTransactionId()); assertEquals("mobicents/ivr/1@127.0.0.1:2427", request.getEndpointId()); assertEquals("1", request.getParameter(MgcpParameterType.REQUEST_ID)); assertEquals("AU/pa(an=http: assertEquals("AU/oc(N),AU/of(N)", request.getParameter(MgcpParameterType.REQUESTED_EVENTS)); }
@Test public void testParseNtfyRequest() throws MgcpParseException { StringBuilder builder = new StringBuilder(); builder.append("NTFY 2 mobicents/ivr/1@127.0.0.1:2427").append(System.lineSeparator()); builder.append("N:restcomm@127.0.0.1:2727").append(System.lineSeparator()); builder.append("O:AU/oc(rc=100)").append(System.lineSeparator()); builder.append("X:1").append(System.lineSeparator()); MgcpMessageParser parser = new MgcpMessageParser(); MgcpRequest request = parser.parseRequest(builder.toString()); assertEquals(MgcpRequestType.NTFY, request.getRequestType()); assertEquals(2, request.getTransactionId()); assertEquals("mobicents/ivr/1@127.0.0.1:2427", request.getEndpointId()); assertEquals("1", request.getParameter(MgcpParameterType.REQUEST_ID)); assertEquals("AU/oc(rc=100)", request.getParameter(MgcpParameterType.OBSERVED_EVENT)); }