KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > core > support > JdbcDaoSupportTests


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

33 public class JdbcDaoSupportTests extends TestCase {
34
35     public void testJdbcDaoSupportWithDataSource() throws Exception JavaDoc {
36         MockControl dsControl = MockControl.createControl(DataSource JavaDoc.class);
37         DataSource JavaDoc ds = (DataSource JavaDoc) dsControl.getMock();
38         final List JavaDoc test = new ArrayList JavaDoc();
39         JdbcDaoSupport dao = new JdbcDaoSupport() {
40             protected void initDao() {
41                 test.add("test");
42             }
43         };
44         dao.setDataSource(ds);
45         dao.afterPropertiesSet();
46         assertEquals("Correct DataSource", ds, dao.getDataSource());
47         assertEquals("Correct JdbcTemplate", ds, dao.getJdbcTemplate().getDataSource());
48         assertEquals("initDao called", test.size(), 1);
49     }
50
51     public void testJdbcDaoSupportWithJdbcTemplate() throws Exception JavaDoc {
52         JdbcTemplate template = new JdbcTemplate();
53         final List JavaDoc test = new ArrayList JavaDoc();
54         JdbcDaoSupport dao = new JdbcDaoSupport() {
55             protected void initDao() {
56                 test.add("test");
57             }
58         };
59         dao.setJdbcTemplate(template);
60         dao.afterPropertiesSet();
61         assertEquals("Correct JdbcTemplate", dao.getJdbcTemplate(), template);
62         assertEquals("initDao called", test.size(), 1);
63     }
64
65 }
66
Popular Tags