public void testSimple() throws Exception
{
Presentity presentity = new Presentity("sip:alice@cipango.org");
assertTrue(presentity.isDone());
PresenceDocument doc = (PresenceDocument) presentity.getState().getContent();
assertEquals(presentity.getNeutralState().getContent().toString(),
doc.toString());
PresenceDocument doc1 = PresenceDocument.Factory.newInstance();
Tuple tuple1 = doc1.addNewPresence().addNewTuple();
tuple1.setId("tuple1");
tuple1.addNewStatus().setBasic(Basic.OPEN);
SoftState state1 = presentity.addState(PresenceEventPackage.PIDF, doc1, 60);
doc = (PresenceDocument) presentity.getState().getContent();
assertEquals(1, doc.getPresence().getTupleArray().length);
assertEquals("tuple1",
doc.getPresence().getTupleArray(0).getId());
assertEquals(Basic.OPEN,
doc.getPresence().getTupleArray(0).getStatus().getBasic());
PresenceDocument doc2 = PresenceDocument.Factory.newInstance();
Tuple tuple2 = doc2.addNewPresence().addNewTuple();
tuple2.setId("tuple2");
tuple2.addNewStatus().setBasic(Basic.CLOSED);
SoftState state2 = presentity.addState(PresenceEventPackage.PIDF, doc2, 60);
doc = (PresenceDocument) presentity.getState().getContent();
assertEquals(2, doc.getPresence().getTupleArray().length);
assertEquals("tuple1",
doc.getPresence().getTupleArray(0).getId());
assertEquals(Basic.OPEN,
doc.getPresence().getTupleArray(0).getStatus().getBasic());
assertEquals("tuple2",
doc.getPresence().getTupleArray(1).getId());
assertEquals(Basic.CLOSED,
doc.getPresence().getTupleArray(1).getStatus().getBasic());
assertFalse(presentity.isDone());
presentity.removeState(state1.getETag());
assertNull(presentity.getState(state1.getETag()));
doc = (PresenceDocument) presentity.getState().getContent();
assertEquals(1, doc.getPresence().getTupleArray().length);
assertEquals("tuple2",
doc.getPresence().getTupleArray(0).getId());
String etag = state2.getETag();
assertEquals(state2, presentity.getState(etag));
doc2 = (PresenceDocument) doc2.copy();
doc2.getPresence().getTupleArray(0).getStatus().setBasic(Basic.OPEN);
presentity.modifyState(state2, PresenceEventPackage.PIDF, doc2, 30);
doc = (PresenceDocument) presentity.getState().getContent();
assertEquals(Basic.OPEN,
doc.getPresence().getTupleArray(0).getStatus().getBasic());
assertNotSame(etag, state2.getETag());