Forum Discussion
12 Replies
- RJanecekRegular Contributor
- robjahnContributorThank you, but I can get SQL in and the connection going in a script,but looking to re-use the soapUI JDBC project connections. For use these connections in both soapUI steps and want to use in groovy steps as well.
- Hi!
have a look at the code samples for the Event Handler in this blog post: http://blog.smartbear.com/post/11-12-08 ... nnections/ - it shows you how to use project level connections in your scripts as you seem to want to do..
regards!
/Ole
SmartBear Software - RJanecekRegular Contributorwhen you can connection you can save it:
def sqlcon = Sql.newInstance(....
context.setProperty("sqlcon", sqlcon)
then you can get in in test steps: context.getProperty("sqlcon").firstrow ...
and in teardown script close context.getProperty("sqlcon").close() - robjahnContributorI can try that approach, but was looking to change the configurations established from the wizard. Using your example on the blog....I want to change the values for the connection "loadTestDB" from groovy Code. If I look in my project.XML (pro 4.01)....I see these configuaration infomation (in my case 2 oracle grid connections ... one called A and one called B)...I would think there is some what to get and set the various values like "connectionString" and "Password". how might I achieve this?
<con:databaseConnectionContainer>
<con:databaseConnection>
<con:name>A</con:name>
<con:driver>oracle.jdbc.driver.OracleDriver</con:driver>
<con:connectionString>jdbc:oracle:thin:user/password@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = server.com)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = servicename)))
</con:connectionString><con:password>password</con:password>
</con:databaseConnection><con:databaseConnection>
<con:name>B</con:name>
<con:driver>oracle.jdbc.driver.OracleDriver</con:driver>
<con:connectionString>jdbc:oracle:thin:muser/password@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = server.com)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = servicename)))</con:connectionString><con:password>password</con:password>
</con:databaseConnection>
</con:databaseConnectionContainer> - RJanecekRegular Contributora found this class: http://www.soapui.org/apidocs/pro/com/e ... ainer.html and here you can get connection list of getDatabaseConnectionList() and then get or set get/set ConnectionString()
- robjahnContributorsorry for a basic question....how would I refer to that class in a groovy step?
- RJanecekRegular Contributoryes that is right question and I supposed that support answer it because I dont know too
- Here's the method you are looking for: http://www.soapui.org/apidocs/pro/com/e ... Container()
You can use it like this from a Groovy TestStep (for example):myDatabaseConnection = testRunner.testCase.testSuite.project.databaseConnectionContainer.getDatabaseConnectionByName('The name of a connection')
myDatabaseConnection.setPassword('passwordOfYourChoice')
Hope this helps!
Henrik
SmartBear Software - robjahnContributorThis helps. But with the new project environment feature. What is best way to get connection object and connection string for a given JDBC connection. For example I have TEST and DEV as my two environment profiles with the DB Connection name of MYDATABASE