summaryrefslogtreecommitdiff
path: root/src/test/java/ScriptTest.java
blob: 1cac1b5faf0145f82c0af80e5b45a92c384fb543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.OutcomeValidator;
import com.c2kernel.persistency.outcome.Schema;
import com.c2kernel.scripting.Script;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
import com.c2kernel.utils.Resource;

public class ScriptTest {

	String testScriptString;
	Script testScript;
	
	public ScriptTest() throws Exception {
		Resource.initKernelBaseURL();
		Logger.addLogStream(System.out, 9);
		testScriptString = FileStringUtility.url2String(ScriptTest.class.getResource("TestScript.xml"));
	}
	
	public void testScriptValid() throws Exception {

		String schemaText = Resource.getTextResource(null, "boot/OD/Script.xsd");
		Schema scriptSchema = new Schema("Script", 0, false, schemaText);
		OutcomeValidator valid = new OutcomeValidator(scriptSchema);
		Outcome script = new Outcome("/Script/0/0", testScriptString);
		String errors = valid.validate(script);
		System.out.println("Script validation errors: "+errors);
		assert errors.length() == 0;
	}
	
	public void testParsing() throws Exception {
		testScript = new Script(testScriptString);
		System.out.println("Param size: "+testScript.getInputParams().size());
		assert testScript.getInputParams().size()==1;
		System.out.println("Param 1: "+testScript.getInputParams().get("test"));
		assert testScript.getInputParams().get("test")!=null;
		testScript.setInputParamValue("test", "Test");
		System.out.println("Param 1 initialized: "+testScript.getInputParams().get("test").getInitialised());
		assert testScript.getInputParams().get("test").getInitialised();
		Object result = testScript.execute();
		assert result!=null;
		assert result instanceof String;
		assert ((String)result).equals("TestTest");
	}
	

}