You need to sign in to do that
Don't have an account?
jayesh pagare
Please Help me to write Test Class for below apex class?
public class theControllerMyTEST {
public user currentuser{get;set;}
public string emailAddress{get;set;}
public List<PersonInfo> lstPersonInfo{get;set;}
public class PersonInfo {
public integer g_id{get;set;}
public string sportname{get;set;}
public string description{get;set;}
public string imageUrl{get;set;}
public PersonInfo(){
}
}
// Constructor
public theControllerMyTEST () {
currentuser=[Select FirstName,LastName,Email from User where Id=:userinfo.getuserId()];
emailAddress =currentuser.Email ;
system.debug('Email Id :'+emailAddress );
getGames();
}
// getGame method definition
public void getGames()
{
Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String endpoint ='http://mytest.test.com/gedetails.php?id='+emailAddress;
request.setEndPoint(endpoint);
request.setMethod('GET');
request.setEndpoint(endpoint);
request.setTimeOut(60000);
HTTPResponse response = httpProtocol.send(request);
String jsonString = response.getBody();
System.debug(jsonString);
parseJSON(jsonString );
}
// Json Parser Method
public void parseJSON(String jsonstr) {
if (jsonstr != null){
lstPersonInfo= new List<PersonInfo>();
JSONParser parser = JSON.createParser(jsonstr);
while (parser.nextToken() != null)
{
if (parser.getCurrentToken() == JSONToken.START_ARRAY)
{
while (parser.nextToken()!= JSONToken.END_ARRAY)
{
if (parser.getCurrentToken() == JSONToken.START_OBJECT)
{
PersonInfo ci = new PersonInfo();
while (parser.nextToken() != JSONToken.END_OBJECT)
{
if((parser.getCurrentToken() ==JSONToken.FIELD_NAME)&&(parser.getText().tolowercase()== 'id'))
{
parser.nextToken();
ci.g_id = integer.valueof( parser.getText());
system.debug('ID OF CELERY: '+ci.g_id);
}
if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText().tolowercase() == 'description'))
{
parser.nextToken();
ci.description= parser.getText();
}
}
lstPersonInfo.add(ci);
}
}
}
}
}
}
}
public user currentuser{get;set;}
public string emailAddress{get;set;}
public List<PersonInfo> lstPersonInfo{get;set;}
public class PersonInfo {
public integer g_id{get;set;}
public string sportname{get;set;}
public string description{get;set;}
public string imageUrl{get;set;}
public PersonInfo(){
}
}
// Constructor
public theControllerMyTEST () {
currentuser=[Select FirstName,LastName,Email from User where Id=:userinfo.getuserId()];
emailAddress =currentuser.Email ;
system.debug('Email Id :'+emailAddress );
getGames();
}
// getGame method definition
public void getGames()
{
Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String endpoint ='http://mytest.test.com/gedetails.php?id='+emailAddress;
request.setEndPoint(endpoint);
request.setMethod('GET');
request.setEndpoint(endpoint);
request.setTimeOut(60000);
HTTPResponse response = httpProtocol.send(request);
String jsonString = response.getBody();
System.debug(jsonString);
parseJSON(jsonString );
}
// Json Parser Method
public void parseJSON(String jsonstr) {
if (jsonstr != null){
lstPersonInfo= new List<PersonInfo>();
JSONParser parser = JSON.createParser(jsonstr);
while (parser.nextToken() != null)
{
if (parser.getCurrentToken() == JSONToken.START_ARRAY)
{
while (parser.nextToken()!= JSONToken.END_ARRAY)
{
if (parser.getCurrentToken() == JSONToken.START_OBJECT)
{
PersonInfo ci = new PersonInfo();
while (parser.nextToken() != JSONToken.END_OBJECT)
{
if((parser.getCurrentToken() ==JSONToken.FIELD_NAME)&&(parser.getText().tolowercase()== 'id'))
{
parser.nextToken();
ci.g_id = integer.valueof( parser.getText());
system.debug('ID OF CELERY: '+ci.g_id);
}
if((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText().tolowercase() == 'description'))
{
parser.nextToken();
ci.description= parser.getText();
}
}
lstPersonInfo.add(ci);
}
}
}
}
}
}
}