org.mule.transport.sftp
Class AbstractSftpTestCase

java.lang.Object
  extended by org.mule.tck.junit4.AbstractMuleTestCase
      extended by org.mule.tck.junit4.AbstractMuleContextTestCase
          extended by org.mule.tck.junit4.FunctionalTestCase
              extended by org.mule.tck.AbstractServiceAndFlowTestCase
                  extended by org.mule.transport.sftp.AbstractSftpTestCase
Direct Known Subclasses:
AbstractSftpDataIntegrityTestCase, SftpArchiveFunctionalTestCase, SftpDuplicateHandlingFunctionalTestCase, SftpEndpointTestCase, SftpExpressionFilenameParserTestCase, SftpFileAgeFunctionalTestCase, SftpIdentityFileFunctionalTestCase, SftpNotificationFunctionalTestCase, SftpPoolingFunctionalTestCase, SftpQuartzRequesterFunctionalTestCase, SftpSendReceiveFunctionalTestCase, SftpSendReceiveLargeFileFunctionalTestCase, SftpSizeCheckFunctionalTestCase, SftpTempDirFunctionalTestCase

public abstract class AbstractSftpTestCase
extends AbstractServiceAndFlowTestCase

Author:
Lennart Häggkvist, Magnus Larsson Date: Jun 8, 2009

Nested Class Summary
 class AbstractSftpTestCase.DispatchParameters
          Helper class for dynamic assignment of parameters to the method dispatchAndWaitForDelivery() Only inboundEndpoint and outboundEndpoint are mandatory, the rest of the parameters are optional.
 
Nested classes/interfaces inherited from class org.mule.tck.AbstractServiceAndFlowTestCase
AbstractServiceAndFlowTestCase.ConfigVariant
 
Field Summary
protected static String FILENAME
           
protected static String INBOUND_ENDPOINT_DIR
           
protected static Map<String,String> MESSAGE_PROPERTIES
           
protected static String OUTBOUND_ENDPOINT_DIR
           
 DynamicPort port
           
protected  SftpClient sftpClient
           
protected  SftpServer sftpServer
           
 
Fields inherited from class org.mule.tck.AbstractServiceAndFlowTestCase
configResources, variant
 
Fields inherited from class org.mule.tck.junit4.AbstractMuleContextTestCase
callbackCalled, CLASSNAME_ANNOTATIONS_CONFIG_BUILDER, IGNORED_DOT_MULE_DIRS, LOCK_TIMEOUT, muleContext, RECEIVE_TIMEOUT, TEST_MESSAGE
 
Fields inherited from class org.mule.tck.junit4.AbstractMuleTestCase
DEFAULT_TEST_TIMEOUT_SECS, globalTimeout, logger, name, TEST_TIMEOUT_SYSTEM_PROPERTY
 
Constructor Summary
AbstractSftpTestCase(AbstractServiceAndFlowTestCase.ConfigVariant variant, String configResources)
           
 
Method Summary
protected  void assertFilesInEndpoint(MuleClient muleClient, String endpointName, String expectedFile)
          Asserts that only the expectedFile is found on the path that the endpointName use, where filenames can be expressed as a regular expression.
protected  void assertFilesInEndpoint(MuleClient muleClient, String endpointName, String[] expectedFiles)
          Asserts that only the expectedFiles are found on the path that the endpointName use, where filenames can be expressed as a regular expression.
protected  void assertFilesInEndpoint(MuleClient muleClient, String endpointName, String subDirectory, String expectedFile)
          Asserts that only the expectedFile is found on the sub directory subDirectory under the path that endpointName use, where filenames can be expressed as a regular expression.
protected  void assertFilesInEndpoint(MuleClient muleClient, String endpointName, String subDirectory, String[] expectedFiles)
          Asserts that only the expectedFiles are found on the sub directory subDirectory under the path that endpointName use, where filenames can be expressed as a regular expression.
protected  void assertFilesInLocalFilesystem(String path, String expectedFile)
          Asserts that only the expectedFile is found on the path path, where filenames can be expressed as a regular expression.
protected  void assertFilesInLocalFilesystem(String path, String[] expectedFiles)
          Asserts that only the expectedFiles are found on the path path, where filenames can be expressed as a regular expression.
protected  void assertNoFilesInEndpoint(MuleClient muleClient, String endpointName)
          Asserts that no files are found on the path that the endpointName use.
protected  void assertNoFilesInEndpoint(MuleClient muleClient, String endpointName, String subDirectory)
          Asserts that no files are found on the sub directory subDirectory under the path that endpointName use.
protected  void assertNoFilesInLocalFilesystem(String path)
          Asserts that there are no files found on the path path.
 void before()
           
 void checkConnectors()
          Check that all of the connectors are running.
protected  void createRemoteDirectory(MuleClient muleClient, String endpointName, String directoryName)
          Creates the directoryName under the endpoint path
protected  void dispatchAndWaitForDelivery(AbstractSftpTestCase.DispatchParameters p)
          Helper method for initiating a test and wait for the test to complete.
protected  Exception dispatchAndWaitForException(AbstractSftpTestCase.DispatchParameters p, String expectedFailingConnector)
           
protected  Exception dispatchAndWaitForException(AbstractSftpTestCase.DispatchParameters p, String expectedFailingConnector, String serviceName)
          Helper method for initiating a test and wait for an exception to be caught by the sftp-connector.
protected  void executeBaseAssertionsAfterCall(int sendSize, int receivedSize)
          To be overridden by the test-classes if required
protected  void executeBaseAssertionsBeforeCall()
          To be overridden by the test-classes if required
protected  void executeBaseTest(String inputEndpointName, String sendUrl, String filename, int size, String receivingTestComponentName, long timeout)
          Base method for executing tests...
protected  void executeBaseTest(String inputEndpointName, String sendUrl, String filename, int size, String receivingTestComponentName, long timeout, String expectedFailingConnector)
           
protected  void executeBaseTest(String inputEndpointName, String sendUrl, String filename, int size, String receivingTestComponentName, long timeout, String expectedFailingConnector, String serviceName)
          Base method for executing tests...
protected  String getAddressByEndpoint(MuleClient muleClient, String endpointName)
           
protected  ImmutableEndpoint getImmutableEndpoint(MuleClient muleClient, String endpointName)
           
protected  String getPathByEndpoint(MuleClient muleClient, SftpClient sftpClient, String endpointName)
           
protected  SftpClient getSftpClient(MuleClient muleClient, String endpointName)
          Returns a SftpClient that is logged in to the sftp server that the endpoint is configured against.
protected  SftpClient getSftpClient(String host, int port, String user, String password)
          Returns a SftpClient that is logged in to the sftp server that the endpoint is configured against.
protected  EndpointURI getUriByEndpointName(MuleClient muleClient, String endpointName)
           
protected  void initEndpointDirectories(String[] serviceNames, String[] endpointNames)
          Initiates a list of sftp-endpoint-directories.
protected  void initEndpointDirectory(String endpointName)
          Ensures that the directory exists and is writable by deleting the directory and then recreate it.
protected  void recursiveDelete(MuleClient muleClient, SftpClient sftpClient, String endpointName, String relativePath)
          Deletes a directory with all its files and sub-directories.
protected  void recursiveDeleteInLocalFilesystem(File parent)
           
protected  void remoteChmod(MuleClient muleClient, SftpClient sftpClient, String endpointName, int permissions)
           
protected  boolean verifyFileExists(SftpClient sftpClient, EndpointURI endpointURI, String file)
          Checks if the file exists on the server
protected  boolean verifyFileExists(SftpClient sftpClient, String path, String file)
           
 
Methods inherited from class org.mule.tck.AbstractServiceAndFlowTestCase
doSetUp, doSetUpForFlow, doSetUpForService, getConfigResources, getTestHeader
 
Methods inherited from class org.mule.tck.junit4.FunctionalTestCase
clearFlowAssertions, getBuilder, getComponent, getComponent, getFlowConstruct, getFunctionalTestComponent, loadResource, loadResourceAsString, stopFlowConstruct, testFlow, testFlow
 
Methods inherited from class org.mule.tck.junit4.AbstractMuleContextTestCase
addBuilders, configureMuleContext, createMuleContext, createObject, createObject, disposeContext, disposeContextPerTest, doTearDown, getConfigurationResources, getSensingNullMessageProcessor, getStartUpProperties, getTestConnector, getTestEvent, getTestEvent, getTestEvent, getTestEvent, getTestEvent, getTestEvent, getTestEvent, getTestEventContext, getTestEventContext, getTestEventUsingFlow, getTestInboundEndpoint, getTestInboundEndpoint, getTestInboundEndpoint, getTestInboundEndpoint, getTestInboundEndpoint, getTestOutboundEndpoint, getTestOutboundEndpoint, getTestOutboundEndpoint, getTestOutboundEndpoint, getTestOutboundEndpoint, getTestService, getTestService, getTestService, getTestSession, getTestTransactedInboundEndpoint, getTestTransformer, getTriggerableMessageSource, getTriggerableMessageSource, initialiseObject, isDisposeContextPerClass, isGracefulShutdown, isStartContext, setDisposeContextPerClass, setStartContext, setUpMuleContext
 
Methods inherited from class org.mule.tck.junit4.AbstractMuleTestCase
clearExcludedFlag, clearRequestContext, createTestTimeoutRule, getTestTimeoutSecs, getTimeoutSystemProperty, initializeMuleTest, isDisabledInThisEnvironment, isDisabledInThisEnvironment, isExcluded, isFailOnTimeout, isOffline, isTestIncludedInExclusionFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_PROPERTIES

protected static final Map<String,String> MESSAGE_PROPERTIES

INBOUND_ENDPOINT_DIR

protected static String INBOUND_ENDPOINT_DIR

OUTBOUND_ENDPOINT_DIR

protected static String OUTBOUND_ENDPOINT_DIR

FILENAME

protected static final String FILENAME
See Also:
Constant Field Values

port

public DynamicPort port

sftpServer

protected SftpServer sftpServer

sftpClient

protected SftpClient sftpClient
Constructor Detail

AbstractSftpTestCase

public AbstractSftpTestCase(AbstractServiceAndFlowTestCase.ConfigVariant variant,
                            String configResources)
Method Detail

recursiveDelete

protected void recursiveDelete(MuleClient muleClient,
                               SftpClient sftpClient,
                               String endpointName,
                               String relativePath)
                        throws IOException
Deletes a directory with all its files and sub-directories. The reason it do a "chmod 700" before the delete is that some tests changes the permission, and thus we have to restore the right to delete it...

Parameters:
muleClient -
endpointName -
relativePath -
Throws:
IOException

createRemoteDirectory

protected void createRemoteDirectory(MuleClient muleClient,
                                     String endpointName,
                                     String directoryName)
                              throws IOException
Creates the directoryName under the endpoint path

Throws:
IOException

getUriByEndpointName

protected EndpointURI getUriByEndpointName(MuleClient muleClient,
                                           String endpointName)
                                    throws IOException
Throws:
IOException

getAddressByEndpoint

protected String getAddressByEndpoint(MuleClient muleClient,
                                      String endpointName)
Parameters:
muleClient -
endpointName -
Returns:
the endpoint address in the form 'sftp://user:password@host/path'

getPathByEndpoint

protected String getPathByEndpoint(MuleClient muleClient,
                                   SftpClient sftpClient,
                                   String endpointName)

getSftpClient

protected SftpClient getSftpClient(MuleClient muleClient,
                                   String endpointName)
                            throws IOException
Returns a SftpClient that is logged in to the sftp server that the endpoint is configured against.

Throws:
IOException

getSftpClient

protected SftpClient getSftpClient(String host,
                                   int port,
                                   String user,
                                   String password)
                            throws IOException
Returns a SftpClient that is logged in to the sftp server that the endpoint is configured against.

Throws:
IOException

verifyFileExists

protected boolean verifyFileExists(SftpClient sftpClient,
                                   EndpointURI endpointURI,
                                   String file)
                            throws IOException
Checks if the file exists on the server

Throws:
IOException

verifyFileExists

protected boolean verifyFileExists(SftpClient sftpClient,
                                   String path,
                                   String file)
                            throws IOException
Throws:
IOException

executeBaseTest

protected void executeBaseTest(String inputEndpointName,
                               String sendUrl,
                               String filename,
                               int size,
                               String receivingTestComponentName,
                               long timeout)
                        throws Exception
Base method for executing tests...

Throws:
Exception

executeBaseTest

protected void executeBaseTest(String inputEndpointName,
                               String sendUrl,
                               String filename,
                               int size,
                               String receivingTestComponentName,
                               long timeout,
                               String expectedFailingConnector)
                        throws Exception
Throws:
Exception

executeBaseTest

protected void executeBaseTest(String inputEndpointName,
                               String sendUrl,
                               String filename,
                               int size,
                               String receivingTestComponentName,
                               long timeout,
                               String expectedFailingConnector,
                               String serviceName)
                        throws Exception
Base method for executing tests...

Throws:
Exception

executeBaseAssertionsBeforeCall

protected void executeBaseAssertionsBeforeCall()
To be overridden by the test-classes if required


executeBaseAssertionsAfterCall

protected void executeBaseAssertionsAfterCall(int sendSize,
                                              int receivedSize)
To be overridden by the test-classes if required


getImmutableEndpoint

protected ImmutableEndpoint getImmutableEndpoint(MuleClient muleClient,
                                                 String endpointName)
                                          throws IOException
Throws:
IOException

remoteChmod

protected void remoteChmod(MuleClient muleClient,
                           SftpClient sftpClient,
                           String endpointName,
                           int permissions)
                    throws com.jcraft.jsch.SftpException
Throws:
com.jcraft.jsch.SftpException

initEndpointDirectories

protected void initEndpointDirectories(String[] serviceNames,
                                       String[] endpointNames)
                                throws Exception
Initiates a list of sftp-endpoint-directories. Ensures that affected services are stopped during the initiation.

Parameters:
serviceNames -
endpointNames -
Throws:
Exception

initEndpointDirectory

protected void initEndpointDirectory(String endpointName)
                              throws MuleException,
                                     IOException,
                                     com.jcraft.jsch.SftpException
Ensures that the directory exists and is writable by deleting the directory and then recreate it.

Parameters:
endpointName -
Throws:
MuleException
IOException
com.jcraft.jsch.SftpException

dispatchAndWaitForDelivery

protected void dispatchAndWaitForDelivery(AbstractSftpTestCase.DispatchParameters p)
Helper method for initiating a test and wait for the test to complete. The method sends a file to an inbound endpoint and waits for a dispatch event on a outbound endpoint, i.e. that the file has been consumed by the inbound endpoint and that the content of the file has been sent to the outgoing endpoint.

Parameters:
p - where inboundEndpoint and outboundEndpoint are mandatory, @see DispatchParameters for details.

dispatchAndWaitForException

protected Exception dispatchAndWaitForException(AbstractSftpTestCase.DispatchParameters p,
                                                String expectedFailingConnector)

dispatchAndWaitForException

protected Exception dispatchAndWaitForException(AbstractSftpTestCase.DispatchParameters p,
                                                String expectedFailingConnector,
                                                String serviceName)
Helper method for initiating a test and wait for an exception to be caught by the sftp-connector.

Parameters:
p - where sftpConnector and inboundEndpoint are mandatory, @see DispatchParameters for details.

recursiveDeleteInLocalFilesystem

protected void recursiveDeleteInLocalFilesystem(File parent)
                                         throws IOException
Throws:
IOException

assertNoFilesInLocalFilesystem

protected void assertNoFilesInLocalFilesystem(String path)
                                       throws IOException
Asserts that there are no files found on the path path.

Parameters:
path - The path in the local filesystem to check
Throws:
IOException - Exception

assertNoFilesInEndpoint

protected void assertNoFilesInEndpoint(MuleClient muleClient,
                                       String endpointName)
                                throws IOException
Asserts that no files are found on the path that the endpointName use.

Parameters:
muleClient - MuleClient
endpointName - The endpoint name
Throws:
IOException - Exception

assertNoFilesInEndpoint

protected void assertNoFilesInEndpoint(MuleClient muleClient,
                                       String endpointName,
                                       String subDirectory)
                                throws IOException
Asserts that no files are found on the sub directory subDirectory under the path that endpointName use.

Parameters:
muleClient - MuleClient
endpointName - The endpoint name
subDirectory - The sub directory
Throws:
IOException - Exception

assertFilesInLocalFilesystem

protected void assertFilesInLocalFilesystem(String path,
                                            String expectedFile)
                                     throws IOException
Asserts that only the expectedFile is found on the path path, where filenames can be expressed as a regular expression.

Parameters:
path - The path in the local filesystem to check
expectedFile - Expected file
Throws:
IOException - Exception

assertFilesInLocalFilesystem

protected void assertFilesInLocalFilesystem(String path,
                                            String[] expectedFiles)
                                     throws IOException
Asserts that only the expectedFiles are found on the path path, where filenames can be expressed as a regular expression.

Parameters:
path - The path in the local filesystem to check
expectedFiles - Expected files
Throws:
IOException - Exception

assertFilesInEndpoint

protected void assertFilesInEndpoint(MuleClient muleClient,
                                     String endpointName,
                                     String expectedFile)
                              throws IOException
Asserts that only the expectedFile is found on the path that the endpointName use, where filenames can be expressed as a regular expression.

Parameters:
muleClient - MuleClient
endpointName - The endpoint name
expectedFile - Expected file
Throws:
IOException - Exception

assertFilesInEndpoint

protected void assertFilesInEndpoint(MuleClient muleClient,
                                     String endpointName,
                                     String[] expectedFiles)
                              throws IOException
Asserts that only the expectedFiles are found on the path that the endpointName use, where filenames can be expressed as a regular expression.

Parameters:
muleClient - MuleClient
endpointName - The endpoint name
expectedFiles - Expected files
Throws:
IOException - Exception

assertFilesInEndpoint

protected void assertFilesInEndpoint(MuleClient muleClient,
                                     String endpointName,
                                     String subDirectory,
                                     String expectedFile)
                              throws IOException
Asserts that only the expectedFile is found on the sub directory subDirectory under the path that endpointName use, where filenames can be expressed as a regular expression.

Parameters:
muleClient - MuleClient
endpointName - The endpoint name
subDirectory - The sub directory
expectedFile - Expected files
Throws:
IOException - Exception

assertFilesInEndpoint

protected void assertFilesInEndpoint(MuleClient muleClient,
                                     String endpointName,
                                     String subDirectory,
                                     String[] expectedFiles)
                              throws IOException
Asserts that only the expectedFiles are found on the sub directory subDirectory under the path that endpointName use, where filenames can be expressed as a regular expression.

Parameters:
muleClient - MuleClient
endpointName - The endpoint name
subDirectory - The sub directory
expectedFiles - Expected files
Throws:
IOException - Exception

checkConnectors

public void checkConnectors()
Check that all of the connectors are running. I don't know if this makes a difference in test reliability per se; it may just delay the start of the test long enough for the MuleContext to be usable.


before

public void before()
            throws Exception
Throws:
Exception


Copyright © 2003-2012 MuleSoft, Inc.. All Rights Reserved.