I have tried to write a test class for the below class with post method. But i am not able to bring the coverage.How can I approach this. Thanks in advance.
/* code starts here*/
@RestResource(urlMapping='/ABCAVM/Property/Analytics/')
global class ABCAVMService {
@HttpPost
global static ABCGlobalTypes.ABCStatusResponse doPo
st(){
ABCGlobalTypes.ABCStatusResponse resp;
//Handle incoming request
RestRequest req = RestContext.request;
Map<String,String> params = req.params;
String requestData = req.requestBody.toString();
//Check for blank request
if(String.isBlank(requestData)){
resp=new ABCGlobalTypes.ABCStatusResponse();
resp.wsResponse = new ABCCommon.wsResponseType();
resp.wsResponse.wmstatus = 'error';
resp.wsResponse.wmmessage = 'Request body was empty';
return resp;
}
//Hand off request to main processing class
ABCAVM avm = new ABCAVM();
resp = new ABCGlobalTypes.ABCStatusResponse();
resp.wsResponse = avm.insertAnalytics(requestData);
return resp;
}
}
This is my test Class
@isTest
private class Test_GNWAVMService {
static {
// setup test data
}
static testMethod void testdoPost() {
String requestData = '1234';
GNWGlobalTypes.GNWStatusResponse app = new GNWGlobalTypes.GNWStatusResponse();
//new app.doPost();
//RestRequest req = new GNWGlobalTypes.GNWStatusRequest();
//RestResponse res = new GNWStatusResponse();
RestRequest sas = RestContext.request;
RestResponse res = new RestResponse();
//req.requestURI = 'https://cs9.salesforce.com/services/apexrest/v.9/member/me/results/today';
//res.httpMethod = 'POST';
//RestContext.request = req;
RestContext.response = res;
RestContext.request= sas;
//GNWGlobalTypes.GNWStatusResponse results = GNWAVMService.doPost();
//System.assertEquals('true', results.success);
//System.assertEquals(10, results.records.size());
//System.assertEquals('Query executed successfully.', results.message);
}
}