The H2
is not supporting stored procedures. In place of stored procedure we can create a function which returns an output like a stored-procedures. Same as we're using in registerInOut parameters.
For example, if your QueryConst looks like this:
public static final String INSERT_EMPLOYEE = "{call INSERT_EMPLOYEE(?,?,?)}";
then,
We can use schema.sql
(which executes before @Test
)
DROP ALIAS IF EXISTS INSERT_EMPLOYEE;
CREATE ALIAS INSERT_EMPLOYEE FOR "com.test.EmployeeDaoImplTest.updateEmpStoredproc";
package com.test;
@ContextConfiguration(locations = { "classpath:configxmltest.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@Sql(scripts = { "classpath:schema.sql" }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
public class EmployeeDaoImplTest {
public static final String INSERT_EMPLOYEE = "{call INSERT_EMPLOYEE(?,?,?)}";
@Autowired
EmployeeDaoImpl employeeDaoTest;
and other dependencies....(if any)
@Test
public void testUpdateEmployee() {
..ur logic if any input data settings
assertEquals("Inserted Successfully", employeeDaoTest.updateEmployee(input, INSERT_EMPLOYEE));
}
public static ResultSet updateEmpStoredproc(String name, String w, Integer i) throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("input", Types.VARCHAR, 255, 0);
rs.addColumn("error", Types.VARCHAR, 255, 0);
rs.addColumn("count", Types.INTEGER, 10, 0);
rs.addRow(0, "Inserted Successfully");
rs.addRow(1, 10);
return rs;
}
}