}
@Test
public void testLifecycle() throws Exception {
// query non-existent ticket
TicketModel nonExistent = service.getTicket(getRepository(), 0);
assertNull(nonExistent);
// create and insert a ticket
Change c1 = newChange("testCreation() " + Long.toHexString(System.currentTimeMillis()));
TicketModel ticket = service.createTicket(getRepository(), c1);
assertTrue(ticket.number > 0);
// retrieve ticket and compare
TicketModel constructed = service.getTicket(getRepository(), ticket.number);
compare(ticket, constructed);
assertEquals(1, constructed.changes.size());
// C1: create the ticket
int changeCount = 0;
c1 = newChange("testUpdates() " + Long.toHexString(System.currentTimeMillis()));
ticket = service.createTicket(getRepository(), c1);
assertTrue(ticket.number > 0);
changeCount++;
constructed = service.getTicket(getRepository(), ticket.number);
compare(ticket, constructed);
assertEquals(1, constructed.changes.size());
// C2: set owner
Change c2 = new Change("C2");
c2.comment("I'll fix this");
c2.setField(Field.responsible, c2.author);
constructed = service.updateTicket(getRepository(), ticket.number, c2);
assertNotNull(constructed);
assertEquals(2, constructed.changes.size());
assertEquals(c2.author, constructed.responsible);
changeCount++;
// C3: add a note
Change c3 = new Change("C3");
c3.comment("yeah, this is working");
constructed = service.updateTicket(getRepository(), ticket.number, c3);
assertNotNull(constructed);
assertEquals(3, constructed.changes.size());
changeCount++;
if (service.supportsAttachments()) {
// C4: add attachment
Change c4 = new Change("C4");
Attachment a = newAttachment();
c4.addAttachment(a);
constructed = service.updateTicket(getRepository(), ticket.number, c4);
assertNotNull(constructed);
assertTrue(constructed.hasAttachments());
Attachment a1 = service.getAttachment(getRepository(), ticket.number, a.name);
assertEquals(a.content.length, a1.content.length);
assertTrue(Arrays.areEqual(a.content, a1.content));
changeCount++;
}
// C5: close the issue
Change c5 = new Change("C5");
c5.comment("closing issue");
c5.setField(Field.status, Status.Resolved);
constructed = service.updateTicket(getRepository(), ticket.number, c5);
assertNotNull(constructed);
changeCount++;
assertTrue(constructed.isClosed());
assertEquals(changeCount, constructed.changes.size());
List<TicketModel> allTickets = service.getTickets(getRepository());
List<TicketModel> openTickets = service.getTickets(getRepository(), new TicketFilter() {
@Override