如何使用SoapUI JDBC测试步骤连接到MongoDB?

时间:2015-06-05 17:27:16

标签: mongodb jdbc driver soapui

我正在使用SoapUI来测试REST / SOAP服务。在某一点上,我需要连接到MongoDB并从db中提取一些值。

我很难初始化db。

下面的错误代码段:

com.eviware.soapui.support.SoapUIException: Failed to init connection for driver[com.mongodb.mongo], connectionString [mongodb://<userName>:<pwd>@<domain>:<port>/<collectionName>]

我无法调用连接。

我做了什么?

  1. 我安装了mongoDB驱动程序“mongodb-driver-3.0.0”@“C:\ Program Files \ SmartBear \ SoapUI-5.1.2 \ bin \ ext”
  2. 下面是我试图实现它的截图 SoapUI Screenshot of JDBC Test Step used to invoke mongoDB
  3. SoapUI日志如下:

        Sun Jun 07 14:39:24 IST 2015:ERROR:An error occurred [No suitable driver], see error log for details
    
    Sun Jun 07 14:39:24 IST 2015:ERROR:java.sql.SQLException: No suitable driver
       java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getDriver(Unknown Source)
        at com.eviware.soapui.support.jdbc.JdbcUtils.initConnection(JdbcUtils.java:51)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcRequestTestStepDesktopPanel$TestConnectionAction.actionPerformed(JdbcRequestTestStepDesktopPanel.java:616)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
        at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$200(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
    

    我首先看到的是无法通过mongoDB的驱动程序类连接。

2 个答案:

答案 0 :(得分:0)

一个可能的选择是在你的mongodb上安装 sleepy mongoose ,因此它可以响应HTTP / REST请求。然后,您可以使用SOAPUI中的HTTP请求测试步骤直接从mongo中提取您想要的任何信息。

如果这有用,请告诉我。

答案 1 :(得分:0)

你可以在&#34; Groovy测试步骤&#34;中轻松使用下面的groovy代码。您的测试用例并连接到mongodb。在此之前,请确保mongodb java客户端jar文件和gmongo位于soapUI安装的{Installation Directory} \ bin \ ext文件夹中

Gmongo:http://mvnrepository.com/artifact/com.gmongo/gmongo/1.5

Mongodb Java客户端:http://mvnrepository.com/artifact/org.mongodb/mongo-java-driver/3.2.2

import com.gmongo.GMongoClient
import com.gmongo.GMongo
import com.mongodb.MongoCredential
import com.mongodb.ServerAddress

//def credentials = MongoCredential.createMongoCRCredential('admin', 'students', 'admin' as char[])

//def client = new GMongoClient(new ServerAddress("127.0.0.1:27017"))

context.gmongo=new GMongo()
def db=context.gmongo.getDB("test")
log.info db.fruit.find().count()

db.fruit.find().each{

    doc->log.info doc

    }