一个标准的REST API测试代码

代码及过程都非常标准;以后可能会很少做Rest API测试了,权且作为纪念
  @Test(author="elbert.chenh", description="测试用例描述")
 public void TestCase1() throws Exception
 {
  String url =" http://apiurl?service=servicename&" +
    "seller_user_id=elbert0000800002&" +
    "trade_no=elbert0000800002&" +
    "sign=1234&sign_type=DSA&"+
    "child_order_id=800080012&"+
    "amount=100.01&"+
    "date=2010-02-05 13:13:13&"+
    "amount_type=F&"+
    "repay_type=0&"+
    "repay_channel=E&"+
    "status=T&repay_no=elbert0000800002";
 
  //清理数据现场
  String Sql1= "select * from "+SchemaName+".LOAN where CUSTOMER_ID = '80000001'";
  String Sql2= "select * from "+SchemaName+".LOAN_ORDER where trade_no = 'elbert0000800002'";
  String Sql3= "select * from "+SchemaName+".SERIAL_REPAY_RECORD where trade_no = 'elbert0000800002'";
  String Sql4= "select * from "+alibankSchemaName+".LOAN_ORDER_PAYMENT_INFO where trade_no = 'elbert0000800002'";
  deleteData("LOAN", Sql1);
  deleteData("LOAN_ORDER", Sql2);
  deleteData("SERIAL_REPAY_RECORD", Sql3);
  deleteData("LOAN_ORDER_PAYMENT_INFO", Sql4);
  //准备测试数据
  loadCaseData("TestCase1.xml",alibankSchemaName);
  //发起url请求15958189400
  System.out.println(url);
  WebConversation conversation = new WebConversation();
  WebRequest request = new PostMethodWebRequest(url);
  WebResponse response = conversation.getResponse(request);
  String ActXmlText = response.getText();
  System.out.println(ActXmlText);
  //数据库断言
  dataSetLoanExp = TestData.getExpDataSet("testCase1_Exp.xml", db);
  // 检测SERIAL_REPAY_RECORD
  QueryDataSet queryDataSet = new QueryDataSet(db.getConnection());
  queryDataSet.addTable("SERIAL_REPAY_RECORD", "select REPAY_NO,CUSTOMER_ALIPAY_ID,TRADE_NO,REPAY_AMOUNT," +
    "TO_CHAR(REPAY_DATE,'YYYY-MM-DD hh24:MI:SS') as REPAY_DATE,REPAY_CHANNEL,REPAY_TYPE,REPAY_STATUS,ERROR_CODE," +
    "AMOUNT_TYPE from "
    + alibankSchemaName + ".SERIAL_REPAY_RECORD where trade_no= 'elbert0000800002'");
  ITable filteredAccount = DefaultColumnFilter.includedColumnsTable(
    queryDataSet.getTable("SERIAL_REPAY_RECORD"), dataSetLoanExp.getTable(
      "SERIAL_REPAY_RECORD").getTableMetaData().getColumns());
  util.aliAssert.assertEquals(dataSetLoanExp.getTable("SERIAL_REPAY_RECORD"), filteredAccount, "ERROR_CODE", null);
  //检查loan_order表 CALCULATE_INTEREST_DATE,
  queryDataSet.addTable("tablename1", "select LOAN_ORDER_ID,....,TO_CHAR(ORDER_DATE,'YYYY-MM-DD hh24:MI:SS') as ORDER_DATE,PRODUCT_NAME,PRODUCT_COUNT," +
    "....," +
    "......," +
    "TO_CHAR(CALCULATE_INTEREST_DATE,'YYYY-MM-DD hh24:MI:SS') as CALCULATE_INTEREST_DATE," +
    "....from "
    + alibankSchemaName + ".LOAN_ORDER where trade_no= 'elbert0000800002'");
  ITable filteredAccount1 = DefaultColumnFilter.includedColumnsTable(
    queryDataSet.getTable("tablename2"), dataSetLoanExp.getTable(
      "LOAN_ORDER").getTableMetaData().getColumns());
  Assertion.assertEquals(dataSetLoanExp.getTable("LOAN_ORDER"),
    filteredAccount1);
  //LOAN_ORDER_PAYMENT_INFO 验证
  queryDataSet.addTable("tablename3", "select ....,TO_CHAR(REPAY_DATE,'YYYY-MM-DD hh24:MI:SS') as REPAY_DATE,LOAN_ID  from "
    + alibankSchemaName + ".LOAN_ORDER_PAYMENT_INFO where trade_no= 'elbert0000800002'");
  ITable filteredAccount2 = DefaultColumnFilter.includedColumnsTable(
    queryDataSet.getTable("LOAN_ORDER_PAYMENT_INFO"), dataSetLoanExp.getTable(
      "LOAN_ORDER_PAYMENT_INFO").getTableMetaData().getColumns());
  Assertion.assertEquals(dataSetLoanExp.getTable("LOAN_ORDER_PAYMENT_INFO"),
    filteredAccount2);
 }

你可能感兴趣的:(代码,api,职场,REST,休闲)