1
2
3
4
5
6
7
8
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
48
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
56
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
67 Thread.sleep(2000);
68 files = store.listFiles();
69 assertNotNull(files);
70 assertEquals(0, files.length);
71 }
72 }