01: /*
02: * This file is part of the WfMOpen project.
03: * Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
04: * All rights reserved.
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * $Id: JSExecutorTest.java,v 1.1 2007/03/22 15:49:12 schnelle Exp $
21: *
22: * $Log: JSExecutorTest.java,v $
23: * Revision 1.1 2007/03/22 15:49:12 schnelle
24: * Component renamed.
25: *
26: * Revision 1.1 2007/03/22 13:49:11 schnelle
27: * Initial release.
28: *
29: */
30:
31: package de.danet.an.workflow.tools.test;
32:
33: import java.io.BufferedReader;
34: import java.io.File;
35: import java.io.FileReader;
36: import java.io.IOException;
37:
38: import de.danet.an.workflow.spis.aii.ToolAgent;
39: import de.danet.an.workflow.tools.rhino.JSExecutor2;
40:
41: /**
42: * TestCase facility to test scripts for the {@link JSExecutor2} tool.
43: *
44: * @author Dirk Schnelle
45: */
46: public abstract class JSExecutorTest extends ToolAgentTestBase {
47: /**
48: * Constructs a test case without a name.
49: */
50: public JSExecutorTest() {
51: this (null);
52: }
53:
54: /**
55: * Constructs a test case with the specified name.
56: * @param name name of the test.
57: */
58: public JSExecutorTest(String name) {
59: super (name);
60: }
61:
62: /* (non-Javadoc)
63: * Comment copied from interface or super class.
64: */
65: public ToolAgent createToolAgent() {
66: return new JSExecutor2();
67: }
68:
69: /**
70: * Retrieves the JSExecutor2 tool.
71: *
72: * @return The JSExecutor2 tool.
73: */
74: public JSExecutor2 getJSExecutorTool() {
75: return (JSExecutor2) getTool();
76: }
77:
78: /**
79: * Loads the script and sets it in the tool.
80: * @param script Filename of the script to load.
81: * @throws IOException Error reading the script.
82: */
83: protected void loadScript(String script) throws IOException {
84: File js = new File(script);
85: FileReader reader = new FileReader(js);
86: BufferedReader bufreader = new BufferedReader(reader);
87:
88: StringBuffer buffer = new StringBuffer();
89: String line = bufreader.readLine();
90: while (line != null) {
91: buffer.append(line);
92: buffer.append("\n");
93: line = bufreader.readLine();
94: }
95:
96: getJSExecutorTool().setScript(buffer.toString());
97: }
98: }
|