1 | /* |
---|
2 | * Copyright (C) 2013 DASISH |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU General Public License |
---|
6 | * as published by the Free Software Foundation; either version 2 |
---|
7 | * of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
17 | */ |
---|
18 | package eu.dasish.annotation.backend.dao.impl; |
---|
19 | |
---|
20 | import eu.dasish.annotation.backend.TestBackendConstants; |
---|
21 | import eu.dasish.annotation.backend.TestInstances; |
---|
22 | import eu.dasish.annotation.backend.dao.UserDao; |
---|
23 | import eu.dasish.annotation.backend.identifiers.UserIdentifier; |
---|
24 | import eu.dasish.annotation.schema.UserWithPermission; |
---|
25 | import java.util.List; |
---|
26 | import org.jmock.Expectations; |
---|
27 | import org.jmock.Mockery; |
---|
28 | import org.junit.Test; |
---|
29 | import org.springframework.beans.factory.annotation.Autowired; |
---|
30 | import static org.junit.Assert.*; |
---|
31 | import org.junit.Ignore; |
---|
32 | import org.junit.runner.RunWith; |
---|
33 | import org.springframework.test.context.ContextConfiguration; |
---|
34 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
---|
35 | |
---|
36 | /** |
---|
37 | * |
---|
38 | * @author olhsha |
---|
39 | */ |
---|
40 | |
---|
41 | @RunWith(SpringJUnit4ClassRunner.class) |
---|
42 | @ContextConfiguration({"/spring-config/dataSource.xml", "/spring-config/permissionsDao.xml"}) |
---|
43 | public class JdbcPermissionsDaoTest extends JdbcResourceDaoTest{ |
---|
44 | |
---|
45 | @Autowired |
---|
46 | JdbcPermissionsDao jdbcPermissionsDao; |
---|
47 | TestInstances testInstances = new TestInstances(); |
---|
48 | |
---|
49 | /** |
---|
50 | * Test of retrievePermissions method, of class PermissionsDao. |
---|
51 | * public List<UserWithPermission> retrievePermissions(Number annotationId) |
---|
52 | */ |
---|
53 | @Test |
---|
54 | @Ignore |
---|
55 | public void testRetrievePermissions() { |
---|
56 | Number testAnnotationId = 2; |
---|
57 | final String external_1 = TestBackendConstants._TEST_USER_3_EXT_ID; |
---|
58 | final String external_2 = TestBackendConstants._TEST_USER_4_EXT_ID; |
---|
59 | final String external_3 = TestBackendConstants._TEST_USER_5_EXT_ID; |
---|
60 | final int principal_1 = 3; |
---|
61 | final int principal_2 = 4; |
---|
62 | final int principal_3 = 5; |
---|
63 | String permission_1 = "owner"; |
---|
64 | String permission_2 = "writer"; |
---|
65 | String permission_3 = "reader"; |
---|
66 | |
---|
67 | // mockery.checking(new Expectations() { |
---|
68 | // { |
---|
69 | // oneOf(userDao).getExternalID(principal_1); |
---|
70 | // will(returnValue(new UserIdentifier(external_1))); |
---|
71 | // |
---|
72 | // oneOf(userDao).getExternalID(principal_2); |
---|
73 | // will(returnValue(new UserIdentifier(external_2))); |
---|
74 | // |
---|
75 | // oneOf(userDao).getExternalID(principal_3); |
---|
76 | // will(returnValue(new UserIdentifier(external_3))); |
---|
77 | // |
---|
78 | // } |
---|
79 | // }); |
---|
80 | |
---|
81 | |
---|
82 | List<UserWithPermission> test = jdbcPermissionsDao.retrievePermissions(testAnnotationId); |
---|
83 | assertEquals(external_1, test.get(0).getRef()); |
---|
84 | assertEquals(external_2, test.get(1).getRef()); |
---|
85 | assertEquals(external_3, test.get(2).getRef()); |
---|
86 | assertEquals(permission_1, test.get(0).getPermission().value()); |
---|
87 | assertEquals(permission_2, test.get(1).getPermission().value()); |
---|
88 | assertEquals(permission_3, test.get(2).getPermission().value()); |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | } |
---|