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); }
@Test public void testDestroySessionWithNullBayeuxClient() throws Exception { SalesforceConnector connector = new SalesforceConnector(); PartnerConnection partnerConnection = Mockito.mock(PartnerConnection.class); connector.setConnection(partnerConnection); LoginResult loginResult = Mockito.mock(LoginResult.class); connector.setLoginResult(loginResult); connector.destroySession(); verify(partnerConnection, atLeastOnce()).logout(); assertNull(connector.getConnection()); assertNull(connector.getLoginResult()); }
@Test public void testDestroySessionWithBayeuxClient() throws Exception { SalesforceConnector connector = new SalesforceConnector(); SalesforceBayeuxClient salesforceBayeuxClient = Mockito.mock(SalesforceBayeuxClient.class); PartnerConnection partnerConnection = Mockito.mock(PartnerConnection.class); connector.setBayeuxClient(salesforceBayeuxClient); connector.setConnection(partnerConnection); LoginResult loginResult = Mockito.mock(LoginResult.class); connector.setLoginResult(loginResult); when(salesforceBayeuxClient.isConnected()).thenReturn(true); connector.destroySession(); verify(salesforceBayeuxClient, atLeastOnce()).disconnect(); assertNull(connector.getConnection()); assertNull(connector.getLoginResult()); }