out-xpath: unit test – parameter types
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 04 Sep 2014 18:42:02 +0200
changeset 73bb0aa5d23f2e
parent 72 4ba54a632eb8
child 74 6d1fc2895273
out-xpath: unit test – parameter types
java/alt2xml-out-xpath/test/cz/frantovo/alt2xml/out/xpath/XPathActionNGTest.java
     1.1 --- a/java/alt2xml-out-xpath/test/cz/frantovo/alt2xml/out/xpath/XPathActionNGTest.java	Thu Sep 04 18:33:34 2014 +0200
     1.2 +++ b/java/alt2xml-out-xpath/test/cz/frantovo/alt2xml/out/xpath/XPathActionNGTest.java	Thu Sep 04 18:42:02 2014 +0200
     1.3 @@ -46,11 +46,11 @@
     1.4  		documentBuilder = documentBuilderFactory.newDocumentBuilder();
     1.5  	}
     1.6  
     1.7 -	private DOMResult generateEmptyResult() {
     1.8 +	private DOMResult makeEmptyResult() {
     1.9  		return new DOMResult(documentBuilder.newDocument());
    1.10  	}
    1.11  
    1.12 -	private static byte[] generateStringResult(String value) {
    1.13 +	private static byte[] makeStringResult(String value) {
    1.14  		return (value + "\n").getBytes();
    1.15  	}
    1.16  
    1.17 @@ -65,18 +65,55 @@
    1.18  	public void testRun_simple() throws Exception {
    1.19  		actionData.add("1+1");
    1.20  
    1.21 -		doTest(generateEmptyResult(), actionData, actionProperties, generateStringResult("2"));
    1.22 +		doTest(makeEmptyResult(), actionData, actionProperties, makeStringResult("2"));
    1.23 +	}
    1.24 +
    1.25 +	private void setTyped(Boolean typed) {
    1.26 +		actionProperties.put(XPathAction.PARAMETER_TYPED_PARAMETERS, typed.toString());
    1.27  	}
    1.28  
    1.29  	@Test
    1.30  	public void testRun_simpleParameters() throws Exception {
    1.31 -		actionProperties.put(XPathAction.PARAMETER_TYPED_PARAMETERS, Boolean.FALSE);
    1.32 +		setTyped(false);
    1.33  
    1.34  		actionData.add("1+$a");
    1.35 +
    1.36  		actionData.add("a");
    1.37  		actionData.add("2");
    1.38  
    1.39 -		doTest(generateEmptyResult(), actionData, actionProperties, generateStringResult("3"));
    1.40 +		doTest(makeEmptyResult(), actionData, actionProperties, makeStringResult("3"));
    1.41 +	}
    1.42 +
    1.43 +	@Test
    1.44 +	public void testRun_simpleMoreParameters() throws Exception {
    1.45 +		setTyped(false);
    1.46 +
    1.47 +		actionData.add("$a+$b");
    1.48 +
    1.49 +		actionData.add("a");
    1.50 +		actionData.add("2");
    1.51 +
    1.52 +		actionData.add("b");
    1.53 +		actionData.add("4");
    1.54 +
    1.55 +		doTest(makeEmptyResult(), actionData, actionProperties, makeStringResult("6"));
    1.56 +	}
    1.57 +
    1.58 +	@Test
    1.59 +	public void testRun_simpleTypedParameters() throws Exception {
    1.60 +		setTyped(true);
    1.61 +
    1.62 +		actionData.add("$a+$b");
    1.63 +
    1.64 +		actionData.add("a");
    1.65 +		actionData.add("InteGER");
    1.66 +		actionData.add("4");
    1.67 +
    1.68 +		actionData.add("b");
    1.69 +		actionData.add("integeR");
    1.70 +		actionData.add("4");
    1.71 +
    1.72 +		doTest(makeEmptyResult(), actionData, actionProperties, makeStringResult("8"));
    1.73  	}
    1.74  
    1.75  	private void doTest(DOMResult domResult, List<String> actionData, Properties actionProperties, byte[] expectedResult) throws Exception {