overall structure of the project
Create a JUnit Testcase
Create a new JUnit TestCase class under the Test/java package directory, as follows:
Applyrequestspeedv3test.java
Package com.yirendai.borrowbase.node.applyrequest.yrd.fast3;
Import Com.yirendai.borrowbase.api.ServiceResult;
Import Com.yirendai.borrowbase.api.applyrequest.IApplyRequestSpeedV3Facade;
Import Com.yirendai.borrowbase.api.applyrequest.model.ApplyRequestSpeedV3Query;
Import Com.yirendai.borrowbase.api.applyrequest.model.ResultApplyRequestVO;
Import Com.yirendai.borrowbase.api.applyrequest.model.common.SpeedV3TransportInVO;
Import Com.yirendai.borrowbase.node.test.util.ParamUtil;
Import Org.junit.Before;
Import Org.junit.Test;
Import Org.junit.runner.RunWith;
Import org.springframework.beans.factory.annotation.Autowired;
Import org.springframework.test.context.ContextConfiguration;
Import Org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Import java.io.IOException; /** * * @author Ricky Fung * @create 2016-07-08 10:28 * * @RunWith (Springjunit4classrunner.class) @ContextConfiguration (locations = {"Classpath:applicationContext.xml"}) public class applyrequestspeedv3tEST {@Autowired private iapplyrequestspeedv3facade applyrequestspeedv3facade;
Private String Basedir = "/data/applyrequest/speed3";
Private applyrequestspeedv3query query; @Before public void Init () throws IOException {Speedv3transportinvo transportinvo = Paramutil.readjsonfile (b
Asedir, "Apply_request_info.json", Speedv3transportinvo.class); query = applyrequestspeedv3query. Custom (). Setclientidentify ("the"). Setp
Latformcode ("YrdAs3"). Setsystemmodel ("Coolpad 8730L"). Setsystemphone ("Android 4.3")
. Settransportinvo (TRANSPORTINVO). build (); } @Test public void Testapplyrequest () {serviceresult<resultapplyrequestvo> result = Applyrequests
Peedv3facade.applyrequest (query);
SYSTEM.OUT.PRINTLN ("Preliminary examination results:" +result);
}
}
Paramutil.java
Package com.yirendai.borrowbase.node.test.util;
Import Com.alibaba.fastjson.JSON;
Import Com.google.common.io.Files;
Import Java.io.File;
Import java.io.IOException;
Import Java.nio.charset.Charset;
/**
* Created by 123 on 2015/12/16.
*
/public class Paramutil {public
static <T> T readjsonfile (String file, class<t> clazz)
Throws IOException {
String path = Class.class.getResource (file). GetFile ();
String JSON = files.tostring (new File (path), Charset.defaultcharset ());
Return Json.parseobject (JSON, clazz);
}
public static <T> T readjsonfile (String dir, String fileName, Class<t> clazz) throws IOException {
return Readjsonfile (dir + '/' + fileName, clazz);
}
public static <T> T readxmlfile (String file, class<t> clazz) {
return null;
}
}
Test resource File
Create a new/data/applyrequest/speed3 directory under the Test/resources directory, creating a Apply_request_info.json file