Commit 30ac403a authored by zhouzihao's avatar zhouzihao

dev-添加车动态接口测试的实现

parent e3a699e2
...@@ -29,6 +29,7 @@ public class Tmp { ...@@ -29,6 +29,7 @@ public class Tmp {
case1 = new CarListDecorator(case1); case1 = new CarListDecorator(case1);
case1 = new CarInfoDecorator(case1); case1 = new CarInfoDecorator(case1);
case1 = new CarDetectDecorator(case1); case1 = new CarDetectDecorator(case1);
case1 = new CarStatusDecorator(case1);
case1.check(); case1.check();
} }
......
package com.vandyo.sentry.core.cases;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.vandyo.sentry.core.dto.ErrStatus;
import com.vandyo.sentry.core.dto.Res;
import com.vandyo.sentry.core.tools.Signature;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* 车动态测试实例
*/
public class CarStatusDecorator extends CaseDecorator{
private final static String carStatusUrl = "/carDynamic/api/status/car/state/get";
public CarStatusDecorator(Case aCase) {
super(aCase);
}
@Override
public Res<Map<String, String>> check() {
Res<Map<String,String>> oldRes = super.check();
if (oldRes.getSuccess()) {
Map<String, String> carMap = oldRes.getData();
Res<Map<String,String>> newRes = new Res<>();
newRes.setSId(oldRes.getSId());
newRes.setUId(oldRes.getUId());
if (Objects.isNull(carMap) || !carMap.containsKey("cid")){
newRes.setStatus(ErrStatus.ErrUnexpected);
newRes.setSuccess(false);
}else {
String cid = carMap.get("cid");
Map<String,String> paramMap = new HashMap<>();
paramMap.put("cid",cid);
paramMap.put("uid",oldRes.getUId());
paramMap.put("start",String.valueOf(System.currentTimeMillis()/1000));
HttpResponse response = HttpRequest.get(
Signature.host + carStatusUrl + "?"
+ Signature.getUrlParamsByMap(Signature.sign(paramMap,oldRes.getSId()))
).execute();
if (response.isOk()){
JSONObject jsonObject = JSONUtil.parseObj(response.body());
//todo 检测 返回值可用性
newRes.setData(carMap);
newRes.setSuccess(true);
}else {
newRes.setStatus(Signature.matchStatus(response.getStatus()));
newRes.setSuccess(false);
}
}
return newRes;
}else {
return oldRes;
}
}
}
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