I've been very impressed with the functionality and ease of the JOOQ thus far, but I think I've stumbled into my first real-head scratcher.
I am attempting to mock an oracle stored proc that utilized JOOQ's code generator capabilities. The procedure has multiple input params and one single return value parameter of type Result<Record>.
public static Result<Record> fGetArms(
Configuration configuration
, String param1
, Number param2
) {
FGetArms f = new FGetArms();
f.setParam1(param1);
f.setParam2(param2);
f.execute(configuration);
return f.getReturnValue();
}
When I run my integration tests it works as expected. However unit tests I cannot seem to be able to create a successful mock of the Result<Record> return type with configured values.
With the following code I am getting this exceptions
java.lang.ClassCastException: class org.jooq.impl.ResultImpl cannot be cast to class java.sql.ResultSet (org.jooq.impl.ResultImpl is in module org....@3.14.6 of loader 'app'; java.sql.ResultSet is in module java.sql of loader 'platform')
Perhaps I am fundamentally misunderstanding how to return the data via the returnValue field.
final MockDataProvider mockDataProvider;
mockDataProvider = (MockExecuteContext context) -> {
// Use ordinary jOOQ API to create an org.jooq.Result object.
// You can also use ordinary jOOQ API to load CSV files or
// other formats, here!
DSLContext create = DSL.using(SQLDialect.ORACLE);
// Cursor column definitions.
Field<String> meterName = DSL.field("METER_NAME", SQLDataType.VARCHAR);
Field<String> armDescription = DSL.field("ARM_DESCRIPTION", SQLDataType.VARCHAR);
Field<String> meterId = DSL.field("METER_ID", SQLDataType.VARCHAR);
// Add rows to cursor results.
Result cursorResult = create.newResult(meterName, armDescription, meterId);
cursorResult.add(create.newRecord(meterName, armDescription, meterId).values("B1", "Arm Desc", "B1HK"));
cursorResult.add(create.newRecord(meterName, armDescription, meterId).values("B2", "Arm Desc", "B2DB"));
// Define the return value column as defined by the code-gen.
Field<Result<Record>> returnValue = DSL.field("RETURN_VALUE", SQLDataType.RESULT);
// Create new Result and set its single row value for returnValue to the cursor results.
Result outResult = create.newResult(returnValue);
outResult.add(create.newRecord(returnValue).values(cursorResult));
// Now, return 1-many results, depending on whether this is
// a batch/multi-result context
return new MockResult[]
{
new MockResult(1, outResult)
};
};
Cheers,
Ben