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 test assertable" );
    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.getAssertionType() );
    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        WsdlMessageAssertion assertion = assertable.addAssertion( selection );
    58        if( assertion == null )
    59        {
    60        	UISupport.showErrorMessage( "Failed to add assertion" );
    61           return;
    62        }
    63
    64        if( assertion.isConfigurable() )
    65        {
    66        	assertion.configure();
    67        }
    68     }
    69  }