01: package org.jzonic.webtester.commands;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05: import java.io.InputStream;
06: import java.util.Properties;
07:
08: import org.jzonic.webtester.WebTestContext;
09:
10: /**
11: * Reads a properties file and these properties can be used by certain
12: * commands. The property can be accessed using ${ and the name of
13: * the property followed by the closing }.
14: * <br/>
15: * parameter: the name of the properties file
16: * <br/>
17: * examples:
18: * <br/>
19: * read_properties | my_testcases/test.properties
20: *
21: * @author Mecky
22: */
23: public class ReadPropertiesCommand implements WebTestNode {
24:
25: public static final String COMMAND_NAME = "read_properties";
26: private String fileName;
27:
28: public void setParameter(String value) {
29: fileName = value;
30: }
31:
32: public WebTestNodeResult execute(WebTestContext context) {
33: WebTestNodeResult result = new WebTestNodeResult(COMMAND_NAME,
34: fileName);
35: try {
36: Properties props = new Properties();
37: InputStream is = new FileInputStream(new File(fileName));
38: props.load(is);
39: context.setVariables(props);
40: result.setSuccess(true);
41: } catch (Exception e) {
42: result.setSuccess(false);
43: result.setException(e);
44: }
45: return result;
46: }
47:
48: public String getName() {
49: return COMMAND_NAME;
50: }
51:
52: }
|