@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2019 the original author or authors .
* Copyright 2002 - 202 1 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -47,30 +47,26 @@ import static org.mockito.Mockito.verify;
@@ -47,30 +47,26 @@ import static org.mockito.Mockito.verify;
* @author Thomas Risberg
* @author Kiril Nugmanov
* /
public class SimpleJdbcCallTests {
class SimpleJdbcCallTests {
private Connection connection ;
private final Connection connection = mock ( Connection . class ) ;
private DatabaseMetaData databaseMetaData ;
private final DatabaseMetaData databaseMetaData = mock ( DatabaseMetaData . class ) ;
private DataSource dataSource ;
private final DataSource dataSource = mock ( DataSource . class ) ;
private CallableStatement callableStatement ;
private final CallableStatement callableStatement = mock ( CallableStatement . class ) ;
@BeforeEach
public void setUp ( ) throws Exception {
connection = mock ( Connection . class ) ;
databaseMetaData = mock ( DatabaseMetaData . class ) ;
dataSource = mock ( DataSource . class ) ;
callableStatement = mock ( CallableStatement . class ) ;
void setUp ( ) throws Exception {
given ( connection . getMetaData ( ) ) . willReturn ( databaseMetaData ) ;
given ( dataSource . getConnection ( ) ) . willReturn ( connection ) ;
}
@Test
public void testN oSuchStoredProcedure( ) throws Exception {
void n oSuchStoredProcedure( ) throws Exception {
final String NO_SUCH_PROC = "x" ;
SQLException sqlException = new SQLException ( "Syntax error or access violation exception" , "42000" ) ;
given ( databaseMetaData . getDatabaseProductName ( ) ) . willReturn ( "MyDB" ) ;
@ -81,8 +77,8 @@ public class SimpleJdbcCallTests {
@@ -81,8 +77,8 @@ public class SimpleJdbcCallTests {
given ( connection . prepareCall ( "{call " + NO_SUCH_PROC + "()}" ) ) . willReturn ( callableStatement ) ;
SimpleJdbcCall sproc = new SimpleJdbcCall ( dataSource ) . withProcedureName ( NO_SUCH_PROC ) ;
try {
assertThatExceptionOfType ( BadSqlGrammarException . class ) . isThrownBy ( ( ) - >
sproc . execute ( ) )
assertThatExceptionOfType ( BadSqlGrammarException . class )
. isThrownBy ( ( ) - > sproc . execute ( ) )
. withCause ( sqlException ) ;
}
finally {
@ -92,7 +88,7 @@ public class SimpleJdbcCallTests {
@@ -92,7 +88,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testU nnamedParameterHandling( ) throws Exception {
void u nnamedParameterHandling( ) throws Exception {
final String MY_PROC = "my_proc" ;
SimpleJdbcCall sproc = new SimpleJdbcCall ( dataSource ) . withProcedureName ( MY_PROC ) ;
// Shouldn't succeed in adding unnamed parameter
@ -101,7 +97,7 @@ public class SimpleJdbcCallTests {
@@ -101,7 +97,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testA ddInvoiceProcWithoutMetaDataUsingMapParamSource( ) throws Exception {
void a ddInvoiceProcWithoutMetaDataUsingMapParamSource( ) throws Exception {
initializeAddInvoiceWithoutMetaData ( false ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withProcedureName ( "add_invoice" ) ;
adder . declareParameters (
@ -117,7 +113,7 @@ public class SimpleJdbcCallTests {
@@ -117,7 +113,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testA ddInvoiceProcWithoutMetaDataUsingArrayParams( ) throws Exception {
void a ddInvoiceProcWithoutMetaDataUsingArrayParams( ) throws Exception {
initializeAddInvoiceWithoutMetaData ( false ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withProcedureName ( "add_invoice" ) ;
adder . declareParameters (
@ -131,7 +127,7 @@ public class SimpleJdbcCallTests {
@@ -131,7 +127,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testA ddInvoiceProcWithMetaDataUsingMapParamSource( ) throws Exception {
void a ddInvoiceProcWithMetaDataUsingMapParamSource( ) throws Exception {
initializeAddInvoiceWithMetaData ( false ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withProcedureName ( "add_invoice" ) ;
Number newId = adder . executeObject ( Number . class , new MapSqlParameterSource ( )
@ -143,7 +139,7 @@ public class SimpleJdbcCallTests {
@@ -143,7 +139,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testA ddInvoiceProcWithMetaDataUsingArrayParams( ) throws Exception {
void a ddInvoiceProcWithMetaDataUsingArrayParams( ) throws Exception {
initializeAddInvoiceWithMetaData ( false ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withProcedureName ( "add_invoice" ) ;
Number newId = adder . executeObject ( Number . class , 1103 , 3 ) ;
@ -153,7 +149,7 @@ public class SimpleJdbcCallTests {
@@ -153,7 +149,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testA ddInvoiceFuncWithoutMetaDataUsingMapParamSource( ) throws Exception {
void a ddInvoiceFuncWithoutMetaDataUsingMapParamSource( ) throws Exception {
initializeAddInvoiceWithoutMetaData ( true ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withFunctionName ( "add_invoice" ) ;
adder . declareParameters (
@ -169,7 +165,7 @@ public class SimpleJdbcCallTests {
@@ -169,7 +165,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testA ddInvoiceFuncWithoutMetaDataUsingArrayParams( ) throws Exception {
void a ddInvoiceFuncWithoutMetaDataUsingArrayParams( ) throws Exception {
initializeAddInvoiceWithoutMetaData ( true ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withFunctionName ( "add_invoice" ) ;
adder . declareParameters (
@ -183,7 +179,7 @@ public class SimpleJdbcCallTests {
@@ -183,7 +179,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testA ddInvoiceFuncWithMetaDataUsingMapParamSource( ) throws Exception {
void a ddInvoiceFuncWithMetaDataUsingMapParamSource( ) throws Exception {
initializeAddInvoiceWithMetaData ( true ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withFunctionName ( "add_invoice" ) ;
Number newId = adder . executeFunction ( Number . class , new MapSqlParameterSource ( )
@ -192,22 +188,20 @@ public class SimpleJdbcCallTests {
@@ -192,22 +188,20 @@ public class SimpleJdbcCallTests {
assertThat ( newId . intValue ( ) ) . isEqualTo ( 4 ) ;
verifyAddInvoiceWithMetaData ( true ) ;
verify ( connection , atLeastOnce ( ) ) . close ( ) ;
}
@Test
public void testA ddInvoiceFuncWithMetaDataUsingArrayParams( ) throws Exception {
void a ddInvoiceFuncWithMetaDataUsingArrayParams( ) throws Exception {
initializeAddInvoiceWithMetaData ( true ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withFunctionName ( "add_invoice" ) ;
Number newId = adder . executeFunction ( Number . class , 1103 , 3 ) ;
assertThat ( newId . intValue ( ) ) . isEqualTo ( 4 ) ;
verifyAddInvoiceWithMetaData ( true ) ;
verify ( connection , atLeastOnce ( ) ) . close ( ) ;
}
@Test
public void testC orrectFunctionStatement( ) throws Exception {
void c orrectFunctionStatement( ) throws Exception {
initializeAddInvoiceWithMetaData ( true ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withFunctionName ( "add_invoice" ) ;
adder . compile ( ) ;
@ -215,7 +209,7 @@ public class SimpleJdbcCallTests {
@@ -215,7 +209,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testC orrectFunctionStatementNamed( ) throws Exception {
void c orrectFunctionStatementNamed( ) throws Exception {
initializeAddInvoiceWithMetaData ( true ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withNamedBinding ( ) . withFunctionName ( "add_invoice" ) ;
adder . compile ( ) ;
@ -223,7 +217,7 @@ public class SimpleJdbcCallTests {
@@ -223,7 +217,7 @@ public class SimpleJdbcCallTests {
}
@Test
public void testC orrectProcedureStatementNamed( ) throws Exception {
void c orrectProcedureStatementNamed( ) throws Exception {
initializeAddInvoiceWithMetaData ( false ) ;
SimpleJdbcCall adder = new SimpleJdbcCall ( dataSource ) . withNamedBinding ( ) . withProcedureName ( "add_invoice" ) ;
adder . compile ( ) ;