2 * Copyright 2005-2010 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.
16 package org.wamblee.usermgt.hibernate;
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;
23 import org.wamblee.test.spring.TestTransactionCallback;
25 import org.wamblee.usermgt.GroupSet;
26 import org.wamblee.usermgt.InMemoryGroupSetTest;
28 import java.sql.ResultSet;
29 import java.sql.SQLException;
31 import java.util.HashMap;
35 * Tests for {@link org.wamblee.usermgt.hibernate.HibernateGroupSet}
37 * @author Erik Brakkee
39 public class HibernateGroupSetTest extends InMemoryGroupSetTest {
40 private static final String GROUP_TABLE = "GROUPS";
42 private static final String GROUP_QUERY = "select * from " + GROUP_TABLE +
45 private DefaultContainer container;
49 private DatabaseTesterComponent databaseTester;
51 private GroupSet groupSet;
54 protected void setUp() throws Exception {
55 container = new UserMgtRepositoryTestContainer("top");
57 ObjectConfiguration config = new ObjectConfiguration(
58 HibernateGroupSetTest.class);
59 config.getSetterConfig().clear().add("setGroupSet").add(
61 container.addComponent("testcase", this, config);
63 scope = container.start();
65 databaseTester.cleanDatabase();
70 protected void tearDown() throws Exception {
71 container.stop(scope);
75 public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
76 databaseTester = aDatabaseTester;
79 public void setGroupSet(GroupSet aGroupSet) {
86 * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupCount(int)
89 protected void checkGroupCount(int aSize) throws SQLException {
90 databaseTester.flush();
91 super.checkGroupCount(aSize);
92 assertEquals(aSize, databaseTester.getTableSize(GROUP_TABLE));
99 * org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String
103 protected void checkGroupExists(final String aGroup) throws SQLException {
104 databaseTester.flush();
106 Map<String, Integer> result = databaseTester
107 .executeTransaction(new TestTransactionCallback() {
111 * @see org.wamblee.test.TestTransactionCallback#execute()
114 public Map execute() throws Exception {
115 ResultSet result = databaseTester.executeQuery(GROUP_QUERY,
117 Map<String, Integer> res = new HashMap<String, Integer>();
118 res.put("result", databaseTester.countResultSet(result));
124 int count = result.get("result");
125 assertEquals(1, count);
132 * org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang
136 protected void checkGroupNotExists(String aGroup) throws SQLException {
137 databaseTester.flush();
139 ResultSet result = databaseTester.executeQuery(GROUP_QUERY, aGroup);
140 assertEquals(0, databaseTester.countResultSet(result));
146 * @see org.wamblee.usermgt.InMemoryGroupSetTest#createGroupSet()
149 protected GroupSet createGroupSet() {