View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.testcase;
14  
15  import com.eviware.soapui.SoapUI;
16  import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
17  import com.eviware.soapui.model.propertyexpansion.PropertyExpander;
18  import com.eviware.soapui.model.settings.Settings;
19  import com.eviware.soapui.model.support.AbstractSubmitContext;
20  import com.eviware.soapui.model.testsuite.TestCase;
21  import com.eviware.soapui.model.testsuite.TestSuite;
22  import com.eviware.soapui.model.testsuite.TestSuiteRunContext;
23  import com.eviware.soapui.model.testsuite.TestSuiteRunner;
24  import com.eviware.soapui.support.types.StringToObjectMap;
25  
26  /***
27   * TestRunContext for WsdlTestCase runners
28   * 
29   * @author Ole.Matzura
30   */
31  
32  public class WsdlTestSuiteRunContext extends AbstractSubmitContext<WsdlTestSuite> implements TestSuiteRunContext
33  {
34  	private final WsdlTestSuiteRunner testRunner;
35  	private TestSuite testSuite;
36  
37  	public WsdlTestSuiteRunContext( TestSuiteRunner testRunner, StringToObjectMap properties )
38  	{
39  		super( ( WsdlTestSuite )testRunner.getTestSuite(), properties );
40  		this.testRunner = ( WsdlTestSuiteRunner )testRunner;
41  	}
42  
43  	public TestSuiteRunner getTestRunner()
44  	{
45  		return testRunner;
46  	}
47  
48  	public TestSuite getTestSuite()
49  	{
50  		return testRunner.getTestSuite();
51  	}
52  
53  	@Override
54  	public Object get( Object key )
55  	{
56  		if( "currentTestCase".equals( key ) )
57  			return getCurrentTestCase();
58  
59  		if( "currentTestCaseIndex".equals( key ) )
60  			return getCurrentTestCaseIndex();
61  
62  		if( "settings".equals( key ) )
63  			return getSettings();
64  
65  		if( "testSuite".equals( key ) )
66  			return getTestSuite();
67  
68  		if( "testRunner".equals( key ) )
69  			return getTestRunner();
70  
71  		return super.get( key );
72  	}
73  
74  	@Override
75  	public Object put( String key, Object value )
76  	{
77  		Object oldValue = get( key );
78  		setProperty( key, value );
79  		return oldValue;
80  	}
81  
82  	public void reset()
83  	{
84  		resetProperties();
85  	}
86  
87  	public String expand( String content )
88  	{
89  		return PropertyExpander.expandProperties( this, content );
90  	}
91  
92  	public Settings getSettings()
93  	{
94  		return testSuite == null ? SoapUI.getSettings() : testSuite.getSettings();
95  	}
96  
97  	public TestCase getCurrentTestCase()
98  	{
99  		return testRunner.getCurrentTestCase();
100 	}
101 
102 	public int getCurrentTestCaseIndex()
103 	{
104 		return testRunner.getCurrentTestCaseIndex();
105 	}
106 
107 	public TestSuiteRunner getTestSuiteRunner()
108 	{
109 		return testRunner;
110 	}
111 
112 	public Object getProperty( String name )
113 	{
114 		return super.get( name );
115 	}
116 }