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.component.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 "setGroupSet").add("setDatabaseTester");
58 _container.addComponent("testcase", this, config);
60 _scope = _container.start();
62 _databaseTester.cleanDatabase();
67 protected void tearDown() throws Exception {
68 _container.stop(_scope);
72 public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
73 _databaseTester = aDatabaseTester;
76 public void setGroupSet(GroupSet aGroupSet) {
77 _groupSet = aGroupSet;
81 * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupCount(int)
84 protected void checkGroupCount(int aSize) throws SQLException {
85 _databaseTester.flush();
86 super.checkGroupCount(aSize);
87 assertEquals(aSize, _databaseTester.getTableSize(GROUP_TABLE));
91 * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String)
94 protected void checkGroupExists(final String aGroup) throws SQLException {
95 _databaseTester.flush();
96 Map<String,Integer> result =
97 _databaseTester.executeTransaction(new TestTransactionCallback() {
99 * @see org.wamblee.test.TestTransactionCallback#execute()
102 public Map execute() throws Exception {
103 ResultSet result = _databaseTester.executeQuery(GROUP_QUERY, aGroup);
104 Map<String,Integer> res = new HashMap<String,Integer>();
105 res.put("result", _databaseTester.countResultSet(result));
110 int count = result.get("result");
111 assertEquals(1, count);
115 * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang.String)
118 protected void checkGroupNotExists(String aGroup) throws SQLException {
119 _databaseTester.flush();
120 ResultSet result = _databaseTester.executeQuery(GROUP_QUERY, aGroup);
121 assertEquals(0, _databaseTester.countResultSet(result));
125 * @see org.wamblee.usermgt.InMemoryGroupSetTest#createGroupSet()
128 protected GroupSet createGroupSet() {