View Javadoc

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