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