Commit 77e633d5 authored by 马博's avatar 马博

Init

parents
Pipeline #71143 failed with stages
in 0 seconds
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.duiba</groupId>
<artifactId>test-platform</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!--spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.8.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.8.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.8.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2.8.RELEASE</version>
</dependency>
<!--testng-->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
<!--rest-assured-->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>
<!-- 依赖reportNg-->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 依赖Guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<!--日志-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>cn.com.duiba</groupId>
<artifactId>java-sdk</artifactId>
<version>0.0.16</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.23</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!--<suiteXmlFiles>-->
<!--<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>-->
<!--</suiteXmlFiles>-->
<includes><include>${run}</include></includes>
<parallel>classes</parallel>
<threadCount>5</threadCount>
<!-- ReportNG配置 -->
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,common.RetryListener,common.TestListener,common.TestReport</value>
</property>
</properties>
<workingDirectory>target/</workingDirectory>
<systemPropertyVariables>
<runEnv>tst.deploy.dui88.com</runEnv>
<noticeDD>false</noticeDD>
<noticePerson>false</noticePerson>
<sendPlatform>false</sendPlatform>
<run>${run}</run>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>data/*</directory>
</resource>
<resource>
<directory>lib/*</directory>
</resource>
<resource>
<directory>key/*</directory>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/test/resources</directory>
<excludes>
<exclude>application-test.properties</exclude>
<exclude>application-dev.properties</exclude>
<exclude>application-product.properties</exclude>
<exclude>application.properties</exclude>
</excludes>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/test/profiles/${environment}</directory>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>aliyun</id>
<properties>
<environment>aliyun</environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<environment>test</environment>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<environment>dev</environment>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<environment>product</environment>
</properties>
</profile>
</profiles>
<properties>
<run>**/*_signTest.java</run>
</properties>
</project>
\ No newline at end of file
package common;
import io.restassured.response.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static io.restassured.RestAssured.given;
/**
* Created by hanzhanli on 2017/11/11.
*/
public class BeTested {
//从jenkins爬取变更log,取最新一个,即第一个
private static AbstractMap.SimpleEntry<String,String> getChanges(String url) {
System.out.println("链接:"+url);
Response response=given().header("Accept-Language","zh-CN,zh;q=0.8").get(url);
String s=response.asString();
Document document=Jsoup.parse(s);
Elements elements=null;
String changeTime=null;
try{
elements= document.getElementsByTag("ol");
changeTime=document.getElementsByTag("h2").get(0).getElementsByTag("a").get(0).text();
}catch(Exception e){
return new AbstractMap.SimpleEntry<String,String>("2018-1-24 20:17:09","未修改");
}
String regex="(?<=\\()(.+?)(?=\\))";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(changeTime);
String s3=null;
while (matcher.find()) {
s3 = matcher.group(0);
}
/*String s1=changeTime.split("\\(")[1];
String s2=s1.split("\\)")[0];*/
//String s3="2017-11-13 10:14:11";
return new AbstractMap.SimpleEntry<String,String>(s3,elements.get(0).text().replace("detail","").replace(" ",""));
}
//将各job的最新变更放到一个排序map,最新的在最上
public static Map<String,String> getLatestChanges(String[] jobs){
System.out.println("获取以下job的更改信息:"+jobs);
Map<String, String> map = new TreeMap<String, String>(
new Comparator<String>() {
public int compare(String obj1, String obj2) {
return compareTime(obj2,obj1);
}
});
for (String job:jobs){
job=job.trim();
String url= "http://tst.deploy.dui88.com/view/duiba/job/"+job+"/changes";
AbstractMap.SimpleEntry entry=getChanges(url);
map.put((String)entry.getKey(),job+":"+(String)entry.getValue());
}
return map;
}
public static void main(String[] args) {
String activityGroup="tuia-activity-center,tuia-ssp-center,tuia-ssp-web,tuia-ssp-manager,tuia-open-web";
String adGroup="tuia-engine,tuia-advert-center,tuia-advert-manager,tuia-advert-web,tuia-engine-billing";
String duibaGroup="credits-home-web,developer-center,goods-access-web,goods-center,activity-access-web,activity-center,trade-center,trade-access-web,duiba-manager,duiba-manager-web";
Map<String,String> map=getLatestChanges(duibaGroup.split(","));
System.out.println(map);
// System.out.println(getChangesWithin(90,map));
//System.out.println(map);
/*Set<String> keySet=map.keySet();
String[] group;
group=new String[]{map.get(keySet.toArray()[0])};
System.out.println(group[0]);*/
}
public static Map<String,String> getChangesWithin(int min, Map<String,String> changes){
if(changes==null){
return null;
}else {
System.out.println("最近更改筛选:" + changes);
Map<String, String> map = new TreeMap<String, String>(
new Comparator<String>() {
public int compare(String obj1, String obj2) {
return compareTime(obj2, obj1);
}
});
Set<String> keySet = changes.keySet();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date timeLimit = new Date(System.currentTimeMillis() - min * 60 * 1000);
String limit = sdf.format(timeLimit);
System.out.println(limit);
for (String key : keySet) {
if (compareTime(key, limit) >= 0) {
map.put(key, changes.get(key));
}
}
return map;
}
}
public static int compareTime(String time1,String time2)
{
//如果想比较日期则写成"yyyy-MM-dd"就可以了
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//将字符串形式的时间转化为Date类型的时间
Date a= null;
Date b=null;
try {
a = sdf.parse(time1);
b = sdf.parse(time2);
} catch (ParseException e) {
e.printStackTrace();
}
//Date类的一个方法,如果a早于b返回true,否则返回false
//return a.getTime()-b.getTime();
if(a.before(b))
return -1;
else if(a.equals(b)){
return 0;
}else
return 1;
}
}
package common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by hanzhanli on 2017/10/31.
*/
public class ClassResult {
String className;
int count;
List<Map<String,String>> resultList=new ArrayList<>();
public ClassResult(String className){
this.className=className;
}
public void addResult(String testName,String duration,String testOut){
this.count++;
Map<String,String> resultMap=new HashMap<>();
resultMap.put("testName",testName);
resultMap.put("duration",duration);
resultMap.put("testOut",testOut);
this.resultList.add(resultMap);
}
}
package common;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
/**
* Created by mabo on 2018/9/20
*/
@Configuration
@ComponentScan(basePackages = {"ui","http","common"})
@PropertySource(value = {"duiba.properties"})
public class Config {
@Bean
public PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
pspc.setFileEncoding("UTF-8");
return pspc;
}
}
package common;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.Environment;
import java.io.UnsupportedEncodingException;
import java.util.*;
/**
* Created by hanzhanli on 2017/11/9.
*/
public class DingdingResult {
private static Logger logger = LogManager.getLogger(DingdingResult.class);
Object[] group={"test"};
String project="tuia-media";
String changes="";
int total;
int passCount;
int skipCount;
int failCount;
String resultUrl;
List<String> names = new ArrayList<>();
private transient String activityGroup="tuia-activity-center,tuia-ssp-manager,tuia-open-web,tuia-activity-web";
private transient String duibaGroup="credits-home-web,developer-center,goods-access-web,goods-center,activity-access-web,activity-center,trade-center,trade-access-web,duiba-manager,duiba-manager-web,activity-cms-web,activity-comm-center,consumer-center,goods-access-web,goods-center,hdtool-web,hdtool-center,intersection-service,kvtable-service,plugin-web,plugin-center,prize-center,seckill-web,sign-web,sign-center,stock-service,thirdparty-service,trade-access-web,trade-center";
private transient String adGroup="tuia-engine,tuia-advert-center,tuia-advert-manager,tuia-advert-web,tuia-engine-billing";
private transient String sspGroup="tuia-ssp-center,tuia-ssp-web,tuia-ssp-manager,tuia-open-web";
transient String caseSuites=System.getProperty("test");
private transient String run = System.getProperty("run");
transient ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
transient Environment env=context.getBean(Environment.class);
public transient static String[] name;
String path=null;
public DingdingResult(int total, int passCount, int skipCount, int failCount) throws UnsupportedEncodingException {
logger.info("job-name:"+System.getProperty("JOB_NAME"));
logger.info("属性:"+System.getProperties());
Map<String,String> changeMap=null;
group = duibaGroup.split(",");
changeMap = BeTested.getLatestChanges(duibaGroup.split(","));
project = "duiba-service";
String getName = getByRun(run,"names");
String[] getNames = getName.split(",");
name = getNames;
names.addAll(Arrays.asList(getNames));
Map<String,String> resentChanges=BeTested.getChangesWithin(30,changeMap);
System.out.println(resentChanges);
if(resentChanges!=null&&resentChanges.size()>0){
List<String> changeList=new ArrayList<>();
for(Object key:resentChanges.keySet().toArray()){
//changeList.add(key+"-"+resentChanges.get(key));
if(changes!=null&&changes.length()>0){
changes=changes+","+key+"-"+resentChanges.get(key);
}else
changes=key+"-"+resentChanges.get(key);
}
//group=changeList.toArray();
//this.changes=changeList.toString();
}else {
if(changeMap==null){
this.changes="";
}else {
Set<String> keySet = changeMap.keySet();
this.changes = keySet.toArray()[0] + "-" + changeMap.get(keySet.toArray()[0]);
}
}
if(changes.length()>140){
changes=changes.substring(0,141)+"……";
}
//project="tuia-media";
this.total=total;
this.passCount=passCount;
this.skipCount=skipCount;
this.failCount=failCount;
resultUrl=getresultUrl();
}
private String getresultUrl() throws UnsupportedEncodingException {
String resultUrl=null;
String host=System.getProperty("runEnv");
String serviceLine=null;
String caseSuites=System.getProperty("test");
resultUrl = getByRun(run,"resultUrl");
return resultUrl;
}
public Map<String,Object> getResult() throws UnsupportedEncodingException {
Map<String,Object> result=new HashMap<>();
Object[] mygroup = new Object[1];
mygroup[0]=getByRun(run,"group");
result.put("group",mygroup);
result.put("project",project);
result.put("total",this.total);
result.put("passCount",this.passCount);
result.put("skipCount",this.skipCount);
result.put("failCount",this.failCount);
result.put("resultUrl",this.resultUrl);
List<String> exceptionServices=SFExpress.getExceptionServices();
List<String> exceptionMessage=SFExpress.getExceptionMessage();
String others=null;
if(exceptionServices.size()>0){
others="以下被测服务未启动:"+exceptionServices.toString()+"<br>跳过用例总数:"+this.total;
changes=changes+"<br>"+others;
logger.info(others);
result.put("passCount",0);
result.put("skipCount",this.total);
result.put("failCount",0);
}
if(exceptionMessage.size()>0){
others="以下原因导致测试跳过:"+exceptionMessage.toString()+"<br>跳过用例总数:"+this.total;
changes=changes+"<br>"+others;
logger.info(others);
result.put("passCount",0);
result.put("skipCount",this.total);
result.put("failCount",0);
}
result.put("changes",this.changes+"<br>");
if(this.failCount>0||exceptionServices.size()>0||exceptionMessage.size()>0){
try{
String name = this.changes.split("—")[1].split("/")[0];
names.add(name);
}catch(Exception e){
System.out.println(e);
}
}else {
names.clear();
}
result.put("names",names);
return result;
}
public String getByRun(String run,String type) throws UnsupportedEncodingException {
run = run.substring(run.indexOf("_")+1, run.indexOf("."));
run =this.env.getProperty(run+"."+type);
return new String(run.getBytes("ISO-8859-1"), "UTF-8");//ISO-8859-1
}
public static void main(String[] args) throws UnsupportedEncodingException {
String s = "**/*_signTest.java";
s = s.substring(s.indexOf("_")+1,s.indexOf("."));
System.out.println(s);
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
Environment env=context.getBean(Environment.class);
String ss = env.getProperty("pluginTest.names");
System.out.println(ss =new String(ss.getBytes("ISO-8859-1"), "UTF-8"));
String run = "**/*_signTest.java";
String type = "names";
run = run.substring(run.indexOf("_")+1, run.indexOf("."));
run =env.getProperty(run+"."+type);
System.out.println(run = new String(run.getBytes("ISO-8859-1"), "UTF-8"));
String[] sp =run.split(",");
List<String> list = Arrays.asList(sp);
List<String> names = new ArrayList<>();
names.addAll(list);
}
}
\ No newline at end of file
package common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import javax.annotation.PostConstruct;
/**
* Created by mabo on 2018/9/20
*/
@ContextConfiguration(classes =Config.class)
public class DuibaBase extends AbstractTestNGSpringContextTests {
@Autowired
public MysqlConnPool jdbc;
@PostConstruct
public void setUp() {
System.out.println("setUp执行");
jdbc.initDataSource();
}
}
package common;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.Reporter;
import sun.reflect.Reflection;
/**
* Created by mabo on 2018/10/8
*/
public class DuibaLog {
private Logger logger;
private DuibaLog(){
/*Class c = Reflection.getCallerClass(2);
//Field logger=c.getField("logger");
Field[] fields= c.getDeclaredFields();
for (Field field:fields){
System.out.println(field);
}*/
Logger logger= LogManager.getLogger(Reflection.getCallerClass(3));
//logger=LogManager.getRootLogger();
//logger=LogManager.getLogger("name");
this.logger=logger;
}
private DuibaLog(Logger logger){
this.logger=logger;
}
public static DuibaLog getLogger(){
return new DuibaLog();
}
public void info(String msg){
logger.info(msg);
Reporter.log(msg);
}
}
This diff is collapsed.
package common;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.BeforeSuite;
/**
* Created by mabo on 2018/10/9
*/
public class DuibaTestBase extends DuibaBase {
// @Autowired
// public MysqlConnPool jdbc;
//
// @BeforeSuite
// public void setUp() {
// if(jdbc == null){
// return;
// }
//
// jdbc.getDbs();
//
// }
}
package common;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.test.context.ContextConfiguration;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by mabo on 2018/10/9
*/
//@Component
@Service
public class MysqlConnPool {
//数据库用户名
@Value("${db.name}")
String USERNAME;
//数据库密码
@Value("${db.password}")
String PASSWORD;
//url
@Value("${db.url}")
String URL;
//驱动信息
@Value("${db.driver}")
String DRIVER;
//最大连接池
@Value("${db.maxtotal}")
int maxtotal;
public BasicDataSource bds;
public DuibaLog log = DuibaLog.getLogger();
public void initDataSource(){
if(bds != null){
return;
}
synchronized (MysqlConnPool.class){
if(bds != null){
return;
}
System.out.println("初始化数据库");
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName(DRIVER);
bds.setUrl(URL);
bds.setUsername(USERNAME);
bds.setPassword(PASSWORD);
bds.setMaxTotal(maxtotal);
this.bds = bds;
}
}
/**
* 查询结果只有一行数据
* @param sql sql语句
* @param params 可变参数,替换 ?
* @return map
* @throws SQLException
*/
public Map<String, Object> findSimpleResult(String sql, Object ...params) throws SQLException {
Map<String, Object> map = null;
try(Connection conn = bds.getConnection()){
map = new HashMap<String, Object>();
int index = 1;
PreparedStatement pstmt = conn.prepareStatement(sql);
log.info(conn.toString());
if(params != null && !(params.length==0)){
for(int i=0; i<params.length; i++){
pstmt.setObject(index++, params[i]);
}
}
ResultSet resultSet = pstmt.executeQuery();//返回查询结果
ResultSetMetaData metaData = resultSet.getMetaData();
int col_len = metaData.getColumnCount();
while(resultSet.next()){
for(int i=0; i<col_len; i++ ){
String cols_name = metaData.getColumnName(i+1);
Object cols_value = resultSet.getObject(cols_name);
if(cols_value == null){
cols_value = "";
}
map.put(cols_name, cols_value);
}
}
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}catch(Exception e){
e.printStackTrace();
}
return map;
}
/**
* 增加、删除、改
* @param sql sql语句
* @param params 参数,替换 ?
* @return true or false
* @throws SQLException
*/
public boolean update(String sql, Object ...params) throws SQLException{
Connection conn=null;
boolean flag = false;
try{
int result = -1;
conn = bds.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
int index = 1;
if(params != null && !(params.length==0)){
for(int i=0; i<params.length; i++){
pstmt.setObject(index++, params[i]);
}
}
result = pstmt.executeUpdate();
flag = result > 0 ? true : false;
}catch(Exception e){
e.printStackTrace();
}finally {
if(conn!=null) conn.close();
}
return flag;
}
/**
* 返回多条数据
* @param sql sql语句
* @param params 可变参数,替换 ?
* @return list
* @throws SQLException
*/
public List<Map<String, Object>> findModeResult(String sql, Object ...params) throws SQLException{
Connection conn=null;
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try{
int index = 1;
conn = bds.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
if(params != null && !(params.length==0)){
for(int i=0; i<params.length; i++){
pstmt.setObject(index++, params[i]);
}
}
ResultSet resultSet = pstmt.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
int cols_len = metaData.getColumnCount();
while(resultSet.next()){
Map<String, Object> map = new HashMap<String, Object>();
for(int i=0; i<cols_len; i++){
String cols_name = metaData.getColumnName(i+1);
Object cols_value = resultSet.getObject(cols_name);
if(cols_value == null){
cols_value = "";
}
map.put(cols_name, cols_value);
}
list.add(map);
}
}catch (Exception e){
e.printStackTrace();
}finally {
if(conn!=null) conn.close();
}
return list;
}
}
package common;
import org.apache.commons.dbcp2.BasicDataSource;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by mabo on 2018/10/8
*/
public class MysqlUtils {
//数据库用户名
private String USERNAME;// = "root";
//数据库密码
private String PASSWORD; //= "yanzi";
//驱动信息
private String DRIVER="com.mysql.jdbc.Driver";
private BasicDataSource bds;
public DuibaLog log = DuibaLog.getLogger();
//数据库地址
private String URL;// = "jdbc:mysql://localhost:3306/mydb";
private Connection connection;
private PreparedStatement pstmt;
private ResultSet resultSet;
private DuibaLog logger = DuibaLog.getLogger();
private MysqlUtils(String username,String password,String url){
USERNAME = username;
PASSWORD = password;
URL = url;
connection = getConnection();
}
public MysqlUtils(){
bds = getDbs();
}
/**
*
* @param username 用户名
* @param password 密码
* @param ip 数据库ip
* @param port 端口号
* @param databaseName 数据库名
*/
public MysqlUtils(String username,String password,String ip,String port,String databaseName){
this(username,password,"jdbc:mysql://"+ip+":"+port+"/"+databaseName);
}
/**
* 阿里云数据库连接
* @param databaseName 数据库名字
*/
public MysqlUtils(String databaseName){
this("duiba_test","svbP3KUw2PurAnBb2rbs3vohF","rdswy2b9wy53044250u1o.mysql.rds.aliyuncs.com","3306",databaseName);
}
public static MysqlUtils mysqlDuiba(String databaseName){
return new MysqlUtils("duiba_test","svbP3KUw2PurAnBb2rbs3vohF","rdswy2b9wy53044250u1o.mysql.rds.aliyuncs.com","3306",databaseName);
}
/**
* 获得数据库的连接
* @return
*/
public Connection getConnection(){
try {
try {
Class.forName(DRIVER);
logger.info("数据库连接成功!");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
}
public BasicDataSource getDbs(){
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName("com.mysql.jdbc.Driver");
bds.setUrl("jdbc:mysql://rdswy2b9wy53044250u1o.mysql.rds.aliyuncs.com:3306/");
bds.setUsername("duiba_test");
bds.setPassword("svbP3KUw2PurAnBb2rbs3vohF");
bds.setMaxTotal(2);
return bds;
}
public Connection getconnectionByDataSource() throws SQLException {
return bds.getConnection();
}
/**
* 增加、删除、改
* @param sql sql语句
* @param params 参数,替换 ?
* @return true or false
* @throws SQLException
*/
public boolean update(String sql, Object ...params)throws SQLException{
boolean flag = false;
int result = -1;
pstmt = connection.prepareStatement(sql);
int index = 1;
if(params != null && !(params.length==0)){
for(int i=0; i<params.length; i++){
pstmt.setObject(index++, params[i]);
}
}
result = pstmt.executeUpdate();
flag = result > 0 ? true : false;
return flag;
}
/**
* 查询结果只有一行数据
* @param sql sql语句
* @param params 可变参数,替换 ?
* @return map
* @throws SQLException
*/
public Map<String, Object> findSimpleResult(String sql, Object ...params) throws SQLException{
Map<String, Object> map = new HashMap<String, Object>();
int index = 1;
pstmt = connection.prepareStatement(sql);
if(params != null && !(params.length==0)){
for(int i=0; i<params.length; i++){
pstmt.setObject(index++, params[i]);
}
}
resultSet = pstmt.executeQuery();//返回查询结果
ResultSetMetaData metaData = resultSet.getMetaData();
int col_len = metaData.getColumnCount();
while(resultSet.next()){
for(int i=0; i<col_len; i++ ){
String cols_name = metaData.getColumnName(i+1);
Object cols_value = resultSet.getObject(cols_name);
if(cols_value == null){
cols_value = "";
}
map.put(cols_name, cols_value);
}
}
return map;
}
/**
* 返回多条数据
* @param sql sql语句
* @param params 可变参数,替换 ?
* @return list
* @throws SQLException
*/
public List<Map<String, Object>> findModeResult(String sql, Object ...params) throws SQLException{
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
int index = 1;
pstmt = connection.prepareStatement(sql);
if(params != null && !(params.length==0)){
for(int i=0; i<params.length; i++){
pstmt.setObject(index++, params[i]);
}
}
resultSet = pstmt.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
int cols_len = metaData.getColumnCount();
while(resultSet.next()){
Map<String, Object> map = new HashMap<String, Object>();
for(int i=0; i<cols_len; i++){
String cols_name = metaData.getColumnName(i+1);
Object cols_value = resultSet.getObject(cols_name);
if(cols_value == null){
cols_value = "";
}
map.put(cols_name, cols_value);
}
list.add(map);
}
return list;
}
/**
* 释放数据库连接
*/
public void releaseConn(){
if(resultSet != null){
try{
resultSet.close();
logger.info("数据库连接释放成功");
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
package common;
import io.restassured.RestAssured;
import io.restassured.config.RestAssuredConfig;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* Created by hanzhanli on 2017/11/9.
*/
public class Postman {
static String dingdingUrl="https://shark.dui88.com/test/integration";
static String testPlatformUrl = "http://101.37.27.82:8080/insert";
//dingdingUrl="http://www.json.cn/";
private Logger logger = LogManager.getLogger(Postman.class);
public static void send2Dingding(Map result){
System.out.println("Dingding:"+result);
RestAssuredConfig config = RestAssured.config();
config.getHttpClientConfig()
.setParam(ClientPNames.CONN_MANAGER_TIMEOUT, 150000) // HttpConnectionManager connection return time
.setParam(CoreConnectionPNames.CONNECTION_TIMEOUT, 150000) // Remote host connection time
.setParam(CoreConnectionPNames.SO_TIMEOUT, 150000) ; // Remote host response time
Response response=given().relaxedHTTPSValidation().contentType(ContentType.JSON).body(result).post(dingdingUrl);
System.out.println("--------DingdingTest--------:");
response.prettyPrint();
System.out.println("--------DingdingTest1--------:");
Boolean bl = response.jsonPath().getString("success").equals("false");
if(bl){
String[] name = DingdingResult.name;
result.put("names",name);
response=given().contentType(ContentType.JSON).body(result).post(dingdingUrl);
System.out.println("--------DingdingTest2--------:");
response.prettyPrint();
System.out.println("--------DingdingTest2--------:");
}
}
public static void sendTestPlatform(Map result){
Response response=given().contentType(ContentType.JSON).body(result).post(testPlatformUrl);
System.out.println("--------testPlatform--------:");
response.prettyPrint();
System.out.println("--------testPlatform--------:");
}
public static Boolean getName(){
Calendar c = Calendar.getInstance();
Date date = new Date();
c.setTime(date);
int week_num =c.get(Calendar.WEEK_OF_YEAR);
System.out.println(week_num);
System.out.println(week_num==0);
if(week_num%2==0)return true;
else return false;
}
}
package common;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import com.sun.net.httpserver.Authenticator;
import org.testng.IAnnotationTransformer;
import org.testng.IRetryAnalyzer;
import org.testng.annotations.ITestAnnotation;
/**
* Created by mabo on 2018/9/29
*/
public class RetryListener implements IAnnotationTransformer {
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
IRetryAnalyzer retry = annotation.getRetryAnalyzer();
if (retry == null) {
annotation.setRetryAnalyzer(RetryToRunCase.class);
}
}
}
\ No newline at end of file
package common;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
/**
* Created by mabo on 2018/9/29
*/
public class RetryToRunCase implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 0; // retry a failed test 2 additional times
public boolean retry(ITestResult result) {
if (retryCount <maxRetryCount) {
retryCount++;
return true;
}
return false;
}
}
package common;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by hanzhanli on 2017/11/30.
*/
public class SFExpress {
private final static List<String> exceptionServices=new ArrayList<>();
private final static List<String> exceptionMessage=new ArrayList<>();
private final static Set<String> toBeTestedServices=new HashSet<>();
public static void addToBeTestedServices(Set<String> services){
toBeTestedServices.addAll(services);
}
public static void addExceptionService(String service){
exceptionServices.add(service);
}
public static void addExceptionMessage(String message){
exceptionMessage.add(message);
}
public static void addExceptionService(List<String> service){
exceptionServices.addAll(service);
}
public static Set<String> getToBeTestedServices(){
return toBeTestedServices;
}
public static List<String> getExceptionServices(){
return exceptionServices;
}
public static List<String> getExceptionMessage(){
return exceptionMessage;
}
}
package common;
import org.testng.IClass;
import org.testng.ISuiteResult;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.uncommons.reportng.HTMLReporter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
/**
* Created by hanzhanli on 2017/11/1.
*/
public class SuiteResult {
String suiteName;
int total=0;
int passCount=0;
int skipCount=0;
public int getTotal() {
return total;
}
public int getPassCount() {
return passCount;
}
public int getSkipCount() {
return skipCount;
}
public int getFailCount() {
return failCount;
}
int failCount=0;
Map<String,List<ClassResult>> result=new HashMap<>();
public SuiteResult(String suiteName){
this.suiteName=suiteName;
}
public void addResult(String key,List<ClassResult> classResultList,int count){
result.put(key,classResultList);
this.total=total+count;
if(key.equals("pass")){
this.passCount=count;
}else if(key.equals("skip")){
this.skipCount=count;
}else if (key.equals("fail")){
this.failCount=count;
}
}
//{"suiteName":"myName","results":{"total":3,"data":{"pass":{"count":1,"data":{"method":"mathodNameB","duration":10,"out":"contents"}},"skip":null,"fail":null}}}
// public SuiteResult(ISuiteResult result){
// this.result=new HashMap<>();
// int total=0;
// Map<String,Object> data=new HashMap<>();
// SortedMap<IClass, List<ITestResult>> failedMap = HTMLReporter.sortByTestClassTool(result.getTestContext().getFailedConfigurations());
// Map<String,Object> failedResultMap=new HashMap<>();
//
// for(IClass testClass:failedMap.keySet()){
// List<ITestResult> testResultList=failedMap.get(testClass);
//
// for(ITestResult testResult:testResultList){
//
// }
// }
//
//
// }
public Map<String,String> getMethodResult(ITestResult testResult){
Map<String,String> methodResult=new HashMap<>();
String title=testResult.getName();
String description=testResult.getMethod().getDescription();
if(description!=null&&description.length()>0){
title=title+":"+description;
}
String duration=String.valueOf(testResult.getEndMillis()-testResult.getStartMillis());
String output= Reporter.getOutput(testResult).toString();
methodResult.put("title",title);
methodResult.put("duration",duration);
methodResult.put("output",output);
return methodResult;
}
}
package common;
import java.util.Iterator;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
/**
* Created by mabo on 2018/9/29
*/
public class TestListener implements ITestListener {
private static DuibaLog logger = DuibaLog.getLogger();
public void onFinish(ITestContext context) {
Iterator<ITestResult> listOfFailedTests = context.getFailedTests().getAllResults().iterator();
while (listOfFailedTests.hasNext()) {
ITestResult failedTest = listOfFailedTests.next();
ITestNGMethod method = failedTest.getMethod();
if (context.getFailedTests().getResults(method).size() > 1) {
listOfFailedTests.remove();
} else {
if (context.getPassedTests().getResults(method).size() > 0) {
listOfFailedTests.remove();
}
}
}
}
// Following are all the method stubs that you do not have to implement
public void onTestStart(ITestResult result) {
// TODO Auto-generated method stub
logger.info("Current Thread Id: " + Thread.currentThread().getId());
}
public void onTestSuccess(ITestResult result) {
// TODO Auto-generated method stub
}
public void onTestFailure(ITestResult result) {
// TODO Auto-generated method stub
}
public void onTestSkipped(ITestResult result) {
// TODO Auto-generated method stub
}
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
// TODO Auto-generated method stub
}
public void onStart(ITestContext context) {
// TODO Auto-generated method stub
}
}
\ No newline at end of file
package common;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.testng.*;
import org.testng.xml.XmlSuite;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by mabo on 2018/10/12
*/
public class TestReport implements IReporter{
private DuibaLog logger = DuibaLog.getLogger();
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
int total=0;
int passCount=0;
int skipCount=0;
int failCount=0;
List<String> failCase = new ArrayList<>();
for (ISuite suite : suites) {
Map<String, ISuiteResult> result = suite.getResults();
for (ISuiteResult r : result.values()) {
ITestContext context = r.getTestContext();
total = context.getAllTestMethods().length;
passCount = context.getPassedTests().size();
failCount = context.getFailedTests().size();
skipCount = context.getSkippedTests().size();
for (ITestNGMethod m:
context.getFailedTests().getAllMethods()) {
String[] classes = m.getTestClass().toString().split(" ");
String cla = classes[classes.length-1];
failCase.add( cla.substring(0,cla.length()-1)+"."+m.getMethodName());
}
}
}
DingdingResult ddResult=null;
try{
ddResult=new DingdingResult(total,passCount,skipCount,failCount);
}catch (Exception e){
e.printStackTrace();
}
boolean noticeDD=Boolean.parseBoolean(System.getProperty("noticeDD"));
boolean noticePerson=Boolean.parseBoolean(System.getProperty("noticePerson"));
boolean sendPlatform=Boolean.parseBoolean(System.getProperty("sendPlatform"));
Gson gson=new GsonBuilder().create();
Map<String,Object> map = null;
try {
map = ddResult.getResult();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
map.put("failCase",failCase);
logger.info("gson.toJson(ddResult)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
logger.info("钉钉通知:"+gson.toJson(map));
//发送运行结果到自动化数据收集平台
if(sendPlatform)
Postman.sendTestPlatform(map);
//发送钉钉通知
if(noticeDD){
if(!noticePerson){
map.put("names",new ArrayList<>());
}
logger.info("noticeDD:"+noticeDD);
Postman.send2Dingding(map);
}
}
}
package http;
import org.springframework.stereotype.Service;
/**
* Created by mabo on 2018/9/20
*/
@Service
public class Testhttp_Test {
public void test(){
// throw new Exception("hello");
System.out.println("hello");
}
}
package http.cases.SignTest;
import org.testng.SkipException;
import org.testng.annotations.BeforeSuite;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by hanzhanli on 2017/9/21.
*/
public class Server_signTest {
// private DuibaLog logger = DuibaLog.getLogger();
// private Map<String,String> fromMap=new HashMap<>();
// private Map<String,List<String>> logMap=new HashMap<>();
// @BeforeSuite
// public void onStart() {
// //logger.info("job-name:"+System.getProperty("JOB_NAME"));
// //logger.info("属性:"+System.getProperties());
// logger.info("duiba-server开始检测");
// ServiceDoctor serviceDoctor=new ServiceDoctor("duiba-server.properties");
// SFExpress.addToBeTestedServices(serviceDoctor.getToBeTestedServices());
// //fromMap.putAll(serviceDoctor.getLogLenth());
// SFExpress.addExceptionService(serviceDoctor.getExceptionService(60*2));
// logger.info("duiba-server检测完毕");
// logger.info("duiba-server-center开始检测");
// serviceDoctor=new ServiceDoctor("duiba-server-center.properties");
// SFExpress.addToBeTestedServices(serviceDoctor.getToBeTestedServices());
// //fromMap.putAll(serviceDoctor.getLogLenth());
// SFExpress.addExceptionService(serviceDoctor.getExceptionService(60*2));
// logger.info("duiba-server-center检测完毕");
// if(SFExpress.getExceptionServices().size()>0){
// logger.info("服务未启动:"+SFExpress.getExceptionServices().toString());
// throw new SkipException("被测服务未全部启动");
// }
//
// }
public static void main(String[] args) {
// String s = "最近变更:2018-1-3 13:48:07-activity-access-web:疯狂打气球—jiangxixi/疯狂打气球—jiangxixi/\n";
// String name = s.split("—")[1].split("/")[0];
// System.out.println(name);
// List<String> list = new ArrayList<>();
// list.clear();
// Map<String,Object> map = new HashMap<>();
// map.put("name",list);
// ServiceDoctor serviceDoctor=new ServiceDoctor("duiba-server.properties");
}
}
This diff is collapsed.
This diff is collapsed.
package http.cases;
import common.DuibaBase;
import common.DuibaLog;
import common.DuibaTestBase;
import common.MysqlUtils;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.testng.annotations.Test;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by mabo on 2018/9/30
*/
public class http1_Test extends DuibaBase {
@Value("${pluginTest.project}")
String ManagerHost;
@Value("${db.driver}")
String DRIVER;
public DuibaLog log = DuibaLog.getLogger();
@Test
public void test1() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(5);
System.out.println(ManagerHost);
System.out.println(DRIVER);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
}
@Test
public void test2() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(6);
log.info(" log test ");
log.info(" log test1 ");
log.info(" log test2 ");
log.info(" log test3 ");
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
}
@Test
public void test3() throws InterruptedException, SQLException {
Thread.sleep(1000);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
System.out.println(7);
}
@Test
public void test4() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(8);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
}
public static void main(String[] args) throws SQLException {
// BasicDataSource bds = new BasicDataSource();
// bds.setDriverClassName("com.mysql.jdbc.Driver");
// bds.setUrl("jdbc:mysql://rdswy2b9wy53044250u1o.mysql.rds.aliyuncs.com:3306/");
// bds.setUsername("duiba_test");
// bds.setPassword("svbP3KUw2PurAnBb2rbs3vohF");
// bds.setMaxTotal(3);
//
// Connection conn = bds.getConnection();
// System.out.println(conn);
// conn = bds.getConnection();
// System.out.println(conn);
// conn = bds.getConnection();
// System.out.println(conn);
// conn.close();
// conn = bds.getConnection();
// System.out.println(conn);
// MysqlUtils sql = new MysqlUtils();
// Map<String,Object> map = sql.findSimpleResultBybds("select * from dafuweng.user where id=2709");
// System.out.println("hello");
}
}
package http.cases;
import common.DuibaBase;
import common.DuibaTestBase;
import org.testng.annotations.Test;
import java.sql.SQLException;
import java.util.Map;
/**
* Created by mabo on 2018/9/30
*/
public class http2_Test extends DuibaBase {
@Test
public void test1() throws InterruptedException, SQLException {
Thread.sleep(1000);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
System.out.println(9);
}
@Test
public void test2() throws InterruptedException, SQLException {
Thread.sleep(1000);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
System.out.println(10);
}
@Test
public void test3() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(11);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
}
@Test
public void test4() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(12);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
}
}
package http.cases;
import common.DuibaBase;
import common.DuibaTestBase;
import common.MysqlConnPool;
import http.service.testservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.sql.SQLException;
import java.util.Map;
import java.util.Random;
/**
* Created by mabo on 2018/9/30
*/
public class http_Test extends DuibaBase{
@Autowired
testservice test;
@Test
public void test1() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(1);
System.out.println("run");
test.test();
// Map<String,Object> map = jdbc1.findSimpleResult("select * from dafuweng.user where id=2709");
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
System.out.println("run111");
}
@Test
public void test2() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(2);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
Random rand = new Random();
Assert.assertEquals(1,rand.nextInt(2));
}
@Test
public void test3() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(3);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
Assert.assertEquals(1,2);
}
@Test
public void test4() throws InterruptedException, SQLException {
Thread.sleep(1000);
System.out.println(4);
Map<String,Object> map = jdbc.findSimpleResult("select * from dafuweng.user where id=2709");
}
}
package http.service.Activity;
import common.DuibaLog;
import http.service.Authorization;
import io.restassured.http.Cookies;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.testng.Assert;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
@Service
public class ActivityPlugDrawInfoService {
@Autowired
Authorization authorization;
@Value("${activity.host}")
String activityHost;
private DuibaLog logger = DuibaLog.getLogger();
/**
* 插件皮肤请求接口
* @param cookies
* @param plActSkinId
* @return
* @throws Exception
*/
public Response getPlActSkin(Cookies cookies,String plActSkinId) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("plActSkinId",plActSkinId);
Response response = given().cookies(cookies).params(map).get(activityHost+"/activityPlugDrawInfo/getPlActSkin");
try {
Assert.assertEquals(response.jsonPath().getString("success"), "true", "/activityPlugDrawInfo/getPlActSkin接口失败");
} catch (Exception e) {
throw new Exception("/activityPlugDrawInfo/getPlActSkin接口失败,返回信息:" + response.asString());
} catch (Error er) {
throw new Exception("/activityPlugDrawInfo/getPlActSkin接口失败,返回信息:" + response.asString());
}
return response;
}
/**
* 获取插件活动奖品接口
* @param cookies
* @param activityId 插件活动id
* @return
* @throws Exception
*/
public Response getPrizeInfo(Map cookies,String activityId) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("activityId",activityId);
Response response = given().cookies(cookies).params(map).post(activityHost+"/activityPlugDrawInfo/getPrizeInfo");
try {
Assert.assertEquals(response.jsonPath().getString("success"), "true", "/activityPlugDrawInfo/getPrizeInfo接口失败");
} catch (Exception e) {
throw new Exception("/activityPlugDrawInfo/getPrizeInfo接口失败,返回信息:" + response.asString());
} catch (Error er) {
throw new Exception("/activityPlugDrawInfo/getPrizeInfo接口失败,返回信息:" + response.asString());
}
return response;
}
public Response doJoinPlugdraw(int uid,String id) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("activityId",id);
map.put("token","n42agd4");
logger.info("请求doJoinPlugdraw接口,id="+id);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).post(activityHost+"/activityPlugDrawInfo/doJoinPlugdraw");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/activityPlugDrawInfo/doJoinPlugdraw接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/activityPlugDrawInfo/doJoinPlugdraw接口失败,返回信息:"+response.asString());
}
return response;
}
public Response doJoinPlugdraw_false(int uid,String id) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("activityId",id);
map.put("token","n42agd4");
logger.info("请求doJoinPlugdraw接口,id="+id);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).post(activityHost+"/activityPlugDrawInfo/doJoinPlugdraw");
return response;
}
public Response doJoinPlugdraw_credits(int uid,String id) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("activityId",id);
map.put("deductCredits","true");
map.put("token","n42agd4");
logger.info("请求doJoinPlugdraw接口,id="+id);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).post(activityHost+"/activityPlugDrawInfo/doJoinPlugdraw");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/activityPlugDrawInfo/doJoinPlugdraw接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/activityPlugDrawInfo/doJoinPlugdraw接口失败,返回信息:"+response.asString());
}
return response;
}
public Response getOrderStatusPlugdraw(int uid,String orderId) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("orderId",orderId);
logger.info("请求getOrderStatusPlugdraw接口,orderId="+orderId);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).post(activityHost+"/activityPlugDrawInfo/getOrderStatusPlugdraw");
Assert.assertEquals(response.jsonPath().getString("success"),"true");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/activityPlugDrawInfo/getOrderStatusPlugdraw接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/activityPlugDrawInfo/getOrderStatusPlugdraw接口失败,返回信息:"+response.asString());
}
return response;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package http.service.hd;
import common.DuibaLog;
import http.service.Authorization;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.testng.Assert;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
@Service
public class SigninService {
@Value("${hdserver.host}")
String hdHost;
@Autowired
Authorization authorization;
private DuibaLog logger = DuibaLog.getLogger();
private String url = "http://activity.m.duibatest.com.cn";
public Response getSignActivityUrl(String appId,String id) {
Map<String,String> map = new HashMap<>();
map.put("appId",appId);
map.put("id",id);
Response response = given().cookies(authorization.hdLogin()).params(map).get("http://"+hdHost+"/signin/getSignActivityUrl");
response.prettyPrint();
return response;
}
//开发者自有弹层签到
public Response ajaxBanners() throws Exception{
Map<String,String> map = new HashMap<>();
map.put("activityId","");
map.put("url","chome");
map.put("preview","false");
Response response = given().cookies(authorization.dafuwengLogin(2720)).params(map).get(url+"/activityPlugin/ajaxBanners");
response.prettyPrint();
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/activityPlugin/ajaxBanners接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/activityPlugin/ajaxBanners接口失败,返回信息:"+response.asString());
}
return response;
}
//插件弹层抽奖
public Response doJoin(String activityId) throws Exception{
Map<String,String> map = new HashMap<>();
map.put("activityId",activityId);
map.put("url","chome");
Response response = given().cookies(authorization.dafuwengLogin(2720)).params(map).get(url+"/activitySign/doJoin");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/activitySign/doJoin接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/activitySign/doJoin接口失败,返回信息:"+response.asString());
}
return response;
}
//插件弹层抽奖获取抽奖结果
public Response getOrderStatus(String orderId) throws Exception{
Map<String,String> map = new HashMap<>();
map.put("orderId",orderId);
Response response = given().cookies(authorization.dafuwengLogin(2720)).params(map).get(url+"/activitySign/getOrderStatus");
response.prettyPrint();
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/activitySign/getOrderStatus接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/activitySign/getOrderStatus接口失败,返回信息:"+response.asString());
}
return response;
}
}
package http.service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* Created by mabo on 2018/10/9
*/
@Service
public class testservice {
//数据库用户名
@Value("${db.name}")
String USERNAME;
public void test(){
System.out.println(USERNAME);
}
}
This diff is collapsed.
package ui;
import org.springframework.stereotype.Service;
/**
* Created by mabo on 2018/9/20
*/
@Service
public class Testui {
public void test(){
System.out.println("ui");
}
}
This diff is collapsed.
package utils;
import java.math.BigInteger;
import java.security.MessageDigest;
/**
* Created by mabo on 2018/10/9
*/
public class SecurityUtils {
public static String getMD5(String str) {
String result=null;
try {
// 生成一个MD5加密计算摘要
MessageDigest md = MessageDigest.getInstance("MD5");
// 计算md5函数
md.update(str.getBytes());
// digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符
// BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
result=new BigInteger(1, md.digest()).toString(16);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment