    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.impl.wsdl.submit.filters;
    14
    15  import junit.framework.TestCase;
    16
    17  import com.eviware.soapui.impl.wsdl.WsdlSubmitContext;
    18
    19  public class PropertyExpansionTestCase extends TestCase
    20  {
    21     public void testExpansion() throws Exception
    22     {
    23     	WsdlSubmitContext context = new WsdlSubmitContext( null );
    24
    25     	context.setProperty( "test", "value" );
    26
    27     	assertEquals( "value", PropertyExpansionRequestFilter.expandProperties( context, "${test}" ));
    28     	assertEquals( "value", PropertyExpansionRequestFilter.expandProperties( context, "${#test}" ));
    29     	assertEquals( " value ", PropertyExpansionRequestFilter.expandProperties( context, " ${test} " ));
    30     	assertEquals( "${testa}", PropertyExpansionRequestFilter.expandProperties( context, "${testa}" ));
    31     	assertEquals( "valuevalue", PropertyExpansionRequestFilter.expandProperties( context, "${test}${test}" ));
    32
    33     	context.setProperty( "testa", "" );
    34     	assertEquals( "", PropertyExpansionRequestFilter.expandProperties( context, "${testa}" ));
    35     }
    36
    37     public void testRecursiveExpansion() throws Exception
    38     {
    39     	WsdlSubmitContext context = new WsdlSubmitContext( null );
    40
    41     	context.setProperty( "test", "value" );
    42     	context.setProperty( "testexp", "${test}" );
    43
    44     	assertEquals( "value", PropertyExpansionRequestFilter.expandProperties( context, "${testexp}" ));
    45
    46     	context.setProperty( "exp", "${exp}" );
    47     	assertEquals( "${exp}", PropertyExpansionRequestFilter.expandProperties( context, "${exp}" ));
    48     }
    49
    50     public void testNestedExpansion() throws Exception
    51     {
    52     	WsdlSubmitContext context = new WsdlSubmitContext( null );
    53
    54     	context.setProperty( "test", "value" );
    55     	context.setProperty( "testexp", "${test}" );
    56     	context.setProperty( "exp", "exp" );
    57
    58     	assertEquals( "value", PropertyExpansionRequestFilter.expandProperties( context, "${test${exp}}" ));
    59
    60     	context.setProperty( "id", "123" );
    61     	context.setProperty( "testxml", "<test><value id=\"123\">hello</value></test>" );
    62     	assertEquals( "hello",
    63     				PropertyExpansionRequestFilter.expandProperties( context, "${#testxml#//value[@id=${id}]/text()}" ));
    64
    65     	context.setProperty( "testxpath", "//value[@id=${id}]/text()" );
    66     	assertEquals( "hello",
    67     				PropertyExpansionRequestFilter.expandProperties( context, "${#testxml#${testxpath}}" ));
    68     }
    69
    70     public void testXPathExpansion() throws Exception
    71     {
    72     	WsdlSubmitContext context = new WsdlSubmitContext( null );
    73
    74     	context.setProperty( "test", "<test><value>hello</value></test>" );
    75     	assertEquals( "hello", PropertyExpansionRequestFilter.expandProperties( context, "${#test#//value/text()}" ));
    76     }
    77  }