1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.testcase.actions;
14
15 import java.awt.BorderLayout;
16 import java.awt.Dimension;
17 import java.awt.event.ActionEvent;
18
19 import javax.swing.AbstractAction;
20 import javax.swing.Action;
21 import javax.swing.BorderFactory;
22 import javax.swing.JButton;
23 import javax.swing.JDialog;
24 import javax.swing.JPanel;
25
26 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
27 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
28 import com.eviware.soapui.model.testsuite.TestStep;
29 import com.eviware.soapui.support.UISupport;
30 import com.eviware.soapui.support.components.SimpleForm;
31 import com.jgoodies.forms.factories.ButtonBarFactory;
32
33 /***
34 * Set the credentials for all requests in a testcase
35 *
36 * @author Ole.Matzura
37 */
38
39 public class SetCredentialsAction extends AbstractAction
40 {
41 private final WsdlTestCase testCase;
42 private JDialog dialog;
43 private SimpleForm form;
44
45 private static final String DOMAIN = "Domain";
46 private static final String PASSWORD = "Password";
47 private static final String USERNAME = "Username";
48
49 public SetCredentialsAction( WsdlTestCase testCase )
50 {
51 this.testCase = testCase;
52 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/set_credentials.gif"));
53 putValue( Action.SHORT_DESCRIPTION, "Sets the credentials for all requests in this testcase" );
54 }
55
56 public void actionPerformed(ActionEvent e)
57 {
58 if( dialog == null )
59 {
60 buildDialog();
61 }
62
63 UISupport.showDialog( dialog );
64 }
65
66 private void buildDialog()
67 {
68 dialog = new JDialog( UISupport.getMainFrame(), "Set TestCase Credentials" );
69 form = new SimpleForm();
70 form.appendTextField( USERNAME, "Username to use for authentication" );
71 form.appendTextField( PASSWORD, "Password to use for authentication" );
72 form.appendTextField( DOMAIN, "Domain to specify (for NTLM)" );
73 form.getPanel().setBorder( BorderFactory.createEmptyBorder( 0, 0, 10, 0 ));
74
75 JPanel panel = new JPanel( new BorderLayout() );
76 panel.add( form.getPanel(), BorderLayout.CENTER );
77
78 JPanel buttonBar = ButtonBarFactory.buildOKCancelBar( new JButton( new OkAction() ), new JButton( new CancelAction() ));
79 panel.add( buttonBar, BorderLayout.SOUTH );
80 panel.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ));
81 panel.setPreferredSize( new Dimension( 270, (int) panel.getPreferredSize().getHeight() ));
82
83 dialog.getContentPane().add( panel );
84 dialog.pack();
85 }
86
87 private class OkAction extends AbstractAction
88 {
89 public OkAction()
90 {
91 super( "Ok" );
92 }
93
94 public void actionPerformed(ActionEvent e)
95 {
96 for( int c = 0; c < testCase.getTestStepCount(); c++ )
97 {
98 TestStep step = testCase.getTestStepAt( c );
99 if( step instanceof WsdlTestRequestStep )
100 {
101 WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
102 requestStep.getTestRequest().setUsername( form.getComponentValue( USERNAME ));
103 requestStep.getTestRequest().setPassword( form.getComponentValue( PASSWORD ));
104 requestStep.getTestRequest().setDomain( form.getComponentValue( DOMAIN ));
105 }
106 }
107
108 dialog.setVisible( false );
109 }
110 }
111
112 private class CancelAction extends AbstractAction
113 {
114 public CancelAction()
115 {
116 super( "Cancel" );
117 }
118
119 public void actionPerformed(ActionEvent e)
120 {
121 dialog.setVisible( false );
122 }
123 }
124 }