接口的测试(学会2个系统接口测试)

public class SyncDataFromTabulation {
	private static final String BASE_URL = "http://192.168.31.207:10077";
	private static final String PULL_PATH = BASE_URL + "/budget/api/v1/material-template-info/findByXMMC";
	private static final String PUSH_PATH = BASE_URL + "/budget/api/v1/converstion-entity/batchUpdate";

	public void pullData(String projectName) {
		CommonDao commonDao = AppUtils.getBean(CommonDao.class);
		String json = HttpClient.get(PULL_PATH).queryString("xmmc", Base64.encode(projectName)).asString();
		json = Base64.decodeStr(json);
		JSONArray objs = JSON.parseArray(json);
		if (null != objs && !objs.isEmpty()) {
			Object object = objs.get(0);
			MaterialTemplateInfo info = JSON.parseObject(object.toString(), MaterialTemplateInfo.class);
			String sql = "DELETE FROM material_template where xmmc = ?";
			commonDao.updateBySql(sql, info.getXmmc());
		}
		for (Object object : objs) {
			MaterialTemplateInfo info = JSON.parseObject(object.toString(), MaterialTemplateInfo.class);
			commonDao.save(info);
		}

	}

	public void pushData(List infos) {
		String json = JSON.toJSONString(infos);//将数组转换成json字符串
		json = HttpClient.textBody(PUSH_PATH).json(Base64.encode(json)).asString();
		System.out.println(json);
	}
	
}

 

你可能感兴趣的:(java)