コード例 #1
0
  @Test(expected = ConnectionException.class)
  public void testCreateBatchForQueryWithConnectionException() throws Exception {
    SalesforceConnector connector = new SalesforceConnector();
    BulkConnection bulkConnection = Mockito.mock(BulkConnection.class);
    ArgumentCaptor<JobInfo> expectedJobInfo = ArgumentCaptor.forClass(JobInfo.class);
    AsyncApiException exception = Mockito.mock(AsyncApiException.class);
    connector.setBulkConnection(bulkConnection);

    JobInfo actualJobInfo = new JobInfo();
    String query = "SELECT Id FROM Contact";

    Mockito.when(exception.getExceptionCode()).thenReturn(AsyncExceptionCode.InvalidSessionId);
    Mockito.when(
            bulkConnection.createBatchFromStream(
                expectedJobInfo.capture(), Mockito.isA(InputStream.class)))
        .thenThrow(exception);
    connector.createBatchForQuery(actualJobInfo, query);
    assertEquals(expectedJobInfo.getValue(), actualJobInfo);
  }
コード例 #2
0
  @Test
  public void testCreateBatchStream() throws Exception {
    SalesforceConnector connector = new SalesforceConnector();
    BulkConnection bulkConnection = Mockito.mock(BulkConnection.class);
    ArgumentCaptor<JobInfo> expectedJobInfo = ArgumentCaptor.forClass(JobInfo.class);
    connector.setBulkConnection(bulkConnection);

    JobInfo actualJobInfo = new JobInfo();
    InputStream stream = Mockito.mock(InputStream.class);

    BatchInfo expectedBatchInfo = new BatchInfo();
    Mockito.when(
            bulkConnection.createBatchFromStream(
                expectedJobInfo.capture(), Mockito.isA(InputStream.class)))
        .thenReturn(expectedBatchInfo);
    BatchInfo actualBatchInfo = connector.createBatchStream(actualJobInfo, stream);

    assertEquals(expectedBatchInfo, actualBatchInfo);
    assertEquals(expectedJobInfo.getValue(), actualJobInfo);
  }