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(
79 new CancelAction() ) );
80 panel.add( buttonBar, BorderLayout.SOUTH );
81 panel.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) );
82 panel.setPreferredSize( new Dimension( 270, ( int )panel.getPreferredSize().getHeight() ) );
83
84 dialog.getContentPane().add( panel );
85 dialog.pack();
86 }
87
88 private class OkAction extends AbstractAction
89 {
90 public OkAction()
91 {
92 super( "Ok" );
93 }
94
95 public void actionPerformed( ActionEvent e )
96 {
97 for( int c = 0; c < testCase.getTestStepCount(); c++ )
98 {
99 TestStep step = testCase.getTestStepAt( c );
100 if( step instanceof WsdlTestRequestStep )
101 {
102 WsdlTestRequestStep requestStep = ( WsdlTestRequestStep )step;
103 requestStep.getTestRequest().setUsername( form.getComponentValue( USERNAME ) );
104 requestStep.getTestRequest().setPassword( form.getComponentValue( PASSWORD ) );
105 requestStep.getTestRequest().setDomain( form.getComponentValue( DOMAIN ) );
106 }
107 }
108
109 dialog.setVisible( false );
110 }
111 }
112
113 private class CancelAction extends AbstractAction
114 {
115 public CancelAction()
116 {
117 super( "Cancel" );
118 }
119
120 public void actionPerformed( ActionEvent e )
121 {
122 dialog.setVisible( false );
123 }
124 }
125 }