View Javadoc

    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.panels.support;
    14
    15  import java.util.ArrayList;
    16  import java.util.List;
    17
    18  import org.apache.log4j.Logger;
    19
    20  import com.eviware.soapui.SoapUI;
    21  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
    22  import com.eviware.soapui.model.testsuite.TestCase;
    23  import com.eviware.soapui.model.testsuite.TestRunner;
    24  import com.eviware.soapui.model.testsuite.TestStepResult;
    25
    26  /***
    27   * Dummy TestRunner used when executing TestSteps one by one
    28   *
    29   * @author ole.matzura
    30   */
    31
    32  public class MockTestRunner implements TestRunner
    33  {
    34  	private long startTime;
    35  	private String reason;
    36  	private final WsdlTestCase testCase;
    37  	private final Logger logger;
    38
    39  	public MockTestRunner( WsdlTestCase testCase )
    40  	{
    41  		this( testCase, null );
    42  	}
    43
    44  	public MockTestRunner( WsdlTestCase testCase, Logger logger )
    45  	{
    46  		this.testCase = testCase;
    47  		this.logger = logger == null ? SoapUI.ensureGroovyLog() : logger;
    48  		startTime = System.currentTimeMillis();
    49  	}
    50
    51  	public Logger getLog()
    52  	{
    53  		return logger;
    54  	}
    55
    56  	public TestCase getTestCase()
    57  	{
    58  		return testCase;
    59  	}
    60
    61  	public List<TestStepResult> getResults()
    62  	{
    63  		return new ArrayList<TestStepResult>();
    64  	}
    65
    66  	public Status getStatus()
    67  	{
    68  		return Status.RUNNING;
    69  	}
    70
    71  	public void start( boolean async )
    72  	{
    73
    74  	}
    75
    76  	public long getTimeTaken()
    77  	{
    78  		return System.currentTimeMillis()-startTime;
    79  	}
    80
    81  	public Status waitUntilFinished()
    82  	{
    83  		return Status.FINISHED;
    84  	}
    85
    86  	public void cancel(String reason)
    87  	{
    88  		this.reason = reason;
    89  		logger.info( "Canceled with reason [" + reason + "]" );
    90  	}
    91
    92  	public void gotoStep(int index)
    93  	{
    94  		logger.info( "Going to step " + index + " [" +
    95  					testCase.getTestStepAt( index ).getName() + "]");
    96  	}
    97
    98  	public void gotoStepByName(String stepName)
    99  	{
    100 		logger.info( "Going to step [" + stepName + "]" );
    101 	}
    102
    103 	public void fail(String reason)
    104 	{
    105 		this.reason = reason;
    106 		logger.error( "Failed with reason [" + reason + "]" );
    107 	}
    108
    109 	public long getStartTime()
    110 	{
    111 		return startTime;
    112 	}
    113
    114 	public String getReason()
    115 	{
    116 		return reason;
    117 	}
    118 }