LocalConnectionOptionsParser { public LocalConnectionOptions parse(String options) throws MgcpParseException { LocalConnectionOptions obj = new LocalConnectionOptions(); try { String[] tokens = options.split(","); for (String token : tokens) { token = token.trim(); int separator = token.indexOf(":"); if (separator == -1) { LocalConnectionOptionType option = LocalConnectionOptionType.fromCode(token); obj.add(option, ""); } else { String code = token.substring(0, separator); try { LocalConnectionOptionType option = LocalConnectionOptionType.fromCode(code); String value = token.substring(separator + 1); obj.add(option, value); } catch (IllegalArgumentException e) { log.warn("Skipping unknown option: " + code); } } } return obj; } catch (Exception e) { throw new MgcpParseException("Could not parse Local Connection Options.", e); } }  LocalConnectionOptions parse(String options); static final LocalConnectionOptionsParser INSTANCE; }
@Test public void testParsingSuccessful() throws MgcpParseException { String text = "p:20, a:PCMU;PCMA;G726-32, e:on, s:off, t:00, webrtc:true"; LocalConnectionOptionsParser parser = new LocalConnectionOptionsParser(); LocalConnectionOptions options = parser.parse(text); Assert.assertEquals("20", options.get(LocalConnectionOptionType.PACKETIZATION_PERIOD)); Assert.assertEquals("PCMU;PCMA;G726-32", options.get(LocalConnectionOptionType.CODECS)); Assert.assertEquals("on", options.get(LocalConnectionOptionType.ECHO_CANCELATION)); Assert.assertEquals("off", options.get(LocalConnectionOptionType.SILENCE_SUPPRESSION)); Assert.assertEquals("00", options.get(LocalConnectionOptionType.TYPE_OF_SERVICE)); Assert.assertEquals("true", options.get(LocalConnectionOptionType.WEBRTC)); Assert.assertNull(options.get(LocalConnectionOptionType.BANDWIDTH)); Assert.assertNull(options.get(LocalConnectionOptionType.TYPE_OF_NETWORK)); Assert.assertNull(options.get(LocalConnectionOptionType.GAIN_CONTROL)); Assert.assertNull(options.get(LocalConnectionOptionType.RESOURCE_RESERVATION)); Assert.assertNull(options.get(LocalConnectionOptionType.ENCRYPTION_KEY)); Assert.assertNull(options.get(LocalConnectionOptionType.DTMF_CLAMP)); Assert.assertNull(options.get(LocalConnectionOptionType.BANDWIDTH)); Assert.assertNull(options.get(LocalConnectionOptionType.BANDWIDTH)); }
@Test public void testParsingSkipUnknownOption() throws MgcpParseException { String text = "p:20, a:PCMU;PCMA;G726-32, e:on, s:off, t:00, webrtc:true, XYZ:???"; LocalConnectionOptionsParser parser = new LocalConnectionOptionsParser(); LocalConnectionOptions options = parser.parse(text); Assert.assertEquals("20", options.get(LocalConnectionOptionType.PACKETIZATION_PERIOD)); Assert.assertEquals("PCMU;PCMA;G726-32", options.get(LocalConnectionOptionType.CODECS)); Assert.assertEquals("on", options.get(LocalConnectionOptionType.ECHO_CANCELATION)); Assert.assertEquals("off", options.get(LocalConnectionOptionType.SILENCE_SUPPRESSION)); Assert.assertEquals("00", options.get(LocalConnectionOptionType.TYPE_OF_SERVICE)); Assert.assertEquals("true", options.get(LocalConnectionOptionType.WEBRTC)); Assert.assertNull(options.get(LocalConnectionOptionType.BANDWIDTH)); Assert.assertNull(options.get(LocalConnectionOptionType.TYPE_OF_NETWORK)); Assert.assertNull(options.get(LocalConnectionOptionType.GAIN_CONTROL)); Assert.assertNull(options.get(LocalConnectionOptionType.RESOURCE_RESERVATION)); Assert.assertNull(options.get(LocalConnectionOptionType.ENCRYPTION_KEY)); Assert.assertNull(options.get(LocalConnectionOptionType.DTMF_CLAMP)); Assert.assertNull(options.get(LocalConnectionOptionType.BANDWIDTH)); Assert.assertNull(options.get(LocalConnectionOptionType.BANDWIDTH)); }