View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.persistence;
8   
9   
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.util.FileUtils;
13  
14  import java.io.File;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertFalse;
20  import static org.junit.Assert.assertNotNull;
21  
22  public class FilePersistenceTestCase extends FunctionalTestCase
23  {
24  
25      @Override
26      protected String getConfigResources()
27      {
28          return "org/mule/test/integration/persistence/file-persistence-config.xml";
29      }
30  
31      @Test
32      public void testFilesStored() throws Exception
33      {
34          // Note that the FunctionalTestCase will remove the working directory after
35          // each execution
36          String path = muleContext.getConfiguration().getWorkingDirectory() + "/queuestore/test.queue";
37          File store = FileUtils.newFile(path);
38          assertFalse(store.exists());
39  
40          MuleClient client = new MuleClient(muleContext);
41          client.dispatch("vm://test.queue", "test", null);
42          // Give the vm dispatcher chance to persist message.  Cannot use send because send does not use queue.
43          Thread.sleep(500);
44          File[] files = store.listFiles();
45          assertNotNull(files);
46          assertEquals(1, files.length);
47  
48          muleContext.getRegistry().lookupService("TestComponent").start();
49          // give the service some time to initialise
50          Thread.sleep(2000);
51          files = store.listFiles();
52          assertNotNull(files);
53          assertEquals(0, files.length);
54      }
55  }