You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TicgitUtilsTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.tests;
  17. import java.util.List;
  18. import junit.framework.TestCase;
  19. import org.eclipse.jgit.lib.Repository;
  20. import com.gitblit.models.RefModel;
  21. import com.gitblit.models.TicketModel;
  22. import com.gitblit.models.TicketModel.Comment;
  23. import com.gitblit.utils.TicgitUtils;
  24. public class TicgitUtilsTest extends TestCase {
  25. public void testTicgitBranch() throws Exception {
  26. Repository repository = GitBlitSuite.getTicgitRepository();
  27. RefModel branch = TicgitUtils.getTicketsBranch(repository);
  28. repository.close();
  29. assertTrue("Ticgit branch does not exist!", branch != null);
  30. repository = GitBlitSuite.getHelloworldRepository();
  31. branch = TicgitUtils.getTicketsBranch(repository);
  32. repository.close();
  33. assertTrue("Ticgit branch exists!", branch == null);
  34. }
  35. public void testRetrieveTickets() throws Exception {
  36. Repository repository = GitBlitSuite.getTicgitRepository();
  37. List<TicketModel> ticketsA = TicgitUtils.getTickets(repository);
  38. List<TicketModel> ticketsB = TicgitUtils.getTickets(repository);
  39. repository.close();
  40. assertTrue("No tickets found!", ticketsA.size() > 0);
  41. for (int i = 0; i < ticketsA.size(); i++) {
  42. TicketModel ticketA = ticketsA.get(i);
  43. TicketModel ticketB = ticketsB.get(i);
  44. assertTrue("Tickets are not equal!", ticketA.equals(ticketB));
  45. assertFalse(ticketA.equals(""));
  46. assertTrue(ticketA.hashCode() == ticketA.id.hashCode());
  47. for (int j = 0; j < ticketA.comments.size(); j++) {
  48. Comment commentA = ticketA.comments.get(j);
  49. Comment commentB = ticketB.comments.get(j);
  50. assertTrue("Comments are not equal!", commentA.equals(commentB));
  51. assertFalse(commentA.equals(""));
  52. assertTrue(commentA.hashCode() == commentA.text.hashCode());
  53. }
  54. }
  55. repository = GitBlitSuite.getHelloworldRepository();
  56. List<TicketModel> ticketsC = TicgitUtils.getTickets(repository);
  57. repository.close();
  58. assertTrue(ticketsC == null);
  59. }
  60. public void testReadTicket() throws Exception {
  61. Repository repository = GitBlitSuite.getTicgitRepository();
  62. List<TicketModel> tickets = TicgitUtils.getTickets(repository);
  63. TicketModel ticket = TicgitUtils
  64. .getTicket(repository, tickets.get(tickets.size() - 1).name);
  65. repository.close();
  66. assertTrue(ticket != null);
  67. assertTrue(ticket.name
  68. .equals("1254123752_comments-on-ticgits-longer-than-5-lines-can-t-be-viewed-entirely_266"));
  69. }
  70. }