KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > persistence > core > RoleDAOTest


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.persistence.core;
17
18 import com.blandware.atleap.model.core.Role;
19 import org.springframework.dao.DataAccessException;
20
21 /**
22  * <p>This class is used to test current implementation of RoleDAO interface</p>
23  * <p><a HREF="RoleDAOTest.java.htm"><i>View Source</i></a></p>
24  *
25  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
26  * @version $Revision: 1.5 $ $Date: 2006/03/11 14:06:34 $ * @see com.blandware.atleap.persistence.core.RoleDAO
27  */

28 public class RoleDAOTest extends BaseDAOTestCase {
29     private RoleDAO roleDAO = null;
30
31     protected void setUp() throws Exception JavaDoc {
32         super.setUp();
33         roleDAO = (RoleDAO) ctx.getBean("roleDAO");
34     }
35
36     protected void tearDown() throws Exception JavaDoc {
37         super.tearDown();
38         roleDAO = null;
39     }
40
41     public void testRetrieveInvalidRole() throws Exception JavaDoc {
42         Role role = roleDAO.retrieveRole("badrolename");
43         assertNull(role);
44     }
45
46     public void testRetrieveRole() throws Exception JavaDoc {
47         Role role = roleDAO.retrieveRole("core-commons-login");
48         assertNotNull(role);
49     }
50
51     public void testUpdateRole() throws Exception JavaDoc {
52         Role role = roleDAO.retrieveRole("core-commons-login");
53         role.setDescription("test description");
54
55         roleDAO.updateRole(role);
56         assertEquals(role.getDescription(), "test description");
57     }
58
59     public void testCreateAndDeleteRole() throws Exception JavaDoc {
60         Role role = new Role();
61         role.setName("testrole");
62         role.setTitle("Test Role");
63         role.setFixed(Boolean.FALSE);
64         role.setDescription("new role description");
65
66         roleDAO.createRole(role);
67         assertNotNull(role.getName());
68
69         roleDAO.deleteRole(role);
70
71         try {
72             role = roleDAO.retrieveRole("testrole");
73             fail("retrieveRole should throw DataAccessException, because role has been previously deleted in the same session");
74         } catch ( DataAccessException e ) {
75             assertNotNull(e);
76         }
77     }
78 }
79
Popular Tags