View Javadoc

1   /*
2    * $Id: FilePersistenceTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.persistence;
12  
13  
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.util.FileUtils;
17  
18  import java.io.File;
19  
20  public class FilePersistenceTestCase extends FunctionalTestCase
21  {
22  
23      protected String getConfigResources()
24      {
25          return "org/mule/test/integration/persistence/file-persistence-config.xml";
26      }
27  
28      public void testFilesStored() throws Exception
29      {
30          // Note that the FunctionalTestCase will remove the working directory after
31          // each execution
32          String path = muleContext.getConfiguration().getWorkingDirectory() + "/queuestore/test.queue";
33          File store = FileUtils.newFile(path);
34          assertFalse(store.exists());
35  
36          MuleClient client = new MuleClient(muleContext);
37          client.dispatch("vm://test.queue", "test", null);
38          // Give the vm dispatcher chance to persist message.  Cannot use send because send does not use queue.
39          Thread.sleep(500);
40          File[] files = store.listFiles();
41          assertNotNull(files);
42          assertEquals(1, files.length);
43  
44          muleContext.getRegistry().lookupService("TestComponent").start();
45          // give the service some time to initialise
46          Thread.sleep(2000);
47          files = store.listFiles();
48          assertNotNull(files);
49          assertEquals(0, files.length);
50      }
51  }