0611 接口自动化实战

课堂PPT

PPT地址

MapperUtil

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.csv.CsvFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.File;
import java.io.IOException;

public class MapperUtil<T> implements  java.io.Serializable{
    private static final long serialVersionUID = 2L; // as of 2.9
    ObjectMapper objectMapper;

    T readValue ;


    public T getReadValue(String pathName){
        try {
            //兼容json yaml csv 解析
            if(pathName.endsWith(".json")){
                objectMapper = new ObjectMapper(new JsonFactory());
            }else if (pathName.endsWith(".yaml") | pathName.endsWith(".yml")){
                objectMapper = new ObjectMapper(new YAMLFactory());
            }else if(pathName.endsWith(".csv") ){
                objectMapper = new ObjectMapper(new CsvFactory());
            }
            TypeReference<T> valueTypeRef =
                    new TypeReference<T>() {};
            //解析数据
            readValue = objectMapper.readValue( new File(pathName), valueTypeRef);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return readValue;
    }

}

token.yaml

master:
  contacts:
    corpid: wwecb0ab2da18a7c3b
    corpsecret: 6Yg1wwQ_gZIUTXezXfVtnbSfD01619-jo1LpopQT7w0
  sendMessage:
    corpid: wwecb0ab2da18a7c3b
    corpsecret: Qpj8Te-MJirkiBGxQafctksBFYEkW07Xuy7CQPiyCKM
dev:
  contacts:
    corpid: wwecb0ab2da18a7c3b
    corpsecret: 6Yg1wwQ_gZIUTXezXfVtnbSfD01619-jo1LpopQT7w0
  sendMessage:
    corpid: wwecb0ab2da18a7c3b
    corpsecret: Qpj8Te-MJirkiBGxQafctksBFYEkW07Xuy7CQPiyCKM

代码仓库

没来得及查id和secret