0

Need help in writing a test class for REST API call through Oauth2 authentication between two Salesforce instances.

I have remote class (Method @HttpPOST) in provider instance which return sets of records. From Salesforce client instance, first i am sending request to get Access token and then sending again with some parameter to retrieve set of records. referred Salesforce https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_multistaticresourcecalloutmock.htm,

Here is test class i have written, it is still incomplete.

`

@isTest
public class ExSearchPageControllerTest{    
    static testMethod void ExSearchPageControllerTestMethod() {
        MultiStaticResourceCalloutMock mock = new MultiStaticResourceCalloutMock();
mock.setStaticResource('https://test.salesforce.com//services/apexrest/SearchData','SearchDataTest');
        mock.setStatusCode(200);
        mock.setHeader('Content-Type', 'application/json');
        Test.startTest();
        List<SearchWrapperClass> swcl=new List<SearchWrapperClass>();
        ExSearchPageController myclass1=new ExSearchPageController();

        // Set the mock callout mode
        Test.setMock(HttpCalloutMock.class, mock);
        myclass1.name='Test Name';
        myclass1.runSearch();

        ExSearchPageController myclass=new ExSearchPageController();
        myclass.name='Test Name ';
        myclass.street='Test Street Address ';
        myclass.city='Test City ';
        List<SelectOption> countryLs=myClass.countryList;
        myclass.selectedCountry='US';
        myclass.ReturnAccessToken ();
        Test.stopTest();
    }

` Issue is, in my original class i have called another instance twice, first to retrieve access token by passing secret key and username, password. In 2nd call i am passing values "test name" ect. But it failed to retrieve result as token is null.

2
  • If you wish to receive good answer prefer to share your code Commented Nov 26, 2016 at 20:36
  • re Edited my question
    – user35059
    Commented Nov 27, 2016 at 8:50

1 Answer 1

2

With the amount of information you have provided, this should get you started:

@isTest
private class myTestClass{

    private static test method void myFirstTestMethod(){
        //...Do Some stuff...
    }

}

Note the annotated class with @isTest

From here you might want to visit Apex Testing Trailhead to learn and expand on the answer to fit your unknown requirements

0

You must log in to answer this question.

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