@Test public void testGetUpdatedObjects() throws Exception { SalesforceConnector connector = Mockito.spy(new SalesforceConnector()); connector.setConnection(connection); when(connection.getConfig()).thenReturn(createConnectorConfig("userX")); connector.setObjectStoreHelper(objectStoreHelper); Calendar lastUpdateTime = createCalendar(4, 15); when(objectStoreHelper.getTimestamp("Account")).thenReturn(lastUpdateTime); setServerTime(connection, 5, 15); when(connection.getUpdated(anyString(), any(Calendar.class), any(Calendar.class))) .thenReturn(getUpdatedResult); Calendar latestDateCovered = createCalendar(5, 10); when(getUpdatedResult.getLatestDateCovered()).thenReturn(latestDateCovered); when(getUpdatedResult.getIds()).thenReturn(new String[] {"1", "3"}); List<Map<String, Object>> updatedObjects = new ArrayList<Map<String, Object>>(); doReturn(updatedObjects) .when(connector) .retrieve("Account", Arrays.asList("1", "3"), Arrays.asList("Id", "Name")); assertSame( updatedObjects, connector.getUpdatedObjects("Account", 60, Arrays.asList("Id", "Name"))); verify(connection) .getUpdated(eq("Account"), startTimeCaptor.capture(), endTimeCaptor.capture()); assertStartTime(4, 15); assertEndTime(5, 15); verify(objectStoreHelper).updateTimestamp(getUpdatedResult, "Account"); }
private SalesforceBayeuxClient mockBayeuxClient() throws MalformedURLException { PartnerConnection connection = Mockito.mock(PartnerConnection.class); LoginResult loginResult = Mockito.mock(LoginResult.class); ConnectorConfig connectorConfig = Mockito.mock(ConnectorConfig.class); SalesforceConnector connector = Mockito.mock(SalesforceConnector.class); when(connector.getConnection()).thenReturn(connection); when(connector.getLoginResult()).thenReturn(loginResult); when(connector.getSessionId()).thenReturn("001"); when(connection.getConfig()).thenReturn(connectorConfig); when(connectorConfig.getServiceEndpoint()).thenReturn("http://xxx.salesforce.com"); when(connectorConfig.getUsername()).thenReturn("mulesoft"); return new SalesforceBayeuxClient(connector); }