bc1e67d173184484245fb57485387063a2c31345
[utils] / security / src / test / java / org / wamblee / usermgt / hibernate / HibernateGroupSetTest.java
1 /*
2  * Copyright 2005 the original author or authors.
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
17 package org.wamblee.usermgt.hibernate;
18
19 import java.sql.ResultSet;
20 import java.sql.SQLException;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.wamblee.general.BeanKernel;
25 import org.wamblee.test.TestTransactionCallback;
26 import org.wamblee.usermgt.GroupSet;
27 import org.wamblee.usermgt.InMemoryGroupSetTest;
28 import org.wamblee.usermgt.UsermgtHibernateMappingFiles;
29 import org.wamblee.usermgt.UsermgtSpringConfigFiles;
30
31 /**
32  * Tests for {@link org.wamblee.usermgt.hibernate.HibernateGroupSet} 
33  */
34 public class HibernateGroupSetTest extends InMemoryGroupSetTest {
35     
36     private static final String GROUP_TABLE = "GROUPS"; 
37     
38     private static final String GROUP_QUERY = "select * from " + GROUP_TABLE + " where name = ?";
39     
40     public HibernateGroupSetTest() { 
41         super(UsermgtSpringConfigFiles.class, UsermgtHibernateMappingFiles.class);
42     }
43
44     /* (non-Javadoc)
45      * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupCount(int)
46      */
47     @Override
48     protected void checkGroupCount(int aSize) throws SQLException {
49         super.flush(); 
50         super.checkGroupCount(aSize);
51         assertEquals(aSize, getTableSize(GROUP_TABLE));
52     }
53     
54     /* (non-Javadoc)
55      * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String)
56      */
57     @Override
58     protected void checkGroupExists(final String aGroup) throws SQLException {
59         flush();
60         Map<String,Integer> result = 
61         executeTransaction(new TestTransactionCallback()  { 
62             /* (non-Javadoc)
63              * @see org.wamblee.test.TestTransactionCallback#execute()
64              */
65             @Override
66             public Map execute() throws Exception {
67                 ResultSet result = executeQuery(GROUP_QUERY, aGroup);
68                 Map<String,Integer> res = new HashMap<String,Integer>(); 
69                 res.put("result", countResultSet(result));
70                 return res; 
71             }
72         }); 
73       
74         int count = result.get("result");
75         assertEquals(1, count);
76     }
77     
78     /* (non-Javadoc)
79      * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang.String)
80      */
81     @Override
82     protected void checkGroupNotExists(String aGroup) throws SQLException {
83        flush(); 
84        ResultSet result = executeQuery(GROUP_QUERY, aGroup); 
85        assertEquals(0, countResultSet(result));
86     }
87     
88     /* (non-Javadoc)
89      * @see org.wamblee.usermgt.InMemoryGroupSetTest#createGroupSet()
90      */
91     @Override
92     protected GroupSet createGroupSet() {
93         return BeanKernel.getBeanFactory().find(GroupSet.class); 
94     }
95     
96 }