myZbjComment 接口

package com.tougu.apitest.LiveRoom;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;


import org.json.JSONObject;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;


import com.al.api.net.HttpFactory;
import com.al.api.test.base.APIBase;
import com.al.common.config.JDBCDriver;
import com.al.core.annotation.DataFactory;
import com.al.core.dataprovider.ProviderFactory;
import com.al.core.nassert.NAssert;
import com.al.core.report.NReporter;
import com.al.db.DbUtils;
import com.google.common.collect.Maps;
import com.pazq.apitest.common.LoginCommonMethods;




@DataFactory(dataPathKey="LiveRoom")
public class MyZbjComment extends APIBase{


  @BeforeClass
  public void beforeClass() {
  }


  @Test(dataProvider = "ExcelRowsDP", dataProviderClass = ProviderFactory.class)
  @DataFactory(dataName = "normal", author = "谢玉娟", category = "回复我的/我的提问接口")
  public void myZbjComment(Map<String,String> caseData) {
 
 String tokenId="";
 String appName="";
 if(caseData.get("tokenId").equals("null")&&!caseData.get("description").contains("不传tokenId")){
 //用户先通过统一登录获取对应的tokenId
 Map<String, String> data = Maps.newHashMap();
 data.put("account", conf.get("account"));
 data.put("pwd", conf.get("pwd"));
 data.put("servername", "login");
 data.put("appName", conf.get("appName"));
 data.put("appChannel",conf.get("appChannel"));
 data.put("kbChannel", conf.get("kbChannel"));
 
 tokenId=LoginCommonMethods.loginByAccount(conf.get("loginCommonUrl"), data);
 }else{
 tokenId=caseData.get("tokenId");
 }
 
 if(caseData.get("appName").equals("null")){
 appName=conf.get("appName");
 }else{
 appName=caseData.get("appName");
 }
 
 //构造请求体
 Map<String,String> data1= Maps.newHashMap();
 data1.put("appName", appName);
 data1.put("tokenId", tokenId);
 data1.put("whose", caseData.get("whose"));
 data1.put("objectsPerPage", caseData.get("objectsPerPage"));
 data1.put("pageNumber", caseData.get("pageNumber"));
 
 //发送请求,WHOSE必须传入,并且传入正确
 HttpFactory hf = HttpFactory.newInstance();
 hf.post(conf.get("LiveRoomCommonUrl")+conf.get("myZbjComment"), data1);
 
 //校验返回值
 
 checkPoint(hf,caseData);
  }
  
  public void checkPoint(HttpFactory hf,Map<String, String> caseData) {
// String channelId=caseData.get("channelId");
JSONObject jo = new JSONObject(hf.getResponse());
if(hf.getStatus()==200){

if(jo.getString("responseCode").equals("0")){
 NAssert.assertEquals(hf.getStatus(), 200, "验证请求状态码");
//  if (jo.getInt whose =="01")
 int listSize=Integer.valueOf(caseData.get("objectsPerPage"));
//  NAssert.assertEquals(getJsonString(jo,"responseCode"), caseData.get("responseCode"), "校验responseCode");
 NAssert.assertEquals(jo.getString("responseCode"), caseData.get("responseCode"), "校验responseCode");
 Connection conuserdb = DbUtils.getConnection(JDBCDriver.ORACLE, conf.get("livedburl"), conf.get("livedbuser"), conf.get("livedbpsw"));
 int listSize1=jo.getInt("listSize");
 //对返回list校验
 if(listSize1>0){
 for(int i=0;i<listSize;i++){
 NAssert.assertEquals(jo.getInt("listSize"),listSize,"校验每页展示条数");  
 String question_answers_id=jo.getJSONArray("list").getJSONObject(i).getString("commentId");
 NReporter.info(question_answers_id);
 NReporter.info("查询数据库信息");
 String sql="select id_live_room as channelId,question_answers_content as commentContent,TO_CHAR(CREATED_DATE,'YYYY-MM-DD') as created_date from sis_live_question_answers where user_id='9726150' and question_answers_Id='"+question_answers_id+"'";  
 NReporter.info("执行SQL语句:" + sql);
 ResultSet rs1 = DbUtils.getResultSet(conuserdb, sql);
 try{
 while(rs1.next()){
 NAssert.assertEquals(jo.getJSONArray("list").getJSONObject(i).getString("channelId"), rs1.getString("channelId")); 
NAssert.assertEquals(jo.getJSONArray("list").getJSONObject(i).getString("commentContent"), rs1.getString("commentContent"));
//NAssert.assertEquals(jo.getJSONArray("list").getJSONObject(i).getInt("createdDate"), rs1.getInt("created_date"));
 }
 }catch(SQLException e){
 e.printStackTrace();
 }finally{
 try {
rs1.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 }
 }
 DbUtils.closeConnection(conuserdb);
}
}else{
NAssert.assertEquals(jo.getString("responseCode"), caseData.get("responseCode"), "校验responseCode");
NAssert.assertEquals(jo.getString("responseMsg"), caseData.get("responseMsg"), "校验responseMsg");
}
 
 } else{
 NAssert.assertEquals(hf.getStatus(), 400, "验证请求状态码");
 }
}
  
  @AfterClass
  public void afterClass() {
  }


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值