Search in sources :

Example 1 with GetServerTimestampResult

use of com.sforce.soap.partner.GetServerTimestampResult in project pentaho-kettle by pentaho.

the class SalesforceConnectionIT method setUp.

@Before
public void setUp() throws RemoteException, ConnectionException {
    GetServerTimestampResult serverTime = new GetServerTimestampResult();
    serverTime.setTimestamp(Calendar.getInstance());
    LoginResult result = mock(LoginResult.class);
    bindingStub = mock(PartnerConnection.class);
    when(bindingStub.login(anyString(), anyString())).thenReturn(result);
    when(bindingStub.getServerTimestamp()).thenReturn(serverTime);
}
Also used : PartnerConnection(com.sforce.soap.partner.PartnerConnection) LoginResult(com.sforce.soap.partner.LoginResult) GetServerTimestampResult(com.sforce.soap.partner.GetServerTimestampResult) Before(org.junit.Before)

Example 2 with GetServerTimestampResult

use of com.sforce.soap.partner.GetServerTimestampResult in project pentaho-kettle by pentaho.

the class SalesforceConnectionIT method testConnectOptions.

@Test
public void testConnectOptions() {
    LogChannelInterface logInterface = mock(LogChannelInterface.class);
    String url = SalesforceConnectionUtils.TARGET_DEFAULT_URL;
    String username = "username";
    String password = "password";
    Integer timeout = 30;
    try {
        SalesforceConnection connection = spy(new SalesforceConnection(logInterface, url, username, password));
        connection.setTimeOut(timeout);
        LoginResult loginResult = mock(LoginResult.class);
        GetUserInfoResult userInfo = mock(GetUserInfoResult.class);
        GetServerTimestampResult serverTime = new GetServerTimestampResult();
        serverTime.setTimestamp(Calendar.getInstance());
        ArgumentCaptor<ConnectorConfig> captorConfig = ArgumentCaptor.forClass(ConnectorConfig.class);
        doReturn(loginResult).when(bindingStub).login(anyString(), anyString());
        doReturn(userInfo).when(bindingStub).getUserInfo();
        when(loginResult.getServerUrl()).thenReturn("http://localhost/services/Soap/u/37.0");
        when(loginResult.getSessionId()).thenReturn(UUID.randomUUID().toString());
        when(userInfo.getUserFullName()).thenReturn(UUID.randomUUID().toString());
        when(userInfo.getUserEmail()).thenReturn(UUID.randomUUID().toString());
        when(userInfo.getUserLanguage()).thenReturn(UUID.randomUUID().toString());
        when(userInfo.getOrganizationName()).thenReturn(UUID.randomUUID().toString());
        doReturn(serverTime).when(bindingStub).getServerTimestamp();
        connection.setTimeOut(timeout);
        connection.setUsingCompression(true);
        connection.setRollbackAllChangesOnError(true);
        try {
            connection.connect();
        } catch (KettleException e) {
        // The connection should fail
        // We just want to see the generated ConnectorConfig
        }
        verify(connection).createBinding(captorConfig.capture());
        ConnectorConfig config = captorConfig.getValue();
        assertNotNull(config);
        assertEquals(url, config.getAuthEndpoint());
        assertTrue(config.isCompression());
        assertTrue(config.isManualLogin());
        assertEquals(timeout, Integer.valueOf(config.getConnectionTimeout()));
        assertEquals(timeout, Integer.valueOf(config.getReadTimeout()));
    } catch (Exception e) {
        fail("Connection fail: " + e.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) GetUserInfoResult(com.sforce.soap.partner.GetUserInfoResult) ConnectorConfig(com.sforce.ws.ConnectorConfig) LoginResult(com.sforce.soap.partner.LoginResult) Matchers.anyString(org.mockito.Matchers.anyString) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) KettleException(org.pentaho.di.core.exception.KettleException) ConnectionException(com.sforce.ws.ConnectionException) RemoteException(java.rmi.RemoteException) GetServerTimestampResult(com.sforce.soap.partner.GetServerTimestampResult) Test(org.junit.Test)

Aggregations

GetServerTimestampResult (com.sforce.soap.partner.GetServerTimestampResult)2 LoginResult (com.sforce.soap.partner.LoginResult)2 GetUserInfoResult (com.sforce.soap.partner.GetUserInfoResult)1 PartnerConnection (com.sforce.soap.partner.PartnerConnection)1 ConnectionException (com.sforce.ws.ConnectionException)1 ConnectorConfig (com.sforce.ws.ConnectorConfig)1 RemoteException (java.rmi.RemoteException)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 KettleException (org.pentaho.di.core.exception.KettleException)1 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)1