コード例 #1
0
  @Test
  public void testQueryResultStreamNoResults() throws Exception {
    SalesforceConnector connector = new SalesforceConnector();
    BatchInfo batchInfo = setupBulkConnection(connector);
    QueryResultList queryResultList = Mockito.mock(QueryResultList.class);
    BulkConnection bulkConnection = connector.getBulkConnection();
    String[] queryResults = new String[0];

    when(bulkConnection.getQueryResultList(batchInfo.getJobId(), batchInfo.getId()))
        .thenReturn(queryResultList);
    when(queryResultList.getResult()).thenReturn(queryResults);
    InputStream actualIs = connector.queryResultStream(batchInfo);
    assertEquals(null, actualIs);
  }
コード例 #2
0
  @Test
  public void testQueryResultStream() throws Exception {
    SalesforceConnector connector = new SalesforceConnector();
    BatchInfo batchInfo = setupBulkConnection(connector);
    QueryResultList queryResultList = Mockito.mock(QueryResultList.class);
    BulkConnection bulkConnection = connector.getBulkConnection();
    String[] queryResults = {"ID1", "ID2"};
    byte[] a = {'a'};
    byte[] b = {'b'};
    InputStream[] sourceIs = {new ByteArrayInputStream(a), new ByteArrayInputStream(b)};

    when(bulkConnection.getQueryResultList(batchInfo.getJobId(), batchInfo.getId()))
        .thenReturn(queryResultList);
    when(queryResultList.getResult()).thenReturn(queryResults);
    when(bulkConnection.getQueryResultStream(batchInfo.getJobId(), batchInfo.getId(), "ID1"))
        .thenReturn(sourceIs[0]);
    when(bulkConnection.getQueryResultStream(batchInfo.getJobId(), batchInfo.getId(), "ID2"))
        .thenReturn(sourceIs[1]);
    InputStream actualIs = connector.queryResultStream(batchInfo);
    assertTrue(actualIs instanceof SequenceInputStream);
    assertEquals(actualIs.read(), a[0]);
    assertEquals(actualIs.read(), b[0]);
  }