James Moger
2012-08-07 749110b462b3147c6dfff076fb5d1bf0460a4f99
commit | author | age
793f76 1 /*
JM 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
7e8873 18 import static org.junit.Assert.assertEquals;
JM 19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue;
23
793f76 24 import java.util.List;
JM 25
26 import org.eclipse.jgit.lib.Repository;
7e8873 27 import org.junit.Test;
793f76 28
JM 29 import com.gitblit.models.RefModel;
30 import com.gitblit.models.TicketModel;
31 import com.gitblit.models.TicketModel.Comment;
32 import com.gitblit.utils.TicgitUtils;
33
7e8873 34 public class TicgitUtilsTest {
793f76 35
7e8873 36     @Test
a125cf 37     public void testTicgitBranch() throws Exception {
793f76 38         Repository repository = GitBlitSuite.getTicgitRepository();
JM 39         RefModel branch = TicgitUtils.getTicketsBranch(repository);
a125cf 40         repository.close();
7e8873 41         assertNotNull("Ticgit branch does not exist!", branch);
008322 42
a125cf 43         repository = GitBlitSuite.getHelloworldRepository();
JM 44         branch = TicgitUtils.getTicketsBranch(repository);
45         repository.close();
7e8873 46         assertNull("Ticgit branch exists!", branch);
a125cf 47     }
JM 48
7e8873 49     @Test
a125cf 50     public void testRetrieveTickets() throws Exception {
JM 51         Repository repository = GitBlitSuite.getTicgitRepository();
793f76 52         List<TicketModel> ticketsA = TicgitUtils.getTickets(repository);
JM 53         List<TicketModel> ticketsB = TicgitUtils.getTickets(repository);
54         repository.close();
55         assertTrue("No tickets found!", ticketsA.size() > 0);
56         for (int i = 0; i < ticketsA.size(); i++) {
57             TicketModel ticketA = ticketsA.get(i);
58             TicketModel ticketB = ticketsB.get(i);
59             assertTrue("Tickets are not equal!", ticketA.equals(ticketB));
60             assertFalse(ticketA.equals(""));
61             assertTrue(ticketA.hashCode() == ticketA.id.hashCode());
62             for (int j = 0; j < ticketA.comments.size(); j++) {
63                 Comment commentA = ticketA.comments.get(j);
64                 Comment commentB = ticketB.comments.get(j);
65                 assertTrue("Comments are not equal!", commentA.equals(commentB));
66                 assertFalse(commentA.equals(""));
7e8873 67                 assertEquals(commentA.hashCode(), commentA.text.hashCode());
793f76 68             }
JM 69         }
008322 70
a125cf 71         repository = GitBlitSuite.getHelloworldRepository();
JM 72         List<TicketModel> ticketsC = TicgitUtils.getTickets(repository);
73         repository.close();
7e8873 74         assertNull(ticketsC);
a125cf 75     }
JM 76
7e8873 77     @Test
a125cf 78     public void testReadTicket() throws Exception {
JM 79         Repository repository = GitBlitSuite.getTicgitRepository();
80         List<TicketModel> tickets = TicgitUtils.getTickets(repository);
81         TicketModel ticket = TicgitUtils
82                 .getTicket(repository, tickets.get(tickets.size() - 1).name);
83         repository.close();
7e8873 84         assertNotNull(ticket);
f3ce6e 85         assertEquals("1206206148_add-attachment-to-ticket_138", ticket.name);
793f76 86     }
JM 87 }