use of com.gitblit.tickets.ITicketService.TicketFilter in project gitblit by gitblit.
the class TicketServiceTest method testLifecycle.
@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
public boolean accept(TicketModel ticket) {
return ticket.isOpen();
}
});
List<TicketModel> closedTickets = service.getTickets(getRepository(), new TicketFilter() {
@Override
public boolean accept(TicketModel ticket) {
return ticket.isClosed();
}
});
assertTrue(allTickets.size() > 0);
assertEquals(1, openTickets.size());
assertEquals(1, closedTickets.size());
// build a new Lucene index
service.reindex(getRepository());
List<QueryResult> hits = service.searchFor(getRepository(), "working", 1, 10);
assertEquals(1, hits.size());
// reindex a ticket
ticket = allTickets.get(0);
Change change = new Change("reindex");
change.comment("this is a test of reindexing a ticket");
service.updateTicket(getRepository(), ticket.number, change);
ticket = service.getTicket(getRepository(), ticket.number);
hits = service.searchFor(getRepository(), "reindexing", 1, 10);
assertEquals(1, hits.size());
service.stop();
service = getService(false);
// Lucene field query
List<QueryResult> results = service.queryFor(Lucene.status.matches(Status.New.name()), 1, 10, Lucene.created.name(), true);
assertEquals(1, results.size());
assertTrue(results.get(0).title.startsWith("testCreation"));
// Lucene field query
results = service.queryFor(Lucene.status.matches(Status.Resolved.name()), 1, 10, Lucene.created.name(), true);
assertEquals(1, results.size());
assertTrue(results.get(0).title.startsWith("testUpdates"));
// check the ids
assertEquals("[1, 2]", service.getIds(getRepository()).toString());
// delete all tickets
for (TicketModel aTicket : allTickets) {
assertTrue(service.deleteTicket(getRepository(), aTicket.number, "D"));
}
}
Aggregations