RtcpAttributeParser implements SdpParser<RtcpAttribute> { @Override public RtcpAttribute parse(String sdp) throws SdpException { try { int separator = sdp.indexOf(AttributeField.ATTRIBUTE_SEPARATOR); if(separator == -1) { throw new IllegalArgumentException("No value found"); } String[] values = sdp.trim().substring(separator + 1).split(" "); int port = Integer.parseInt(values[0]); if(values.length > 1) { String netType= values[1]; String addressType = values[2]; String address = values[3]; return new RtcpAttribute(port, netType, addressType, address); } return new RtcpAttribute(port); } catch (Exception e) { throw new SdpException(PARSE_ERROR + sdp, e); } }  @Override boolean canParse(String sdp); @Override RtcpAttribute parse(String sdp); @Override void parse(RtcpAttribute field, String sdp);  }
@Test public void testParseSimpleAttribute() throws SdpException { String sdp1 = "a=rtcp:65000\n\r"; RtcpAttribute obj = parser.parse(sdp1); Assert.assertEquals(65000, obj.getPort()); Assert.assertNull(obj.getNetworkType()); Assert.assertNull(obj.getAddressType()); Assert.assertNull(obj.getAddress()); }
@Test public void testParseComplexAttribute() throws SdpException { String sdp1 = "a=rtcp:65000 IN IP4 127.0.0.1\n\r"; RtcpAttribute obj = parser.parse(sdp1); Assert.assertEquals(65000, obj.getPort()); Assert.assertEquals("IN", obj.getNetworkType()); Assert.assertEquals("IP4", obj.getAddressType()); Assert.assertEquals("127.0.0.1", obj.getAddress()); }
@Test public void testParseSimpleToComplexOverwrite() throws SdpException { String sdp1 = "a=rtcp:65000\n\r"; String sdp2 = "a=rtcp:64000 IN IP4 127.0.0.1\n\r"; RtcpAttribute obj = parser.parse(sdp1); parser.parse(obj, sdp2); Assert.assertEquals(64000, obj.getPort()); Assert.assertEquals("IN", obj.getNetworkType()); Assert.assertEquals("IP4", obj.getAddressType()); Assert.assertEquals("127.0.0.1", obj.getAddress()); }
@Test public void testParseComplexToSimpleOverwrite() throws SdpException { String sdp1 = "a=rtcp:64000 IN IP4 127.0.0.1\n\r"; String sdp2 = "a=rtcp:65000\n\r"; RtcpAttribute obj = parser.parse(sdp1); parser.parse(obj, sdp2); Assert.assertEquals(65000, obj.getPort()); Assert.assertNull(obj.getNetworkType()); Assert.assertNull(obj.getAddressType()); Assert.assertNull(obj.getAddress()); }