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.teststeps.assertions.WsdlAssertionRegistry;
21 import com.eviware.soapui.model.testsuite.Assertable;
22 import com.eviware.soapui.model.testsuite.TestAssertion;
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 TestAssertion 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 }