KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > hibernate3 > support > HibernateDaoSupportTests


1 /*
2  * Copyright 2002-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
17 package org.springframework.orm.hibernate3.support;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import junit.framework.TestCase;
23 import org.hibernate.SessionFactory;
24 import org.easymock.MockControl;
25
26 import org.springframework.orm.hibernate3.HibernateTemplate;
27
28 /**
29  * @author Juergen Hoeller
30  * @since 05.03.2005
31  */

32 public class HibernateDaoSupportTests extends TestCase {
33
34     public void testHibernateDaoSupportWithSessionFactory() throws Exception JavaDoc {
35         MockControl sfControl = MockControl.createControl(SessionFactory.class);
36         SessionFactory sf = (SessionFactory) sfControl.getMock();
37         sfControl.replay();
38         final List JavaDoc test = new ArrayList JavaDoc();
39         HibernateDaoSupport dao = new HibernateDaoSupport() {
40             protected void initDao() {
41                 test.add("test");
42             }
43         };
44         dao.setSessionFactory(sf);
45         dao.afterPropertiesSet();
46         assertEquals("Correct SessionFactory", sf, dao.getSessionFactory());
47         assertEquals("Correct HibernateTemplate", sf, dao.getHibernateTemplate().getSessionFactory());
48         assertEquals("initDao called", test.size(), 1);
49         sfControl.verify();
50     }
51
52     public void testHibernateDaoSupportWithHibernateTemplate() throws Exception JavaDoc {
53         HibernateTemplate template = new HibernateTemplate();
54         final List JavaDoc test = new ArrayList JavaDoc();
55         HibernateDaoSupport dao = new HibernateDaoSupport() {
56             protected void initDao() {
57                 test.add("test");
58             }
59         };
60         dao.setHibernateTemplate(template);
61         dao.afterPropertiesSet();
62         assertEquals("Correct HibernateTemplate", template, dao.getHibernateTemplate());
63         assertEquals("initDao called", test.size(), 1);
64     }
65
66 }
67
Popular Tags