TEST CLASS:
@istest
public class TestEtoCKroger {
static testMethod void TestEtoCKroger () {
// create a new email and envelope object
Messaging.InboundEmail email = new Messaging.InboundEmail() ;
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
Map<ID,Schema.RecordTypeInfo> rt_Map = Case.sObjectType.getDescribe().getRecordTypeInfosById();
Id RecordTypeIdCase = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Service - Managed Service Case').getRecordTypeId();
Id rtId = RecordTypeIdCase;
Account acc = new Account();
acc.Name = 'Test Account';
acc.BillingStreet = '123 St.';
acc.BillingCity = 'Springfield';
acc.BillingState = 'IL';
acc.BillingPostalCode = '62704';
insert acc;
SVMXC__Site__c loc = new SVMXC__Site__c();
loc.Name = 'Sample Test';
loc.NTT_Metro_Remote__c = 'Zone A';
loc.SVMXC__Street__c = '123 E Main St.';
loc.SVMXC__City__c = 'Springfield';
loc.SVMXC__State__c = 'ILLINOIS';
loc.SVMXC__Zip__c = '62511';
loc.SVMXC__Country__c = 'United States';
loc.NTT_Legacy_Location_ID__c = 'Sample Test';
loc.SVMXC__Account__c = acc.Id;
loc.BSP_Location_Contact_Phone__c = '111 222 1343';
insert loc;
Case cse = new CASE(
Subject = 'Test Subject',
Description = 'Test description',
Origin = 'Email',
SVMXC__Site__c = loc.Id,
Status = 'New',
recordtypeid = rtId,
accountid= acc.Id,
KA_PO__c = '1001',
BSP_Location_Contact_Phone__c = '111 222 3443',
Case_Type__c = 'Service Request',
Location_Contact_Name__c = 'Test Man'
);
insert cse;
// setup the data for the email
email.subject = 'Kroger Service Call Notification 10935174/1 (HIGH) Sample Test';
env.fromAddress = '[email protected]';
email.plainTextBody = 'email body for testing';
EtoCKroger TestEtoCKroger=new EtoCKroger ();
TestEtoCKroger.handleInboundEmail(email, env);
Messaging.InboundEmailResult result = TestEtoCKroger.handleInboundEmail(email, env);
System.assertEquals( result.success , true);
Case[] c = [select id, SVMXC__site__r.id, SVMXC__Site__c, recordtypeid, KA_PO__c, Location_Contact_Name__c, description, BSP_Location_Contact_Phone__c, subject, Case_Type__c, Origin, Status, Account.Name, account.id from Case where SVMXC__Site__c = :loc.Id limit 1];
system.debug('TestEtoCKroger: [' + TestEtoCKroger + ']' );
if(c.size() > 0)
System.assertEquals(c[0].SVMXC__Site__c, loc.Id);
System.assertEquals(c[0].account.Id, acc.Id);
System.assertEquals(c[0].recordtypeId, 'rtId');
System.assertEquals(c[0].KA_PO__c, '1001');
System.assertEquals(c[0].Location_Contact_Name__c, 'Test Man');
System.assertEquals(c[0].BSP_Location_Contact_Phone__c, '111 222 3443');
System.assertEquals(c[0].subject, 'Test Subject');
System.assertEquals(c[0].Case_Type__c, 'Service Request');
System.assertEquals(c[0].Origin, 'Email');
System.assertEquals(c[0].Status, 'New');
System.assertEquals(c[0].description, 'Test description');
update c;
}
}