View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.panels.support;
14  
15  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
16  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
17  import com.eviware.soapui.model.settings.Settings;
18  import com.eviware.soapui.model.support.AbstractSubmitContext;
19  import com.eviware.soapui.model.testsuite.TestCase;
20  import com.eviware.soapui.model.testsuite.TestRunContext;
21  import com.eviware.soapui.model.testsuite.TestRunner;
22  import com.eviware.soapui.model.testsuite.TestStep;
23  
24  /***
25   * Dummy TestRunContext used when executing TestSteps one by one
26   *
27   * @author ole.matzura
28   */
29  
30  public class MockTestRunContext extends AbstractSubmitContext implements TestRunContext
31  {
32     private final MockTestRunner mockTestRunner;
33     private final WsdlTestStep testStep;
34  
35     public MockTestRunContext( MockTestRunner mockTestRunner, WsdlTestStep testStep )
36     {
37        super( testStep == null ? mockTestRunner.getTestCase() : testStep );
38        this.mockTestRunner = mockTestRunner;
39        this.testStep = testStep;
40        setProperty( "log", mockTestRunner.getLog() );
41     }
42  
43     public TestStep getCurrentStep()
44     {
45        return testStep;
46     }
47  
48     @Override
49     public void setProperty( String name, Object value )
50     {
51        super.setProperty( name, value, getTestCase() );
52     }
53  
54     public int getCurrentStepIndex()
55     {
56        return testStep == null ? -1 : testStep.getTestCase().getIndexOfTestStep( testStep );
57     }
58  
59     public TestRunner getTestRunner()
60     {
61        return mockTestRunner;
62     }
63  
64     @Override
65     public Object get( Object key )
66     {
67        if( "currentStep".equals( key ) )
68           return getCurrentStep();
69  
70        if( "currentStepIndex".equals( key ) )
71           return getCurrentStepIndex();
72  
73        if( "settings".equals( key ) )
74           return getSettings();
75  
76        if( "testCase".equals( key ) )
77           return getTestCase();
78  
79        if( "testRunner".equals( key ) )
80           return getTestRunner();
81  
82        Object result = getProperty( key.toString() );
83  
84        if( result == null )
85        {
86           result = super.get( key );
87        }
88  
89        return result;
90     }
91  
92     @Override
93     public Object put( String key, Object value )
94     {
95        Object oldValue = get( key );
96        setProperty( key, value );
97        return oldValue;
98     }
99  
100    public Object getProperty( String name )
101    {
102       return getProperty( name, testStep, testStep == null ? null : (WsdlTestCase) testStep.getTestCase() );
103    }
104 
105    public Object getProperty( String testStepName, String propertyName )
106    {
107       TestStep ts = testStep == null ? null : testStep.getTestCase().getTestStepByName( testStepName );
108       return ts == null ? null : ts.getPropertyValue( propertyName );
109    }
110 
111    public TestCase getTestCase()
112    {
113       return testStep == null ? null : testStep.getTestCase();
114    }
115 
116    public Settings getSettings()
117    {
118       return testStep == null ? null : testStep.getSettings();
119    }
120 }