Groovy
Groovy JDK,Process Management,Regular Expressions, Getting Started Guide
Date
String VS Array
Map
Find last modified file(a unix/linux way,it is not compatible with windows)
Java
Java API
String
SoapUI
SoapUI API
TestCase,TestRunner
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。