Hi i'm triying to mock a DB interaction because i can't access the development database during the test runned by jenkins.
My plan is to "record" my DB interactions in local, storing the objects returned in json files and use them during the jenkins tests.
To do that i have used the CGLIBG to intercept all query methods of the JdbcTemplate i'm using to query the DB and store its results in json files whose names are a hash derived from the original JdbcTemplate call and its parameter values
This is what i'm triying to do
public static JdbcTemplate createMockJdbcTemplate(DataSource dataSource) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(JdbcTemplate.class);
enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
if(DbMode.RESTORE.equals(mode) && method.getName().startsWith("query")) {
return restoreCall(obj, method, args);
}else {
Object retorno=proxy.invokeSuper(obj, args);
if(DbMode.STORE.equals(mode) && method.getName().startsWith("query")) {
storeCall(obj, method, args, retorno);
}
return retorno;
}
});
return (JdbcTemplate)enhancer.create(new Class[] {DataSource.class}, new Object[] {dataSource});
}
My problem is that when i'm going to deserialize the files during the tests, if the expected result object is a collection i'm only going to know that i shoud return a List, a Set, a Map... but not the type of the elements, thanks to the type erasure.
Can I include some info in the serialized json so the deserialzating ObjectMapper can build the correct objects?