I'm working on two apex classes with use the HttpCalloutMock interface and they're working fine when I manually test, but I'm having trouble with the automated test class. Everything seems to look good, but I keep getting the following exception, any tips?
System.JSONException: no content to map to Object due to end of input
Class One
public class ReportDataComponentController{
/*public String reportId{get;set;}
public ReportWrapper__c reportWrapper {get{
return reportWrapper();
}set;}
public String htmlBody {get{
return generateReportData();
}set;}*/
public String reportId{get;set;}
public Contact reportWrapper {get;set;}
public String htmlBody {get;set;}
public ReportDataComponentController(){
reportId = '';
htmlBody = '';
reportWrapper = new Contact();
if(ApexPages.currentPage().getParameters().containsKey('reportId')){
reportId = ApexPages.currentPage().getParameters().get('reportId');
}
populateReportWrapper();
generateReportData();
}
Public void populateReportWrapper(){
//ReportWrapper__c repWrapper = new ReportWrapper__c();
for(Contact wrapper : [ Select id, name, email, firstname, lastname
from Contact
where id = :reportId]){
reportWrapper = wrapper;
}
//return repWrapper;
}
public void generateReportData(){
ReportCallout rptCallout = new ReportCallOut();
String serverName = Apexpages.currentpage().getheaders().get('X-Salesforce-Forwarded-To');
if(String.isBlank(serverName)) {
serverName = 'prerelna1.pre.salesforce.com';
}
String json = rptCallout.getJSONFromReport(serverName, reportId);
ReportParser reportParser = new ReportParser(json);
htmlBody = reportParser.getHtmlTable();
//return htmlExp;
}
}
Class Two
global class ReportCallOut implements HttpCalloutMock {
public String getJSONFromReport(String currentSFDCServerName,String reportID){
//return getReportJSON();
String baseURL = 'https://' + currentSFDCServerName +
+ '/services/data/v29.0/analytics/reports/' + reportID + '?includeDetails=true';
HttpRequest request = new HttpRequest();
request.setMethod('GET');
request.setEndPoint(baseURL);
request.setHeader('Authorization','OAuth ' + UserInfo.getSessionID());
request.setHeader('X-PrettyPrint','1');
Http http = new Http();
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200) {
return response.getBody();
}
else
{
return null;
}
}
global HttpResponse respond(HttpRequest request) {
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
//httpResponse.setBody(getReportJSON());
return httpResponse;
}
}
Test Class
@isTest
global class TestReportCallOutAndReportData{
public TestReportCallOutAndReportData(){
}
static testMethod void TestReportCallAndReportData(){
ReportCallOut rco = new ReportCallOut();
String currentSFDCServerName;
String reportID;
HttpRequest hr = new HttpRequest();
Test.setMock(HttpCalloutMock.class, new ReportCallOut());
String srt = rco.getJSONFromReport(currentSFDCServerName,reportID);
HttpResponse hrs = rco.respond(hr);
rco.getJSONFromReport(currentSFDCServerName,reportID);
rco.respond(hr);
String contentType = hrs.getHeader('Content-Type');
String actualValue = hrs.getBody();
String expectedValue = '{"foo":"bar"}';
//System.assertEquals(actualValue, expectedValue);
//System.assertEquals(200, hrs.getStatusCode());
ReportDataComponentController rdcc = new ReportDataComponentController();
rdcc.populateReportWrapper();
rdcc.generateReportData();
}
}