[英]Getting error when passing parameters from Where block in Groovy-Spock code
I have written a code for my application. 我已经为我的应用程序编写了代码。
def "Test for file type #FileFormat"() {
given:
HttpURLConnection connection = getHandlerURL('endpoint')
connection.setDoOutput(true)
connection.setRequestMethod("POST")
connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, "RdfFormat."+RDFFileFormat+".toMIME()")
rdfStatement = ModelFactory.createDefaultModel().read(new ByteArrayInputStream(readRDFfromfile(Filename).bytes), null, "RdfFormat."+RDFFileFormat.toString()).listStatements().nextStatement()
when:
connection.getOutputStream().write(readRDFfromfile(Filename).bytes)
then:
connection.getResponseCode() == HTTP_CREATED
where:
FileFormat | Filename | RDFFileFormat
'N-TRIPLES' | 'n-triples.nt' | "NTRIPLES"
}
When I run my code I am getting error: SampleTest.Test for file type #FileFormat:37 » Riot
in last line of Given clause. 当我运行代码时,出现错误:
SampleTest.Test for file type #FileFormat:37 » Riot
在Given子句的最后一行。
The test is passing if I use RdfFormat.NTRIPLES.toString()
instead of using the parameter RDFFileFormat passed from Where clause. 如果我使用
RdfFormat.NTRIPLES.toString()
而不是使用从Where子句传递的参数RDFFileFormat,则测试通过。
Tried assigning def format1 = "RdfFormat."+RDFFileFormat+".toString()"
and using format1 , but got same error. 尝试分配
def format1 = "RdfFormat."+RDFFileFormat+".toString()"
并使用format1 ,但是遇到了同样的错误。
Is there any way I can make it work? 有什么办法可以使它起作用?
我想您可能想要:
connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, RdfFormat."$RDFFileFormat".toMIME())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.