Groovy and SoapUI

4 篇文章 0 订阅
1 篇文章 0 订阅
Groovy
Groovy JDK, Process Management, Regular Expressions, Getting Started Guide
Date
String VS Array
#!/usr/bin/groovy
str = "str1,str2, S333, S566, S88A88G"
def strArray = str.split('[ \t]*,[ \t]*')
println strArray
println strArray.join("-") 

Map
def items = [:]
items["key1"] = "4.00"
items["key2"] = "4.02"
println items
items = items.minus(["key2":"4.02"])
// after v1.8.7 items = items.dropWhile {it.key == "key2"}
println items

Find last modified file(a unix/linux way, it is not compatible with windows)
import java.util.regex.Pattern

def lsDateFormat = "%Y-%m-%d_%H:%M:%S" // for ls command
def dateFormat = "yyyy-MM-dd_HH:mm:ss" // for Date
def lscmd = """ls -lt --time-style=""" + "\"+${lsDateFormat}\" "
lscmd += """/home/Prime/cycles/ | grep .*.csv\$ -m 1 | cut -d ' ' -f 6-7"""

def f = File.createTempFile('bash', '.sh')
f.write("#!/bin/bash\n")
f.append(lscmd)
f.append("\n")
def fpath = f.getAbsolutePath()

"chmod +x ${fpath}".execute()

def cmd = fpath
log.info(cmd)
def proc1 = cmd.execute()
proc1.waitFor()
if ( 0 != proc1.exitValue() ) {
	throw new Exception("Execute ${cmd} failed.")
}
def str = proc1.in.text
f.delete()

def pattern = Pattern.compile('([^ ]{1,}) (.*)')
def matcher = pattern.matcher(str)
def dStr = (new Date()).format(dateFormat)

if (matcher.find()) {
	//count = Integer.valueOf(matcher.group(1));
	dStr = matcher.group(1)
	fileName = matcher.group(2)
	def d = Date.parse(dateFormat, dStr)
	log.info(dStr)
	log.info("Last modified file: ${fileName}. Modified date: ${d}" )
} else {
	log.error("Non file found.")
}

Java
Java API
String

SoapUI
SoapUI API
TestCase, TestRunner
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值