Unable to mock a return value Result<Record> from an oracle proc.

239 views
Skip to first unread message

Benjamin Greiner

unread,
Feb 25, 2021, 12:31:41 PM2/25/21
to jOOQ User Group
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 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

Lukas Eder

unread,
Feb 25, 2021, 1:21:12 PM2/25/21
to jOOQ User Group
Hi Benjamin,

Thanks for your message. I'll try to reproduce your case, soon. In the meantime, for that particular case of mocking, it might be easier to use e.g. mockito to mock the fGetArms() method directly, I suppose?

Will report with findings about the exception soon.
Lukas

--
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 jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/22cd3d7a-6d8f-4aea-99a7-90b82a59da4an%40googlegroups.com.

Lukas Eder

unread,
Mar 3, 2021, 11:09:49 AM3/3/21
to jOOQ User Group
Hi Ben,

Thanks a lot for your patience. I can reproduce this. Looks like a bug: https://github.com/jOOQ/jOOQ/issues/11560

I can't think of a workaround from within jOOQ other than mocking your logic on a different layer than JDBC

Thanks again for your report,
Lukas

Lukas Eder

unread,
Mar 3, 2021, 11:47:09 AM3/3/21
to jOOQ User Group
This has been fixed for jOOQ 3.15.0 and 3.14.9. Thanks again for your report.

Lukas

Benjamin Greiner

unread,
Mar 3, 2021, 1:46:56 PM3/3/21
to jOOQ User Group
Thank you Lukas for your timely response and fix. 

It appears that the fix is only available in the snapshot version for now. I am not sure if those versions are available for download or not, but currently I am unable to, not a huge problem. Do you have an estimate on when those versions will be available to be pulled? For now we are just stubbing out those tests and we can fill them back in later. 

Cheers,
B. Greiner

Lukas Eder

unread,
Mar 4, 2021, 3:57:24 AM3/4/21
to jOOQ User Group
Hi Benjamin,

Yes, the fix is available in the snapshot version from here: https://www.jooq.org/download/versions. Snapshot builds are available to licensed customers. 3.14.9 will probably ship at the end of March or early April. We've just shipped 3.14.8 and 3.14.9 doesn't have much to offer yet:

If you're interested in continuing your jOOQ evaluation with a 3.14.9-SNAPSHOT version, please get in touch at sa...@datageekery.com, and I'll send you an extended trial license key, which gives you access to the above download page

Thanks,
Lukas

Benjamin Greiner

unread,
Mar 4, 2021, 10:14:56 AM3/4/21
to jooq...@googlegroups.com
I have a professional license but was unable to download it. The link was effectively dead.

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/uU09EB5zblc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAB4ELO7-FsXbq9HFemvFd0gKh8e69VwGt3FCxEUei-MHmhA-qQ%40mail.gmail.com.

Lukas Eder

unread,
Mar 4, 2021, 11:52:50 AM3/4/21
to jOOQ User Group
Thanks a lot for letting us know! It's now fixed, snapshots can be downloaded again.

I've noticed that the 3.14.9-SNAPSHOT build that is available from the versions page doesn't yet include the fix. I'll run another deployment right away, should be available within about 1h.

Best Regards,
Lukas

Reply all
Reply to author
Forward
0 new messages