@SuppressWarnings("unchecked")
public void testMultipleContacts() throws Exception
{
RegisterSession session = new RegisterSession(getAlicePhone());
Request request = session.createRegister(null, 1800);
ContactHeader contact2 = newContact("<sip:localhost>");
contact2.setExpires(1500);
request.addHeader(contact2);
Response response =
session.sendRegistrationMessage(request, Response.OK);
ListIterator<ContactHeader> contacts = response.getHeaders(ContactHeader.NAME);
while (contacts.hasNext()) {
ContactHeader contact = (ContactHeader) contacts.next();
if (contact.getExpires() > 1795 && contact.getExpires() <= 1800)
assertEquals(getAlicePhone().getContactInfo().getContactHeader().getAddress(), contact.getAddress());
else
{
assertBetween(contact2.getExpires() -5, contact2.getExpires(), contact.getExpires());
assertEquals(contact2.getAddress(), contact.getAddress());
}
}
request = session.createRegister(contact2.getAddress().toString(), 0);
response = session.sendRegistrationMessage(request, Response.OK);
contacts = response.getHeaders(ContactHeader.NAME);
ContactHeader contact = contacts.next();
assertBetween(1780, 1800, contact.getExpires());
assertEquals(getAlicePhone().getContactInfo().getContactHeader().getAddress(), contact.getAddress());
assertFalse(contacts.hasNext());
}