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.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.al.api.net.HttpFactory;
import com.al.api.test.base.APIBase;
import com.al.common.Configuration;
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;
/**
* 作者: 日期:20180119
* 测试用例方法 - AttentionAdviser
* FAT测试数据:
* UAT测试数据:
*/
@DataFactory(dataPathKey = "LiveRoom")
public class AttentionAdviser extends APIBase{
@BeforeClass
public void beforeClass() {
}
@Test(dataProvider = "ExcelRowsDP", dataProviderClass = ProviderFactory.class)
@DataFactory(dataName = "normal", author = "AA", category = "关注投顾接口")
public void getBeforeSignStatus(Map<String,String> caseData) {
String 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);
//发送请求
Map<String, String> data1 = Maps.newHashMap();
data1.put("appName", conf.get("appName"));
data1.put("tokenId", tokenId);
data1.put("advisterUnionId",caseData.get("follow_adviser_uid"));
HttpFactory hf = HttpFactory.newInstance();
hf.post(conf.get("LiveRoomCommonUrl")+conf.get("attentionAdviser"),data1);
NReporter.saveJSON("tttttttttttttttttttttttttttttt"+hf.getRequest(), hf.getResponse());
//校验返回信息
checkPoint(hf, caseData);
}
public void checkPoint(HttpFactory hf, Map<String, String> caseData){
if(hf.getStatus()==200){
NAssert.assertEquals(hf.getStatus(), 200, "验证请求状态码");
JSONObject jo = new JSONObject(hf.getResponse());
follow_status=getDataUser(conf,caseData);
System.out.println("11111111111111111111111111"+follow_status);
if(follow_status.equals("01")) {
NAssert.assertEquals(jo.getString("responseCode"), caseData.get("responseCode"), "校验responseCode");
NAssert.assertEquals(jo.getString("responseMsg"), caseData.get("responseMsg"), "校验responseMsg");
}else{
NAssert.assertEquals(hf.getStatus(), 400, "验证请求状态码");
}
}
}
/**
* 数据库查询 - totalSize
*/
// int totalSize;
String follow_status;
public String getDataUser(Configuration conf, Map<String, String> caseData) {
// 重置user库数据
NReporter.info("查询数据库信息");
String sql="select m.follow_status from sis_live_follow_adviser m where m.follow_adviser_uid='"+caseData.get("follow_adviser_uid")+"'and m.user_code='"+caseData.get("user_code")+"'";
Connection conuserdb = DbUtils.getConnection(JDBCDriver.ORACLE, conf.get("livedburl"), conf.get("livedbuser"), conf.get("livedbpsw"));
NReporter.info("执行SQL语句:" + sql);
ResultSet rs = DbUtils.getResultSet(conuserdb, sql);
try {
while(rs.next()){
follow_status=rs.getString("follow_status");
// totalSize=rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DbUtils.closeConnection(conuserdb);
return follow_status;
}
@AfterClass
public void afterClass() {
}
}
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import org.json.JSONObject;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.al.api.net.HttpFactory;
import com.al.api.test.base.APIBase;
import com.al.common.Configuration;
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;
/**
* 作者: 日期:20180119
* 测试用例方法 - AttentionAdviser
* FAT测试数据:
* UAT测试数据:
*/
@DataFactory(dataPathKey = "LiveRoom")
public class AttentionAdviser extends APIBase{
@BeforeClass
public void beforeClass() {
}
@Test(dataProvider = "ExcelRowsDP", dataProviderClass = ProviderFactory.class)
@DataFactory(dataName = "normal", author = "AA", category = "关注投顾接口")
public void getBeforeSignStatus(Map<String,String> caseData) {
String 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);
//发送请求
Map<String, String> data1 = Maps.newHashMap();
data1.put("appName", conf.get("appName"));
data1.put("tokenId", tokenId);
data1.put("advisterUnionId",caseData.get("follow_adviser_uid"));
HttpFactory hf = HttpFactory.newInstance();
hf.post(conf.get("LiveRoomCommonUrl")+conf.get("attentionAdviser"),data1);
NReporter.saveJSON("tttttttttttttttttttttttttttttt"+hf.getRequest(), hf.getResponse());
//校验返回信息
checkPoint(hf, caseData);
}
public void checkPoint(HttpFactory hf, Map<String, String> caseData){
if(hf.getStatus()==200){
NAssert.assertEquals(hf.getStatus(), 200, "验证请求状态码");
JSONObject jo = new JSONObject(hf.getResponse());
follow_status=getDataUser(conf,caseData);
System.out.println("11111111111111111111111111"+follow_status);
if(follow_status.equals("01")) {
NAssert.assertEquals(jo.getString("responseCode"), caseData.get("responseCode"), "校验responseCode");
NAssert.assertEquals(jo.getString("responseMsg"), caseData.get("responseMsg"), "校验responseMsg");
}else{
NAssert.assertEquals(hf.getStatus(), 400, "验证请求状态码");
}
}
}
/**
* 数据库查询 - totalSize
*/
// int totalSize;
String follow_status;
public String getDataUser(Configuration conf, Map<String, String> caseData) {
// 重置user库数据
NReporter.info("查询数据库信息");
String sql="select m.follow_status from sis_live_follow_adviser m where m.follow_adviser_uid='"+caseData.get("follow_adviser_uid")+"'and m.user_code='"+caseData.get("user_code")+"'";
Connection conuserdb = DbUtils.getConnection(JDBCDriver.ORACLE, conf.get("livedburl"), conf.get("livedbuser"), conf.get("livedbpsw"));
NReporter.info("执行SQL语句:" + sql);
ResultSet rs = DbUtils.getResultSet(conuserdb, sql);
try {
while(rs.next()){
follow_status=rs.getString("follow_status");
// totalSize=rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DbUtils.closeConnection(conuserdb);
return follow_status;
}
@AfterClass
public void afterClass() {
}
}