@Test
public void testCreateDeleteMessages() throws IOException, SQLException {
RMMessage msg1 = control.createMock(RMMessage.class);
RMMessage msg2 = control.createMock(RMMessage.class);
Identifier sid1 = new Identifier();
sid1.setValue("sequence1");
EasyMock.expect(msg1.getMessageNumber()).andReturn(ONE).anyTimes();
EasyMock.expect(msg2.getMessageNumber()).andReturn(ONE).anyTimes();
byte[] bytes = new byte[89];
EasyMock.expect(msg1.getContent()).andReturn(new ByteArrayInputStream(bytes)).anyTimes();
EasyMock.expect(msg2.getContent()).andReturn(new ByteArrayInputStream(bytes)).anyTimes();
EasyMock.expect(msg1.getAttachments()).andReturn(new ArrayList<InputStream>()).anyTimes();
EasyMock.expect(msg2.getAttachments()).andReturn(new ArrayList<InputStream>()).anyTimes();
control.replay();
Connection con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
store.storeMessage(con, sid1, msg2, false);
store.commit(con);
} finally {
releaseConnection(con);
}
control.verify();
control.reset();
EasyMock.expect(msg1.getMessageNumber()).andReturn(ONE);
EasyMock.expect(msg1.getContent()).andReturn(new ByteArrayInputStream(bytes));
control.replay();
con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
} catch (SQLException ex) {
assertEquals("23505", ex.getSQLState());
store.abort(con);
} finally {
releaseConnection(con);
}
control.verify();
control.reset();
EasyMock.expect(msg1.getMessageNumber()).andReturn(TEN).anyTimes();
EasyMock.expect(msg2.getMessageNumber()).andReturn(TEN).anyTimes();
EasyMock.expect(msg1.getContent()).andReturn(new ByteArrayInputStream(bytes)).anyTimes();
EasyMock.expect(msg2.getContent()).andReturn(new ByteArrayInputStream(bytes)).anyTimes();
EasyMock.expect(msg1.getAttachments()).andReturn(new ArrayList<InputStream>()).anyTimes();
EasyMock.expect(msg2.getAttachments()).andReturn(new ArrayList<InputStream>()).anyTimes();
control.replay();
con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
store.storeMessage(con, sid1, msg2, false);
store.commit(con);
} finally {
releaseConnection(con);
}
control.verify();
Collection<Long> messageNrs = new ArrayList<Long>();
messageNrs.add(ZERO);
messageNrs.add(TEN);
messageNrs.add(ONE);
messageNrs.add(TEN);
store.removeMessages(sid1, messageNrs, true);
store.removeMessages(sid1, messageNrs, false);
Identifier sid2 = new Identifier();
sid1.setValue("sequence2");
store.removeMessages(sid2, messageNrs, true);
}