1 package org.itracker.persistence.dao;
2
3 import org.itracker.AbstractDependencyInjectionTest;
4 import org.itracker.model.Permission;
5 import org.itracker.model.Project;
6 import org.itracker.model.User;
7 import org.junit.Test;
8 import org.springframework.dao.DataAccessException;
9
10 import java.util.List;
11 import static org.itracker.Assert.*;
12
13 public class PermissionDAOImplIT extends AbstractDependencyInjectionTest {
14
15 @SuppressWarnings("unused")
16 private UserDAO userDAO;
17 @SuppressWarnings("unused")
18 private ProjectDAO projectDAO;
19 private PermissionDAO permissionDAO;
20
21 @Test
22 public void testFindByUserId() {
23
24 List<Permission> permissions = permissionDAO.findByUserId(2);
25
26 assertNotNull("permissions", permissions);
27 assertEquals(3, permissions.size());
28
29 }
30
31
32 @Test
33 public void testFailedFindByUserId() {
34
35 try {
36 List<Permission> permissions = permissionDAO.findByUserId(-1);
37 fail("Should have thrown a DataAccessException. Size of list:"
38 + permissions.size());
39 } catch (DataAccessException e) {
40
41 }
42 }
43
44 @Test
45 public void testCreatePermission() {
46
47 Permission foundPermission = permissionDAO.findByUserId(2).get(1);
48 User foundUser = foundPermission.getUser();
49 Project foundProject = foundPermission.getProject();
50
51 assertNotNull(foundPermission);
52 assertNotNull(foundUser);
53 assertNotNull(foundProject);
54 assertEquals(Integer.valueOf(2), foundPermission.getPermissionType().getCode());
55 assertEquals("admin_test1", foundUser.getLogin());
56 assertEquals("test_name", foundProject.getName());
57
58 }
59
60 @Override
61 public void onSetUp() throws Exception {
62 super.onSetUp();
63 userDAO = (UserDAO) applicationContext.getBean("userDAO");
64 projectDAO = (ProjectDAO) applicationContext.getBean("projectDAO");
65 permissionDAO = (PermissionDAO) applicationContext
66 .getBean("permissionDAO");
67 }
68
69 protected String[] getDataSetFiles() {
70 return new String[]{
71 "dataset/userpreferencesbean_dataset.xml",
72 "dataset/userbean_dataset.xml",
73 "dataset/projectbean_dataset.xml",
74 "dataset/permissionbean_dataset.xml"};
75 }
76
77
78 }