我正在嘗試將我的應用程序從grails 2升級到grails 3.但是,在grails 2中工作的功能測試現在無法運行。在Grails 2中,我使用RestBuilder發送請求並獲得響應。在Grails 3中,沒有相應的RestBuilder版本。我如何發送我的文章並獲得grails 3功能測試的請求?Grails 3功能測試
非常感謝。
我測試代碼的grails 2:
void testRequestNewEnvironment() {
setup:
def rest = new RestBuilder(connectTimeout:1000, readTimeout:20000)
int timeout = 10
String environmentId = 0
String environmentStatus = "Not Ready"
when:
/**
* PostMethod. Send out a post and response status should be 200 and the body of response include env_id
*/
def resp = rest.post('http://localhost:8080/test-environment-manager/environment') {
contentType "multipart/form-data"
buildfile= new File('script.sh')
username = "apps"
keepEnvflag = "false"
env_flavor = "default"
}
then:
resp.getStatus() == 200
environmentId = resp.json.env_id
println "Environment ID: $environmentId"
println ("Environment Status"+resp.json.Status)
嗨,首先感謝您的回答。但是,當我在build.gradle中添加「compile」:rest:0.8「」或「compile」:rest-client-builder:2.0.0「」時。服務器始終無法啓動。該錯誤信息是:錯誤初始化類路徑:org.gradle.api.internal.artifacts.DefaultModuleVersionSelector – sspqingda
@sspqingda嘗試添加該代替'編譯「org.codehaus.groovy.modules.http建設者:HTTP建設者:0.7.1」 ' –
謝謝。編譯「org.grails.plugins:rest-client-builder:2.0.0」也可以。 – sspqingda