You need to sign in to do that
Don't have an account?
MoreThanWYSIWYG
Need help calling a URL with parameters and parsing the results in a Unit Test.
So, I have a class that is called by a URL and based on the information provided in the parameters, it runs it through a query and returns results as XML in a VisualForce page.
Here's the Class:
Here's the VF page:
So, what i need to do is write a test class that:
1. Creates an account - done
4. Parses the XML results to ensure results match (or don't)
1 and 2 are done, 3 and 4 are where I am stuck. What do I need to do to get 3 and 4 working?
Here's the Class:
public without sharing class Five9Query {
public string cid { get;set; }
public string phone { get;set; }
public boolean accAccess { get;set; }
public boolean access { get;set; }
public string priority { get;set; }
public string id { get;set; }
public string pin { get;set; }
public string tempCid { get;set; }
public Integer errorCode { get;set; }
private string secPin = '11111111';
public Five9Query() {
string pin = ApexPages.currentPage().getParameters().get('pin');
if (pin == secPin){
system.debug('Pin: ' + pin);
string tempCid = ApexPages.currentPage().getParameters().get('cid');
system.debug('tempCID: ' +tempCid);
Integer cidLength = tempCid.length();
if (cidLength == 10){
cid = '(' + tempCid.substring(0,3) + ') ' + tempCid.substring(3,6) + '-' + tempCid.substring(6,10);
system.debug('cid: ' +cid);
}
else if (cidLength > 10){
cid = tempCid;
}
List<Contact> conMobile = [SELECT id, MobilePhone, Dealer_Portal_Account_Created__c, Account.PortalLoginCreatedEmailed__c , account.discount_tier__c FROM Contact WHERE MobilePhone = :cid limit 1];
List<Contact> conPhone = [SELECT id, Phone,Dealer_Portal_Account_Created__c, account.portalLoginCreatedEmailed__c, account.discount_tier__c FROM Contact WHERE Phone = :cid limit 1];
List<Account> accPhone = [SELECT id, Phone, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Phone = :cid limit 1];
List<Account> accFax = [SELECT id, Fax, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Fax = :cid limit 1];
List<Contact> conFax = [SELECT id, Fax,Dealer_Portal_Account_Created__c, account.portalLoginCreatedEmailed__c, account.discount_tier__c FROM Contact WHERE Fax = :cid limit 1];
List<Account> accBillingPhone = [SELECT id, Billing_Contact_Phone__c, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Billing_Contact_Phone__c = :cid limit 1];
//Checking Contact Mobile Phone
if (!conMobile.isEmpty()){
if(conMobile[0].account.portalLoginCreatedEmailed__c == true){
errorCode = 0;
id = conMobile[0].Id;
phone = conMobile[0].MobilePhone;
access = conMobile[0].Dealer_Portal_Account_Created__c;
priority = conMobile[0].account.discount_tier__c;
}
else{
errorCode = 3;
id = conMobile[0].Id;
phone = conMobile[0].MobilePhone;
access = conMobile[0].account.portalLoginCreatedEmailed__c ;
priority = conMobile[0].account.discount_tier__c;
}
}
//Checking Contact Phone
else if (!conPhone.isEmpty()){
if(conPhone[0].account.portalLoginCreatedEmailed__c == true){
errorCode = 0;
id = conPhone[0].Id;
phone = conPhone[0].Phone;
access = conPhone[0].Dealer_Portal_Account_Created__c;
priority = conPhone[0].account.discount_tier__c;
}
else{
errorCode = 3;
id = conPhone[0].Id;
phone = conPhone[0].Phone;
access = conPhone[0].account.portalLoginCreatedEmailed__c;
priority = conPhone[0].account.discount_tier__c;
}
}
//Checking Account Phone
else if (!accPhone.isEmpty()){
errorCode = 0;
id = accPhone[0].Id;
phone = accPhone[0].Phone;
access = accPhone[0].portalLoginCreatedEmailed__c;
priority = accPhone[0].discount_tier__c;
}
//Checking Account Billing Phone
else if (!accBillingPhone.isEmpty()){
errorCode = 0;
id = accBillingPhone[0].Id;
phone = accBillingPhone[0].Billing_Contact_Phone__c;
access = accBillingPhone[0].portalLoginCreatedEmailed__c;
priority = accBillingPhone[0].discount_tier__c;
}
//Checking Account Fax
else if (!accFax.isEmpty()){
errorCode = 0;
id = accFax[0].Id;
phone = accFax[0].Fax;
access = accFax[0].portalLoginCreatedEmailed__c;
priority = accFax[0].discount_tier__c;
}
//Checking Contact Fax
else if (!conFax.isEmpty()){
if(conFax[0].account.portalLoginCreatedEmailed__c == true){
errorCode = 0;
id = conFax[0].Id;
phone = conFax[0].Fax;
access = conFax[0].Dealer_Portal_Account_Created__c;
priority = conFax[0].account.discount_tier__c;
}
else{
errorCode = 3;
id = conFax[0].Id;
phone = conFax[0].Fax;
access = conFax[0].account.portalLoginCreatedEmailed__c;
priority = conFax[0].account.discount_tier__c;
}
}
else{
System.debug('No Match');
errorCode = 1;
}
}
else {
system.debug('invalid pin');
errorCode = 2;
}
}
}
public string cid { get;set; }
public string phone { get;set; }
public boolean accAccess { get;set; }
public boolean access { get;set; }
public string priority { get;set; }
public string id { get;set; }
public string pin { get;set; }
public string tempCid { get;set; }
public Integer errorCode { get;set; }
private string secPin = '11111111';
public Five9Query() {
string pin = ApexPages.currentPage().getParameters().get('pin');
if (pin == secPin){
system.debug('Pin: ' + pin);
string tempCid = ApexPages.currentPage().getParameters().get('cid');
system.debug('tempCID: ' +tempCid);
Integer cidLength = tempCid.length();
if (cidLength == 10){
cid = '(' + tempCid.substring(0,3) + ') ' + tempCid.substring(3,6) + '-' + tempCid.substring(6,10);
system.debug('cid: ' +cid);
}
else if (cidLength > 10){
cid = tempCid;
}
List<Contact> conMobile = [SELECT id, MobilePhone, Dealer_Portal_Account_Created__c, Account.PortalLoginCreatedEmailed__c , account.discount_tier__c FROM Contact WHERE MobilePhone = :cid limit 1];
List<Contact> conPhone = [SELECT id, Phone,Dealer_Portal_Account_Created__c, account.portalLoginCreatedEmailed__c, account.discount_tier__c FROM Contact WHERE Phone = :cid limit 1];
List<Account> accPhone = [SELECT id, Phone, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Phone = :cid limit 1];
List<Account> accFax = [SELECT id, Fax, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Fax = :cid limit 1];
List<Contact> conFax = [SELECT id, Fax,Dealer_Portal_Account_Created__c, account.portalLoginCreatedEmailed__c, account.discount_tier__c FROM Contact WHERE Fax = :cid limit 1];
List<Account> accBillingPhone = [SELECT id, Billing_Contact_Phone__c, portalLoginCreatedEmailed__c, discount_tier__c FROM Account WHERE Billing_Contact_Phone__c = :cid limit 1];
//Checking Contact Mobile Phone
if (!conMobile.isEmpty()){
if(conMobile[0].account.portalLoginCreatedEmailed__c == true){
errorCode = 0;
id = conMobile[0].Id;
phone = conMobile[0].MobilePhone;
access = conMobile[0].Dealer_Portal_Account_Created__c;
priority = conMobile[0].account.discount_tier__c;
}
else{
errorCode = 3;
id = conMobile[0].Id;
phone = conMobile[0].MobilePhone;
access = conMobile[0].account.portalLoginCreatedEmailed__c ;
priority = conMobile[0].account.discount_tier__c;
}
}
//Checking Contact Phone
else if (!conPhone.isEmpty()){
if(conPhone[0].account.portalLoginCreatedEmailed__c == true){
errorCode = 0;
id = conPhone[0].Id;
phone = conPhone[0].Phone;
access = conPhone[0].Dealer_Portal_Account_Created__c;
priority = conPhone[0].account.discount_tier__c;
}
else{
errorCode = 3;
id = conPhone[0].Id;
phone = conPhone[0].Phone;
access = conPhone[0].account.portalLoginCreatedEmailed__c;
priority = conPhone[0].account.discount_tier__c;
}
}
//Checking Account Phone
else if (!accPhone.isEmpty()){
errorCode = 0;
id = accPhone[0].Id;
phone = accPhone[0].Phone;
access = accPhone[0].portalLoginCreatedEmailed__c;
priority = accPhone[0].discount_tier__c;
}
//Checking Account Billing Phone
else if (!accBillingPhone.isEmpty()){
errorCode = 0;
id = accBillingPhone[0].Id;
phone = accBillingPhone[0].Billing_Contact_Phone__c;
access = accBillingPhone[0].portalLoginCreatedEmailed__c;
priority = accBillingPhone[0].discount_tier__c;
}
//Checking Account Fax
else if (!accFax.isEmpty()){
errorCode = 0;
id = accFax[0].Id;
phone = accFax[0].Fax;
access = accFax[0].portalLoginCreatedEmailed__c;
priority = accFax[0].discount_tier__c;
}
//Checking Contact Fax
else if (!conFax.isEmpty()){
if(conFax[0].account.portalLoginCreatedEmailed__c == true){
errorCode = 0;
id = conFax[0].Id;
phone = conFax[0].Fax;
access = conFax[0].Dealer_Portal_Account_Created__c;
priority = conFax[0].account.discount_tier__c;
}
else{
errorCode = 3;
id = conFax[0].Id;
phone = conFax[0].Fax;
access = conFax[0].account.portalLoginCreatedEmailed__c;
priority = conFax[0].account.discount_tier__c;
}
}
else{
System.debug('No Match');
errorCode = 1;
}
}
else {
system.debug('invalid pin');
errorCode = 2;
}
}
}
Here's the VF page:
<apex:page Controller="Five9Query" contentType="text/xml" showHeader="false" sidebar="false" cache="false">
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<id>{!id}</id>
<access>{!access}</access>
<priority>{!priority}</priority>
<errorcode>{!errorCode}</errorcode>
</response>
</apex:page>
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<id>{!id}</id>
<access>{!access}</access>
<priority>{!priority}</priority>
<errorcode>{!errorCode}</errorcode>
</response>
</apex:page>
So, what i need to do is write a test class that:
1. Creates an account - done
1.1 verifies creation - done
2. Creates a contact - done
2.1 verifies creation - done
3. Calls a URL with a variable from the account and/or contact4. Parses the XML results to ensure results match (or don't)
1 and 2 are done, 3 and 4 are where I am stuck. What do I need to do to get 3 and 4 working?
Please review the below posts that might help
http://salesforce.stackexchange.com/questions/31289/need-help-calling-a-url-with-parameters-and-parsing-the-results-in-a-unit-test
http://salesforce.stackexchange.com/questions/23625/how-to-assert-a-pagereference-in-test-method-for-visualforce-controller