View Javadoc

1   /*
2    * $Id: FileRuntimeExceptionStrategyFunctionalTestCase.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 FileRuntimeExceptionStrategyFunctionalTestCase 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-runtime-exception-strategy-service.xml"},
33              {ConfigVariant.FLOW,
34                  "org/mule/test/integration/providers/file/file-runtime-exception-strategy-flow.xml"}});
35      }
36  
37      public FileRuntimeExceptionStrategyFunctionalTestCase(ConfigVariant variant, String configResources)
38      {
39          super(variant, configResources);
40      }
41  
42      @Test
43      public void testExceptionInTransformer() throws Exception
44      {
45          File f = FileUtils.newFile("./.mule/in/test.txt");
46          f.createNewFile();
47  
48          // try a couple of times with backoff strategy, then fail
49          File errorFile = FileUtils.newFile("./.mule/errors/test-0.out");
50          boolean testSucceded = false;
51          int timesTried = 0;
52          while (timesTried <= 3)
53          {
54              Thread.sleep(500 * ++timesTried);
55              if (errorFile.exists())
56              {
57                  testSucceded = true;
58                  break;
59              }
60          }
61  
62          if (!testSucceded)
63          {
64              fail("Exception strategy hasn't moved the file to the error folder.");
65          }
66      }
67  }