1
2
3
4
5
6
7
8
9
10
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.panels.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 }