Hi Lukas, Thank you for taking your time. I got it working after I read your answer, thanks.
Yes, I use the DSL.min/max functions. I case some one else looking for the same here is how I did it (using one single column, for two or more columns just add more fields in the dslContext.newResult(...) and in the dslContext.newRecord(...)). // create sql with JOOQ DSLContext database; SelectJoinStep<Record1<Double>> query = database.select(MYTABLE.COLUMN1.max()).from(MYTABLE); // mocking DSLContext dslContext; Double maxValue = 333d; Result<Record1<Double>> result = dslContext.newResult(MYTABLE.COLUMN1.max())); result.add(dslContext.newRecord(MYTABLE.COLUMN1.max())); result.get(0).setValue(MYTABLE.COLUMN1.max(), maxValue); results[0] = new MockResult(1, record1Result); return results; // log output 20:12:57.116 [main] DEBUG org.jooq.tools.StopWatch - Query executed : Total: 85.461ms 20:12:57.127 [main] DEBUG org.jooq.tools.LoggerListener - Fetched result : +-----+ 20:12:57.127 [main] DEBUG org.jooq.tools.LoggerListener - : | max| 20:12:57.128 [main] DEBUG org.jooq.tools.LoggerListener - : +-----+ 20:12:57.128 [main] DEBUG org.jooq.tools.LoggerListener - : |333.0| 20:12:57.128 [main] DEBUG org.jooq.tools.LoggerListener - : +-----+ 20:12:57.129 [main] DEBUG org.jooq.tools.StopWatch - Finishing : Total: 99.993ms, +14.531ms Cheers Carlos Den tisdag 3 februari 2015 kl. 12:33:54 UTC+1 skrev Lukas Eder: > > Hi Carlos, > > The interseting part will now be: How are you creating this query with > jOOQ? > > SELECT MIN(column_name), MAX(column_name) FROM table_name > > > Because from your log output, I suspect you're just using simple DSL.min() > and DSL.max() functions, which produce "min" and "max" column names if you > do not alias them: > > 10:46:22.460 [main] DEBUG org.jooq.tools.LoggerListener - Fetched result >> : +------+------+ >> 10:46:22.460 [main] DEBUG org.jooq.tools.LoggerListener - >> : | min| max| >> 10:46:22.460 [main] DEBUG org.jooq.tools.LoggerListener - >> : +------+------+ > > > However, in your MockDataProvider, you're producing a result that has only > one column called MyTable.DOBLEVALUE_COLUMN > > In other words, the mock database produces a record of type > > +-----------------+ > |DOBLEVALUE_COLUMN| > +-----------------+ > > But your query selects only: > > +------+------+ > | min| max| > +------+------+ > > The "min" and "max" values don't exist in your mock databases's result > set, which is why they are null. > > I hope this helps, > Lukas > > 2015-02-03 10:52 GMT+01:00 <[email protected] <javascript:>>: > >> Hi, >> >> I try to find a way to create JUnit test the following sql statement; >> SELECT MIN(column_name), MAX(column_name) FROM table_name >> >> but I can't understand how to? Any one who has ideas on how to mock the >> sql statement above? >> >> I have tried do the following using the MockDataProvider to mock the >> result without luck. >> >> In the execute method I do; >> >> DSLContext dslContext = DSL.using(SQLDialect.SQLSERVER2008); >> >> >> Result<MyTableRecord> tableRecords = dslContext.newResult(MyTable); >> >> tableRecords.add(dslContext.newRecord(MyTable)); >> tableRecords.get(0).setValue(MyTable.DOBLEVALUE_COLUMN, minValue); >> >> tableRecords.add(dslContext.newRecord(turbineTable)); >> tableRecords.get(1).setValue(MyTable.DOBLEVALUE_COLUMN, maxValue); >> >> results[0] = new MockResult(1, tableRecords); >> return results; >> >> >> And I get the following result?? >> 10:46:22.460 [main] DEBUG org.jooq.tools.LoggerListener - Fetched result >> : +------+------+ >> 10:46:22.460 [main] DEBUG org.jooq.tools.LoggerListener >> - : | min| max| >> 10:46:22.460 [main] DEBUG org.jooq.tools.LoggerListener >> - : +------+------+ >> 10:46:22.460 [main] DEBUG org.jooq.tools.LoggerListener >> - : |{null}|{null}| >> 10:46:22.461 [main] DEBUG org.jooq.tools.LoggerListener >> - : |{null}|{null}| >> 10:46:22.461 [main] DEBUG org.jooq.tools.LoggerListener >> - : +------+------+ >> 10:46:22.461 [main] DEBUG org.jooq.tools.StopWatch - >> Finishing : Total: 14.906s, +4.469s >> >> >> >> Best regards >> Carlos >> >> -- >> 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] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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]. For more options, visit https://groups.google.com/d/optout.
