Hello,
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
[email protected] 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
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jooq-user/22cd3d7a-6d8f-4aea-99a7-90b82a59da4an%40googlegroups.com.