private SaveResult[] constructSaveResultArray() { SaveResult saveResult = new SaveResult(); saveResult.setId(DUMMY_SOBJECT_ID); saveResult.setSuccess(true); return new SaveResult[] {saveResult}; }
private void writeOutputToWriter(Object[] results, List<Map<String, Object>> dataArray) throws DataAccessObjectException, LoadException { if (results.length != dataArray.size()) { getLogger().fatal(Messages.getString("Visitor.errorResultsLength")); // $NON-NLS-1$ throw new LoadException(Messages.getString("Visitor.errorResultsLength")); } // have to do this because although saveResult and deleteResult // are a) not the same class yet b) not subclassed for (int i = 0; i < results.length; i++) { Map<String, Object> dataRow = dataArray.get(i); String statusMsg = null; if (results instanceof SaveResult[]) { SaveResult saveRes = (SaveResult) results[i]; if (saveRes.getSuccess()) { if (OperationInfo.insert == getConfig().getOperationInfo()) { statusMsg = Messages.getString("DAOLoadVisitor.statusItemCreated"); } else { statusMsg = Messages.getString("DAOLoadVisitor.statusItemUpdated"); } } dataRow.put(Config.STATUS_COLUMN_NAME, statusMsg); processResult(dataRow, saveRes.getSuccess(), saveRes.getId(), saveRes.getErrors()); } else if (results instanceof DeleteResult[]) { DeleteResult deleteRes = (DeleteResult) results[i]; if (deleteRes.getSuccess()) { statusMsg = Messages.getString("DAOLoadVisitor.statusItemDeleted"); } dataRow.put(Config.STATUS_COLUMN_NAME, statusMsg); processResult(dataRow, deleteRes.getSuccess(), deleteRes.getId(), deleteRes.getErrors()); } else if (results instanceof UpsertResult[]) { UpsertResult upsertRes = (UpsertResult) results[i]; if (upsertRes.getSuccess()) { statusMsg = upsertRes.getCreated() ? Messages.getString("DAOLoadVisitor.statusItemCreated") : Messages.getString("DAOLoadVisitor.statusItemUpdated"); } dataRow.put(Config.STATUS_COLUMN_NAME, statusMsg); processResult(dataRow, upsertRes.getSuccess(), upsertRes.getId(), upsertRes.getErrors()); } } }
@Test public void testPublishTopic() throws Exception { SalesforceConnector connector = new SalesforceConnector(); PartnerConnection partnerConnection = Mockito.mock(PartnerConnection.class); connector.setConnection(partnerConnection); BulkConnection bulkConnection = Mockito.mock(BulkConnection.class); connector.setBulkConnection(bulkConnection); SaveResult saveResult = Mockito.mock(SaveResult.class); when(saveResult.isSuccess()).thenReturn(true); when(partnerConnection.create(Mockito.argThat(new SObjectArrayMatcher()))) .thenReturn(new SaveResult[] {saveResult}); QueryResult queryResult = Mockito.mock(QueryResult.class); when(partnerConnection.query(eq("SELECT Id FROM PushTopic WHERE Name = 'TopicName'"))) .thenReturn(queryResult); when(queryResult.getSize()).thenReturn(0); connector.publishTopic("TopicName", "SELECT * FROM Account", "Description"); verify(partnerConnection, atLeastOnce()).create(Mockito.argThat(new SObjectArrayMatcher())); }