1 16 17 package org.springframework.jdbc.core.support; 18 19 import java.sql.ResultSet ; 20 import java.sql.Statement ; 21 22 import org.easymock.MockControl; 23 24 import org.springframework.beans.TestBean; 25 import org.springframework.beans.factory.support.DefaultListableBeanFactory; 26 import org.springframework.jdbc.AbstractJdbcTests; 27 28 31 public class JdbcBeanDefinitionReaderTests extends AbstractJdbcTests { 32 33 public void testValid() throws Exception { 34 String sql = "SELECT NAME AS NAME, PROPERTY AS PROPERTY, VALUE AS VALUE FROM T"; 35 36 MockControl ctrlResultSet = MockControl.createControl(ResultSet .class); 37 ResultSet mockResultSet = (ResultSet ) ctrlResultSet.getMock(); 38 ctrlResultSet.expectAndReturn(mockResultSet.next(), true, 2); 39 ctrlResultSet.expectAndReturn(mockResultSet.next(), false); 40 41 ctrlResultSet.expectAndReturn(mockResultSet.getString(1), "one"); 43 ctrlResultSet.expectAndReturn(mockResultSet.getString(2), "class"); 44 ctrlResultSet.expectAndReturn(mockResultSet.getString(3), "org.springframework.beans.TestBean"); 45 46 ctrlResultSet.expectAndReturn(mockResultSet.getString(1), "one"); 48 ctrlResultSet.expectAndReturn(mockResultSet.getString(2), "age"); 49 ctrlResultSet.expectAndReturn(mockResultSet.getString(3), "53"); 50 51 mockResultSet.close(); 52 ctrlResultSet.setVoidCallable(); 53 54 MockControl ctrlStatement = MockControl.createControl(Statement .class); 55 Statement mockStatement = (Statement ) ctrlStatement.getMock(); 56 ctrlStatement.expectAndReturn(mockStatement.executeQuery(sql), mockResultSet); 57 ctrlStatement.expectAndReturn(mockStatement.getWarnings(), null); 58 mockStatement.close(); 59 ctrlStatement.setVoidCallable(); 60 61 mockConnection.createStatement(); 62 ctrlConnection.setReturnValue(mockStatement); 63 64 ctrlResultSet.replay(); 65 ctrlStatement.replay(); 66 replay(); 67 68 DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); 69 JdbcBeanDefinitionReader reader = new JdbcBeanDefinitionReader(bf); 70 reader.setDataSource(mockDataSource); 71 reader.loadBeanDefinitions(sql); 72 assertEquals("Incorrect number of bean definitions", 1, bf.getBeanDefinitionCount()); 73 TestBean tb = (TestBean) bf.getBean("one"); 74 assertEquals("Age in TestBean was wrong.", 53, tb.getAge()); 75 76 ctrlResultSet.verify(); 77 ctrlStatement.verify(); 78 } 79 80 } 81 | Popular Tags |