View Javadoc

1   /*
2    * $Id: InboundMessageLossFlowTestCase.java 22491 2011-07-21 10:04:30Z claude.mamo $
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.ftp.reliability;
12  
13  import org.mule.tck.probe.Probe;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  
18  import org.junit.Test;
19  import org.junit.runners.Parameterized.Parameters;
20  
21  
22  /**
23   * Verify that no inbound messages are lost when exceptions occur.
24   * The message must either make it all the way to the SEDA queue (in the case of
25   * an asynchronous inbound endpoint), or be restored/rolled back at the source.
26   *
27   * In the case of FTP, this will cause the postProcess() method to not be executed
28   * and therefore the source file will not be deleted.
29   */
30  public class InboundMessageLossFlowTestCase extends InboundMessageLossTestCase
31  {
32      @Parameters
33      public static Collection<Object[]> parameters()
34      {
35          return Arrays.asList(new Object[][]{            
36              {ConfigVariant.FLOW, "reliability/inbound-message-loss-flow.xml"}
37          });
38      }      
39      
40      public InboundMessageLossFlowTestCase(ConfigVariant variant, String configResources)
41      {
42          super(variant, configResources);     
43      }
44      
45      @Override
46      @Test
47      public void testTransformerException() throws Exception
48      {
49          createFileOnFtpServer("transformerException/test1");
50          prober.check(new Probe()
51          {
52              @Override
53              public boolean isSatisfied()
54              {
55                  // Exception occurs after the SEDA queue for an asynchronous request, so from the client's
56                  // perspective, the message has been delivered successfully.
57                  // Note that this behavior is different from services because the exception occurs before
58                  // the SEDA queue for services.
59                  return !fileExists("transformerException/test1");
60              }
61  
62              @Override
63              public String describeFailure()
64              {
65                  return "File should be gone";
66              }
67          });
68      }
69  
70      @Override
71      @Test
72      public void testRouterException() throws Exception
73      {
74          createFileOnFtpServer("routerException/test1");
75          prober.check(new Probe()
76          {
77              @Override
78              public boolean isSatisfied()
79              {
80                  // Exception occurs after the SEDA queue for an asynchronous request, so from the client's
81                  // perspective, the message has been delivered successfully.
82                  // Note that this behavior is different from services because the exception occurs before
83                  // the SEDA queue for services.
84                  return !fileExists("routerException/test1");
85              }
86  
87              @Override
88              public String describeFailure()
89              {
90                  return "File should be gone";
91              }
92          });
93      }
94  }