SsrcAttributeParser implements SdpParser<SsrcAttribute> { @Override public SsrcAttribute parse(String sdp) throws SdpException { try { String[] values = sdp.trim().substring(7).split(WHITESPACE); int separator = values[1].indexOf(COLON); String attName = (separator == -1) ? values[1] : values[1].substring(0, separator); String attValue = (separator == -1) ? null : values[1].substring(separator + 1); SsrcAttribute ssrc = new SsrcAttribute(values[0]); ssrc.addAttribute(attName, attValue); return ssrc; } catch (Exception e) { throw new SdpException(PARSE_ERROR + sdp, e); } }  @Override boolean canParse(String sdp); @Override SsrcAttribute parse(String sdp); @Override void parse(SsrcAttribute field, String sdp);  }
@Test public void testParseSimpleAttribute() throws SdpException { String sdp1 = "a=ssrc:1993357196 xyz\n\r"; SsrcAttribute ssrc = parser.parse(sdp1); Assert.assertNotNull(ssrc); Assert.assertEquals("1993357196", ssrc.getSsrcId()); Assert.assertNull(ssrc.getAttributeValue("xyz")); }
@Test public void testParseComplexAttribute() throws SdpException { String sdp1 = "a=ssrc:1993357196 cname:rfQMs6/rvuHHWkM4\n\r"; SsrcAttribute ssrc = parser.parse(sdp1); Assert.assertNotNull(ssrc); Assert.assertEquals("1993357196", ssrc.getSsrcId()); Assert.assertEquals("rfQMs6/rvuHHWkM4", ssrc.getAttributeValue("cname")); }
@Test public void testParseOverwriteSameSsrc() throws SdpException { String sdp1 = "a=ssrc:1993357196 cname:rfQMs6/rvuHHWkM4\n\r"; String sdp2 = "a=ssrc:1993357196 label:753ad6b1-31a6-4fea-8070-269c6df6ff0e\n\r"; SsrcAttribute ssrc = parser.parse(sdp1); parser.parse(ssrc, sdp2); Assert.assertNotNull(ssrc); Assert.assertEquals("1993357196", ssrc.getSsrcId()); Assert.assertEquals("rfQMs6/rvuHHWkM4", ssrc.getAttributeValue("cname")); Assert.assertEquals("753ad6b1-31a6-4fea-8070-269c6df6ff0e", ssrc.getAttributeValue("label")); }
@Test public void testParseOverwriteNewSsrc() throws SdpException { String sdp1 = "a=ssrc:1993357196 cname:rfQMs6/rvuHHWkM4\n\r"; String sdp2 = "a=ssrc:1111111111 label:753ad6b1-31a6-4fea-8070-269c6df6ff0e\n\r"; SsrcAttribute ssrc = parser.parse(sdp1); parser.parse(ssrc, sdp2); Assert.assertNotNull(ssrc); Assert.assertEquals("1111111111", ssrc.getSsrcId()); Assert.assertNull(ssrc.getAttributeValue("cname")); Assert.assertEquals("753ad6b1-31a6-4fea-8070-269c6df6ff0e", ssrc.getAttributeValue("label")); }