API Test Coverage
As with any Salesforce Apex class functionality, you will need to create test classes to validate your code for deployment. Stantive provides a helper method in order to create mock responses for OrchestraCMS API calls. A developer can then build up their mock responses accordingly, which will be used during Apex test executions. Parameters can then be configured as needed to achieve the necessary coverage in your Apex classes.
Simple Mock Response
The following example creates a ContentBundle to be returned as a mock response.
JSONMessage.APIResponse apiResponse = new JSONMessage.APIResponse();
apiResponse.isSuccess = true;
ContentBundle testContentBundle = new ContentBundle();
testContentBundle.originId = 'a00000000000000';
apiResponse.responseObject = JSON.serialize(testContentBundle);
cms.ServiceEndpoint.addMockResponse('ContentAPI', JSON.serialize(apiResponse));
Advanced Mock Response
There may be times where you will need multiple mock responses to support your test classes to pass. The following example would test creating a taxonomy piece of content, creating root nodes in that taxonomy, and finally creating child nodes for those root nodes. It is important that mock responses are added in the order they will be used.
// Create Taxonomy
JSONMessage.APIResponse apiResponse = new JSONMessage.APIResponse();
apiResponse.isSuccess = true;
ContentBundle testContentBundle = new ContentBundle();
testContentBundle.originId = 'a00000000000000';
apiResponse.responseObject = JSON.serialize(testContentBundle);
cms.ServiceEndpoint.addMockResponse('ContentAPI', JSON.serialize(apiResponse));
// Create Taxonomy Root Nodes
apiResponse = new JSONMessage.APIResponse();
apiResponse.isSuccess = true;
TaxonomyBundle testTaxonomyBundle = new TaxonomyBundle();
testTaxonomyBundle.taxonomyID = 'a00000000000000';
testTaxonomyBundle.tagDefinitionID = 'a01000000000000';
testTaxonomyBundle.languageMapOfTagNames = new Map<String, String>{'en_US' => 'Account'};
List<TaxonomyBundle> testTaxonomyBundles = new List<TaxonomyBundle>{testTaxonomyBundle};
apiResponse.responseObject = JSON.serialize(testTaxonomyBundles);
cms.ServiceEndpoint.addMockResponse('TaxonomyAPI', JSON.serialize(apiResponse));
// Create Taxonomy Child Nodes
apiResponse = new JSONMessage.APIResponse();
apiResponse.isSuccess = true;
testTaxonomyBundle = new TaxonomyBundle();
testTaxonomyBundle.taxonomyID = 'a00000000000000';
testTaxonomyBundle.tagID = 'a01000000000000';
testTaxonomyBundle.tagDefinitionID = 'a02000000000000';
testTaxonomyBundle.languageMapOfTagNames = new Map<String, String>{'en_US' => 'Account'};
TaxonomyBundle testTaxonomyBundleChild = new TaxonomyBundle();
testTaxonomyBundleChild.taxonomyID = 'a00000000000000';
testTaxonomyBundleChild.tagID = 'a01000000000001';
testTaxonomyBundleChild.tagDefinitionID = 'a02000000000001';
testTaxonomyBundleChild.languageMapOfTagNames = new Map<String, String>{'en_US' => 'Type'};
testTaxonomyBundle.children = new List<TaxonomyBundle>{testTaxonomyBundleChild};
apiResponse.responseObject = JSON.serialize(testTaxonomyBundle);
cms.ServiceEndpoint.addMockResponse('TaxonomyAPI', JSON.serialize(apiResponse));