View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.sftp;
8   
9   import org.mule.transport.sftp.notification.SftpTransportNotificationTestListener;
10  
11  import org.junit.Test;
12  
13  import static org.junit.Assert.assertFalse;
14  import static org.junit.Assert.assertTrue;
15  
16  /**
17   * Test the notification features.
18   */
19  public class SftpNotificationFunctionalTestCase extends AbstractSftpTestCase
20  {
21      
22      private static final long TIMEOUT = 15000;
23  
24      // Size of the generated stream - 2 Mb
25      private final static int SEND_SIZE = 1024 * 1024 * 2;
26  
27      @Override
28      protected void doSetUp() throws Exception
29      {
30          super.doSetUp();
31  
32          initEndpointDirectory("inboundEndpoint");
33  
34          SftpTransportNotificationTestListener.reset();
35      }
36  
37      @Override
38      protected String getConfigResources()
39      {
40          return "mule-sftp-notification-test-config.xml";
41      }
42  
43      /**
44       * Test notification.
45       */
46      @Test
47      public void testNotification() throws Exception
48      {
49          executeBaseTest("inboundEndpoint", "vm://test.upload", FILE_NAME, SEND_SIZE, "receiving", TIMEOUT);
50      }
51  
52      /**
53       * To be overridden by the test-classes if required
54       */
55      @Override
56      protected void executeBaseAssertionsBeforeCall()
57      {
58  
59          super.executeBaseAssertionsBeforeCall();
60  
61          // Assert that none of the sftp-notifications already are set
62          assertFalse(SftpTransportNotificationTestListener.gotSftpPutNotification());
63          assertFalse(SftpTransportNotificationTestListener.gotSftpRenameNotification());
64          assertFalse(SftpTransportNotificationTestListener.gotSftpGetNotification());
65          assertFalse(SftpTransportNotificationTestListener.gotSftpDeleteNotification());
66      }
67  
68      /**
69       * To be overridden by the test-classes if required
70       */
71      @Override
72      protected void executeBaseAssertionsAfterCall(int sendSize, int receivedSize)
73      {
74  
75          super.executeBaseAssertionsAfterCall(sendSize, receivedSize);
76  
77          // Now also verify that we got the expected sftp-notifications
78          assertTrue(SftpTransportNotificationTestListener.gotSftpPutNotification());
79          assertTrue(SftpTransportNotificationTestListener.gotSftpRenameNotification());
80          assertTrue(SftpTransportNotificationTestListener.gotSftpGetNotification());
81          assertTrue(SftpTransportNotificationTestListener.gotSftpDeleteNotification());
82      }
83  }