簡體   English   中英

將SoapUI屬性值設置為今天+ 1年

[英]Set SoapUI property value to today + 1 year

目標 :以yyyy-MM-dd格式分配具有今天+ 1年值的SoapUI屬性(例如,今天是2018-10-10,所以我希望該屬性具有2019-10-10)。

我嘗試過的:


嘗試#1(在線財產):

不起作用,因為JDK 8似乎不是默認Soap UI包的一部分:

${=LocalDate.now().plusYears(1).format(DateTimeFormatter.ISO_DATE)}

嘗試#2(groovy腳本):

返回錯誤,因為Date.format不接受Stringjava.util.Date

def today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MILLISECOND, 0);
today.add(Calendar.YEAR, 1);
def nextYear = today.getTime();
def nextYear_formatted = Date.format("yyyy-MM-dd", nextYear);
testRunner.testCase.setPropertyValue( "nextYear", nextYear_formatted )

錯誤:

groovy.lang.MissingMethodException:沒有方法簽名:static java.util.Date.format()適用於參數類型:(java.lang.String,java.util.Date)值:[yyyy-MM-dd,Thu 10月10日00:00:00 EDT 2019]可能的解決方案:格式(java.lang.String,java.util.TimeZone),格式(java.lang.String),from(java.time.Instant)錯誤行:8


嘗試#3(groovy腳本):

返回錯誤,因為SimpleDateFormat似乎無法編譯:

def today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MILLISECOND, 0);
today.add(Calendar.YEAR, 1);
def nextYear = today.getTime();
def nextYear_formatted = new SimpleDateFormat("yyyy-MM-dd").format(nextYear);
testRunner.testCase.setPropertyValue( "nextYear", nextYear_formatted )

org.codehaus.groovy.control.MultipleCompilationErrorsException:startup failed:Script20.groovy:8:無法解析類SimpleDateFormat @第8行,第27行.def nextYear_formatted = new SimpleDateFormat(“yyyy-MM-dd”)。format(nextYear) ; ^ org.codehaus.groovy.syntax.SyntaxException:無法在org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:149)解析類SimpleDateFormat @第8行第27列。

(為簡潔省略了其余的堆棧跟蹤)


如何在SoapUI中添加具有今天+ 1年值的屬性?

獎金問題:如何添加JDK 8以便在groovy腳本中使用它?

你有常規嗎?

def nextYear = use( groovy.time.TimeCategory ) { new Date() + 1.year }.format( 'yyyy-MM-dd' )

進一步的研究得出了答案: SimpleDateFormat需要java.text. 在它面前。 所以

def today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MILLISECOND, 0);
today.add(Calendar.YEAR, 1);
def nextYear = today.getTime();
def nextYear_formatted = new java.text.SimpleDateFormat("yyyy-MM-dd").format(nextYear);
testRunner.testCase.setPropertyValue( "nextYear", nextYear_formatted )

作品。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM