肥皂用户界面(免费版)
我有一个测试用例,它是一个接受 XML 作为有效负载的 POST。我在测试用例中编写了一个 groovy 脚本来计算 readingDate 字段。
Groovy 脚本:
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.TimeZone
Calendar currentTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
dateFormat.setTimeZone(currentTime.getTimeZone())
String readingDate = dateFormat.format(currentTime.getTime())
context.setProperty("readingDate", readingDate)
XML 负载:
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="http://www.foo.com/data">
<foobar foobarId="1553310377_20">
<foobarReading>
<readingDate>${readingDate}</readingDate>
<readingValue>451.045</readingValue>
</foobarReading>
</foobar>
</foo>
请求显示:
POST http://foo:8080/WebServices/rest/data HTTP/1.1
Connection: close
Accept-Encoding: gzip,deflate
Content-Type: application/xml
Authorization: Basic TlJDYW46TlJDYW4=
Content-Length: 301
Host: foo:8080
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="http://www.foo.com/data">
<foobar foobarId="1553310377_20">
<foobarReading>
<!-- Should not be empty it should show the current time -->
<readingDate></readingDate>
<readingValue>451.045</readingValue>
</foobarReading>
</foobar>
</foo>