KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > jdo > support > JdoDaoSupportTests


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.jdo.support;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.jdo.PersistenceManagerFactory;
23
24 import junit.framework.TestCase;
25 import org.easymock.MockControl;
26
27 import org.springframework.orm.jdo.JdoTemplate;
28
29 /**
30  * @author Juergen Hoeller
31  * @since 30.07.2003
32  */

33 public class JdoDaoSupportTests extends TestCase {
34
35     public void testJdoDaoSupportWithPersistenceManagerFactory() throws Exception JavaDoc {
36         MockControl pmfControl = MockControl.createControl(PersistenceManagerFactory.class);
37         PersistenceManagerFactory pmf = (PersistenceManagerFactory) pmfControl.getMock();
38         pmfControl.replay();
39         final List JavaDoc test = new ArrayList JavaDoc();
40         JdoDaoSupport dao = new JdoDaoSupport() {
41             protected void initDao() {
42                 test.add("test");
43             }
44         };
45         dao.setPersistenceManagerFactory(pmf);
46         dao.afterPropertiesSet();
47         assertEquals("Correct PersistenceManagerFactory", pmf, dao.getPersistenceManagerFactory());
48         assertEquals("Correct JdoTemplate", pmf, dao.getJdoTemplate().getPersistenceManagerFactory());
49         assertEquals("initDao called", test.size(), 1);
50         pmfControl.verify();
51     }
52
53     public void testJdoDaoSupportWithJdoTemplate() throws Exception JavaDoc {
54         JdoTemplate template = new JdoTemplate();
55         final List JavaDoc test = new ArrayList JavaDoc();
56         JdoDaoSupport dao = new JdoDaoSupport() {
57             protected void initDao() {
58                 test.add("test");
59             }
60         };
61         dao.setJdoTemplate(template);
62         dao.afterPropertiesSet();
63         assertEquals("Correct JdoTemplate", template, dao.getJdoTemplate());
64         assertEquals("initDao called", test.size(), 1);
65     }
66
67 }
68
Popular Tags