Added author to all java files with class comments.
[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  * @author Erik Brakkee
35  */
36 public class HibernateGroupSetTest extends InMemoryGroupSetTest {
37     
38     private static final String GROUP_TABLE = "GROUPS"; 
39     
40     private static final String GROUP_QUERY = "select * from " + GROUP_TABLE + " where name = ?";
41     
42     public HibernateGroupSetTest() { 
43         super(UsermgtSpringConfigFiles.class, UsermgtHibernateMappingFiles.class);
44     }
45
46     /* (non-Javadoc)
47      * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupCount(int)
48      */
49     @Override
50     protected void checkGroupCount(int aSize) throws SQLException {
51         super.flush(); 
52         super.checkGroupCount(aSize);
53         assertEquals(aSize, getTableSize(GROUP_TABLE));
54     }
55     
56     /* (non-Javadoc)
57      * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String)
58      */
59     @Override
60     protected void checkGroupExists(final String aGroup) throws SQLException {
61         flush();
62         Map<String,Integer> result = 
63         executeTransaction(new TestTransactionCallback()  { 
64             /* (non-Javadoc)
65              * @see org.wamblee.test.TestTransactionCallback#execute()
66              */
67             @Override
68             public Map execute() throws Exception {
69                 ResultSet result = executeQuery(GROUP_QUERY, aGroup);
70                 Map<String,Integer> res = new HashMap<String,Integer>(); 
71                 res.put("result", countResultSet(result));
72                 return res; 
73             }
74         }); 
75       
76         int count = result.get("result");
77         assertEquals(1, count);
78     }
79     
80     /* (non-Javadoc)
81      * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang.String)
82      */
83     @Override
84     protected void checkGroupNotExists(String aGroup) throws SQLException {
85        flush(); 
86        ResultSet result = executeQuery(GROUP_QUERY, aGroup); 
87        assertEquals(0, countResultSet(result));
88     }
89     
90     /* (non-Javadoc)
91      * @see org.wamblee.usermgt.InMemoryGroupSetTest#createGroupSet()
92      */
93     @Override
94     protected GroupSet createGroupSet() {
95         return BeanKernel.getBeanFactory().find(GroupSet.class); 
96     }
97     
98 }