首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Groovy代码中从Where块传递参数时出错

在Groovy代码中从Where块传递参数时出错
EN

Stack Overflow用户
提问于 2016-10-25 03:41:33
回答 1查看 91关注 0票数 0

我已经为我的申请写了一个代码。

代码语言:javascript
复制
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"
}

当我运行我的代码时,我在给定子句的最后一行中得到了错误:SampleTest.Test for file type #FileFormat:37 » Riot

如果我使用RdfFormat.NTRIPLES.toString()而不是使用从Where子句传递的参数RDFFileFormat,测试就会通过。

尝试分配def format1 = "RdfFormat."+RDFFileFormat+".toString()"和使用format1,但得到了相同的错误。

有什么办法可以让它起作用吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-25 07:45:30

我想你可能想:

代码语言:javascript
复制
connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, RdfFormat."$RDFFileFormat".toMIME())
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40230996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档