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.junit.Ignore;
19 import org.wamblee.system.adapters.DefaultContainer;
20 import org.wamblee.system.adapters.ObjectConfiguration;
21 import org.wamblee.system.core.Scope;
22 import org.wamblee.system.spring.component.DatabaseTesterComponent;
24 import org.wamblee.test.spring.TestTransactionCallback;
26 import org.wamblee.usermgt.GroupSet;
27 import org.wamblee.usermgt.InMemoryGroupSetTest;
29 import java.sql.ResultSet;
30 import java.sql.SQLException;
32 import java.util.HashMap;
36 * Tests for {@link org.wamblee.usermgt.hibernate.HibernateGroupSet}
38 * @author Erik Brakkee
41 public class HibernateGroupSetTest extends InMemoryGroupSetTest {
42 private static final String GROUP_TABLE = "GROUPS";
44 private static final String GROUP_QUERY = "select * from " + GROUP_TABLE +
47 private DefaultContainer container;
51 private DatabaseTesterComponent databaseTester;
53 private GroupSet groupSet;
56 protected void setUp() throws Exception {
57 container = new UserMgtRepositoryTestContainer("top");
59 ObjectConfiguration config = new ObjectConfiguration(
60 HibernateGroupSetTest.class);
61 config.getSetterConfig().clear().add("setGroupSet").add(
63 container.addComponent("testcase", this, config);
65 scope = container.start();
67 databaseTester.cleanDatabase();
72 protected void tearDown() throws Exception {
73 container.stop(scope);
77 public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
78 databaseTester = aDatabaseTester;
81 public void setGroupSet(GroupSet aGroupSet) {
88 * @see org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupCount(int)
91 protected void checkGroupCount(int aSize) throws Exception {
92 databaseTester.flush();
93 super.checkGroupCount(aSize);
94 assertEquals(aSize, databaseTester.getTableSize(GROUP_TABLE));
101 * org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupExists(java.lang.String
105 protected void checkGroupExists(final String aGroup) throws SQLException {
106 databaseTester.flush();
108 Map<String, Integer> result = databaseTester
109 .executeTransaction(new TestTransactionCallback() {
113 * @see org.wamblee.test.TestTransactionCallback#execute()
116 public Map execute() throws Exception {
117 ResultSet result = databaseTester.executeQuery(GROUP_QUERY,
119 Map<String, Integer> res = new HashMap<String, Integer>();
120 res.put("result", databaseTester.countResultSet(result));
126 int count = result.get("result");
127 assertEquals(1, count);
134 * org.wamblee.usermgt.InMemoryGroupSetTest#checkGroupNotExists(java.lang
138 protected void checkGroupNotExists(String aGroup) throws SQLException {
139 databaseTester.flush();
141 ResultSet result = databaseTester.executeQuery(GROUP_QUERY, aGroup);
142 assertEquals(0, databaseTester.countResultSet(result));
148 * @see org.wamblee.usermgt.InMemoryGroupSetTest#createGroupSet()
151 protected GroupSet createGroupSet() {