Message[] messages = createMessages(10);
for (int i = 0; i < 5; i++)
{
Message m1 = messages[i * 2];
Message m2 = messages[i * 2 + 1];
MessageReference ref1_1 = ms.reference(m1);
MessageReference ref1_2 = ms.reference(m1);
MessageReference ref2_1 = ms.reference(m2);
MessageReference ref2_2 = ms.reference(m2);
pm.addReference(channel1.getChannelID(), ref1_1, null);
pm.addReference(channel1.getChannelID(), ref2_1, null);
pm.addReference(channel2.getChannelID(), ref1_2, null);
pm.addReference(channel2.getChannelID(), ref2_2, null);
List refs = getReferenceIds(channel1.getChannelID());
assertNotNull(refs);
assertEquals(2, refs.size());
assertTrue(refs.contains(new Long(m1.getMessageID())));
assertTrue(refs.contains(new Long(m2.getMessageID())));
refs = getReferenceIds(channel2.getChannelID());
assertNotNull(refs);
assertEquals(2, refs.size());
assertTrue(refs.contains(new Long(m1.getMessageID())));
assertTrue(refs.contains(new Long(m2.getMessageID())));
List msgs = getMessageIds();
assertNotNull(msgs);
assertEquals(2, msgs.size());
assertTrue(msgs.contains(new Long(m1.getMessageID())));
assertTrue(msgs.contains(new Long(m2.getMessageID())));
pm.removeReference(channel1.getChannelID(), ref1_1, null);
refs = getReferenceIds(channel1.getChannelID());
assertNotNull(refs);
assertEquals(1, refs.size());
assertTrue(refs.contains(new Long(m2.getMessageID())));
refs = getReferenceIds(channel2.getChannelID());
assertNotNull(refs);
assertEquals(2, refs.size());
assertTrue(refs.contains(new Long(m1.getMessageID())));
assertTrue(refs.contains(new Long(m2.getMessageID())));
msgs = getMessageIds();
assertNotNull(msgs);
assertEquals(2, msgs.size());
assertTrue(msgs.contains(new Long(m1.getMessageID())));
assertTrue(msgs.contains(new Long(m2.getMessageID())));
pm.removeReference(channel2.getChannelID(), ref1_2, null);
refs = getReferenceIds(channel1.getChannelID());
assertNotNull(refs);
assertEquals(1, refs.size());
assertTrue(refs.contains(new Long(m2.getMessageID())));
refs = getReferenceIds(channel2.getChannelID());
assertNotNull(refs);
assertEquals(1, refs.size());
assertTrue(refs.contains(new Long(m2.getMessageID())));
msgs = getMessageIds();
assertNotNull(msgs);
assertEquals(1, msgs.size());
assertTrue(msgs.contains(new Long(m2.getMessageID())));
pm.removeReference(channel1.getChannelID(), ref2_1, null);
refs = getReferenceIds(channel1.getChannelID());
assertNotNull(refs);
assertTrue(refs.isEmpty());
refs = getReferenceIds(channel2.getChannelID());
assertNotNull(refs);
assertEquals(1, refs.size());
assertTrue(refs.contains(new Long(m2.getMessageID())));
msgs = getMessageIds();
assertNotNull(msgs);
assertEquals(1, msgs.size());
assertTrue(msgs.contains(new Long(m2.getMessageID())));
pm.removeReference(channel2.getChannelID(), ref2_2, null);
refs = getReferenceIds(channel1.getChannelID());
assertNotNull(refs);