0

I'm trying to get started with DbFit 4.0.0 as described in Getting Started guide.

I have the following test http://localhost:8085/HelloWorldTest

!path lib/*.jar
!|dbfit.OracleTest|
!|Connect|localhost:1521|integration|integration|XEPDB1|

!|Query| select 'test' as x from dual|
|x|
|test|

But when I run the test I'm getting the following problem:

java.lang.Error: Cannot load Oracle database driver oracle.jdbc.OracleDriver. Is the JDBC driver on the classpath?
    at dbfit.api.DbEnvironmentFactory$EnvironmentDescriptor.checkDriver(DbEnvironmentFactory.java:45)
    at dbfit.api.DbEnvironmentFactory$EnvironmentDescriptor.createEnvironmentInstance(DbEnvironmentFactory.java:60)
    at dbfit.api.DbEnvironmentFactory.createEnvironmentInstance(DbEnvironmentFactory.java:102)
    at dbfit.api.DbEnvironmentFactory.newEnvironmentInstance(DbEnvironmentFactory.java:106)
    at dbfit.OracleTest.(OracleTest.java:5)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at fit.FixtureClass.newInstance(FixtureClass.java:24)
    at fit.FixtureLoader.instantiateFixture(FixtureLoader.java:61)
    at fit.FixtureLoader.instantiateFirstValidFixtureClass(FixtureLoader.java:82)
    at fit.FixtureLoader.disgraceThenLoad(FixtureLoader.java:43)
    at fit.Fixture.loadFixture(Fixture.java:142)
    at fit.Fixture.getLinkedFixtureWithArgs(Fixture.java:134)
    at fit.Fixture.doTables(Fixture.java:79)
    at fit.FitServer.process(FitServer.java:81)
    at fit.FitServer.run(FitServer.java:56)
    at fit.FitServer.main(FitServer.java:41)
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at dbfit.api.DbEnvironmentFactory$EnvironmentDescriptor.checkDriver(DbEnvironmentFactory.java:43)
    ... 19 more

I find nothing relevant from:

I'm running DbFit in Linux (Lubuntu 22.04 LTS).

user272735
  • 10,473
  • 9
  • 65
  • 96

1 Answers1

0

I had to solve the following two problems before I got the example running:

  1. missing Oracle JDBC Driver
  2. incorrect connection string

Problem #1 missing Oracle JDBC driver

I downloaded Oracle JDBC driver (ojdbc8.jar) from the Oracle download page:

https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html

and copied it to <DBFIT_HOME>/lib.

Unfortunately after that I run into the second problem.

Problem #2 incorrect connection string

Now I got the following error:

oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
 
    at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:294)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:347)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1688)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:626)
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:813)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:80)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:816)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:620)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at dbfit.api.AbstractDbEnvironment.connect(AbstractDbEnvironment.java:54)
    at dbfit.api.AbstractDbEnvironment.connect(AbstractDbEnvironment.java:81)
    at dbfit.DatabaseTest.connect(DatabaseTest.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at fitlibrary.closure.MethodClosure.invoke(MethodClosure.java:35)
    at fitlibrary.closure.MethodClosure.invokeTyped(MethodClosure.java:28)
    at fitlibrary.closure.CalledMethodTarget.invokeTyped(CalledMethodTarget.java:77)
    at fitlibrary.closure.CalledMethodTarget.invokeTyped(CalledMethodTarget.java:95)
    at fitlibrary.closure.CalledMethodTarget.invokeAndWrap(CalledMethodTarget.java:358)
    at fitlibrary.traverse.workflow.caller.ActionCaller.run(ActionCaller.java:37)
    at fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretRow(DoTraverseInterpreter.java:176)
    at fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretWholeTable(DoTraverseInterpreter.java:96)
    at fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretWholeTable(DoTraverseInterpreter.java:89)
    at fitlibrary.DoFixture.interpretWholeTable(DoFixture.java:73)
    at fitlibrary.suite.InFlowPageRunner.run(InFlowPageRunner.java:27)
    at fitlibrary.DoFixture.interpretTables(DoFixture.java:42)
    at dbfit.DatabaseTest.interpretTables(DatabaseTest.java:26)
    at fit.Fixture.doTables(Fixture.java:81)
    at fit.FitServer.process(FitServer.java:81)
    at fit.FitServer.run(FitServer.java:56)
    at fit.FitServer.main(FitServer.java:41)

My connection string:

!|Connect|localhost:1521|integration|integration|XEPDB1|

should be correct and I can connect to the database with other tools.

After a bit of tinkering I got the following connection string working:

!|Connect|jdbc:oracle:thin:integration/integration@localhost:1521/XEPDB1|

In general the connection string format is:

jdbc:oracle:thin:<USER>/<PASSWORD>@<HOST>:<PORT>/<SERVICE_NAME>

See e.g. URL string format for connecting to Oracle database with JDBC

Working test

Complete working getting started test: http://localhost:8085/HelloWorldTest

!path lib/*.jar
!|dbfit.OracleTest|
!|Connect|jdbc:oracle:thin:integration/integration@localhost:1521/XEPDB1|

!|Query| select 'test' as x from dual|
|x|
|test|
user272735
  • 10,473
  • 9
  • 65
  • 96