こんにちは私はWebサービスのテストにSoapUIを使用しています。メールアドレスとパスワードを使用して顧客レコードを作成する必要があります。顧客レコードの作成サービスにはemailidとパスワードが含まれています。SoapUIで顧客レコードの作成で実行(リクエストの送信)ボタンをクリックすると、emailidに現在の作成時刻とパスワードが追加されます。
groovyでこれを行う方法は?
There are two common cases of inserting dynamic dateTime value in soapUI using groovy:
Insert formatted timestamp value. Use SimpleDateFormat in this case:
${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date())}
Format timestamp as xsd:dateTime value. Use DatatypeFactory to create instance of newXMLGregorianCalendar:
${=javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance())}
I think that the first case works for you. Insert the code in your request and adjust timestamp format for your needs. BTW, it also works in responses for mock servers.
これは、ApacheCommonsや joda-timeのような日付操作の苦痛を和らげる可能性のあるjarファイルを取得しない簡単な解決策です。
日付を比較するための2行モード(例:時間の前後):
def startDate = new Date()
println(startDate.format("yyyy-MM-dd'T'HH:mm:ss SSS"))
またはワンライナーモード:
println(new Date().format("yyyy-MM-dd'T'HH:mm:ss SSS"))
重い日付操作を行う場合は、上記のAPIのいくつかを使用します。箱から出してすぐにGroovyが日付比較を進めているとは思いません。
コメントは、のような一般的な構文の一部を使用しないpureGroovy
を使用しています。SoapUI
println
log.info
today = new Date().format("yyyy-MM-dd")
log.info today