KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > ojb > support > PersistenceBrokerDaoSupportTests


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.ojb.support;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import junit.framework.TestCase;
23 import org.apache.ojb.broker.PersistenceBrokerFactory;
24
25 import org.springframework.orm.ojb.PersistenceBrokerTemplate;
26
27 /**
28  * @author Juergen Hoeller
29  * @since 08.07.2004
30  */

31 public class PersistenceBrokerDaoSupportTests extends TestCase {
32
33     public void testWithDefaultSettings() throws Exception JavaDoc {
34         final List JavaDoc test = new ArrayList JavaDoc();
35         PersistenceBrokerDaoSupport dao = new PersistenceBrokerDaoSupport() {
36             protected void initDao() {
37                 test.add("test");
38             }
39         };
40         dao.afterPropertiesSet();
41         assertEquals(PersistenceBrokerFactory.getDefaultKey(), dao.getPersistenceBrokerTemplate().getPbKey());
42         assertEquals("initDao called", test.size(), 1);
43     }
44
45     public void testWithJcdAlias() throws Exception JavaDoc {
46         final List JavaDoc test = new ArrayList JavaDoc();
47         PersistenceBrokerDaoSupport dao = new PersistenceBrokerDaoSupport() {
48             protected void initDao() {
49                 test.add("test");
50             }
51         };
52         dao.setJcdAlias("alias1");
53         dao.afterPropertiesSet();
54         assertEquals("alias1", dao.getPersistenceBrokerTemplate().getJcdAlias());
55         assertEquals("initDao called", test.size(), 1);
56     }
57
58     public void testWithPersistenceBrokerTemplate() throws Exception JavaDoc {
59         PersistenceBrokerTemplate template = new PersistenceBrokerTemplate();
60         final List JavaDoc test = new ArrayList JavaDoc();
61         PersistenceBrokerDaoSupport dao = new PersistenceBrokerDaoSupport() {
62             protected void initDao() {
63                 test.add("test");
64             }
65         };
66         dao.setPersistenceBrokerTemplate(template);
67         dao.afterPropertiesSet();
68         assertEquals("Correct PersistenceBrokerTemplate", template, dao.getPersistenceBrokerTemplate());
69         assertEquals("initDao called", test.size(), 1);
70     }
71
72 }
73
Popular Tags