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.TestAssertionRegistry;
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 = TestAssertionRegistry.getInstance().getAvailableAssertionNames( assertable );
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 )
56 return;
57
58 if( !TestAssertionRegistry.getInstance().canAddMultipleAssertions( selection, assertable ) )
59 {
60 UISupport.showErrorMessage( "This assertion can only be added once" );
61 return;
62 }
63
64 TestAssertion assertion = assertable.addAssertion( selection );
65 if( assertion == null )
66 {
67 UISupport.showErrorMessage( "Failed to add assertion" );
68 return;
69 }
70
71 if( assertion.isConfigurable() )
72 {
73 assertion.configure();
74 }
75 }
76 }