2 * Copyright 2005 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.wamblee.usermgt.hibernate;
19 import java.sql.ResultSet;
20 import java.sql.SQLException;
21 import java.util.HashMap;
24 import org.wamblee.system.adapters.DefaultContainer;
25 import org.wamblee.system.adapters.ObjectConfiguration;
26 import org.wamblee.system.core.Scope;
27 import org.wamblee.system.spring.DatabaseTesterComponent;
28 import org.wamblee.test.spring.TestTransactionCallback;
29 import org.wamblee.usermgt.GroupSet;
30 import org.wamblee.usermgt.InMemoryGroupSetTest;
33 * Tests for {@link org.wamblee.usermgt.hibernate.HibernateGroupSet}
35 * @author Erik Brakkee
37 public class HibernateGroupSetTest extends InMemoryGroupSetTest {
39 private static final String GROUP_TABLE = "GROUPS";
41 private static final String GROUP_QUERY = "select * from " + GROUP_TABLE + " where name = ?";
43 private DefaultContainer _container;
46 private DatabaseTesterComponent _databaseTester;
47 private GroupSet _groupSet;
50 protected void setUp() throws Exception {
52 _container = new UserMgtRepositoryTestContainer("top");
54 ObjectConfiguration config = new ObjectConfiguration(
55 HibernateGroupSetTest.class);
56 config.getSetterConfig().clear().add(
57 "groupSet").add("databaseTester");
58 _container.addComponent("testcase", this, config);
60 _scope = _container.start();
62 _databaseTester.cleanDatabase();
66 public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
67 _databaseTester = aDatabaseTester;
70 public void setGroupSet(GroupSet aGroupSet) {
71 _groupSet = aGroupSet;
75 * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupCount(int)
78 protected void checkGroupCount(int aSize) throws SQLException {
79 _databaseTester.flush();
80 super.checkGroupCount(aSize);
81 assertEquals(aSize, _databaseTester.getTableSize(GROUP_TABLE));
85 * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String)
88 protected void checkGroupExists(final String aGroup) throws SQLException {
89 _databaseTester.flush();
90 Map<String,Integer> result =
91 _databaseTester.executeTransaction(new TestTransactionCallback() {
93 * @see org.wamblee.test.TestTransactionCallback#execute()
96 public Map execute() throws Exception {
97 ResultSet result = _databaseTester.executeQuery(GROUP_QUERY, aGroup);
98 Map<String,Integer> res = new HashMap<String,Integer>();
99 res.put("result", _databaseTester.countResultSet(result));
104 int count = result.get("result");
105 assertEquals(1, count);
109 * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang.String)
112 protected void checkGroupNotExists(String aGroup) throws SQLException {
113 _databaseTester.flush();
114 ResultSet result = _databaseTester.executeQuery(GROUP_QUERY, aGroup);
115 assertEquals(0, _databaseTester.countResultSet(result));
119 * @see org.wamblee.usermgt.InMemoryGroupSetTest#createGroupSet()
122 protected GroupSet createGroupSet() {