You need to sign in to do that
Don't have an account?
Amiya Das
test class for two dependant classes
The main apex class is :-
please help me in test class with proper code coverage for the top most class :- POCPAGEV2CaseContrl
Any Help would be appreciated. Thanks in advance.
public without sharing class POCPAGEV2CaseContrl { public String siteKeyValue{get; set;} public boolean caseCreated{Get;set;} public POCPAGEV2CaseContrl(ApexPages.StandardController sc){ caseCreated = false; caseVar = new Case(); siteKeyValue = UTAGoogleRecatcha__c.getValues('GoogleRecaptchaKey').SiteKeyValue__c; } public case caseVar{Get;set;} public pagereference saveRec(){ if(!isCaptchaValid()){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Recaptcha validation failed')); return null; } caseVar.RecordTypeId='01270000000YTjY'; insert caseVar; caseCreated = true; return new pagereference('/apex/POCPage3Case?success=1').setRedirect(true); } // Simranjeet Singh - Commented this Method. public Boolean isCaptchaValid(){ String gRecaptchaResponse = ApexPages.currentPage().getParameters().get('g-recaptcha-response'); GoogleRecaptcha grecaptcha = new GoogleRecaptcha(UTAGoogleRecatcha__c.getValues('GoogleRecaptchaKey').SecretKeyValue__c); return grecaptcha.validCaptcha(gRecaptchaResponse); } }The above apex class has instance of this apex class below :-
public class GoogleRecaptcha { private String secretKey; public GoogleRecaptcha(String secretKey){ this.secretKey = secretKey; } public Boolean validCaptcha(String validationString){ HttpRequest request = new HttpRequest(); request.setMethod('POST'); request.setEndpoint('https://www.google.com/recaptcha/api/siteverify'); request.setBody('secret='+EncodingUtil.urlEncode(secretKey,'UTF-8')+'&response='+EncodingUtil.urlEncode(validationString, 'UTF-8')); Http http = new Http(); HttpResponse httpResponse = http.send(request); RecaptchaResponse response = (RecaptchaResponse)JSON.deserialize(httpResponse.getBody(), RecaptchaResponse.class); return response.success; } public class RecaptchaResponse{ Boolean success {get;set;} } }
please help me in test class with proper code coverage for the top most class :- POCPAGEV2CaseContrl
Any Help would be appreciated. Thanks in advance.