View Javadoc

1   /*
2    * $Id: FileExceptionStrategyFunctionalTestCase.java 22431 2011-07-18 07:40:35Z dirk.olmes $
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.test.integration.transport.file;
12  
13  import org.mule.tck.AbstractServiceAndFlowTestCase;
14  import org.mule.util.FileUtils;
15  
16  import java.io.File;
17  import java.util.Arrays;
18  import java.util.Collection;
19  
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  
23  import static org.junit.Assert.fail;
24  
25  public class FileExceptionStrategyFunctionalTestCase extends AbstractServiceAndFlowTestCase
26  {
27      @Parameters
28      public static Collection<Object[]> parameters()
29      {
30          return Arrays.asList(new Object[][]{
31              {ConfigVariant.SERVICE,
32                  "org/mule/test/integration/providers/file/file-exception-strategy-service.xml"},
33              {ConfigVariant.FLOW, "org/mule/test/integration/providers/file/file-exception-strategy-flow.xml"}});
34      }
35  
36      public FileExceptionStrategyFunctionalTestCase(ConfigVariant variant, String configResources)
37      {
38          super(variant, configResources);
39      }
40  
41      @Test
42      public void testExceptionInTransformer() throws Exception
43      {
44          File f = FileUtils.newFile("./.mule/in/test.txt");
45          f.createNewFile();
46  
47          // try a couple of times with backoff strategy, then fail
48          File errorFile = FileUtils.newFile("./.mule/errors/test-0.out");
49          boolean testSucceded = false;
50          int timesTried = 0;
51          while (timesTried <= 3)
52          {
53              Thread.sleep(500 * ++timesTried);
54              if (errorFile.exists())
55              {
56                  testSucceded = true;
57                  break;
58              }
59          }
60  
61          if (!testSucceded)
62          {
63              fail("Exception strategy hasn't moved the file to the error folder.");
64          }
65      }
66  }