The code used in this section uses Apex test methods (not included in the FormulaForce package) as an easy way to run the API code example in this chapter. We will be using an Apex test to illustrate the use of the Apex APIs included in the sample code in this chapter. The two test methods we will look at call the Compliance API after calling the season API to create some test data (which, of course, only exists on the database within the scope of the test execution).
In the following examples, the Driver records created by the SeasonService.createTestSeason API do not indicate that the drivers hold an FIA Super License. Thus, the expectation is that the ComplianceService.verify method will throw an exception reporting this problem. The following example test code asserts this behavior purely for illustration purposes in this chapter:
@IsTest private class ApplicationAPITest { @IsTest private static void demoComplianceVerifyAPI() {
// Create some test data via the SeasonService fforce.SeasonService.createTestSeason(); // Query Drivers to test compliance against Map<Id, fforce__Driver__c> driversById = new Map<Id, fforce__Driver__c>(
[select Id from fforce__Driver__c]); try { // Invoke the compliance engine for the drivers fforce.ComplianceService.verify(
driversById.keySet()); System.assert(false, 'Expected failures'); } catch (fforce.ComplianceService.ComplianceException e) { // Check the results System.assertEquals(
'4.1', e.failures[0].complianceCode);
System.assertEquals(
'Driver must have a FIA Super License.',
e.failures[0].failureReason); } } }
Run the test to confirm whether the API is working as expected.
Notice that when you click on the Show Dependencies button in the ApplicationAPITest class, it shows the API and Custom Objects being referenced from the package:
Now that you understand how the platform exposes your APIs to your customers' developers, the next section goes into more detail about the implications and restrictions in modifying it.