// Ensure Alice is not registered
RegisterSession registerSession = new RegisterSession(getAlicePhone());
registerSession.register(null, 0);
SubscribeSession session = new SubscribeSession(getAlicePhone(), "reg");
Request subscribe = session.newInitialSubscribe(100, getAliceUri()); // 1
session.sendRequest(subscribe, Response.OK); // 2
ServerTransaction tx = session.waitForNotify();
Request notify = tx.getRequest(); // 3
//System.out.println(notify);
session.sendResponse(Response.OK, tx); // 4
SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
assertBetween(95, 100, subState.getExpires());
assertEquals("reg", ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
Reginfo regInfo = getRegInfo(notify);
int version = regInfo.getVersion().intValue();
Registration registration = regInfo.getRegistrationArray(0);
assertEquals(State.INIT, registration.getState());
assertEquals(getAliceUri(), registration.getAor());
assertEquals(0, registration.getContactArray().length);
registerSession.register(null, 1800); // 5 and 6
tx = session.waitForNotify();
notify = tx.getRequest(); // 7
//System.out.println(notify);
session.sendResponse(Response.OK, tx); // 8
regInfo = getRegInfo(notify);
registration = regInfo.getRegistrationArray(0);
assertEquals(1, registration.getContactArray().length);
assertEquals(version + 1, regInfo.getVersion().intValue());
assertEquals(State.ACTIVE, registration.getState());
Contact contact = registration.getContactArray(0);
assertBetween(1795, 1800, contact.getExpires().intValue());
assertEquals(Event.REGISTERED, contact.getEvent());
registerSession.register(null, 0); // 9 and 10
tx = session.waitForNotify();
notify = tx.getRequest(); // 11
//System.out.println(notify);
session.sendResponse(Response.OK, tx); // 12
regInfo = getRegInfo(notify);
registration = regInfo.getRegistrationArray(0);
assertEquals(1, registration.getContactArray().length);
assertEquals(version + 2, regInfo.getVersion().intValue());
assertEquals(State.TERMINATED, registration.getState());
contact = registration.getContactArray(0);
assertEquals(0, contact.getExpires().intValue());
assertEquals(Event.UNREGISTERED, contact.getEvent());
subscribe = session.newSubsequentSubscribe(0); // 13
session.sendRequest(subscribe, Response.OK); // 14
tx = session.waitForNotify();
notify = tx.getRequest(); // 15
//System.out.println(notify);
session.sendResponse(Response.OK, tx); // 16
subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
assertEquals(SubscriptionStateHeader.TERMINATED.toLowerCase(),
subState.getState());
regInfo = getRegInfo(notify);
registration = regInfo.getRegistrationArray(0);
assertEquals(State.TERMINATED, registration.getState());