+ Start a Discussion
sailersailer 

Error while coding the Test Class when calling the method

Hello Everyone
i am not able to call one method in the test class can you please help me out

public class JSONParserUtil {

    @future(callout=true)
   
   public static void parseJSONResponse(String Acctname,String Ids)
   // public static void parseJSONResponse()
     {      
        String AcctNameJson;
        system.debug('AccountName______________________________'+AcctName);
        String JSONContent = '{"folionum":'+AcctName+'}';
        Http httpProtocol = new Http();
        // Create HTTP request to send.
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        String endpoint = 'http://.cloudapp.net/api/values';
        request.setEndPoint(endpoint);
        request.setHeader('content-type', 'application/json; charset=utf-8');
        request.setMethod('POST');
       // String strbody = '{"folionum":48430721840}';
        request.setBody(JSONContent);
        HttpResponse response = httpProtocol.send(request);
       // String jsonInput = response.getBody(); UCOMMENETED TO READ TEH JSON
        JSONParser parser = JSON.createParser(response.getBody());
        system.debug('JSON PARESER___________________'+parser );
        system.debug('Respone'+Response.getBody());
        String grandTotal ;
         while (parser.nextToken() != null)
         {
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == '12monthspavg'))
             {
               parser.nextToken();
                grandTotal += parser.getDoubleValue();
     
             }
          }
                    system.debug('Grand total=' + grandTotal);
                   
         if (response.getStatusCode() == 200) {

      //update account
      Account acc = new Account(Id=Ids);
      acc.Description =grandTotal ;
      update acc;
    } else {
      System.debug('Callout failed: ' + response);
    }  
         
                   
}
}

###################Test Class####################################
@isTest(SeeAlldata=true)
private class E2PPTestClass {

    @isTest static  void myUnitTest()
     {
     
        // TO DO: implement unit test
        String Acctname;
        String Ids;
        List<Account > Acctquery;
        Account acct = new Account();
         acct.Name='Test';
        insert acct;
        Acctquery=[Select Id,Name from Account limit 1];
       acct.Id =Acct.Id;
       acct.Name='Test';
      Test.startTest();
     Test.setMock(HttpCalloutMock.class, new ExampleCalloutMock());
     HttpResponse res = JSONParserUtil.parseJSONResponse(Acctname, Ids);//I am getting the Error here ave error: Illegal assignment from void to System.HttpResponse
    
     Test.stopTest();
     
    
    }
}

Please help me out

Regards,
Sailer
Vinita_SFDCVinita_SFDC
Hello,

Try like this instead:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm

Further reference: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing.htm
sailersailer
Hi Vinita,
Based on the above example i have started coding ,But on issues which i am facing is there the methods is not taking arguments,But my methods takes the arugments.

KR_ForceKR_Force
Hi Sailer,

Im in the same boat now, did you figured out the solution? if so can you please share your test class code.

thanks