1
2
3
4
5
6
7
8
9
10
11 package org.mule.components.script.refreshable;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.module.client.MuleClient;
15 import org.mule.tck.FunctionalTestCase;
16 import org.mule.util.IOUtils;
17
18 import java.io.FileWriter;
19 import java.io.IOException;
20 import java.net.URL;
21
22 public abstract class AbstractRefreshableBeanTestCase extends FunctionalTestCase
23 {
24
25 protected static final int WAIT_TIME = 1000;
26
27 protected void writeScript(String src, String path) throws IOException
28 {
29 FileWriter scriptFile = new FileWriter(path, false);
30 scriptFile.write(src);
31 scriptFile.flush();
32 scriptFile.close();
33 }
34
35 protected String nameToPath(String name)
36 {
37 URL url = IOUtils.getResourceAsUrl(name, getClass());
38 String path = url.getFile();
39 logger.info(url + " -> " + path);
40 return path;
41 }
42
43
44
45 protected void runScriptTest(String script, String name, String endpoint, String payload, String result) throws Exception
46 {
47
48 writeScript(script, nameToPath(name));
49 Thread.sleep(WAIT_TIME);
50 MuleClient client = new MuleClient();
51 MuleMessage m = client.send(endpoint, payload, null);
52 assertNotNull(m);
53 assertEquals(payload + result, m.getPayloadAsString());
54 }
55
56 }
57
58