1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.request.actions;
14
15 import java.awt.Toolkit;
16 import java.awt.event.ActionEvent;
17 import java.awt.event.KeyEvent;
18
19 import javax.swing.AbstractAction;
20 import javax.swing.Action;
21 import javax.swing.DefaultListModel;
22 import javax.swing.JComponent;
23 import javax.swing.JOptionPane;
24 import javax.swing.JSplitPane;
25 import javax.swing.KeyStroke;
26
27 import com.eviware.soapui.SoapUI;
28 import com.eviware.soapui.impl.wsdl.WsdlInterface;
29 import com.eviware.soapui.impl.wsdl.WsdlOperation;
30 import com.eviware.soapui.impl.wsdl.WsdlRequest;
31 import com.eviware.soapui.impl.wsdl.support.WsdlValidator;
32 import com.eviware.soapui.support.JXmlTextArea;
33 import com.eviware.soapui.impl.wsdl.teststeps.assertions.AssertionError;
34
35 /***
36 * Validates the response XML of a WsdlRequest
37 *
38 * @author Ole.Matzura
39 */
40
41 public class ValidateResponseXmlAction extends AbstractAction
42 {
43 private final JComponent container;
44 private final DefaultListModel errorListModel;
45 private final JSplitPane splitPane;
46 private final JXmlTextArea textArea;
47 private final WsdlRequest request;
48
49 public ValidateResponseXmlAction(WsdlRequest request, JComponent container, DefaultListModel errorListModel, JSplitPane splitPane, JXmlTextArea textArea )
50 {
51 super( "Validate" );
52 putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_V, KeyEvent.ALT_MASK ));
53
54 this.request = request;
55 this.container = container;
56 this.errorListModel = errorListModel;
57 this.splitPane = splitPane;
58 this.textArea = textArea;
59 }
60
61 public void actionPerformed(ActionEvent e)
62 {
63 WsdlOperation operation = (WsdlOperation) request.getOperation();
64 WsdlValidator validator = new WsdlValidator( ((WsdlInterface)operation.getInterface()).getWsdlContext() );
65
66 AssertionError[] errors = validator.assertResponse( textArea.getText(), operation.getBindingOperationName() );
67
68 errorListModel.clear();
69 if( errors == null || errors.length == 0 )
70 {
71 splitPane.setDividerLocation( 1.0 );
72 JOptionPane.showMessageDialog( SoapUI.getInstance().getFrame(), "XML is valid",
73 "Validation", JOptionPane.INFORMATION_MESSAGE );
74 container.setVisible( false );
75 }
76 else
77 {
78 Toolkit.getDefaultToolkit().beep();
79 for( int c = 0; c < errors.length; c++ )
80 {
81 errorListModel.addElement( errors[c] );
82 }
83 container.setVisible( true );
84 splitPane.setDividerLocation( 0.8 );
85 }
86 }
87 }