diff options
author | James Moger <james.moger@gitblit.com> | 2013-12-09 17:19:03 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-03-03 21:34:32 -0500 |
commit | 5e3521f8496511db4df45f011ea72f25623ad90f (patch) | |
tree | 98b4f516d59833b5a8c1ccbcd45672e5b9f3add2 /src/test | |
parent | 94e12c168f5eec300fd23d0de25c7dc93a96c429 (diff) | |
download | gitblit-5e3521f8496511db4df45f011ea72f25623ad90f.tar.gz gitblit-5e3521f8496511db4df45f011ea72f25623ad90f.zip |
Ticket tracker with patchset contributions
A basic issue tracker styled as a hybrid of GitHub and BitBucket issues.
You may attach commits to an existing ticket or you can push a single
commit to create a *proposal* ticket.
Tickets keep track of patchsets (one or more commits) and allow patchset
rewriting (rebase, amend, squash) by detecing the non-fast-forward
update and assigning a new patchset number to the new commits.
Ticket tracker
--------------
The ticket tracker stores tickets as an append-only journal of changes.
The journals are deserialized and a ticket is built by applying the
journal entries. Tickets are indexed using Apache Lucene and all
queries and searches are executed against this Lucene index.
There is one trade-off to this persistence design: user attributions are
non-relational.
What does that mean? Each journal entry stores the username of the
author. If the username changes in the user service, the journal entry
will not reflect that change because the values are hard-coded.
Here are a few reasons/justifications for this design choice:
1. commit identifications (author, committer, tagger) are non-relational
2. maintains the KISS principle
3. your favorite text editor can still be your administration tool
Persistence Choices
-------------------
**FileTicketService**: stores journals on the filesystem
**BranchTicketService**: stores journals on an orphan branch
**RedisTicketService**: stores journals in a Redis key-value datastore
It should be relatively straight-forward to develop other backends
(MongoDB, etc) as long as the journal design is preserved.
Pushing Commits
---------------
Each push to a ticket is identified as a patchset revision. A patchset
revision may add commits to the patchset (fast-forward) OR a patchset
revision may rewrite history (rebase, squash, rebase+squash, or amend).
Patchset authors should not be afraid to polish, revise, and rewrite
their code before merging into the proposed branch.
Gitblit will create one ref for each patchset. These refs are updated
for fast-forward pushes or created for rewrites. They are formatted as
`refs/tickets/{shard}/{id}/{patchset}`. The *shard* is the last two
digits of the id. If the id < 10, prefix a 0. The *shard* is always
two digits long. The shard's purpose is to ensure Gitblit doesn't
exceed any filesystem directory limits for file creation.
**Creating a Proposal Ticket**
You may create a new change proposal ticket just by pushing a **single
commit** to `refs/for/{branch}` where branch is the proposed integration
branch OR `refs/for/new` or `refs/for/default` which both will use the
default repository branch.
git push origin HEAD:refs/for/new
**Updating a Patchset**
The safe way to update an existing patchset is to push to the patchset
ref.
git push origin HEAD:refs/heads/ticket/{id}
This ensures you do not accidentally create a new patchset in the event
that the patchset was updated after you last pulled.
The not-so-safe way to update an existing patchset is to push using the
magic ref.
git push origin HEAD:refs/for/{id}
This push ref will update an exisitng patchset OR create a new patchset
if the update is non-fast-forward.
**Rebasing, Squashing, Amending**
Gitblit makes rebasing, squashing, and amending patchsets easy.
Normally, pushing a non-fast-forward update would require rewind (RW+)
repository permissions. Gitblit provides a magic ref which will allow
ticket participants to rewrite a ticket patchset as long as the ticket
is open.
git push origin HEAD:refs/for/{id}
Pushing changes to this ref allows the patchset authors to rebase,
squash, or amend the patchset commits without requiring client-side use
of the *--force* flag on push AND without requiring RW+ permission to
the repository. Since each patchset is tracked with a ref it is easy to
recover from accidental non-fast-forward updates.
Features
--------
- Ticket tracker with status changes and responsible assignments
- Patchset revision scoring mechanism
- Update/Rewrite patchset handling
- Close-on-push detection
- Server-side Merge button for simple merges
- Comments with Markdown syntax support
- Rich mail notifications
- Voting
- Mentions
- Watch lists
- Querying
- Searches
- Partial miletones support
- Multiple backend options
Diffstat (limited to 'src/test')
5 files changed, 568 insertions, 1 deletions
diff --git a/src/test/java/com/gitblit/tests/BranchTicketServiceTest.java b/src/test/java/com/gitblit/tests/BranchTicketServiceTest.java new file mode 100644 index 00000000..4bd74f51 --- /dev/null +++ b/src/test/java/com/gitblit/tests/BranchTicketServiceTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.tests; + +import com.gitblit.IStoredSettings; +import com.gitblit.manager.INotificationManager; +import com.gitblit.manager.IRepositoryManager; +import com.gitblit.manager.IRuntimeManager; +import com.gitblit.manager.IUserManager; +import com.gitblit.manager.NotificationManager; +import com.gitblit.manager.RepositoryManager; +import com.gitblit.manager.RuntimeManager; +import com.gitblit.manager.UserManager; +import com.gitblit.models.RepositoryModel; +import com.gitblit.tickets.BranchTicketService; +import com.gitblit.tickets.ITicketService; + +/** + * Tests the branch ticket service. + * + * @author James Moger + * + */ +public class BranchTicketServiceTest extends TicketServiceTest { + + final RepositoryModel repo = new RepositoryModel("tickets/branch.git", null, null, null); + + @Override + protected RepositoryModel getRepository() { + return repo; + } + + + @Override + protected ITicketService getService(boolean deleteAll) throws Exception { + + IStoredSettings settings = getSettings(deleteAll); + + IRuntimeManager runtimeManager = new RuntimeManager(settings).start(); + INotificationManager notificationManager = new NotificationManager(settings).start(); + IUserManager userManager = new UserManager(runtimeManager).start(); + IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, userManager).start(); + + BranchTicketService service = new BranchTicketService( + runtimeManager, + notificationManager, + userManager, + repositoryManager).start(); + + if (deleteAll) { + service.deleteAll(getRepository()); + } + return service; + } +} diff --git a/src/test/java/com/gitblit/tests/FileTicketServiceTest.java b/src/test/java/com/gitblit/tests/FileTicketServiceTest.java new file mode 100644 index 00000000..3cc25218 --- /dev/null +++ b/src/test/java/com/gitblit/tests/FileTicketServiceTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.tests; + +import com.gitblit.IStoredSettings; +import com.gitblit.manager.INotificationManager; +import com.gitblit.manager.IRepositoryManager; +import com.gitblit.manager.IRuntimeManager; +import com.gitblit.manager.IUserManager; +import com.gitblit.manager.NotificationManager; +import com.gitblit.manager.RepositoryManager; +import com.gitblit.manager.RuntimeManager; +import com.gitblit.manager.UserManager; +import com.gitblit.models.RepositoryModel; +import com.gitblit.tickets.FileTicketService; +import com.gitblit.tickets.ITicketService; + +/** + * Tests the file ticket service. + * + * @author James Moger + * + */ +public class FileTicketServiceTest extends TicketServiceTest { + + final RepositoryModel repo = new RepositoryModel("tickets/file.git", null, null, null); + + @Override + protected RepositoryModel getRepository() { + return repo; + } + + @Override + protected ITicketService getService(boolean deleteAll) throws Exception { + + IStoredSettings settings = getSettings(deleteAll); + + IRuntimeManager runtimeManager = new RuntimeManager(settings).start(); + INotificationManager notificationManager = new NotificationManager(settings).start(); + IUserManager userManager = new UserManager(runtimeManager).start(); + IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, userManager).start(); + + FileTicketService service = new FileTicketService( + runtimeManager, + notificationManager, + userManager, + repositoryManager).start(); + + if (deleteAll) { + service.deleteAll(getRepository()); + } + return service; + } +} diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java index 9fe7312c..cba575d7 100644 --- a/src/test/java/com/gitblit/tests/GitBlitSuite.java +++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java @@ -63,7 +63,8 @@ import com.gitblit.utils.JGitUtils; GitBlitTest.class, FederationTests.class, RpcTests.class, GitServletTest.class, GitDaemonTest.class,
GroovyScriptTest.class, LuceneExecutorTest.class, RepositoryModelTest.class,
FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class, HtpasswdAuthenticationTest.class,
- ModelUtilsTest.class, JnaUtilsTest.class, LdapSyncServiceTest.class })
+ ModelUtilsTest.class, JnaUtilsTest.class, LdapSyncServiceTest.class, FileTicketServiceTest.class, + BranchTicketServiceTest.class, RedisTicketServiceTest.class }) public class GitBlitSuite {
public static final File BASEFOLDER = new File("data");
@@ -106,6 +107,11 @@ public class GitBlitSuite { return getRepository("test/gitective.git");
}
+ public static Repository getTicketsTestRepository() { + JGitUtils.createRepository(REPOSITORIES, "gb-tickets.git").close(); + return getRepository("gb-tickets.git"); + } + private static Repository getRepository(String name) {
try {
File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
diff --git a/src/test/java/com/gitblit/tests/RedisTicketServiceTest.java b/src/test/java/com/gitblit/tests/RedisTicketServiceTest.java new file mode 100644 index 00000000..5a4bda73 --- /dev/null +++ b/src/test/java/com/gitblit/tests/RedisTicketServiceTest.java @@ -0,0 +1,75 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.tests; + +import com.gitblit.IStoredSettings; +import com.gitblit.Keys; +import com.gitblit.manager.INotificationManager; +import com.gitblit.manager.IRepositoryManager; +import com.gitblit.manager.IRuntimeManager; +import com.gitblit.manager.IUserManager; +import com.gitblit.manager.NotificationManager; +import com.gitblit.manager.RepositoryManager; +import com.gitblit.manager.RuntimeManager; +import com.gitblit.manager.UserManager; +import com.gitblit.models.RepositoryModel; +import com.gitblit.tickets.ITicketService; +import com.gitblit.tickets.RedisTicketService; + +/** + * Tests the Redis ticket service. + * + * @author James Moger + * + */ +public class RedisTicketServiceTest extends TicketServiceTest { + + final RepositoryModel repo = new RepositoryModel("tickets/redis.git", null, null, null); + + @Override + protected RepositoryModel getRepository() { + return repo; + } + + @Override + protected IStoredSettings getSettings(boolean deleteAll) throws Exception { + IStoredSettings settings = super.getSettings(deleteAll); + settings.overrideSetting(Keys.tickets.redis.url, "redis://localhost:6379/10"); + return settings; + } + + @Override + protected ITicketService getService(boolean deleteAll) throws Exception { + + IStoredSettings settings = getSettings(deleteAll); + + IRuntimeManager runtimeManager = new RuntimeManager(settings).start(); + INotificationManager notificationManager = new NotificationManager(settings).start(); + IUserManager userManager = new UserManager(runtimeManager).start(); + IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, userManager).start(); + + RedisTicketService service = new RedisTicketService( + runtimeManager, + notificationManager, + userManager, + repositoryManager).start(); + + if (deleteAll) { + service.deleteAll(getRepository()); + } + return service; + } +} diff --git a/src/test/java/com/gitblit/tests/TicketServiceTest.java b/src/test/java/com/gitblit/tests/TicketServiceTest.java new file mode 100644 index 00000000..5f94a46e --- /dev/null +++ b/src/test/java/com/gitblit/tests/TicketServiceTest.java @@ -0,0 +1,351 @@ +/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.tests;
+
+import java.io.File;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.io.FileUtils;
+import org.bouncycastle.util.Arrays;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
+import com.gitblit.models.Mailing;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.TicketModel;
+import com.gitblit.models.TicketModel.Attachment;
+import com.gitblit.models.TicketModel.Change;
+import com.gitblit.models.TicketModel.Field;
+import com.gitblit.models.TicketModel.Patchset;
+import com.gitblit.models.TicketModel.Status;
+import com.gitblit.models.TicketModel.Type;
+import com.gitblit.tests.mock.MemorySettings;
+import com.gitblit.tickets.ITicketService;
+import com.gitblit.tickets.ITicketService.TicketFilter;
+import com.gitblit.tickets.QueryResult;
+import com.gitblit.tickets.TicketIndexer.Lucene;
+import com.gitblit.tickets.TicketLabel;
+import com.gitblit.tickets.TicketMilestone;
+import com.gitblit.tickets.TicketNotifier;
+import com.gitblit.utils.JGitUtils;
+
+/**
+ * Tests the mechanics of Gitblit ticket management.
+ *
+ * @author James Moger
+ *
+ */
+public abstract class TicketServiceTest extends GitblitUnitTest {
+
+ private ITicketService service;
+
+ protected abstract RepositoryModel getRepository();
+
+ protected abstract ITicketService getService(boolean deleteAll) throws Exception;
+
+ protected IStoredSettings getSettings(boolean deleteAll) throws Exception {
+ File dir = new File(GitBlitSuite.REPOSITORIES, getRepository().name);
+ if (deleteAll) {
+ FileUtils.deleteDirectory(dir);
+ JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, getRepository().name).close();
+ }
+
+ File luceneDir = new File(dir, "tickets/lucene");
+ luceneDir.mkdirs();
+
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put(Keys.git.repositoriesFolder, GitBlitSuite.REPOSITORIES.getAbsolutePath());
+ map.put(Keys.tickets.indexFolder, luceneDir.getAbsolutePath());
+
+ IStoredSettings settings = new MemorySettings(map);
+ return settings;
+ }
+
+ @Before
+ public void setup() throws Exception {
+ service = getService(true);
+ }
+
+ @After
+ public void cleanup() {
+ service.stop();
+ }
+
+ @Test
+ public void testLifecycle() throws Exception {
+ // 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"));
+
+ // delete all tickets
+ for (TicketModel aTicket : allTickets) {
+ assertTrue(service.deleteTicket(getRepository(), aTicket.number, "D"));
+ }
+ }
+
+ @Test
+ public void testChangeComment() throws Exception {
+ // C1: create the ticket
+ Change c1 = newChange("testChangeComment() " + Long.toHexString(System.currentTimeMillis()));
+ TicketModel ticket = service.createTicket(getRepository(), c1);
+ assertTrue(ticket.number > 0);
+ assertTrue(ticket.changes.get(0).hasComment());
+
+ ticket = service.updateComment(ticket, c1.comment.id, "E1", "I changed the comment");
+ assertNotNull(ticket);
+ assertTrue(ticket.changes.get(0).hasComment());
+ assertEquals("I changed the comment", ticket.changes.get(0).comment.text);
+
+ assertTrue(service.deleteTicket(getRepository(), ticket.number, "D"));
+ }
+
+ @Test
+ public void testDeleteComment() throws Exception {
+ // C1: create the ticket
+ Change c1 = newChange("testDeleteComment() " + Long.toHexString(System.currentTimeMillis()));
+ TicketModel ticket = service.createTicket(getRepository(), c1);
+ assertTrue(ticket.number > 0);
+ assertTrue(ticket.changes.get(0).hasComment());
+
+ ticket = service.deleteComment(ticket, c1.comment.id, "D1");
+ assertNotNull(ticket);
+ assertEquals(1, ticket.changes.size());
+ assertFalse(ticket.changes.get(0).hasComment());
+
+ assertTrue(service.deleteTicket(getRepository(), ticket.number, "D"));
+ }
+
+ @Test
+ public void testMilestones() throws Exception {
+ service.createMilestone(getRepository(), "M1", "james");
+ service.createMilestone(getRepository(), "M2", "frank");
+ service.createMilestone(getRepository(), "M3", "joe");
+
+ List<TicketMilestone> milestones = service.getMilestones(getRepository(), Status.Open);
+ assertEquals("Unexpected open milestones count", 3, milestones.size());
+
+ for (TicketMilestone milestone : milestones) {
+ milestone.status = Status.Resolved;
+ milestone.due = new Date();
+ assertTrue("failed to update milestone " + milestone.name, service.updateMilestone(getRepository(), milestone, "ted"));
+ }
+
+ milestones = service.getMilestones(getRepository(), Status.Open);
+ assertEquals("Unexpected open milestones count", 0, milestones.size());
+
+ milestones = service.getMilestones(getRepository(), Status.Resolved);
+ assertEquals("Unexpected resolved milestones count", 3, milestones.size());
+
+ for (TicketMilestone milestone : milestones) {
+ assertTrue("failed to delete milestone " + milestone.name, service.deleteMilestone(getRepository(), milestone.name, "lucifer"));
+ }
+ }
+
+ @Test
+ public void testLabels() throws Exception {
+ service.createLabel(getRepository(), "L1", "james");
+ service.createLabel(getRepository(), "L2", "frank");
+ service.createLabel(getRepository(), "L3", "joe");
+
+ List<TicketLabel> labels = service.getLabels(getRepository());
+ assertEquals("Unexpected open labels count", 3, labels.size());
+
+ for (TicketLabel label : labels) {
+ label.color = "#ffff00";
+ assertTrue("failed to update label " + label.name, service.updateLabel(getRepository(), label, "ted"));
+ }
+
+ labels = service.getLabels(getRepository());
+ assertEquals("Unexpected labels count", 3, labels.size());
+
+ for (TicketLabel label : labels) {
+ assertTrue("failed to delete label " + label.name, service.deleteLabel(getRepository(), label.name, "lucifer"));
+ }
+ }
+
+
+
+ private Change newChange(String summary) {
+ Change change = new Change("C1");
+ change.setField(Field.title, summary);
+ change.setField(Field.body, "this is my description");
+ change.setField(Field.labels, "helpdesk");
+ change.comment("my comment");
+ return change;
+ }
+
+ private Attachment newAttachment() {
+ Attachment attachment = new Attachment("test1.txt");
+ attachment.content = new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
+ 0x4a };
+ return attachment;
+ }
+
+ private void compare(TicketModel ticket, TicketModel constructed) {
+ assertEquals(ticket.number, constructed.number);
+ assertEquals(ticket.createdBy, constructed.createdBy);
+ assertEquals(ticket.responsible, constructed.responsible);
+ assertEquals(ticket.title, constructed.title);
+ assertEquals(ticket.body, constructed.body);
+ assertEquals(ticket.created, constructed.created);
+
+ assertTrue(ticket.hasLabel("helpdesk"));
+ }
+
+ @Test
+ public void testNotifier() throws Exception {
+ Change kernel = new Change("james");
+ kernel.setField(Field.title, "Sample ticket");
+ kernel.setField(Field.body, "this **is** my sample body\n\n- I hope\n- you really\n- *really* like it");
+ kernel.setField(Field.status, Status.New);
+ kernel.setField(Field.type, Type.Proposal);
+
+ kernel.comment("this is a sample comment on a kernel change");
+
+ Patchset patchset = new Patchset();
+ patchset.insertions = 100;
+ patchset.deletions = 10;
+ patchset.number = 1;
+ patchset.rev = 25;
+ patchset.tip = "50f57913f816d04a16b7407134de5d8406421f37";
+ kernel.patchset = patchset;
+
+ TicketModel ticket = service.createTicket(getRepository(), 0L, kernel);
+
+ Change merge = new Change("james");
+ merge.setField(Field.mergeSha, patchset.tip);
+ merge.setField(Field.mergeTo, "master");
+ merge.setField(Field.status, Status.Merged);
+
+ ticket = service.updateTicket(getRepository(), ticket.number, merge);
+ ticket.repository = getRepository().name;
+
+ TicketNotifier notifier = service.createNotifier();
+ Mailing mailing = notifier.queueMailing(ticket);
+ assertNotNull(mailing);
+ }
+}
\ No newline at end of file |