QueryThemeLiveDetails

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 QueryThemeLiveDetails extends APIBase{


  @BeforeClass
  public void beforeClass() {
  }


  @Test(dataProvider = "ExcelRowsDP", dataProviderClass = ProviderFactory.class)
  @DataFactory(dataName = "normal", author = "DD", category = "直播间主题详情接口")
  public void queryThemeLiveDetails(Map<String,String> caseData) {
 
 String tokenId;
 if(caseData.get("tokenId").equals("null")){
 
 //用户先通过统一登录获取对应的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");
 }
 
//发送请求
 Map<String, String> data1 = Maps.newHashMap();
 data1.put("appName", conf.get("appName"));
 data1.put("tokenId", tokenId);
 data1.put("idTheme",caseData.get("idTheme"));
 data1.put("objectPerPage", caseData.get("objectPerPage"));
 data1.put("pageNumber", caseData.get("pageNumber"));
 HttpFactory hf = HttpFactory.newInstance();
 hf.post(conf.get("LiveRoomCommonUrl")+conf.get("queryThemeLiveDetails"),data1);
 NReporter.saveJSON(hf.getRequest(), hf.getResponse());
 
 checkPoint(hf,caseData);
  }
  
  public void checkPoint(HttpFactory hf,Map<String, String> caseData) {
String liveRoomId="";
JSONObject jo = new JSONObject(hf.getResponse());
if(hf.getStatus()==200){

if(jo.getString("responseCode").equals("0")){
 NAssert.assertEquals(hf.getStatus(), 200, "验证请求状态码");  
//  NAssert.assertEquals(getJsonString(jo,"responseCode"), caseData.get("responseCode"), "校验responseCode");
 NAssert.assertEquals(jo.getString("responseCode"), caseData.get("responseCode"), "校验responseCode");
 NAssert.assertEquals(jo.getString("authFlag"), caseData.get("authFlag"), "校验authFlag");
 Connection conuserdb = DbUtils.getConnection(JDBCDriver.ORACLE, conf.get("livedburl"), conf.get("livedbuser"), conf.get("livedbpsw"));
 //对返回theme校验
 String idTheme=caseData.get("idTheme");
 NReporter.info(liveRoomId);
 NReporter.info("查询数据库信息");
 String sql1="select theme_content as theme_content,TO_CHAR(DATE_CREATED,'YYYY-MM-DD') as date_created from sis_live_theme where id_theme='"+idTheme+"'";  
 NReporter.info("执行SQL语句:" + sql1);
 ResultSet rs1 = DbUtils.getResultSet(conuserdb, sql1);
 try{
 while(rs1.next()){
NAssert.assertEquals(jo.getJSONObject("theme").getString("themeContent"), rs1.getString("THEME_CONTENT")); 
NAssert.assertEquals(jo.getJSONObject("theme").getString("dateCreated"), rs1.getString("date_created"));
 }
 }catch(SQLException e){
 e.printStackTrace();
 }finally{
 try {
rs1.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 }
 int listSize=jo.getInt("listSize");
 if(listSize>0){
 for(int j=0;j<listSize;j++){
String id=jo.getJSONArray("list").getJSONObject(j).getString("id");
NReporter.info("查询数据库信息");
String sql2="select * from omm_mop_channel_comment where id_theme='"+idTheme+"' and id='"+id+"'";  
NReporter.info("执行SQL语句:" + sql2);
ResultSet rs2 = DbUtils.getResultSet(conuserdb, sql2);
try{
 while(rs2.next()){
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"userId"), rs2.getString("USER_ID"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"unionId"), rs2.getString("UNION_ID"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"channelId"), rs2.getString("CHANNEL_ID"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"commentId"), rs2.getString("COMMENT_ID"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"parentCommentId"), rs2.getString("PARENT_COMMENT_ID"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"commentContent"), rs2.getString("COMMENT_CONTENT"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"commentStatus"), rs2.getString("COMMENT_STATUS"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"topComment"), rs2.getString("TOP_COMMENT"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"commentType"), rs2.getString("COMMENT_TYPE"));
 NAssert.assertEquals(getJsonString(jo.getJSONArray("list").getJSONObject(j),"ancestorId"), rs2.getString("ANCESTOR_ID"));
 }
 }catch(SQLException e){
// TODO Auto-generated catch block
e.printStackTrace();
 }finally{
 try {
rs2.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, "验证请求状态码");
 }
}

private String getJsonString(JSONObject jo,String key){

if(jo.get(key) instanceof String){
return jo.getString(key);
}else{
return null;
}
}


  
  @AfterClass
  public void afterClass() {
  }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值