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.testcase;
    14
    15  import java.lang.ref.SoftReference;
    16  import java.util.ArrayList;
    17  import java.util.List;
    18
    19  import javax.swing.AbstractListModel;
    20
    21  import com.eviware.soapui.model.testsuite.TestStepResult;
    22
    23  /***
    24   * ListModel for the TestCaseLog
    25   *
    26   * @author ole.matzura
    27   */
    28
    29  public class TestCaseLogModel extends AbstractListModel
    30  {
    31  	private List<Object> items = new ArrayList<Object>();
    32  	private List<SoftReference<TestStepResult>> results = new ArrayList<SoftReference<TestStepResult>>();
    33  	private int stepCount;
    34
    35  	public void addText(String msg)
    36  	{
    37  		synchronized( this )
    38  		{
    39  			items.add(msg);
    40  			results.add(null);
    41  			fireIntervalAdded(this, items.size() - 1, items.size()-1 );
    42  		}
    43  	}
    44
    45  	public void addTestStepResult(TestStepResult result)
    46  	{
    47  		synchronized( this )
    48  		{
    49  			stepCount++;
    50
    51  			int size = items.size();
    52  			items.add("Step " + stepCount + " [" + result.getTestStep().getName() + "] " + result.getStatus() + ": took " + result.getTimeTaken() + " ms");
    53  			SoftReference<TestStepResult> ref = new SoftReference<TestStepResult>(result);
    54  			results.add( ref);
    55  			for (String msg : result.getMessages())
    56  			{
    57  				items.add("-> " + msg);
    58  				results.add(ref);
    59  			}
    60
    61  			fireIntervalAdded(this, size, items.size()-1 );
    62  		}
    63  	}
    64
    65  	public void clear()
    66  	{
    67  		synchronized( this )
    68  		{
    69  			int sz = getSize();
    70  			items.clear();
    71  			results.clear();
    72  			stepCount = 0;
    73  			fireIntervalRemoved(this, 0, sz);
    74  		}
    75  	}
    76
    77  	public int getSize()
    78  	{
    79  		synchronized( this )
    80  		{
    81  			return items.size();
    82  		}
    83  	}
    84
    85  	public Object getElementAt(int arg0)
    86  	{
    87  		try
    88  		{
    89  			return items.get(arg0);
    90  		}
    91  		catch (Throwable e)
    92  		{
    93  			return null;
    94  		}
    95  	}
    96
    97  	public TestStepResult getResultAt(int index)
    98  	{
    99  		if( index >= results.size())
    100 			return null;
    101
    102 		SoftReference<TestStepResult> result = results.get(index);
    103 		return result == null ? null : result.get();
    104 	}
    105 }