lundi 23 février 2015

mockrunner jdbc - no columns/rows in result set

I try to set up a test with mockrunner for the first time. The connection is established, but I only get an empty result set.


The mocking code looks something like this; I get the data from a csv file.



StatementResultSetHandler statementHandler = getJDBCMockObjectFactory()
.getMockConnection().getStatementResultSetHandler();
URL stmtObjectsUrl = this.getClass().getResource("stmtOb.csv");
FileResultSetFactory factory = new FileResultSetFactory(stmtObjectsUrl.getFile());
factory.setFirstLineContainsColumnNames(true);
MockResultSet result = statementHandler.createResultSet(
"stmtObjects", factory);
setUseRegularExpressions(true);
statementHandler.prepareResultSet("SELECT.*", result);


The csv file looks like this:



"OBJECT_NAME" "OBJECT_TYPE"
"ABC" "TRIGGER"
"DEF" "TRIGGER"


As I have no idea where the problem is and the test is rather complex, I tried to reduce the test. I simply execute the method I want to test and then call getExecutedSQLStatements(), to see the statements I want to intercept with MockResultSet.prepareResultSet(). Even this does not work as expected. I only get an empty list, even though I am quite certain that the executed method did execute an SQL statement, as I print out the (empty) resultset inside the tested method after executing the query.



public class ExtractDataTest extends BasicJDBCTestCaseAdapter {
final String DBCONN_USER = "a";
final String DBCONN_PASSWORD = "b";
final String DBCONN_URL = "c";
@Before
public void setUp() throws Exception {
Map<String, String> environmentVars = new HashMap<String, String>();
environmentVars .put("DBCONN_USER", DBCONN_USER);
environmentVars.put("DBCONN_PASSWORD", DBCONN_PASSWORD);
environmentVars.put("DBCONN_URL", DBCONN_URL);
Environment.setEnv(environmentVars);
super.setUp();
/**
* Recreate the values of the original environment variables inside the JVM.
* @throws Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void test() throws Exception {
Constructor<ExtractPLSQL> c = ExtractPLSQL.class.getDeclaredConstructor(String.class, String.class);
c.setAccessible(true);
Path tmpDir = Files.createTempDirectory("extract_plsql_tmp");
ExtractPLSQL sut = c.newInstance(tmpDir.toAbsolutePath().toString(), "UTF-8");
sut.extractAll();
System.out.println(this.getExecutedSQLStatements());
}
}

Aucun commentaire:

Enregistrer un commentaire