加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Groovy(conncet DB, generate xml, get response xml, compare t

发布时间:2020-12-14 17:07:37 所属栏目:大数据 来源:网络整理
导读:import groovy.sql.Sql import groovy.xml.MarkupBuilder import org.custommonkey.xmlunit.* //Conect to DB and get the nessecery data to generate the expected Xml. Sql sql=context.dbConnection; def writer = new StringWriter(); def xml = new gr

import groovy.sql.Sql
import groovy.xml.MarkupBuilder
import org.custommonkey.xmlunit.*

//Conect to DB and get the nessecery data to generate the expected Xml.
Sql sql=context.dbConnection;
def writer = new StringWriter();
def xml = new groovy.xml.MarkupBuilder(writer)
xml.RetailerGroups(){
?? RetailerGroup(Name:"Checkout",Id:"CO")
??
?? {
?? Retailers(){
??? Retailer(Name:"Acme",Id:"Acm")
??? Retailer(Name:"Acme2",Id:"Acm2")
??? def res = sql.firstRow("select scdprj.user3 as 'Brand',"
????+ "schedwin.unix_date_conv (scdslg.air_start) as 'StartDate',"
????+ "schedwin.unix_date_conv (scdslg.air_end) as 'EndDate',"
????+ "scdprj.cl_id as AdvertiserId,clnt.name + ' ' + '-'+ ' ' + user3 as CampaignName,clnt.name as AdvertiserName "
????+ "From schedwin.PROJECTS scdprj "
????+ "Inner join schedwin.SLGUSAGE scdslg "
????+ "ON scdprj.prj_id=scdslg.prj_id "
????+ "Join schedwin.CLNT clnt "
????+ "ON clnt.cl_id=scdprj.cl_id "
????+ "Where? scdprj.cl_id=1228 and (scdprj.stat=1) and scdprj.formid=0 "
????+ "AND (DATEDIFF(dd,schedwin.unix_date_conv(scdslg.AIR_END),'20090707') < =0) "
????+ "AND (DATEDIFF(dd,schedwin.unix_date_conv(scdslg.AIR_START),'20090707') >= 0) ")
???? }
???? }
?? RetailerGroup(Name:"Checkout",Id:"CO")
? }
?
def expectedResult = writer.toString()
log.info writer.toString()?
XMLUnit.setIgnoreWhitespace(true)

//Get the actual result
def step = testRunner.testCase.testSteps["retailer"]
def result = step.testRequest.response.contentAsString
log.info result

//Check the actual result by expected result,and output the test result.def xmlDiff = new Diff(result,expectedResult)def s = xmlDiff.toString();File f = new File("c:/","d.txt"); if( !f.exists()){?f.createNewFile();?}try {? ? FileWriter fileWriter = new FileWriter(f,true); ????? if (s == "org.custommonkey.xmlunit.Diff[identical]"){?????? fileWriter.write("API: '"+ step.name + "' DV Result is? "+ "Passed/r/n");?????? }?????? else{??????? fileWriter.write("API: '"+ step.name + "' DV Result is? "+ "Failed/r/n");??????? } ????? fileWriter.close();?? ???? } catch (IOException e) {?? ???????? e.printStackTrace();?? ???? }????

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读