@Test(expected = ConnectionException.class) public void testCreateBatchWithConnectionException() throws Exception { SalesforceConnector connector = new SalesforceConnector(); BulkConnection bulkConnection = Mockito.mock(BulkConnection.class); AsyncApiException exception = Mockito.mock(AsyncApiException.class); connector.setBulkConnection(bulkConnection); JobInfo jobInfo = new JobInfo(); List<Map<String, Object>> objects = new ArrayList<Map<String, Object>>(); Mockito.when(exception.getExceptionCode()).thenReturn(AsyncExceptionCode.InvalidSessionId); Mockito.when(bulkConnection.createBatch(jobInfo)).thenThrow(exception); connector.createBatch(jobInfo, objects); }
@Test public void testCreateBatch() throws Exception { SalesforceConnector connector = new SalesforceConnector(); BulkConnection bulkConnection = Mockito.mock(BulkConnection.class); BatchRequest batchRequest = Mockito.mock(BatchRequest.class); connector.setBulkConnection(bulkConnection); JobInfo jobInfo = new JobInfo(); List<Map<String, Object>> objects = new ArrayList<Map<String, Object>>(); BatchInfo expectedBatchInfo = new BatchInfo(); Mockito.when(bulkConnection.createBatch(jobInfo)).thenReturn(batchRequest); Mockito.when(batchRequest.completeRequest()).thenReturn(expectedBatchInfo); BatchInfo actualBatchInfo = connector.createBatch(jobInfo, objects); assertEquals(expectedBatchInfo, actualBatchInfo); Mockito.verify(batchRequest).addSObjects(connector.toAsyncSObjectList(objects)); }