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.teststeps.actions;
    14
    15  import java.awt.event.ActionEvent;
    16
    17  import javax.swing.AbstractAction;
    18  import javax.swing.Action;
    19
    20  import com.eviware.soapui.impl.wsdl.support.assertions.Assertable;
    21  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
    22  import com.eviware.soapui.impl.wsdl.teststeps.assertions.WsdlAssertionRegistry;
    23  import com.eviware.soapui.support.UISupport;
    24
    25  /***
    26   * Adds a WsdlAssertion to a WsdlTestRequest
    27   *
    28   * @author Ole.Matzura
    29   */
    30
    31  public class AddAssertionAction extends AbstractAction
    32  {
    33     private final Assertable assertable;
    34
    35  	public AddAssertionAction( Assertable assertable )
    36     {
    37        super( "Add Assertion" );
    38  		this.assertable = assertable;
    39
    40        putValue( Action.SHORT_DESCRIPTION, "Adds an assertion to this item" );
    41        putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/addAssertion.gif"));
    42     }
    43
    44     public void actionPerformed(ActionEvent e)
    45  	{
    46        String [] assertions = WsdlAssertionRegistry.getInstance().getAvailableAssertionNames( assertable.getAssertableType() );
    47
    48        if( assertions == null || assertions.length == 0 )
    49        {
    50           UISupport.showErrorMessage( "No assertions available for this message" );
    51           return;
    52        }
    53
    54        String selection = (String) UISupport.prompt( "Select assertion to add", "Select Assertion", assertions );
    55        if( selection == null ) return;
    56
    57        if( !WsdlAssertionRegistry.getInstance().canAddMultipleAssertions( selection, assertable ) )
    58        {
    59        	UISupport.showErrorMessage( "This assertion can only be added once" );
    60        	return;
    61        }
    62
    63        WsdlMessageAssertion assertion = assertable.addAssertion( selection );
    64        if( assertion == null )
    65        {
    66        	UISupport.showErrorMessage( "Failed to add assertion" );
    67           return;
    68        }
    69
    70        if( assertion.isConfigurable() )
    71        {
    72        	assertion.configure();
    73        }
    74     }
    75  }