View Javadoc

1   /*
2    * $Id: FilePersistenceTestCase.java 22421 2011-07-15 05:05:06Z 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.persistence;
12  
13  import org.mule.module.client.MuleClient;
14  import org.mule.tck.AbstractServiceAndFlowTestCase;
15  import org.mule.util.FileUtils;
16  
17  import java.io.File;
18  import java.util.Arrays;
19  import java.util.Collection;
20  
21  import org.junit.Test;
22  import org.junit.runners.Parameterized.Parameters;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertFalse;
26  import static org.junit.Assert.assertNotNull;
27  
28  public class FilePersistenceTestCase extends AbstractServiceAndFlowTestCase
29  {
30      @Parameters
31      public static Collection<Object[]> parameters()
32      {
33          return Arrays.asList(new Object[][]{
34              {ConfigVariant.SERVICE,
35              "org/mule/test/integration/persistence/file-persistence-config-service.xml"},
36              {ConfigVariant.FLOW, "org/mule/test/integration/persistence/file-persistence-config-flow.xml"}});
37      }
38  
39      public FilePersistenceTestCase(ConfigVariant variant, String configResources)
40      {
41          super(variant, configResources);
42      }
43  
44      @Test
45      public void testFilesStored() throws Exception
46      {
47          // Note that the FunctionalTestCase will remove the working directory after
48          // each execution
49          String path = muleContext.getConfiguration().getWorkingDirectory() + "/queuestore/test.queue";
50          File store = FileUtils.newFile(path);
51          assertFalse(store.exists());
52  
53          MuleClient client = new MuleClient(muleContext);
54          client.dispatch("vm://test.queue", "test", null);
55          // Give the vm dispatcher chance to persist message. Cannot use send because
56          // send does not use queue.
57          Thread.sleep(500);
58          File[] files = store.listFiles();
59          assertNotNull(files);
60          assertEquals(1, files.length);
61  
62          if (variant.equals(ConfigVariant.SERVICE))
63          {
64              muleContext.getRegistry().lookupService("TestComponent").start();
65          }
66          // give the service some time to initialise
67          Thread.sleep(2000);
68          files = store.listFiles();
69          assertNotNull(files);
70          assertEquals(0, files.length);
71      }
72  }