Hi,

Not sure if I should open an issue on github or open a topic here.
But I'm having troubles trying to use the mockDataProviders successfully in 
my unit tests. The following code results in an DataAccessException.
As you can see from the code provided below, I am not using Jooq with the 
code generation portion but just Strings for the column and table names.
Is it possible to use the mock interfaces as such, without any code 
generated types? Or is there some methods I can use to get my test to be 
working. 
 
Thank you for any help you can provide.

Best,
bshum

```
public class MyDataProvider implements MockDataProvider {

@Override
    public MockResult[] execute(MockExecuteContext ctx) throws SQLException{
        DSLContext create = DSL.using(SQLDialect.MYSQL);
        String sql = ctx.sql();
        System.out.println(sql);
        MockResult[] mock = new MockResult[1];
        Result result = create.newResult();
        Field f1 = DSL.field("COLUMN_NAME");
        Record record = create.newRecord(f1);
        record.setValue(f1, "colvalue");
        result.add(record);
        mock[0] = new MockResult(1, result);

        return mock;
    }
```

Test method
```
@Test
    public void JooqTest(){
        MyDataProvider provider = new MyDataProvider();
        MockConnection connection = new MockConnection(provider);
        DSLContext create = DSL.using(connection, SQLDialect.MYSQL);
        ResultQuery rq =  create.select(field("COLNAME")).from("TALBENAME");
        rq.fetch();
    }
```

```
org.jooq.exception.DataAccessException: SQL [select COLNAME from 
TALBENAME]; Unknown column index : 1
    at org.jooq.impl.Utils.translate(Utils.java:1477)
    at 
org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:505)
    at 
org.jooq.impl.CursorImpl$CursorIterator.fetchOne(CursorImpl.java:1423)
    at org.jooq.impl.CursorImpl$CursorIterator.hasNext(CursorImpl.java:1379)
    at org.jooq.impl.CursorImpl.fetch(CursorImpl.java:202)
    at org.jooq.impl.CursorImpl.fetch(CursorImpl.java:177)
    at 
org.jooq.impl.AbstractResultQuery.execute(AbstractResultQuery.java:280)
    at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:331)
    at org.jooq.impl.AbstractResultQuery.fetch(AbstractResultQuery.java:336)
    at org.jooq.impl.SelectImpl.fetch(SelectImpl.java:2256)
    at 
integration.com.turn.samburu.component.HadoopJobLoaderTest.JooqTest(HadoopJobLoaderTest.java:71)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at 
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:842)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1166)
    at 
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.runWorkers(TestRunner.java:1178)
    at org.testng.TestRunner.privateRun(TestRunner.java:757)
    at org.testng.TestRunner.run(TestRunner.java:608)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1158)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1083)
    at org.testng.TestNG.run(TestNG.java:999)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:203)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.sql.SQLException: Unknown column index : 1
    at org.jooq.tools.jdbc.MockResultSet.checkField(MockResultSet.java:148)
    at org.jooq.tools.jdbc.MockResultSet.getValue(MockResultSet.java:381)
    at org.jooq.tools.jdbc.MockResultSet.getObject(MockResultSet.java:726)
    at org.jooq.impl.Utils.getFromResultSet(Utils.java:2621)
    at org.jooq.impl.Utils.getFromResultSet(Utils.java:2461)
    at 
org.jooq.impl.CursorImpl$CursorIterator$CursorRecordInitialiser.setValue(CursorImpl.java:1468)
    at 
org.jooq.impl.CursorImpl$CursorIterator$CursorRecordInitialiser.operate(CursorImpl.java:1451)
    at 
org.jooq.impl.CursorImpl$CursorIterator$CursorRecordInitialiser.operate(CursorImpl.java:1443)
    at org.jooq.impl.RecordDelegate.operate(RecordDelegate.java:123)
    at 
org.jooq.impl.CursorImpl$CursorIterator.fetchOne(CursorImpl.java:1411)
    ... 39 more
```

-- 
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.

Reply via email to