Removed DOCUMENT ME comments that were generated and applied source code
[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 package org.wamblee.usermgt.hibernate;
17
18 import org.wamblee.system.adapters.DefaultContainer;
19 import org.wamblee.system.adapters.ObjectConfiguration;
20 import org.wamblee.system.core.Scope;
21 import org.wamblee.system.spring.component.DatabaseTesterComponent;
22
23 import org.wamblee.test.spring.TestTransactionCallback;
24
25 import org.wamblee.usermgt.GroupSet;
26 import org.wamblee.usermgt.InMemoryGroupSetTest;
27
28 import java.sql.ResultSet;
29 import java.sql.SQLException;
30
31 import java.util.HashMap;
32 import java.util.Map;
33
34 /**
35  * Tests for {@link org.wamblee.usermgt.hibernate.HibernateGroupSet}
36  * 
37  * @author Erik Brakkee
38  */
39 public class HibernateGroupSetTest extends InMemoryGroupSetTest {
40     private static final String GROUP_TABLE = "GROUPS";
41
42     private static final String GROUP_QUERY = "select * from " + GROUP_TABLE +
43         " where name = ?";
44
45     private DefaultContainer container;
46
47     private Scope scope;
48
49     private DatabaseTesterComponent databaseTester;
50
51     private GroupSet groupSet;
52
53     @Override
54     protected void setUp() throws Exception {
55         container = new UserMgtRepositoryTestContainer("top");
56
57         ObjectConfiguration config = new ObjectConfiguration(
58             HibernateGroupSetTest.class);
59         config.getSetterConfig().clear().add("setGroupSet").add(
60             "setDatabaseTester");
61         container.addComponent("testcase", this, config);
62
63         scope = container.start();
64
65         databaseTester.cleanDatabase();
66         super.setUp();
67     }
68
69     @Override
70     protected void tearDown() throws Exception {
71         container.stop(scope);
72         super.tearDown();
73     }
74
75     public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
76         databaseTester = aDatabaseTester;
77     }
78
79     public void setGroupSet(GroupSet aGroupSet) {
80         groupSet = aGroupSet;
81     }
82
83     /*
84      * (non-Javadoc)
85      * 
86      * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupCount(int)
87      */
88     @Override
89     protected void checkGroupCount(int aSize) throws SQLException {
90         databaseTester.flush();
91         super.checkGroupCount(aSize);
92         assertEquals(aSize, databaseTester.getTableSize(GROUP_TABLE));
93     }
94
95     /*
96      * (non-Javadoc)
97      * 
98      * @see
99      * org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String
100      * )
101      */
102     @Override
103     protected void checkGroupExists(final String aGroup) throws SQLException {
104         databaseTester.flush();
105
106         Map<String, Integer> result = databaseTester
107             .executeTransaction(new TestTransactionCallback() {
108                 /*
109                  * (non-Javadoc)
110                  * 
111                  * @see org.wamblee.test.TestTransactionCallback#execute()
112                  */
113                 @Override
114                 public Map execute() throws Exception {
115                     ResultSet result = databaseTester.executeQuery(GROUP_QUERY,
116                         aGroup);
117                     Map<String, Integer> res = new HashMap<String, Integer>();
118                     res.put("result", databaseTester.countResultSet(result));
119
120                     return res;
121                 }
122             });
123
124         int count = result.get("result");
125         assertEquals(1, count);
126     }
127
128     /*
129      * (non-Javadoc)
130      * 
131      * @see
132      * org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang
133      * .String)
134      */
135     @Override
136     protected void checkGroupNotExists(String aGroup) throws SQLException {
137         databaseTester.flush();
138
139         ResultSet result = databaseTester.executeQuery(GROUP_QUERY, aGroup);
140         assertEquals(0, databaseTester.countResultSet(result));
141     }
142
143     /*
144      * (non-Javadoc)
145      * 
146      * @see org.wamblee.usermgt.InMemoryGroupSetTest#createGroupSet()
147      */
148     @Override
149     protected GroupSet createGroupSet() {
150         return groupSet;
151     }
152 }