| 1 |
// https://github.com/financialforcedev/apex-mdapi.git |
| 2 |
// apex-mdapi/apex-mdapi/src/classes/RemoteSiteHelperTest.cls |
| 3 |
@IsTest |
| 4 |
private class RemoteSiteHelperTest |
| 5 |
{ |
| 6 |
@IsTest |
| 7 |
private static void testCheckMetadataAPIConnection() |
| 8 |
{ |
| 9 |
// Metadata API web Service mock implementation for tests |
| 10 |
Test.setMock(WebServiceMock.class, new WebServiceMockImpl()); |
| 11 |
|
| 12 |
RemoteSiteHelperController controller = new RemoteSiteHelperController(); |
| 13 |
System.assertEquals(true, controller.MetadataConnectionWarning); |
| 14 |
controller.MetadataResponse = ''; |
| 15 |
controller.displayMetadataResponse(); |
| 16 |
System.assertEquals(false, controller.MetadataConnectionWarning); |
| 17 |
controller.MetadataResponse = 'Some Error Creating Remote Site Setting'; |
| 18 |
controller.displayMetadataResponse(); |
| 19 |
System.assertEquals(true, controller.MetadataConnectionWarning); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Metadata API web service mock class for tests above |
| 24 |
**/ |
| 25 |
private class WebServiceMockImpl implements WebServiceMock |
| 26 |
{ |
| 27 |
public void doInvoke( |
| 28 |
Object stub, Object request, Map<String, Object> response, |
| 29 |
String endpoint, String soapAction, String requestName, |
| 30 |
String responseNS, String responseName, String responseType) |
| 31 |
{ |
| 32 |
throw new TestException(); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
public class TestException extends Exception { } |
| 37 |
} |