Skip to main content
Looking for help to get my test class working properly. The Code, Trigger, and Test class are listed below... Thanks in advance.

 

/* TEST CLASS FOR QuoteTriggerHandler TO ASSESS HANDLING OF UPDATES TO

BILL TO AND SHIP TO ACCOUNTS, CONTACTS, AND ADDRESSES

- John Scardino, 2015-05-28

*/

@isTest // test classes need the @isTest classification

private class QuoteTriggerHandlerTest {

static testMethod void insertNewQuoteTest() {

// select account to add a new opportunity towards

Account newAccountJawn = new Account(Name='Jawn', Phone='(555) 555-5555',

Customer_Class__c='Defense Industry', Entity_Type__c='Domestic');

insert newAccountJawn;

// create new opportunity on the account

// -> reference new op id on the new quote

Opportunity newOpportunityJawn = new Opportunity(/*RecordType='Transactional Opportunity',*/CloseDate=date.Today(), StageName='Quoted', Name='Test Op', Account=[SELECT Id FROM Account WHERE Id= :[SELECT Id FROM Account WHERE Id= :newAccountJawn.Id]]);

insert newOpportunityJawn;

// create new contact on the account

// -> reference new contact id on the new quote

Contact newContactJawn = new Contact(LastName='Aaron', Account=[SELECT Id FROM Account WHERE Id= :newAccountJawn.Id]);

insert newContactJawn;

// create new BILL TO address on the account

// -> reference new bill to address id on the new quote

Address__c newBillingAddressJawn = new Address__c(Account_Name__c=[SELECT Id FROM Account WHERE Id= :newAccountJawn.Id],

Address_Line_1__c='Apple Inc.', Address_Line_2__c='1 Infinite Loop', City__c='Cupertino', State_Code__c='CA', Postal_Code__c='95014', Postal_Code_Extension__c='2083', Country_Code__c='US', Type__c='Billing');

insert newBillingAddressJawn;

// create new SHIP TO address on the account

// -> reference new ship to address id on the new quote

Address__c newShippingAddressJawn = new Address__c(Account_Name__c=[SELECT Id FROM Account WHERE Id= :newAccountJawn.Id],

Address_Line_1__c='621 Lynnhaven Pkwy', Address_Line_2__c='Ste 400', City__c='Virginia Beach', State_Code__c='VA', Postal_Code__c='23452', Country_Code__c='US', Type__c='Shipping');

insert newShippingAddressJawn;

// create new quote

// <- include new id values for lookup fields to opportunity, contact, bill to and ship to

SBQQ__Quote__c newQuoteJawn = new SBQQ__Quote__c(SBQQ__Opportunity__c=[SELECT Id FROM Opportunity WHERE Id= :newOpportunityJawn.Id],

SBQQ__Type__c='Quote', SBQQ__Status__c='Draft', Contract__c=[SELECT Id FROM Contract__c WHERE Id= :newContactJawn.Id],

Bill_To_Address__c=[SELECT Id FROM Address__c WHERE Id= :newBillingAddressJawn.Id], Ship_To_Address__c=[SELECT Id FROM Address__c WHERE Id= :newShippingAddressJawn.Id], Bill_To_Contact__c=[SELECT Id FROM Contact WHERE Id= :newContactJawn.Id], Ship_To_Contact__c=[SELECT Id FROM Contact WHERE Id= :newContactJawn.Id], Bill_To_Account__c=[SELECT Id FROM Account WHERE Id= :newAccountJawn.Id], Ship_To_Account__c=[SELECT Id FROM Account WHERE Id= :newAccountJawn.Id]);

insert newQuoteJawn;

// inserting the above quote should have fired off the trigger to this point

// the following lines are verification steps to ensure the trigger worked correctly

SBQQ__Quote__c quoteValuesTest = [SELECT Id, Bill_To_Contact_Name__c, Ship_To_Contact_Name__c,

Bill_To_Account_Name__c, Ship_To_Account_Name__c, SBQQ__BillingStreet__c, Bill_To_Street_Line_2__c, SBQQ__BillingCity__c, SBQQ__BillingState__c, SBQQ__BillingPostalCode__c, SBQQ__BillingCountry__c, SBQQ__ShippingStreet__c, Ship_To_Street_Line_2__c, SBQQ__ShippingCity__c, SBQQ__ShippingState__c, SBQQ__ShippingPostalCode__c, SBQQ__ShippingCountry__c FROM SBQQ__Quote__c WHERE id= :newQuoteJawn.Id];

// test contact name

System.assert(quoteValuesTest.Bill_To_Contact_Name__c == newContactJawn.Name);

System.assert(quoteValuesTest.Ship_To_Contact_Name__c == newContactJawn.Name);

// test account name

System.assert(quoteValuesTest.Bill_To_Account_Name__c == newAccountJawn.Name);

System.assert(quoteValuesTest.Ship_To_Account_Name__c == newAccountJawn.Name);

// test billing address information

System.assert(quoteValuesTest.SBQQ__BillingStreet__c == newBillingAddressJawn.Address_Line_1__c);

System.assert(quoteValuesTest.Bill_To_Street_Line_2__c == newBillingAddressJawn.Address_Line_2__c);

System.assert(quoteValuesTest.SBQQ__BillingCity__c == newBillingAddressJawn.City__c);

System.assert(quoteValuesTest.SBQQ__BillingState__c == newBillingAddressJawn.State_Code__c);

System.assert(quoteValuesTest.SBQQ__BillingPostalCode__c == newBillingAddressJawn.Postal_Code__c && '-' && newBillingAddressJawn.Postal_Code_Extension__c);

System.assert(quoteValuesTest.SBQQ__BillingCountry__c == newBillingAddressJawn.Country_Code__c);

// test shipping address information

System.assert(quoteValuesTest.SBQQ__ShippingStreet__c == newShippingAddressJawn.Address_Line_1__c);

System.assert(quoteValuesTest.Ship_To_Street_Line_2__c == newShippingAddressJawn.Address_Line_2__c);

System.assert(quoteValuesTest.SBQQ__ShippingCity__c == newShippingAddressJawn.City__c);

System.assert(quoteValuesTest.SBQQ__ShippingState__c == newShippingAddressJawn.State_Code__c);

System.assert(quoteValuesTest.SBQQ__ShippingPostalCode__c == newShippingAddressJawn.Postal_Code__c && '-' && newShippingAddressJawn.Postal_Code_Extension__c);

System.assert(quoteValuesTest.SBQQ__ShippingCountry__c == newShippingAddressJawn.Country_Code__c);

}

}

 
1 resposta
  1. 29 de mai. de 2015, 11:29
    Hi Chris,

    Please try this.

    /* TEST CLASS FOR QuoteTriggerHandler TO ASSESS HANDLING OF UPDATES TO

    BILL TO AND SHIP TO ACCOUNTS, CONTACTS, AND ADDRESSES

    - John Scardino, 2015-05-28

    */

    @isTest // test classes need the @isTest classification

    private class QuoteTriggerHandlerTest {

    static testMethod void insertNewQuoteTest() {

    // select account to add a new opportunity towards

    Account newAccountJawn = new Account(Name='Jawn', Phone='(555) 555-5555', Customer_Class__c='Defense Industry', Entity_Type__c='Domestic');

    insert newAccountJawn;

    // create new opportunity on the account

    // -> reference new op id on the new quote

    Opportunity newOpportunityJawn = new Opportunity(/*RecordType='Transactional Opportunity',*/CloseDate=date.Today(), StageName='Quoted', Name='Test Op', Account=newAccountJawn);

    insert newOpportunityJawn;

    // create new contact on the account

    // -> reference new contact id on the new quote

    Contact newContactJawn = new Contact(LastName='Aaron', Account=newAccountJawn.Id);

    insert newContactJawn;

    // create new BILL TO address on the account

    // -> reference new bill to address id on the new quote

    Address__c newBillingAddressJawn = new Address__c(Account_Name__c=newAccountJawn.Id,

    Address_Line_1__c='Apple Inc.', Address_Line_2__c='1 Infinite Loop', City__c='Cupertino', State_Code__c='CA', Postal_Code__c='95014', Postal_Code_Extension__c='2083', Country_Code__c='US', Type__c='Billing');

    insert newBillingAddressJawn;

    // create new SHIP TO address on the account

    // -> reference new ship to address id on the new quote

    Address__c newShippingAddressJawn = new Address__c(Account_Name__c=newAccountJawn.Id,

    Address_Line_1__c='621 Lynnhaven Pkwy', Address_Line_2__c='Ste 400', City__c='Virginia Beach', State_Code__c='VA', Postal_Code__c='23452', Country_Code__c='US', Type__c='Shipping');

    insert newShippingAddressJawn;

    // create new quote

    // <- include new id values for lookup fields to opportunity, contact, bill to and ship to

    SBQQ__Quote__c newQuoteJawn = new SBQQ__Quote__c(SBQQ__Opportunity__c=newOpportunityJawn.Id,

    SBQQ__Type__c='Quote', SBQQ__Status__c='Draft', Contract__c=newContactJawn.Id,

    Bill_To_Address__c=newBillingAddressJawn.Id, Ship_To_Address__c=newShippingAddressJawn.Id, Bill_To_Contact__c=newContactJawn.Id, Ship_To_Contact__c=newContactJawn.Id, Bill_To_Account__c=newAccountJawn.Id, Ship_To_Account__c= newAccountJawn.Id);

    insert newQuoteJawn;

    // inserting the above quote should have fired off the trigger to this point

    // the following lines are verification steps to ensure the trigger worked correctly

    SBQQ__Quote__c quoteValuesTest = [SELECT Id, Bill_To_Contact_Name__c, Ship_To_Contact_Name__c,

    Bill_To_Account_Name__c, Ship_To_Account_Name__c, SBQQ__BillingStreet__c, Bill_To_Street_Line_2__c, SBQQ__BillingCity__c, SBQQ__BillingState__c, SBQQ__BillingPostalCode__c, SBQQ__BillingCountry__c, SBQQ__ShippingStreet__c, Ship_To_Street_Line_2__c, SBQQ__ShippingCity__c, SBQQ__ShippingState__c, SBQQ__ShippingPostalCode__c, SBQQ__ShippingCountry__c FROM SBQQ__Quote__c WHERE id= :newQuoteJawn.Id];

    // test contact name

    System.assert(quoteValuesTest.Bill_To_Contact_Name__c == newContactJawn.Name);

    System.assert(quoteValuesTest.Ship_To_Contact_Name__c == newContactJawn.Name);

    // test account name

    System.assert(quoteValuesTest.Bill_To_Account_Name__c == newAccountJawn.Name);

    System.assert(quoteValuesTest.Ship_To_Account_Name__c == newAccountJawn.Name);

    // test billing address information

    System.assert(quoteValuesTest.SBQQ__BillingStreet__c == newBillingAddressJawn.Address_Line_1__c);

    System.assert(quoteValuesTest.Bill_To_Street_Line_2__c == newBillingAddressJawn.Address_Line_2__c);

    System.assert(quoteValuesTest.SBQQ__BillingCity__c == newBillingAddressJawn.City__c);

    System.assert(quoteValuesTest.SBQQ__BillingState__c == newBillingAddressJawn.State_Code__c);

    System.assert(quoteValuesTest.SBQQ__BillingPostalCode__c == newBillingAddressJawn.Postal_Code__c && '-' && newBillingAddressJawn.Postal_Code_Extension__c);

    System.assert(quoteValuesTest.SBQQ__BillingCountry__c == newBillingAddressJawn.Country_Code__c);

    // test shipping address information

    System.assert(quoteValuesTest.SBQQ__ShippingStreet__c == newShippingAddressJawn.Address_Line_1__c);

    System.assert(quoteValuesTest.Ship_To_Street_Line_2__c == newShippingAddressJawn.Address_Line_2__c);

    System.assert(quoteValuesTest.SBQQ__ShippingCity__c == newShippingAddressJawn.City__c);

    System.assert(quoteValuesTest.SBQQ__ShippingState__c == newShippingAddressJawn.State_Code__c);

    System.assert(quoteValuesTest.SBQQ__ShippingPostalCode__c == newShippingAddressJawn.Postal_Code__c && '-' && newShippingAddressJawn.Postal_Code_Extension__c);

    System.assert(quoteValuesTest.SBQQ__ShippingCountry__c == newShippingAddressJawn.Country_Code__c);

    }

    }

    hope this resolve your query. Please mark it best answer if it really helps.

     
0/9000