1
2
3
4 package org.itracker.services;
5
6 import org.apache.log4j.Logger;
7 import org.itracker.IssueException;
8 import org.itracker.core.AuthenticationConstants;
9 import org.itracker.core.resources.ITrackerResources;
10 import org.itracker.model.*;
11 import org.itracker.model.CustomField.Type;
12 import org.itracker.model.util.IssueUtilities;
13 import org.itracker.persistence.dao.*;
14 import org.junit.Test;
15
16 import java.text.SimpleDateFormat;
17 import java.util.*;
18
19 import static junit.framework.Assert.assertSame;
20 import static org.itracker.Assert.*;
21
22
23
24
25 public class IssueServiceIT extends AbstractServicesIntegrationTest {
26
27 private static final Logger logger = Logger
28 .getLogger(IssueServiceIT.class);
29 private IssueService issueService;
30
31 private UserDAO userDAO;
32 private IssueDAO issueDAO;
33 private IssueRelationDAO issueRelationDAO;
34 private IssueHistoryDAO issueHistoryDAO;
35 private IssueAttachmentDAO issueAttachmentDAO;
36 private UserService userService;
37
38
39
40
41
42 @Test
43 public void testGetIssue() {
44
45 Issue issue = this.issueService.getIssue(1);
46
47 assertNotNull("issue#1", issue);
48
49 this.issueService.getIssue(2);
50 assertNotNull("issue#2", issue);
51
52 this.issueService.getIssue(3);
53 assertNotNull("issue#3", issue);
54
55 this.issueService.getIssue(4);
56 assertNotNull("issue#4", issue);
57
58 }
59
60
61
62
63
64 @Test
65 public void testGetNumberIssues() {
66
67 Long nrOfIssues = issueService.getNumberIssues();
68 assertEquals("allissues", (Long) 4L, nrOfIssues);
69
70 }
71
72
73
74
75
76 @Test
77 public void testGetIssuesWithStatus() {
78
79 Collection<Issue> issues = issueService.getIssuesWithStatus(100);
80 assertEquals("status 1 issues", 1, issues.size());
81 issues = issueService.getIssuesWithStatus(200);
82 assertEquals("status 2 issues", 1, issues.size());
83 issues = issueService.getIssuesWithStatus(300);
84 assertEquals("status 3 issues", 2, issues.size());
85
86 }
87
88
89
90
91
92
93 @Test
94 public void testGetIssuesWithStatusLessThan() {
95 Collection<Issue> issues = issueService.getIssuesWithStatusLessThan(200);
96 assertEquals("status less 2 issues", 1, issues.size());
97
98 issues = issueService.getIssuesWithStatusLessThan(300);
99 assertEquals("status less 3 issues", 2, issues.size());
100 }
101
102
103
104
105
106 @Test
107 public void testGetIssuesWithSeverity() {
108 Collection<Issue> issues = issueService.getIssuesWithSeverity(1);
109
110 assertEquals("issues severity#1", 4, issues.size());
111 assertTrue("issue#1 countained", issues.contains(issueService
112 .getIssue(1)));
113 }
114
115
116
117
118
119
120 @Test
121 public void testGetIssuesByProjectIdInteger() {
122 Collection<Issue> issues = issueService.getIssuesByProjectId(2);
123
124 assertEquals("issues by project#2", 4, issues.size());
125 }
126
127
128
129
130
131
132 @Test
133 public void testGetIssuesByProjectIdIntegerInt() {
134 Collection<Issue> issues = issueService.getIssuesByProjectId(2, 200);
135 assertEquals("issues count", 1, issues.size());
136 issues = issueService.getIssuesByProjectId(2, 300);
137 assertEquals("issues count", 2, issues.size());
138 }
139
140
141
142
143
144
145 @Test
146 public void testGetIssuesCreatedByUserInteger() {
147 Collection<Issue> issues = issueService.getIssuesCreatedByUser(3);
148 assertEquals("issues count createdBy#3", 0, issues.size());
149
150 issues = issueService.getIssuesCreatedByUser(2);
151 assertEquals("issues count createdBy#2", 4, issues.size());
152 }
153
154
155
156
157
158
159 @Test
160 public void testGetIssuesCreatedByUserIntegerBoolean() {
161
162 Collection<Issue> issues = issueService
163 .getIssuesCreatedByUser(2, false);
164 assertEquals("issues count createdBy#3", 4, issues.size());
165
166 issues = issueService.getIssuesCreatedByUser(2, true);
167 assertEquals("issues count createdBy#2", 4, issues.size());
168 }
169
170
171
172
173
174
175 @Test
176 public void testGetIssuesOwnedByUserInteger() {
177 Collection<Issue> issues = issueService.getIssuesOwnedByUser(2);
178 assertEquals("issues count owner#2", 4, issues.size());
179 }
180
181
182
183
184
185
186 @Test
187 public void testGetIssuesOwnedByUserIntegerBoolean() {
188
189 Collection<Issue> issues = issueService.getIssuesOwnedByUser(2, false);
190 assertEquals("issues count owner#2", 4, issues.size());
191
192 issues = issueService.getIssuesOwnedByUser(2, true);
193 assertEquals("issues count owner#2", 4, issues.size());
194 }
195
196
197
198
199
200
201 @Test
202 public void testGetIssuesWatchedByUser() {
203 Collection<Issue> issues = issueService.getIssuesWatchedByUser(2);
204 assertNotNull(issues);
205 assertEquals("issues watched by#2", 1, issues.size());
206
207 issues = issueService.getIssuesWatchedByUser(2, false);
208 assertNotNull(issues);
209 assertEquals("issues watched by#2 regardless of project status", 1, issues.size());
210 }
211
212
213
214
215
216 @Test
217 public void testGetUnassignedIssues() {
218 List<Issue> issues = issueService.getUnassignedIssues();
219 assertNotNull(issues);
220
221
222 assertEquals("2 unassigned issues", 2, issues.size());
223
224 issues = issueService.getUnassignedIssues(false);
225 assertNotNull(issues);
226
227
228 assertEquals("2 unassigned issues", 2, issues.size());
229
230
231
232 }
233
234
235
236
237
238
239 @Test
240 public void testCreateIssue() throws Exception {
241 Issue issue = new Issue();
242 issue.setStatus(1);
243 issue.setDescription("hi");
244 issue.setSeverity(1);
245 User user = ((UserService) applicationContext.getBean("userService"))
246 .getUser(2);
247 assertNotNull("user#2", user);
248 IssueHistory history = new IssueHistory(issue, user);
249 history.setDescription("hello");
250 history.setStatus(1);
251
252 Issue newIssue = issueService.createIssue(issue, 2, user.getId(),
253 user.getId());
254 assertNotNull("new issue", newIssue);
255 assertNotNull("model issue id", issue.getId());
256 assertNotNull("new issue id", issue.getId());
257 assertSame("new issue id == model issue id", newIssue.getId(), issue.getId());
258
259 }
260
261
262
263
264
265
266 @Test
267 public void testUpdateIssue() throws Exception {
268 Issue updateIssue = issueService.getIssue(2);
269 assertNotNull("issue", updateIssue);
270
271 User user = ((UserService) applicationContext.getBean("userService"))
272 .getUser(2);
273 assertNotNull("user#2", user);
274
275 IssueHistory history = new IssueHistory(updateIssue, user, "hi", 1);
276 int histCount = updateIssue.getHistory().size();
277
278 updateIssue.getHistory().add(history);
279
280 updateIssue = issueService.updateIssue(updateIssue, 2);
281 assertEquals("new history size", histCount + 1, updateIssue
282 .getHistory().size());
283
284
285 }
286
287 @Test
288 public void testUpdateIssueSeverity() throws Exception {
289 Issue updateIssue = issueService.getIssue(2);
290 assertNotNull("issue", updateIssue);
291
292 User user = ((UserService) applicationContext.getBean("userService"))
293 .getUser(2);
294 assertNotNull("user#2", user);
295
296 IssueHistory history = new IssueHistory(updateIssue, user, "hi", 1);
297
298 int actCount = updateIssue.getActivities().size();
299
300 updateIssue.getHistory().add(history);
301 int severity = updateIssue.getSeverity() + 1;
302
303 updateIssue.setSeverity(severity);
304
305 updateIssue = issueService.updateIssue(updateIssue, 2);
306
307 assertEquals("new activity size", actCount + 1, updateIssue
308 .getActivities().size());
309
310 assertEquals("new issue severity", severity, updateIssue
311 .getSeverity().intValue());
312
313 assertEquals("new added activity type",
314 IssueActivityType.SEVERITY_CHANGE, issueService.getIssue(
315 updateIssue.getId()).getActivities().get(
316 updateIssue.getActivities().size() - 1)
317 .getActivityType());
318
319 }
320
321 @Test
322 public void testUpdateIssueDescription() throws Exception {
323 Issue updateIssue = issueService.getIssue(2);
324 assertNotNull("issue", updateIssue);
325
326 User user = ((UserService) applicationContext.getBean("userService"))
327 .getUser(2);
328 assertNotNull("user#2", user);
329
330 IssueHistory history = new IssueHistory(updateIssue, user, "hi", 1);
331
332 int actCount = updateIssue.getActivities().size();
333
334 updateIssue.getHistory().add(history);
335 String description = "new issue description";
336
337 updateIssue.setDescription(description);
338
339
340 updateIssue = issueService.updateIssue(updateIssue, 2);
341
342 assertEquals("updateIssue.activities.size", actCount + 1,
343 updateIssue.getActivities().size());
344
345 assertEquals("updateIssue.description", description, updateIssue
346 .getDescription());
347
348 assertEquals("updateIssue.activity.last.type",
349 IssueActivityType.DESCRIPTION_CHANGE, updateIssue
350 .getActivities().get(
351 updateIssue.getActivities().size() - 1)
352 .getActivityType());
353
354 Issue reloadedIssue = issueService.getIssue(updateIssue.getId());
355
356 assertEquals("reloadedIssue.activities.size", actCount + 1,
357 updateIssue.getActivities().size());
358
359 assertEquals("reloadedIssue.description", description, updateIssue
360 .getDescription());
361
362 assertEquals("reloadedIssue.activity.last.type",
363 IssueActivityType.DESCRIPTION_CHANGE, reloadedIssue
364 .getActivities().get(
365 reloadedIssue.getActivities().size() - 1)
366 .getActivityType());
367
368 }
369
370 @Test
371 public void testUpdateIssueResolution() throws Exception {
372 Issue updateIssue = issueService.getIssue(2);
373 assertNotNull("issue", updateIssue);
374
375 User user = ((UserService) applicationContext.getBean("userService"))
376 .getUser(2);
377 assertNotNull("user#2", user);
378
379 IssueHistory history = new IssueHistory(updateIssue, user, "hi", 1);
380
381 int actCount = updateIssue.getActivities().size();
382
383 updateIssue.getHistory().add(history);
384 String resolution = "new issue resolution";
385
386 updateIssue.setResolution(resolution);
387
388
389 updateIssue = issueService.updateIssue(updateIssue, 2);
390
391 assertEquals("new activity size", actCount + 1, updateIssue
392 .getActivities().size());
393
394 assertEquals("new issue resolution", resolution, updateIssue
395 .getResolution());
396
397 assertEquals("new added activity type",
398 IssueActivityType.RESOLUTION_CHANGE, issueService.getIssue(
399 updateIssue.getId()).getActivities().get(
400 updateIssue.getActivities().size() - 1)
401 .getActivityType());
402
403 }
404
405
406
407
408
409
410 @Test
411 public void testMoveIssue() {
412
413 Issue issue = issueService.getIssue(1);
414 assertNotNull("issue", issue);
415 User user = ((UserService) applicationContext.getBean("userService"))
416 .getUser(2);
417 int actCount = issue.getActivities().size();
418 assertNotNull("user#2", user);
419 issue = issueService.moveIssue(issue, 3, user.getId());
420
421 Issue reloaded = issueService.getIssue(1);
422
423 assertEquals("issue.project.id", Integer.valueOf(3), issue.getProject()
424 .getId());
425 assertEquals("reloaded.project.id", Integer.valueOf(3), reloaded
426 .getProject().getId());
427
428 assertEquals("reloaded.activities.size", actCount + 1, reloaded
429 .getActivities().size());
430
431
432
433 }
434
435
436
437
438
439
440 @Test
441 public void testAssignIssueIntegerInteger() {
442
443 Issue issue = issueService.getIssue(2);
444 assertNotNull("issue", issue);
445 User user = ((UserService) applicationContext.getBean("userService"))
446 .getUser(4);
447 assertNotNull("user#2", user);
448
449 assertTrue("assigned", issueService.assignIssue(issue.getId(), user
450 .getId()));
451
452 assertEquals("owner", user, issue.getOwner());
453
454 }
455
456
457
458
459
460
461 @Test
462 public void testAssignIssueIntegerIntegerInteger() {
463 Issue issue = issueService.getIssue(2);
464 assertNotNull("issue", issue);
465 User user = ((UserService) applicationContext.getBean("userService"))
466 .getUser(4);
467 User assignerUser = ((UserService) applicationContext
468 .getBean("userService")).getUser(2);
469 assertNotNull("user#2", user);
470
471 assertTrue("assigned", issueService.assignIssue(issue.getId(), user
472 .getId(), assignerUser.getId()));
473
474 assertEquals("owner", user, issue.getOwner());
475
476 try {
477 assertTrue("unassigned", issueService.assignIssue(issue.getId(), null, assignerUser.getId()));
478 fail("null user allowed");
479 } catch (Exception e) { }
480 }
481
482
483
484
485
486
487
488 @Test
489 public void testSetIssueFields() {
490 Issue issue = issueService.getIssue(2);
491 assertNotNull("issue", issue);
492 assertEquals("issue.fields.size", 2, issue.getProject().getCustomFields().size());
493
494 assertEquals("issue.fields[0].customField", issue.getProject().getCustomFields().get(0), issue.getFields().get(0).getCustomField());
495
496 IssueField field = issue.getFields().get(0);
497 assertEquals("issue.fields[0].fieldType", Type.STRING, field.getCustomField().getFieldType());
498
499 try {
500 field.setValue("1", ITrackerResources.getBundle(Locale.US));
501 } catch (IssueException e) {
502 logger.error("testSetIssueFields: failed to set value", e);
503 fail(e.getMessage());
504 }
505
506 issueService.setIssueFields(issue.getId(), issue.getFields());
507
508 CustomField dateField = issue.getProject().getCustomFields().get(1);
509 IssueField dateFieldValue = new IssueField(issue, dateField);
510
511
512 dateFieldValue.setDateValue(new Date(122255164431L));
513
514
515 ArrayList<IssueField> issueFields = new ArrayList<>(issue.getFields().size() + 1);
516 issueFields.add(dateFieldValue);
517
518 issueService.setIssueFields(issue.getId(), issueFields);
519
520 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
521 issue = issueService.getIssue(2);
522
523 assertEquals("issue.fields[0]", field, issue.getFields().get(0));
524 assertEquals("issue.fields[1]", df.format(dateFieldValue.getDateValue()), df.format(issue.getFields().get(1).getDateValue().getTime()));
525
526 boolean added = issueService.setIssueFields(issue.getId(), new ArrayList<IssueField>());
527 assertTrue(added);
528
529 }
530
531 @Test
532 public void testUpdateIssueCustomFields() throws Exception {
533
534 Issue issue = issueService.getIssue(2);
535 assertNotNull("issue", issue);
536 assertEquals("issue.fields.size", 2, issue.getProject().getCustomFields().size());
537
538 assertEquals("issue.fields[0].customField", issue.getProject().getCustomFields().get(0), issue.getFields().get(0).getCustomField());
539
540 IssueField field = issue.getFields().get(0);
541 assertEquals("issue.fields[0].fieldType", Type.STRING, field.getCustomField().getFieldType());
542
543 try {
544 field.setValue("1", ITrackerResources.getBundle(Locale.US));
545
546 } catch (IssueException e) {
547 logger.error("testSetIssueFields: failed to set value", e);
548 fail(e.getMessage());
549 }
550
551 issueService.updateIssue(issue, issue.getOwner().getId());
552
553
554 CustomField dateField = issue.getProject().getCustomFields().get(1);
555 IssueField dateFieldValue = new IssueField(issue, dateField);
556
557
558 dateFieldValue.setDateValue(new Date(122255164431L));
559
560 issue.getFields().add(dateFieldValue);
561
562 issueService.updateIssue(issue, issue.getOwner().getId());
563
564
565 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
566 issue = issueService.getIssue(2);
567
568 assertEquals("issue.fields[0]", field, issue.getFields().get(0));
569 assertEquals("issue.fields[1]", df.format(dateFieldValue.getDateValue()), df.format(issue.getFields().get(1).getDateValue().getTime()));
570
571
572 }
573
574
575
576
577
578
579 @Test
580 public void testSetIssueComponents() {
581 HashSet<Integer> componentIds = new HashSet<>();
582 componentIds.add(1);
583 boolean updated = issueService.setIssueComponents(3, componentIds, 2);
584 assertTrue(updated);
585 assertTrue(issueService.getIssueComponentIds(3).contains(1));
586
587 }
588
589
590
591
592
593
594 @Test
595 public void testSetIssueVersions() {
596 HashSet<Integer> versionIds = new HashSet<>();
597 versionIds.add(1);
598 boolean updated = issueService.setIssueVersions(3, versionIds, 2);
599 assertTrue(updated);
600 assertTrue(issueService.getIssueVersionIds(3).contains(1));
601 }
602
603
604
605
606
607
608 @Test
609 public void testAddIssueHistory() {
610
611 Issue issue = issueDAO.findByPrimaryKey(1);
612 User user = userDAO.findByPrimaryKey(2);
613
614 IssueHistory history = new IssueHistory(issue, user, "", IssueUtilities.STATUS_NEW);
615
616 history.setIssue(issue);
617 issueService.addIssueHistory(history);
618
619 assertNotNull(issueHistoryDAO.findByPrimaryKey(history.getId()));
620 }
621
622
623
624
625
626
627 @Test
628 public void testAddIssueRelation() {
629
630 boolean added = issueService.addIssueRelation(2, 3, IssueRelation.Type.DUPLICATE_C, 2);
631 assertTrue(added);
632
633
634 List<IssueRelation> issueRelations = issueRelationDAO.findByIssue(2);
635 assertNotNull(issueRelations);
636 assertEquals("issueRelations.size()", 1, issueRelations.size());
637 IssueRelation issueRelation = issueRelations.get(0);
638 assertNotNull(issueRelation);
639 assertNotNull("issueRelation.id", issueRelation.getId());
640 assertEquals("issueRelation.relatedIssue.id", new Integer(3), issueRelation.getRelatedIssue().getId());
641 assertEquals("issueRelation.relationType", IssueRelation.Type.DUPLICATE_C, issueRelation.getRelationType());
642
643 }
644
645
646
647
648
649
650 @Test
651 public void testAddIssueAttachment() {
652 Issue issue = issueDAO.findByPrimaryKey(1);
653 assertNotNull(issue.getAttachments());
654 int attachments = issue.getAttachments().size();
655 IssueAttachment attachment = new IssueAttachment(issue, "my_file", "text/xml", "", 0);
656 attachment.setUser(userDAO.findByPrimaryKey(2));
657 boolean added = issueService.addIssueAttachment(attachment, new byte[]{});
658 assertTrue("attachment added", added);
659
660 issue = issueDAO.findByPrimaryKey(1);
661 assertNotNull(issue.getAttachments());
662 assertEquals("atachment added", attachments + 1, issue.getAttachments().size());
663
664 }
665
666 @Test
667 public void testSetIssueAttachmentData() {
668 boolean modified = issueService.setIssueAttachmentData(1, new byte[]{9, 8, 7});
669 assertTrue("attachment modified", modified);
670
671 IssueAttachment attachment = issueAttachmentDAO.findByPrimaryKey(1);
672 assertNotNull(attachment.getFileData());
673 assertTrue("updated data", Arrays.equals(new byte[]{9, 8, 7}, attachment.getFileData()));
674
675
676 modified = issueService.setIssueAttachmentData("Derived Filename 1", new byte[]{7, 8, 9});
677 assertTrue("attachment modified", modified);
678
679 attachment = issueAttachmentDAO.findByPrimaryKey(1);
680 assertNotNull(attachment.getFileData());
681 assertTrue("updated data", Arrays.equals(new byte[]{7, 8, 9}, attachment.getFileData()));
682
683
684 }
685
686
687
688
689
690
691 @Test
692 public void testRemoveIssueAttachment() {
693 boolean removed = issueService.removeIssueAttachment(1);
694 assertTrue("attachment removed", removed);
695 assertNull("no db attachment", issueAttachmentDAO.findByPrimaryKey(1));
696 }
697
698
699
700
701
702
703 @Test
704
705 public void testRemoveIssueHistoryEntry() {
706 IssueHistory issueHistory = issueHistoryDAO.findByPrimaryKey(1);
707 assertNotNull(issueHistory);
708 issueService.removeIssueHistoryEntry(1, 2);
709 issueHistory = issueHistoryDAO.findByPrimaryKey(1);
710 assertNull(issueHistory);
711 }
712
713
714
715
716
717
718 @Test
719 public void testRemoveIssueRelation() {
720 IssueRelation issueRelation = issueRelationDAO.findByPrimaryKey(1);
721 assertNotNull("issueRelation", issueRelation);
722
723 issueService.removeIssueRelation(1, 2);
724
725 issueRelation = issueRelationDAO.findByPrimaryKey(1);
726 assertNull("issueRelation", issueRelation);
727 }
728
729
730
731
732
733
734 @Test
735 public void testGetIssueProject() {
736 Issue issue = issueService.getIssue(2);
737
738 assertEquals("issue project", issue.getProject(), issueService
739 .getIssueProject(issue.getId()));
740 }
741
742
743
744
745
746
747 @Test
748 public void testGetIssueVersions() {
749
750 List<Version> versions = issueService.getIssueVersions(1);
751 assertNotNull(versions);
752 assertEquals(1, versions.size());
753 assertEquals("version id", new Integer(1), versions.get(0).getId());
754
755 }
756
757
758
759
760
761
762 @Test
763 public void testGetIssueVersionIds() {
764 Set<Integer> versions = issueService.getIssueVersionIds(1);
765 assertNotNull(versions);
766 assertEquals(1, versions.size());
767 assertTrue("version id", versions.contains(1));
768 }
769
770
771
772
773
774
775 @Test
776 public void testGetIssueCreator() {
777
778 Collection<Issue> issues = issueService.getIssuesCreatedByUser(2);
779
780 for (Issue issue : issues) {
781 assertEquals("creator", (Integer) 2, issue.getCreator().getId());
782 }
783
784 User creator = issueService.getIssueCreator(1);
785 assertNotNull(creator);
786 assertEquals(new Integer(2), creator.getId());
787
788 }
789
790
791
792
793
794
795 @Test
796 public void testGetIssueOwner() {
797
798 Collection<Issue> issues = issueService.getIssuesOwnedByUser(2);
799
800 for (Issue issue : issues) {
801 assertEquals("creator", (Integer) 2, issue.getOwner().getId());
802 }
803
804 User owner = issueService.getIssueOwner(1);
805 assertNotNull(owner);
806 assertEquals(new Integer(2), owner.getId());
807
808 }
809
810
811
812
813
814
815 @Test
816 public void testGetIssueActivityInteger() {
817 List<IssueActivity> issueActivities = issueService.getIssueActivity(1);
818 assertNotNull(issueActivities);
819 assertEquals("issue activities for issue#1", 1, issueActivities.size());
820
821 issueActivities = issueService.getIssueActivity(4);
822 assertNotNull(issueActivities);
823 assertEquals("issue activities for issue#4", 1, issueActivities.size());
824
825 }
826
827
828
829
830
831
832 @Test
833 public void testGetIssueActivityIntegerBoolean() {
834 List<IssueActivity> issueActivities = issueService.getIssueActivity(1, true);
835 assertNotNull(issueActivities);
836 assertEquals("issue activities for issue#1 (with notification)", 1, issueActivities.size());
837
838 issueActivities = issueService.getIssueActivity(1, false);
839 assertNotNull(issueActivities);
840 assertEquals("issue activities for issue#1 (without notification)", 0, issueActivities.size());
841 }
842
843
844
845
846
847 @Test
848 public void testGetAllIssueAttachmentCount() {
849 assertEquals("total attachments", new Long(4), issueService.getAllIssueAttachmentCount());
850 }
851
852 @Test
853 public void testGetAllIssueAttachmentSize() {
854 long size = 0L;
855 for (IssueAttachment issueAttachment : issueAttachmentDAO.findAll()) {
856 assertNotNull(issueAttachment);
857 size += issueAttachment.getSize();
858 }
859 size = size / 1024;
860 assertEquals("total attachmentsSize", (Long) size, issueService.getAllIssueAttachmentSize());
861 }
862
863
864
865
866
867
868
869 @Test
870 public void testGetLastIssueHistory() {
871 IssueHistory issueHistory = issueService.getLastIssueHistory(2);
872 assertNotNull("issueHistory", issueHistory);
873 assertEquals("issueHistory id", new Integer(1), issueHistory.getId());
874 }
875
876
877
878
879
880
881 @Test
882 public void testCanViewIssue() {
883
884 Issue issue1 = issueDAO.findByPrimaryKey(1);
885
886 assertTrue("view issue#1 permission for user#2",
887 issueService.canViewIssue(1, userDAO.findByPrimaryKey(2)));
888 assertTrue("view issue#1 permission for user#2",
889 issueService.canViewIssue(issue1, userDAO.findByPrimaryKey(2)));
890
891 assertFalse("view issue#1 permission for user#3",
892 issueService.canViewIssue(1, userDAO.findByPrimaryKey(3)));
893 assertFalse("view issue#1 permission for user#3",
894 issueService.canViewIssue(issue1, userDAO.findByPrimaryKey(3)));
895
896 assertTrue("view issue#1 permission for user#4",
897 issueService.canViewIssue(1, userDAO.findByPrimaryKey(4)));
898 assertTrue("view issue#1 permission for user#4",
899 issueService.canViewIssue(issue1, userDAO.findByPrimaryKey(4)));
900
901 }
902
903
904
905
906
907
908 @Test
909 public void testSearchIssues() throws Exception {
910 Issue expected = issueService.getIssue(2);
911 assertNotNull("expected", expected);
912 assertEquals("expected.history[0].description", "hello..", expected
913 .getHistory().get(0).getDescription());
914
915 IssueSearchQuery query = new IssueSearchQuery();
916
917 query.setText("hello");
918
919 ArrayList<Integer> projectIds = new ArrayList<>();
920 projectIds.add(2);
921 query.setProjects(projectIds);
922
923 User user = expected.getOwner();
924
925 Map<Integer, Set<PermissionType>> permissionsMap = userService
926 .getUsersMapOfProjectIdsAndSetOfPermissionTypes(user,
927 AuthenticationConstants.REQ_SOURCE_WEB);
928
929 List<Issue> result = issueService.searchIssues(query, user,
930 permissionsMap);
931 assertTrue("result.contains(expected)", result.contains(expected));
932
933 }
934
935
936 @Test
937 public void testGetIssueComponents() {
938 List<Component> components = issueService.getIssueComponents(1);
939 assertNotNull(components);
940 assertEquals(1, components.size());
941
942 components = issueService.getIssueComponents(4);
943 assertNotNull(components);
944 assertEquals(0, components.size());
945
946 }
947
948 @Test
949 public void testGetIssueComponentIds() {
950 Set<Integer> componentIds = issueService.getIssueComponentIds(1);
951 assertNotNull(componentIds);
952 assertEquals("component ids for issue#1", 1, componentIds.size());
953
954 componentIds = issueService.getIssueComponentIds(4);
955 assertNotNull(componentIds);
956 assertEquals("component ids for issue#4", 0, componentIds.size());
957
958 }
959
960 @Test
961 public void testGetIssueAttachments() {
962 List<IssueAttachment> attachments = issueService.getIssueAttachments(1);
963 assertNotNull(attachments);
964 assertEquals(4, attachments.size());
965
966 attachments = issueService.getIssueAttachments(2);
967 assertNotNull(attachments);
968 assertEquals(0, attachments.size());
969
970 }
971
972 @Test
973 public void testGetIssueAttachment() {
974 IssueAttachment attachment = issueService.getIssueAttachment(1);
975 assertNotNull(attachment);
976 assertEquals("attachment id", new Integer(1), attachment.getId());
977 assertEquals("attachment file name", "Derived Filename 1", attachment.getFileName());
978
979 }
980
981 @Test
982 public void testGetIssueAttachmentData() {
983 byte[] data = issueService.getIssueAttachmentData(1);
984 assertNotNull(data);
985 assertEquals("abc", new String(data));
986
987 }
988
989 @Test
990 public void testGetIssueHistory() {
991 List<IssueHistory> historyItems = issueService.getIssueHistory(1);
992 assertNotNull(historyItems);
993 assertEquals(0, historyItems.size());
994
995 historyItems = issueService.getIssueHistory(2);
996 assertNotNull(historyItems);
997 assertEquals(1, historyItems.size());
998
999 }
1000
1001 @Test
1002 public void testGetIssueAttachmentCount() {
1003 assertEquals("attachment count for issue#1", 4, issueService.getIssueAttachmentCount(1));
1004 assertEquals("attachment count for issue#4", 0, issueService.getIssueAttachmentCount(4));
1005
1006 }
1007
1008 @Test
1009 public void testGetOpenIssueCountByProjectId() {
1010 assertEquals("open issues for project#2", 4, issueService.getOpenIssueCountByProjectId(2));
1011 assertEquals("open issues for project#3", 0, issueService.getOpenIssueCountByProjectId(3));
1012
1013 }
1014
1015 @Test
1016 public void testGetResolvedIssueCountByProjectId() {
1017 assertEquals("resolved issues for project#2", 0, issueService.getResolvedIssueCountByProjectId(2));
1018 assertEquals("resolved issues for project#3", 0, issueService.getResolvedIssueCountByProjectId(3));
1019
1020 }
1021
1022 @Test
1023 public void testGetTotalIssueCountByProjectId() {
1024 assertEquals("total issues for project#2", 4, issueService.getTotalIssueCountByProjectId(2));
1025 assertEquals("total issues for project#3", 0, issueService.getTotalIssueCountByProjectId(3));
1026
1027 }
1028
1029 @Test
1030 public void testGetLatestIssueDateByProjectId() {
1031 Date date = issueService.getLatestIssueDateByProjectId(2);
1032 assertEquals("latest issue date for project#2", "2008-01-01", new SimpleDateFormat("yyyy-MM-dd").format(date));
1033 assertNull("latest issue date for project#3", issueService.getLatestIssueDateByProjectId(3));
1034
1035 }
1036
1037
1038 @Test
1039 public void testSystemUpdateIssue() throws Exception {
1040 Issue issue = issueDAO.findByPrimaryKey(1);
1041
1042 issueService.systemUpdateIssue(issue, 2);
1043 issue = issueDAO.findByPrimaryKey(1);
1044 assertNotNull(issue);
1045 assertNotNull(issue.getActivities());
1046 boolean hasSystemTypeActivity = false;
1047 for (IssueActivity activity : issue.getActivities()) {
1048 if (IssueActivityType.SYSTEM_UPDATE.equals(activity.getActivityType())) {
1049 hasSystemTypeActivity = true;
1050 break;
1051 }
1052 }
1053 assertTrue("has SYSTEM_UPDATE activity", hasSystemTypeActivity);
1054
1055
1056 }
1057
1058 @SuppressWarnings("deprecation")
1059 @Test
1060 public void testSetNotificationService() {
1061 List<Issue> issues = issueService.getAllIssues();
1062 assertNotNull(issues);
1063 assertEquals("4 issues", 4, issues.size());
1064 }
1065
1066 @Test
1067 public void testGetIssueRelation() {
1068 IssueRelation issueRelation = issueService.getIssueRelation(1);
1069 assertNotNull(issueRelation);
1070 assertNotNull("issue", issueRelation.getIssue());
1071 assertNotNull("related issue", issueRelation.getRelatedIssue());
1072 assertEquals("issue 1", new Integer(1), issueRelation.getIssue().getId());
1073 assertEquals("issue 2", new Integer(2), issueRelation.getRelatedIssue().getId());
1074
1075 }
1076
1077
1078 @Override
1079 public void onSetUp() throws Exception {
1080
1081 super.onSetUp();
1082 this.issueService = (IssueService) applicationContext
1083 .getBean("issueService");
1084
1085 this.userDAO = (UserDAO) applicationContext.getBean("userDAO");
1086 this.userService = (UserService) applicationContext.getBean("userService");
1087 this.issueDAO = (IssueDAO) applicationContext.getBean("issueDAO");
1088 this.issueRelationDAO = (IssueRelationDAO) applicationContext.getBean("issueRelationDAO");
1089 this.issueHistoryDAO = (IssueHistoryDAO) applicationContext.getBean("issueHistoryDAO");
1090 this.issueHistoryDAO = (IssueHistoryDAO) applicationContext.getBean("issueHistoryDAO");
1091 this.issueAttachmentDAO = (IssueAttachmentDAO) applicationContext.getBean("issueAttachmentDAO");
1092
1093 }
1094
1095 protected String[] getDataSetFiles() {
1096 return new String[]{"dataset/userpreferencesbean_dataset.xml",
1097 "dataset/userbean_dataset.xml",
1098 "dataset/customfieldbean_dataset.xml",
1099 "dataset/customfieldvaluebean_dataset.xml",
1100 "dataset/projectbean_dataset.xml",
1101 "dataset/projectbean_field_rel_dataset.xml",
1102 "dataset/versionbean_dataset.xml",
1103 "dataset/permissionbean_dataset.xml",
1104 "dataset/issuebean_dataset.xml",
1105 "dataset/issuefieldbean_dataset.xml",
1106 "dataset/issueattachmentbean_dataset.xml",
1107 "dataset/issueactivitybean_dataset.xml",
1108 "dataset/issuehistorybean_dataset.xml",
1109 "dataset/notificationbean_dataset.xml",
1110 "dataset/componentbean_dataset.xml",
1111 "dataset/issue_component_rel_dataset.xml",
1112 "dataset/issue_version_rel_dataset.xml",
1113 "dataset/issuerelationbean_dataset.xml",
1114 };
1115 }
1116
1117
1118 }