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