I am new for test class but I very eager to learn for that, I have created class. Please can any one help me out to my class.
global class Searchaddress
{
public String accName{get;set;}
public String StNumber{get;set;}
public String Bcity{get;set;}
public String BPostalcode{get;set;}
public String BCountry{get;set;}
public Id accId{get;set;}
string Id;
list<Account>updateAdd=new list<Account>();
public Searchaddress(ApexPages.StandardController controller)
{
id=ApexPages.currentPage().getParameters().get('id');
}
public PageReference autosave()
{
for(Account updatelist:[SELECT id,BillingAddress,BillingCity,BillingCountry,BillingLatitude,BillingLongitude,BillingPostalCode,BillingState,BillingStreet
FROM Account where id=:id])
{
updatelist.BillingStreet=StNumber;
updatelist.BillingCity=Bcity;
updatelist.BillingPostalCode=BPostalcode;
updatelist.BillingState='';
updatelist.BillingCountry=BCountry;
updateAdd.add(updatelist);
}
update updateAdd;
PageReference pageRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id')+'?inline=0');
return pageRef;
}
public class Properties
{
public String city;
public String label;
public String id;
public String postcode;
public String name;
public String citycode;
public String context;
public Double score;
public String type;
}
@RemoteAction
global static list<String> restapi(string accName)
{
string jsonStr;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Accept','application/JSON');
req.setEndpoint('http://api-adresse.data.gouv.fr/search/?q='+EncodingUtil.urlEncode(accName,'UTF-8'));//+'&'+'limit'+'='+'10');//
req.setMethod('GET');
HttpResponse res = h.send(req);
List<String> calOut = new List<String>();
jsonStr= res.getBody();
system.debug('res1===>'+res.getBody());
JSONParser parser = JSON.createParser(jsonStr);
List<String> calOut1 = new List<String>();
JSON2Apex parsed = JSON2Apex.parse(res.getBody());
for(JSON2Apex.Features f : parsed.Features)
{
JSON2Apex.Properties p = f.Properties ;
calOut1.add(p.label+' '+'FRANCE');
}
return calOut1;
}
}
http://salesforce.stackexchange.com/questions/3486/testing-httpcallout-with-httpcalloutmock-and-unittest-created-data
Start your test class by creating a test account record.
– Ruchi Aug 12 '15 at 07:47