1 package org.itracker.persistence.dao;
2
3 import org.itracker.AbstractDependencyInjectionTest;
4 import org.itracker.model.*;
5 import org.itracker.model.util.UserUtilities;
6 import org.junit.Test;
7
8 import java.util.*;
9
10 import static org.itracker.Assert.*;
11 public class IssueDAOImplIT extends AbstractDependencyInjectionTest {
12
13 private IssueDAO issueDAO;
14 private UserDAO userDAO;
15
16 @Test
17 public void testCountByProjectAndLowerStatus() {
18
19 Long issueCount = issueDAO.countByProjectAndLowerStatus(2, 300);
20
21 assertEquals(Long.valueOf(2), issueCount);
22 }
23
24 @Test
25 public void testFindByProjectAndHigherStatus() {
26
27 List<Issue> issues = issueDAO.findByProjectAndHigherStatus(2, 200);
28
29 assertEquals(3, issues.size());
30
31 assertContainsIssue(issueDAO.findByPrimaryKey(2), issues);
32 assertContainsIssue(issueDAO.findByPrimaryKey(3), issues);
33
34 }
35
36 @Test
37 public void testIssueDetach() throws Exception {
38
39 Issue issueDetach = issueDAO.findByPrimaryKey(1);
40 issueDAO.detach(issueDetach);
41
42 issueDetach.setDescription("newDescription");
43 issueDetach.setSeverity(issueDetach.getSeverity() + 1);
44
45 Issue issue = issueDAO.findByPrimaryKey(1);
46
47 assertFalse("issueDetach.description equals", issueDetach.getDescription().equals(issue.getDescription()));
48 assertFalse("issueDetach.severity equals", issueDetach.getSeverity().equals(issue.getSeverity()));
49
50
51 issueDetach = issueDAO.findByPrimaryKey(1);
52 issueDetach.setDescription("newDescription");
53 issueDetach.setSeverity(issueDetach.getSeverity() + 1);
54
55 issueDAO.detach(issueDetach);
56
57 issue = issueDAO.findByPrimaryKey(1);
58 issueDAO.refresh(issue);
59
60 assertFalse("issueDetach.description equals - 2", issueDetach.getDescription().equals(issue.getDescription()));
61 assertFalse("issueDetach.severity equals - 2", issueDetach.getSeverity().equals(issue.getSeverity()));
62
63
64 }
65
66 @Test
67 public void testCountByProjectAndHigherStatus() {
68
69 Long issueCount = issueDAO.countByProjectAndHigherStatus(2, 200);
70
71 assertEquals(Long.valueOf(3), issueCount);
72 }
73
74 @Test
75 public void testCountByProject() {
76
77 Long projectCount = issueDAO.countByProject(2);
78
79 assertEquals(Long.valueOf(4), projectCount);
80 }
81
82 @Test
83 public void testQuery() {
84
85 IssueSearchQuery searchQuery = new IssueSearchQuery();
86
87 List<Integer> projectsIDs = new ArrayList<Integer>();
88 projectsIDs.add(2);
89
90 searchQuery.setProjects(projectsIDs);
91
92 User user = userDAO.findByPrimaryKey(2);
93
94 Map<Integer, Set<PermissionType>> permissions = new HashMap<>();
95 HashSet<PermissionType> set = new HashSet(1);
96 set.add(PermissionType.USER_ADMIN);
97 permissions.put(null, set);
98 List<Issue> issues = issueDAO.query(searchQuery, user, permissions);
99
100 assertEquals(4, issues.size());
101
102 }
103
104 @Test
105 public void testFindUnassignedIssues() {
106
107 List<Issue> issues = issueDAO.findUnassignedIssues(100);
108 assertNotNull(issues);
109
110 assertEquals("total unassigned issues, status < 100", 0, issues.size());
111
112 }
113
114 @Test
115 public void testFindByComponent() {
116
117 List<Issue> issues = issueDAO.findByComponent(1);
118 assertNotNull(issues);
119 assertEquals("total issues for component#1", 3, issues.size());
120
121 issues = issueDAO.findByComponent(2);
122 assertNotNull(issues);
123 assertEquals("total issues for component#2", 0, issues.size());
124
125 }
126
127 @Test
128 public void testCountByComponent() {
129
130 assertEquals("total issues for component#1", new Long(3), issueDAO.countByComponent(1));
131 assertEquals("total issues for component#2", new Long(0), issueDAO.countByComponent(2));
132
133 }
134
135 @Test
136 public void testFindByVersion() {
137 List<Issue> issues = issueDAO.findByVersion(1);
138 assertNotNull(issues);
139 assertEquals("total issues for version#1", 3, issues.size());
140
141 issues = issueDAO.findByVersion(2);
142 assertNotNull(issues);
143 assertEquals("total issues for version#2", 0, issues.size());
144
145 }
146
147 @Test
148 public void testCountByVersion() {
149 assertEquals("total issues for version#1", new Long(3), issueDAO.countByVersion(1));
150 assertEquals("total issues for version#2", new Long(0), issueDAO.countByVersion(2));
151
152 }
153
154
155 private void assertContainsIssue(Issue issue, List<Issue> issues) {
156
157 boolean found = false;
158
159 for (Issue issueItem : issues) {
160 if (issueItem.getId().equals(issue.getId())) {
161 found = true;
162 break;
163 }
164 }
165
166 if (!found) {
167 fail("Issue not found in the list.");
168 }
169
170 }
171
172 @Override
173 public void onSetUp() throws Exception {
174 super.onSetUp();
175
176 issueDAO = (IssueDAO) applicationContext.getBean("issueDAO");
177 userDAO = (UserDAO) applicationContext.getBean("userDAO");
178
179
180 }
181
182 protected String[] getDataSetFiles() {
183 return new String[]{
184 "dataset/userpreferencesbean_dataset.xml",
185 "dataset/userbean_dataset.xml",
186 "dataset/projectbean_dataset.xml",
187 "dataset/versionbean_dataset.xml",
188 "dataset/issuebean_dataset.xml",
189 "dataset/issueactivitybean_dataset.xml",
190 "dataset/componentbean_dataset.xml",
191 "dataset/issue_component_rel_dataset.xml",
192 "dataset/issue_version_rel_dataset.xml",
193 };
194 }
195
196
197 }