//Help me to write test class for this class.


global class HttpMethodsJiraToSF

    global static void getvaluefromjira() {

                RestRequest request = RestContext.request;

                RestResponse res = RestContext.response;
                // system.debug('--------------'+request.requestBody.toString());
                String jSONRequestBody=request.requestBody.toString().trim();  

                  HttpMethodsJiraToSFRes.jira resJira = (HttpMethodsJiraToSFRes.jira)JSON.deserialize(jSONRequestBody,HttpMethodsJiraToSFRes.jira.class);


                    case c=[select id,status from case where id =:resJira.caseid];


                    update c;

           }catch(Exception  x)

  • Have u tried this? salesforce.stackexchange.com/questions/24984/… Nov 23, 2015 at 13:48
  • Yes I tried @susanoo .Problem at how to deserialize request.requestBody. Nov 23, 2015 at 13:51
  • What have you written so far? For a REST based class, in my experience you need to create a Mock object. Also in the class itself, you need to add a conditional IsTestRunning if condition.
    – abhi
    Nov 23, 2015 at 14:23

1 Answer 1


As you are explicitly deserializing, you will need to do the corresponding serialize in your test:

static void yourTestMethod() {

    Case c = new Case(...);
    insert c;

    HttpMethodsJiraToSFRes.jira body = new HttpMethodsJiraToSFRes.jira();

    // Fill in fields of body here e.g.:
    body.caseid = c.Id;
    body.Status = 'y';

    RestRequest req = new RestRequest();
    req.httpMethod = 'POST';
    req.requestUri = '...';
    req.requestBody = Blob.valueOf(JSON.serializePretty(body));
    RestContext.request = req;
    RestContext.response = new RestResponse();


    // Add asserts here

The test sets the RestContext global fields that the target @RestResource class then uses.

  • case c=[select id,status from case where id =:resJira.caseid]; This query getting none. All resJira values are not matching.What I required I had given those but unable to verify condition also at Status. Nov 23, 2015 at 15:29
  • @HARIKRISHNA Tests are isolated from data that is already in the org so you need to insert a case as part of your test; I've added a couple of lines to the start of the test method to illustrate where,
    – Keith C
    Nov 23, 2015 at 16:34
  • Thanks Keith.It s really helped me.I am unable to give rank you. Nov 24, 2015 at 4:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .