RtpTimeoutEventParser { public static RtpTimeoutEvent parse(int connectionId, String... parameters) throws MgcpParseException { int timeout = 0; RtpTimeoutStartTime when = RtpTimeoutStartTime.IMMEDIATE; try { for (String parameter : parameters) { if (TIMEOUT_PATTERN.matcher(parameter).matches()) { timeout = Integer.parseInt(parameter); } else if (START_TIME_PATTERN.matcher(parameter).matches()) { int indexOfEqual = parameter.indexOf("="); when = RtpTimeoutStartTime.fromSymbol(parameter.substring(indexOfEqual + 1)); if (when == null) { throw new IllegalArgumentException("Unknown R/rto Start Time parameter: " + parameter); } } } if (timeout <= 0) { throw new IllegalArgumentException("R/rto timeout parameter must be a positive value."); } } catch (Exception e) { throw new MgcpParseException("Could not parse parameters RTP Timeout event.", e); } return new RtpTimeoutEvent(connectionId, timeout, when); }  static RtpTimeoutEvent parse(int connectionId, String... parameters);  }
@Test public void testParseTimeoutandStartTimeParameters() throws MgcpParseException { final int connectionId = 5; final String timeout = "10"; final RtpTimeoutStartTime startTime = RtpTimeoutStartTime.WAIT_RTCP; final String startTimeParam = "st=" + startTime.symbol(); final RtpTimeoutEvent rtpTimeout = RtpTimeoutEventParser.parse(connectionId, timeout, startTimeParam); assertEquals(connectionId, rtpTimeout.getConnectionId()); assertEquals(Integer.parseInt(timeout), rtpTimeout.getTimeout()); assertEquals(RtpTimeoutStartTime.WAIT_RTCP, rtpTimeout.getWhen()); }
@Test public void testDefaultStartTime() throws MgcpParseException { final int connectionId = 5; final String timeout = "10"; final RtpTimeoutEvent rtpTimeout = RtpTimeoutEventParser.parse(connectionId, timeout); assertEquals(Integer.parseInt(timeout), rtpTimeout.getTimeout()); assertEquals(RtpTimeoutStartTime.IMMEDIATE, rtpTimeout.getWhen()); }
@Test(expected = MgcpParseException.class) public void testParseInvalidTimeoutParameter() throws MgcpParseException { final int connectionId = 5; final String timeout = "-1"; RtpTimeoutEventParser.parse(connectionId, timeout); }
@Test(expected = MgcpParseException.class) public void testParseMissingTimeoutParameter() throws MgcpParseException { final int connectionId = 5; final RtpTimeoutStartTime startTime = RtpTimeoutStartTime.WAIT_RTCP; final String startTimeParam = "st=" + startTime.symbol(); RtpTimeoutEventParser.parse(connectionId, startTimeParam); }
@Test(expected = MgcpParseException.class) public void testParseUnknownStartTimeParameter() throws MgcpParseException { final int connectionId = 5; final String startTime = "st=xxx"; RtpTimeoutEventParser.parse(connectionId, startTime); }