View Javadoc

1   /*
2    * $Id: FlowUseCaseProcessingStrategyTestCase.java 22682 2011-08-16 12:24:12Z 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.test.construct;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertFalse;
15  import static org.junit.Assert.assertTrue;
16  
17  import org.mule.api.MuleException;
18  import org.mule.api.MuleMessage;
19  import org.mule.api.client.MuleClient;
20  import org.mule.tck.junit4.FunctionalTestCase;
21  import org.mule.tck.junit4.rule.DynamicPort;
22  import org.mule.util.IOUtils;
23  
24  import java.io.File;
25  import java.io.FileOutputStream;
26  import java.io.IOException;
27  
28  import org.junit.Rule;
29  import org.junit.Test;
30  
31  public class FlowUseCaseProcessingStrategyTestCase extends FunctionalTestCase
32  {
33      @Rule
34      public DynamicPort dynamicPort = new DynamicPort("port1");
35  
36      @Override
37      protected String getConfigResources()
38      {
39          return "org/mule/test/construct/flow-usecase-processing-strategy-config.xml";
40      }
41  
42      @Test
43      public void testHTTPStatusCodeExceptionSyncStrategy() throws MuleException
44      {
45          MuleClient client = muleContext.getClient();
46          MuleMessage exception = client.send("http://localhost:" + dynamicPort.getNumber(), null, null);
47  
48          assertEquals("500", exception.getInboundProperty("http.status", "0"));        
49      }
50  
51      @Test    
52      public void testFileAutoDeleteSyncStrategy() throws Exception
53      {     
54          MuleClient client = muleContext.getClient();    
55          File tempFile = createTempFile("mule-file-test-sync-");        
56          client.request("vm://exception", 5000);       
57          
58          assertTrue(tempFile.exists());                
59      }
60      
61      @Test
62      public void testFileAutoDeleteAsyncStrategy() throws Exception
63      {  
64          MuleClient client = muleContext.getClient();   
65          File tempFile = createTempFile("mule-file-test-async-");
66          client.request("vm://exception", 5000);
67          
68          assertFalse(tempFile.exists());              
69      }
70      
71      private File createTempFile(String fileName) throws IOException
72      {        
73          File directory = new File("./.mule");
74          File file = File.createTempFile(fileName, ".txt", directory);       
75          file.deleteOnExit();
76          FileOutputStream fos = new FileOutputStream(file);
77          IOUtils.write("The quick brown fox jumps over the lazy dog", fos);
78          IOUtils.closeQuietly(fos);
79          
80          return file;
81      }
82           
83  }
84  
85  
86