MockDataTranslator

Posted by Bruce Tsai

  • 透過 Apache POI 轉換假資料 sheet (*.xlsx) 為資料檔
  • Excel 範本檔案 下載

範本 Excel

欄位說明

  • 目標的類別 (targetDeclareType) : 執行方法的實際型別,需包含 package。
  • 目標的執行方法 (targetMethod) : 執行方法的名稱。
  • 執行方法的回傳類別 (outputType) : 方法的回傳型別,需包含 package。
  • 比對的鍵值 (mapper) : 輸入參數或屬性的比對方式。以 #key=value 的形式,記錄符合的參數。多個鍵值時,以多行區隔資料。
  • 是否在執行時丟出例外 (causeException) : 用來測試例外狀況,設定為 true 時,預設會在執行時丟出 RuntimeException。
  • 要丟出的例外型別 (exceptionType) : 當 causeException 設定為 true 時,所丟出例外的型別,需包含 package。
  • 例外訊息 (exceptionType) : 當 causeException 設定為 true 時,所丟出例外的訊息內容。
  • 由外部轉入的假資料物件 (value) : 在鍵值比對符合時,用以替代原始資料的假資料內容。資料將會透過 Gson 轉換為指定物件。

範本 Excel

轉換資料

public class ConvertExcel {

    // 來源的資料檔 sheet
    static String SOURCE_FILE_PATH = "mock.xlsx";
    // 轉換後的資料檔路徑
    static String OUTPUT_FILE_PATH = "mock.txt";

    public static void main(String[] args) {
        Logs.register(new GenericLogger(Level.Debug));
        MockDataTranslator translator 
          = new MockDataTranslator(SOURCE_FILE_PATH, OUTPUT_FILE_PATH);
        translator.execute();
    }

}

轉換後資料檔(範例)

{"targetDeclareType":"com.fet.crm.eservice.generic.mware.siggw.impl.AccountServiceImpl","targetMethod":"getSiggwFetAccountInfo","mapper":{"#1":"FET","#0":"80011111"},"outputType":"com.fet.siggw.vo.FetAccountInfoVo","causeException":false,"exceptionType":"","exceptionMessage":"","value":{...}}
{"targetDeclareType":"com.fet.crm.eservice.generic.mware.siggw.impl.AccountServiceImpl","targetMethod":"getSiggwFetAccountInfo","mapper":{"#1":"FET","#0":"80022222"},"outputType":"com.fet.siggw.vo.FetAccountInfoVo","causeException":true,"exceptionType":"","exceptionMessage":"","value":{...}}
{"targetDeclareType":"com.fet.crm.eservice.generic.mware.siggw.impl.AccountServiceImpl","targetMethod":"getSiggwFetAccountInfo","mapper":{"#1":"FET","#0":"80033333"},"outputType":"com.fet.siggw.vo.FetAccountInfoVo","causeException":true,"exceptionType":"com.fet.crm.eservice.generic.mware.exception.FailedResultException","exceptionMessage":"hahahaha","value":{...}}
{"targetDeclareType":"com.fet.crm.eservice.generic.mware.selfcare.impl.SelfcareServiceImpl","targetMethod":"queryGsmSimStatus","mapper":{"#1.name":"FET","#0":"800011111"},"outputType":"com.fet.crm.eservice.generic.mware.selfcare.service.element.GsmSimStatusInfo","causeException":false,"value":{...}}
{"targetDeclareType":"com.fet.crm.eservice.generic.mware.siggw.impl.SearchService","targetMethod":"retvKeysByMsisdn","mapper":{"#0":"0900123456"},"outputType":"com.fet.crm.eservice.generic.bean.auth.MsisdnKeysInfo","causeException":false,"value":{...}}
{"targetDeclareType":"com.fet.crm.eservice.generic.mware.siggw.impl.SearchService","targetMethod":"retvKeysByMsisdn","mapper":{"#0":"0900238782"},"outputType":"com.fet.crm.eservice.generic.bean.auth.MsisdnKeysInfo","causeException":false,"value":{...}}
{"targetDeclareType":"com.fet.crm.eservice.generic.mware.csp.impl.CspSdkServiceImpl","targetMethod":"getUserProfile","mapper":{"#0":"0900123456"},"outputType":"com.fet.crm.eservice.generic.bean.auth.CspUserProfile","causeException":false,"value":{...}}
{"targetDeclareType":"com.fet.crm.eservice.generic.mware.csp.impl.CspSdkServiceImpl","targetMethod":"getUserProfile","mapper":{"#0":"0900238782"},"outputType":"com.fet.crm.eservice.generic.bean.auth.CspUserProfile","causeException":false,"value":{...}}
{"targetDeclareType":"com.fet.crm.eservice.generic.mware.siggw.impl.SubscriberServiceImpl","targetMethod":"retvServiceDetails","mapper":{"#this.productType":"FET","#this.subscriberId":"700035444"},"outputType":"com.fet.crm.eservice.generic.bean.sig.SrvAgrInfo[]","causeException":false,"value":[...]}

results matching ""

    No results matching ""