@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); }
public QueryResultList getQueryResultList(String jobId, String batchId) throws AsyncApiException { InputStream stream = getBatchResultStream(jobId, batchId); try { XmlInputStream xin = new XmlInputStream(); xin.setInput(stream, "UTF-8"); QueryResultList result = new QueryResultList(); result.load(xin, typeMapper); return result; } catch (ConnectionException e) { throw new AsyncApiException( "Failed to parse query result list ", AsyncExceptionCode.ClientInputError, e); } catch (PullParserException e) { throw new AsyncApiException( "Failed to parse query result list ", AsyncExceptionCode.ClientInputError, e); } catch (IOException e) { throw new AsyncApiException( "Failed to parse query result list ", AsyncExceptionCode.ClientInputError, e); } }
@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]); }