From f9c78c0ccc709509cdf7f83c45c898883d329db2 Mon Sep 17 00:00:00 2001 From: Paul Martin Date: Mon, 29 Sep 2014 22:10:20 +0100 Subject: Tickets - Priority, Severity options + Severity indicated via new character indicator and color of ticket icon on ticket list + Priority indicated via new priority icon and color on ticket list + Indexed as integers to provide sorting and maintain language neutral index + Colours and indicator text controlled through CSS classes priority- & severity- + UITicketTest created to generate tickets of all types to ease debugging --- src/test/java/com/gitblit/tests/GitBlitSuite.java | 2 +- .../java/com/gitblit/tests/TicketServiceTest.java | 44 +++++- src/test/java/com/gitblit/tests/UITicketTest.java | 151 +++++++++++++++++++++ 3 files changed, 193 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/gitblit/tests/UITicketTest.java (limited to 'src/test') diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java index 5a7dcea1..f2dfcc0c 100644 --- a/src/test/java/com/gitblit/tests/GitBlitSuite.java +++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java @@ -65,7 +65,7 @@ import com.gitblit.utils.JGitUtils; FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class, HtpasswdAuthenticationTest.class, ModelUtilsTest.class, JnaUtilsTest.class, LdapSyncServiceTest.class, FileTicketServiceTest.class, BranchTicketServiceTest.class, RedisTicketServiceTest.class, AuthenticationManagerTest.class, - SshKeysDispatcherTest.class }) + SshKeysDispatcherTest.class, UITicketTest.class }) public class GitBlitSuite { public static final File BASEFOLDER = new File("data"); diff --git a/src/test/java/com/gitblit/tests/TicketServiceTest.java b/src/test/java/com/gitblit/tests/TicketServiceTest.java index 1676e341..c654383d 100644 --- a/src/test/java/com/gitblit/tests/TicketServiceTest.java +++ b/src/test/java/com/gitblit/tests/TicketServiceTest.java @@ -293,9 +293,47 @@ public abstract class TicketServiceTest extends GitblitUnitTest { assertTrue("failed to delete label " + label.name, service.deleteLabel(getRepository(), label.name, "lucifer")); } } - - - + + @Test + public void testPriorityAndSeverity() throws Exception { + // C1: create and insert a ticket + Change c1 = newChange("testPriorityAndSeverity() " + Long.toHexString(System.currentTimeMillis())); + TicketModel ticket = service.createTicket(getRepository(), c1); + assertTrue(ticket.number > 0); + assertEquals(TicketModel.Priority.Normal, ticket.priority); + assertEquals(TicketModel.Severity.Unrated, ticket.severity); + + TicketModel constructed = service.getTicket(getRepository(), ticket.number); + compare(ticket, constructed); + + // C2: Change Priority max + Change c2 = new Change("C2"); + c2.setField(Field.priority, TicketModel.Priority.Urgent); + constructed = service.updateTicket(getRepository(), ticket.number, c2); + assertNotNull(constructed); + assertEquals(2, constructed.changes.size()); + assertEquals(TicketModel.Priority.Urgent, constructed.priority); + assertEquals(TicketModel.Severity.Unrated, constructed.severity); + + // C3: Change Severity max + Change c3 = new Change("C3"); + c3.setField(Field.severity, TicketModel.Severity.Catastrophic); + constructed = service.updateTicket(getRepository(), ticket.number, c3); + assertNotNull(constructed); + assertEquals(3, constructed.changes.size()); + assertEquals(TicketModel.Priority.Urgent, constructed.priority); + assertEquals(TicketModel.Severity.Catastrophic, constructed.severity); + + // C4: Change Priority min + Change c4 = new Change("C3"); + c4.setField(Field.priority, TicketModel.Priority.Low); + constructed = service.updateTicket(getRepository(), ticket.number, c4); + assertNotNull(constructed); + assertEquals(4, constructed.changes.size()); + assertEquals(TicketModel.Priority.Low, constructed.priority); + assertEquals(TicketModel.Severity.Catastrophic, constructed.severity); + } + private Change newChange(String summary) { Change change = new Change("C1"); change.setField(Field.title, summary); diff --git a/src/test/java/com/gitblit/tests/UITicketTest.java b/src/test/java/com/gitblit/tests/UITicketTest.java new file mode 100644 index 00000000..54aa1e1e --- /dev/null +++ b/src/test/java/com/gitblit/tests/UITicketTest.java @@ -0,0 +1,151 @@ +/* + * 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.eclipse.jgit.lib.Repository; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.gitblit.IStoredSettings; +import com.gitblit.Keys; +import com.gitblit.manager.INotificationManager; +import com.gitblit.manager.IPluginManager; +import com.gitblit.manager.IRepositoryManager; +import com.gitblit.manager.IRuntimeManager; +import com.gitblit.manager.IUserManager; +import com.gitblit.manager.NotificationManager; +import com.gitblit.manager.PluginManager; +import com.gitblit.manager.RepositoryManager; +import com.gitblit.manager.RuntimeManager; +import com.gitblit.manager.UserManager; +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.Priority; +import com.gitblit.models.TicketModel.Severity; +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.BranchTicketService; +import com.gitblit.tickets.TicketLabel; +import com.gitblit.tickets.TicketMilestone; +import com.gitblit.tickets.TicketNotifier; +import com.gitblit.utils.JGitUtils; +import com.gitblit.utils.XssFilter; +import com.gitblit.utils.XssFilter.AllowXssFilter; + +/** + * Generates the range of tickets to ease testing of the look and feel of tickets + */ +public class UITicketTest extends GitblitUnitTest { + + private ITicketService service; + final String repoName = "UITicketTest.git"; + final RepositoryModel repo = new RepositoryModel(repoName, null, null, null); + + protected ITicketService getService(boolean deleteAll) throws Exception { + + IStoredSettings settings = getSettings(deleteAll); + XssFilter xssFilter = new AllowXssFilter(); + IRuntimeManager runtimeManager = new RuntimeManager(settings, xssFilter).start(); + IPluginManager pluginManager = new PluginManager(runtimeManager).start(); + INotificationManager notificationManager = new NotificationManager(settings).start(); + IUserManager userManager = new UserManager(runtimeManager, pluginManager).start(); + IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, pluginManager, userManager).start(); + + BranchTicketService service = new BranchTicketService( + runtimeManager, + pluginManager, + notificationManager, + userManager, + repositoryManager).start(); + + if (deleteAll) { + service.deleteAll(repo); + } + return service; + } + + protected IStoredSettings getSettings(boolean deleteAll) throws Exception { + File dir = new File(GitBlitSuite.REPOSITORIES, repoName); + if (deleteAll) { + FileUtils.deleteDirectory(dir); + JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repoName).close(); + } + + File luceneDir = new File(dir, "tickets/lucene"); + luceneDir.mkdirs(); + + Map map = new HashMap(); + 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 UITicketOptions() throws Exception { + + for (TicketModel.Type t : TicketModel.Type.values()) + { + for (TicketModel.Priority p : TicketModel.Priority.values()) + { + for (TicketModel.Severity s : TicketModel.Severity.values()) + { + assertNotNull(service.createTicket(repo, newChange(t, p, s))); + } + } + } + } + + private Change newChange(Type type, Priority priority, Severity severity) { + Change change = new Change("JUnit"); + change.setField(Field.title, String.format("Type: %s | Priority: %s | Severity: %s", type, priority, severity)); + change.setField(Field.type, type); + change.setField(Field.severity, severity); + change.setField(Field.priority, priority); + return change; + } + +} \ No newline at end of file -- cgit v1.2.3