1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.mock;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.impl.support.actions.ShowOnlineHelpAction;
17 import com.eviware.soapui.impl.wsdl.actions.mockservice.AddNewMockOperationAction;
18 import com.eviware.soapui.impl.wsdl.actions.mockservice.MockServiceOptionsAction;
19 import com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation;
20 import com.eviware.soapui.impl.wsdl.mock.WsdlMockRunContext;
21 import com.eviware.soapui.impl.wsdl.mock.WsdlMockRunner;
22 import com.eviware.soapui.impl.wsdl.mock.WsdlMockService;
23 import com.eviware.soapui.impl.wsdl.panels.teststeps.support.AbstractGroovyEditorModel;
24 import com.eviware.soapui.impl.wsdl.panels.teststeps.support.PropertyHolderTable;
25 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
26 import com.eviware.soapui.model.ModelItem;
27 import com.eviware.soapui.model.mock.*;
28 import com.eviware.soapui.model.support.MockRunListenerAdapter;
29 import com.eviware.soapui.settings.UISettings;
30 import com.eviware.soapui.support.DocumentListenerAdapter;
31 import com.eviware.soapui.support.StringUtils;
32 import com.eviware.soapui.support.Tools;
33 import com.eviware.soapui.support.UISupport;
34 import com.eviware.soapui.support.action.swing.ActionList;
35 import com.eviware.soapui.support.action.swing.DefaultActionList;
36 import com.eviware.soapui.support.action.swing.SwingActionDelegate;
37 import com.eviware.soapui.support.components.*;
38 import com.eviware.soapui.support.swing.AbstractListMouseListener;
39 import com.eviware.soapui.support.swing.ModelItemListKeyListener;
40 import com.eviware.soapui.support.swing.ModelItemListMouseListener;
41 import com.eviware.soapui.ui.support.ModelItemDesktopPanel;
42
43 import javax.swing.*;
44 import javax.swing.text.Document;
45 import java.awt.*;
46 import java.awt.event.ActionEvent;
47 import java.awt.event.ActionListener;
48 import java.beans.PropertyChangeEvent;
49 import java.beans.PropertyChangeListener;
50 import java.text.SimpleDateFormat;
51 import java.util.*;
52 import java.util.List;
53
54 /***
55 * DesktopPanel for WsdlMockServices
56 *
57 * @author ole.matzura
58 */
59
60 public class WsdlMockServiceDesktopPanel extends ModelItemDesktopPanel<WsdlMockService>
61 {
62 private JButton runButton;
63 private WsdlMockRunner mockRunner;
64 private JButton stopButton;
65 private JProgressBar progressBar;
66 private LogListModel logListModel;
67 private JList testLogList;
68 private JCheckBox enableLogCheckBox;
69 private JScrollPane logScrollPane;
70 private JList operationList;
71 private InternalMockRunListener mockRunListener;
72 private PropertyHolderTable propertiesTable;
73 private JUndoableTextArea descriptionArea;
74 private JButton showWsdlButton;
75 private JButton optionsButton;
76 private JLabel runInfoLabel;
77 private GroovyEditorComponent startGroovyEditor;
78 private GroovyEditorComponent stopGroovyEditor;
79 private GroovyEditorComponent onRequestGroovyEditor;
80 private GroovyEditorComponent afterRequestGroovyEditor;
81
82 public WsdlMockServiceDesktopPanel( WsdlMockService mockService )
83 {
84 super( mockService );
85 buildUI();
86
87 setPreferredSize( new Dimension( 400, 500 ) );
88
89 mockRunListener = new InternalMockRunListener();
90 mockService.addMockRunListener( mockRunListener );
91 }
92
93 public boolean onClose( boolean canCancel )
94 {
95 if( mockRunner != null && mockRunner.isRunning() && canCancel )
96 {
97 if( !UISupport.confirm( "Close and stop MockService", "Close MockService" ) )
98 {
99 return false;
100 }
101 }
102
103 if( mockRunner != null )
104 {
105 if( mockRunner.isRunning() )
106 mockRunner.stop();
107
108 mockRunner.release();
109 }
110
111 getModelItem().removeMockRunListener( mockRunListener );
112 ( (OperationListModel) operationList.getModel() ).release();
113
114 logListModel.clear();
115 propertiesTable.release();
116
117 startGroovyEditor.getEditor().release();
118 stopGroovyEditor.getEditor().release();
119
120 return release();
121 }
122
123 public boolean dependsOn( ModelItem modelItem )
124 {
125 return modelItem == getModelItem() || modelItem == getModelItem().getProject();
126 }
127
128 private void buildUI()
129 {
130 add( buildToolbar(), BorderLayout.NORTH );
131
132 JInspectorPanel inspectorPanel = JInspectorPanelFactory.build( buildContent() );
133 inspectorPanel.setDefaultDividerLocation( 0.5F );
134 inspectorPanel.addInspector( new JComponentInspector<JComponent>(
135 buildLog(), "Message Log", "A log of processed requests and their responses", true ) );
136
137 inspectorPanel.setCurrentInspector( "Message Log" );
138
139 add( inspectorPanel.getComponent(), BorderLayout.CENTER );
140 add( new JLabel( "--" ), BorderLayout.PAGE_END );
141 }
142
143 public boolean logIsEnabled()
144 {
145 return enableLogCheckBox.isSelected();
146 }
147
148 private JComponent buildContent()
149 {
150 JTabbedPane tabs = new JTabbedPane();
151 JInspectorPanel inspectorPanel = JInspectorPanelFactory.build( buildOperationList() );
152
153 tabs.addTab( "Operations", inspectorPanel.getComponent() );
154 addTabs( tabs, inspectorPanel );
155
156 if( StringUtils.hasContent( getModelItem().getDescription() ) && getModelItem().getSettings().getBoolean( UISettings.SHOW_DESCRIPTIONS ) )
157 {
158 inspectorPanel.setCurrentInspector( "Description" );
159 }
160
161 return UISupport.createTabPanel( tabs, true );
162 }
163
164 protected void addTabs( JTabbedPane tabs, JInspectorPanel inspectorPanel )
165 {
166 inspectorPanel.addInspector( new JFocusableComponentInspector<JPanel>( buildDescriptionPanel(),
167 descriptionArea, "Description", "A description for this MockService", true ) );
168 inspectorPanel.addInspector( new JComponentInspector<JComponent>( buildPropertiesPanel(), "Properties", "Properties for this MockService", true ) );
169 inspectorPanel.addInspector( new GroovyEditorInspector( buildStartScriptPanel(), "Start Script", "A Groovy script to run when starting the MockService" ) );
170 inspectorPanel.addInspector( new GroovyEditorInspector( buildStopScriptPanel(), "Stop Script", "A Groovy script to run when stopping the MockService" ) );
171 inspectorPanel.addInspector( new GroovyEditorInspector( buildOnRequestScriptPanel(), "OnRequest Script", "A Groovy script to run when receiving a request before it is dispatched" ) );
172 inspectorPanel.addInspector( new GroovyEditorInspector( buildAfterRequestScriptPanel(), "AfterRequest Script", "A Groovy script to run after a request has been dispatched" ) );
173 }
174
175 protected JComponent buildOperationList()
176 {
177 operationList = new JList( new OperationListModel() );
178 operationList.addMouseListener( new ModelItemListMouseListener()
179 {
180 private ActionList defaultActions;
181
182 protected ActionList getDefaultActions()
183 {
184 if( defaultActions == null )
185 {
186 defaultActions = new DefaultActionList();
187 defaultActions.addAction( SwingActionDelegate.createDelegate( AddNewMockOperationAction.SOAPUI_ACTION_ID, getModelItem(), null,
188 null ) );
189 }
190
191 return defaultActions;
192 }
193 } );
194 operationList.setCellRenderer( new OperationListCellRenderer() );
195 operationList.addKeyListener( new ModelItemListKeyListener()
196 {
197
198 @Override
199 public ModelItem getModelItemAt( int ix )
200 {
201 return getModelItem().getMockOperationAt( ix );
202 }
203 } );
204
205 JScrollPane scrollPane = new JScrollPane( operationList );
206 return UISupport.buildPanelWithToolbar( buildMockOperationListToolbar(), scrollPane );
207 }
208
209 private JComponent buildMockOperationListToolbar()
210 {
211 JXToolBar toolbar = UISupport.createToolbar();
212 toolbar.add( UISupport.createToolbarButton(
213 SwingActionDelegate.createDelegate( AddNewMockOperationAction.SOAPUI_ACTION_ID, getModelItem(),
214 null, "/mockOperation.gif" ) ) );
215
216 return toolbar;
217 }
218
219 protected JComponent buildPropertiesPanel()
220 {
221 JPanel panel = new JPanel( new BorderLayout() );
222 propertiesTable = new PropertyHolderTable( getModelItem() );
223 panel.add( new JScrollPane( propertiesTable ), BorderLayout.CENTER );
224 return panel;
225 }
226
227 protected GroovyEditorComponent buildStartScriptPanel()
228 {
229 startGroovyEditor = new GroovyEditorComponent( new StartScriptGroovyEditorModel(), null );
230 return startGroovyEditor;
231 }
232
233 protected GroovyEditorComponent buildStopScriptPanel()
234 {
235 stopGroovyEditor = new GroovyEditorComponent( new StopScriptGroovyEditorModel(), null );
236 return stopGroovyEditor;
237 }
238
239 protected GroovyEditorComponent buildOnRequestScriptPanel()
240 {
241 onRequestGroovyEditor = new GroovyEditorComponent( new OnRequestScriptGroovyEditorModel(), null );
242 return onRequestGroovyEditor;
243 }
244
245 protected GroovyEditorComponent buildAfterRequestScriptPanel()
246 {
247 afterRequestGroovyEditor = new GroovyEditorComponent( new AfterRequestScriptGroovyEditorModel(), null );
248 return afterRequestGroovyEditor;
249 }
250
251 protected JPanel buildDescriptionPanel()
252 {
253 JPanel panel = new JPanel( new BorderLayout() );
254 descriptionArea = new JUndoableTextArea( getModelItem().getDescription() );
255 descriptionArea.getDocument().addDocumentListener( new DocumentListenerAdapter()
256 {
257 public void update( Document document )
258 {
259 getModelItem().setDescription( descriptionArea.getText() );
260 }
261 } );
262
263 panel.setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 ) );
264 UISupport.addTitledBorder( panel, "MockService Description" );
265 panel.add( new JScrollPane( descriptionArea ), BorderLayout.CENTER );
266
267 return panel;
268 }
269
270 protected JComponent buildLog()
271 {
272 JPanel panel = new JPanel( new BorderLayout() );
273 JXToolBar builder = UISupport.createToolbar();
274
275 enableLogCheckBox = new JCheckBox( " ", true );
276 enableLogCheckBox.addActionListener( new ActionListener()
277 {
278
279 public void actionPerformed( ActionEvent arg0 )
280 {
281 testLogList.setEnabled( enableLogCheckBox.isSelected() );
282 if( mockRunner != null )
283 mockRunner.setLogEnabled( enableLogCheckBox.isSelected() );
284
285
286 logScrollPane.repaint();
287 }
288 } );
289
290 builder.addFixed( enableLogCheckBox );
291 builder.addRelatedGap();
292 builder.addFixed( new JLabel( "Enable" ) );
293 builder.addRelatedGap();
294 addLogActions( builder );
295
296 builder.addGlue();
297 builder.setBorder( BorderFactory.createEmptyBorder( 2, 3, 3, 3 ) );
298
299 panel.add( builder, BorderLayout.NORTH );
300
301 logListModel = new LogListModel();
302 testLogList = new JList( logListModel );
303 testLogList.setCellRenderer( new LogCellRenderer() );
304 testLogList.setPrototypeCellValue( "Testing 123" );
305 testLogList.setFixedCellWidth( -1 );
306 testLogList.addMouseListener( new LogListMouseListener() );
307 testLogList.setBorder( BorderFactory.createLineBorder( Color.GRAY ) );
308
309 logScrollPane = new JScrollPane( testLogList );
310
311 panel.add( logScrollPane, BorderLayout.CENTER );
312
313 return panel;
314 }
315
316 protected void addLogActions( JXToolBar builder )
317 {
318 builder.addFixed( UISupport.createToolbarButton( new ClearLogAction() ) );
319 builder.addRelatedGap();
320 builder.addFixed( UISupport.createToolbarButton( new SetLogOptionsAction() ) );
321 }
322
323 protected JXToolBar buildToolbar()
324 {
325 JXToolBar toolbar = UISupport.createToolbar();
326
327 runButton = createActionButton( new RunMockServiceAction(), true );
328 stopButton = createActionButton( new StopMockServiceAction(), false );
329 optionsButton = createActionButton( SwingActionDelegate.createDelegate(
330 new MockServiceOptionsAction(), getModelItem(), null, "/options.gif" ), true );
331 showWsdlButton = createActionButton( new ShowWsdlAction(), false );
332
333 toolbar.addFixed( runButton );
334 toolbar.addFixed( stopButton );
335 toolbar.addFixed( showWsdlButton );
336 toolbar.addFixed( optionsButton );
337
338 toolbar.addGlue();
339
340 runInfoLabel = new JLabel( "", SwingConstants.RIGHT );
341 toolbar.addFixed( UISupport.setFixedSize( runInfoLabel, 200, 20 ) );
342 toolbar.addRelatedGap();
343
344 progressBar = new JProgressBar();
345 JPanel progressBarPanel = UISupport.createProgressBarPanel( progressBar, 2, false );
346 progressBarPanel.setPreferredSize( new Dimension( 60, 20 ) );
347
348 toolbar.addFixed( progressBarPanel );
349 toolbar.addRelatedGap();
350
351 toolbar.addFixed( createActionButton( new ShowOnlineHelpAction( HelpUrls.MOCKSERVICE_HELP_URL ), true ) );
352
353 return toolbar;
354 }
355
356 public void startMockService()
357 {
358 if( ( mockRunner != null && mockRunner.isRunning() ) || SoapUI.getMockEngine().hasRunningMock( getModelItem() ) )
359 {
360 UISupport.showErrorMessage( "MockService is already running" );
361 }
362 else
363 {
364 if( mockRunner != null )
365 mockRunner.release();
366
367 try
368 {
369 getModelItem().start();
370 }
371 catch( Exception e )
372 {
373 UISupport.showErrorMessage( e );
374 return;
375 }
376 }
377 }
378
379 private final class InternalMockRunListener extends MockRunListenerAdapter
380 {
381 @Override
382 public void onMockRunnerStart( MockRunner runner )
383 {
384 mockRunner = (WsdlMockRunner) runner;
385 mockRunner.setMaxResults( logListModel.getMaxSize() );
386 mockRunner.setLogEnabled( enableLogCheckBox.isSelected() );
387
388 progressBar.setIndeterminate( true );
389
390 runButton.setEnabled( false );
391 stopButton.setEnabled( true );
392 optionsButton.setEnabled( false );
393 showWsdlButton.setEnabled( true );
394
395 runInfoLabel.setText( "running on port " + getModelItem().getPort() );
396 }
397
398 @Override
399 public void onMockRunnerStop( MockRunner mockRunner )
400 {
401 progressBar.setIndeterminate( false );
402
403 runButton.setEnabled( true );
404 stopButton.setEnabled( false );
405 optionsButton.setEnabled( true );
406 showWsdlButton.setEnabled( false );
407
408 runInfoLabel.setText( "" );
409 }
410
411 public void onMockResult( MockResult result )
412 {
413 if( logIsEnabled() )
414 {
415 logListModel.addElement( result );
416 }
417 }
418 }
419
420 public class OperationListModel extends AbstractListModel implements ListModel, MockServiceListener, PropertyChangeListener
421 {
422 private List<WsdlMockOperation> operations = new ArrayList<WsdlMockOperation>();
423
424 public OperationListModel()
425 {
426 for( int c = 0; c < getModelItem().getMockOperationCount(); c++ )
427 {
428 WsdlMockOperation mockOperation = getModelItem().getMockOperationAt( c );
429 mockOperation.addPropertyChangeListener( this );
430
431 operations.add( mockOperation );
432 }
433
434 getModelItem().addMockServiceListener( this );
435 }
436
437 public Object getElementAt( int arg0 )
438 {
439 return operations.get( arg0 );
440 }
441
442 public int getSize()
443 {
444 return operations.size();
445 }
446
447 public void mockOperationAdded( MockOperation operation )
448 {
449 operations.add( (WsdlMockOperation) operation );
450 operation.addPropertyChangeListener( this );
451 fireIntervalAdded( this, operations.size() - 1, operations.size() - 1 );
452 }
453
454 public void mockOperationRemoved( MockOperation operation )
455 {
456 int ix = operations.indexOf( operation );
457 operations.remove( ix );
458 operation.removePropertyChangeListener( this );
459 fireIntervalRemoved( this, ix, ix );
460 }
461
462 public void mockResponseAdded( MockResponse request )
463 {
464 }
465
466 public void mockResponseRemoved( MockResponse request )
467 {
468 }
469
470 public void propertyChange( PropertyChangeEvent arg0 )
471 {
472 if( arg0.getPropertyName().equals( WsdlMockOperation.NAME_PROPERTY ) )
473 {
474 int ix = operations.indexOf( arg0.getSource() );
475 fireContentsChanged( this, ix, ix );
476 }
477 }
478
479 public void release()
480 {
481 for( WsdlMockOperation operation : operations )
482 {
483 operation.removePropertyChangeListener( this );
484 }
485
486 getModelItem().removeMockServiceListener( this );
487 }
488 }
489
490 private final static class OperationListCellRenderer extends JLabel implements ListCellRenderer
491 {
492 public Component getListCellRendererComponent(
493 JList list, Object value, int index, boolean isSelected,
494 boolean cellHasFocus
495 )
496 {
497 MockOperation testStep = (MockOperation) value;
498 setText( testStep.getName() );
499 setIcon( testStep.getIcon() );
500
501 if( isSelected )
502 {
503 setBackground( list.getSelectionBackground() );
504 setForeground( list.getSelectionForeground() );
505 }
506 else
507 {
508 setBackground( list.getBackground() );
509 setForeground( list.getForeground() );
510 }
511
512 setEnabled( list.isEnabled() );
513 setFont( list.getFont() );
514 setOpaque( true );
515 setBorder( BorderFactory.createEmptyBorder( 3, 3, 3, 3 ) );
516
517 return this;
518 }
519 }
520
521 public class RunMockServiceAction extends AbstractAction
522 {
523 public RunMockServiceAction()
524 {
525 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/submit_request.gif" ) );
526 putValue( Action.SHORT_DESCRIPTION, "Starts this MockService on the specified port and endpoint" );
527 putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "alt ENTER" ) );
528 }
529
530 public void actionPerformed( ActionEvent arg0 )
531 {
532 startMockService();
533 }
534 }
535
536 public class ShowWsdlAction extends AbstractAction
537 {
538 public ShowWsdlAction()
539 {
540 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/interface.gif" ) );
541 putValue( Action.SHORT_DESCRIPTION, "Opens the root WSDL page in a browser" );
542 }
543
544 public void actionPerformed( ActionEvent arg0 )
545 {
546 WsdlMockService mockService = getModelItem();
547 Tools.openURL( mockService.getLocalEndpoint() + "?WSDL" );
548 }
549 }
550
551 public class StopMockServiceAction extends AbstractAction
552 {
553 public StopMockServiceAction()
554 {
555 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/cancel_request.gif" ) );
556 putValue( Action.SHORT_DESCRIPTION, "Stops this MockService on the specified port and endpoint" );
557 }
558
559 public void actionPerformed( ActionEvent arg0 )
560 {
561 if( mockRunner == null )
562 {
563 UISupport.showErrorMessage( "MockService is not running" );
564 }
565 else
566 {
567 mockRunner.stop();
568 mockRunner.release();
569 mockRunner = null;
570 }
571 }
572 }
573
574 private static final class LogCellRenderer extends JLabel implements ListCellRenderer
575 {
576 private SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" );
577
578 public LogCellRenderer()
579 {
580 setOpaque( true );
581 setBorder( BorderFactory.createEmptyBorder( 3, 3, 3, 3 ) );
582 }
583
584 public Component getListCellRendererComponent(
585 JList list, Object value, int index, boolean isSelected,
586 boolean cellHasFocus
587 )
588 {
589 if( value instanceof String )
590 {
591 setText( value.toString() );
592 }
593 else if( value instanceof MockResult )
594 {
595 MockResult result = (MockResult) value;
596 String msg = dateFormat.format( new Date( result.getTimestamp() ) );
597 MockResponse mockResponse = result.getMockResponse();
598
599 if( mockResponse == null )
600 {
601 msg += ": [dispatch error; missing response]";
602 }
603 else
604 {
605 try
606 {
607 msg += ": [" + mockResponse.getMockOperation().getName();
608 }
609 catch( Throwable e )
610 {
611 msg += ": [removed operation?]";
612 }
613
614 msg += "] " + result.getTimeTaken() + "ms";
615 }
616
617 setText( msg );
618 }
619
620 if( isSelected )
621 {
622 setBackground( list.getSelectionBackground() );
623 setForeground( list.getSelectionForeground() );
624 }
625 else
626 {
627 setBackground( list.getBackground() );
628 setForeground( list.getForeground() );
629 }
630
631 setEnabled( list.isEnabled() );
632
633 return this;
634 }
635 }
636
637 private long getDefaultMaxSize()
638 {
639 return getModelItem().getSettings().getLong( LogListModel.class.getName() + "@maxSize", 100 );
640 }
641
642 protected long getMaxLogSize()
643 {
644 if( logListModel != null )
645 return logListModel.getMaxSize();
646 else
647 return getDefaultMaxSize();
648 }
649
650 protected void setMaxLogSize( long size )
651 {
652 logListModel.setMaxSize( size );
653 if( mockRunner != null )
654 mockRunner.setMaxResults( logListModel.getMaxSize() );
655 }
656
657 private class LogListModel extends AbstractListModel
658 {
659 private List<MockResult> elements = Collections.synchronizedList( new LinkedList<MockResult>() );
660 private long maxSize;
661
662 public LogListModel()
663 {
664 maxSize = getDefaultMaxSize();
665 }
666
667 public void addElement( MockResult result )
668 {
669 elements.add( result );
670 fireIntervalAdded( this, elements.size() - 1, elements.size() - 1 );
671
672 synchronized( this )
673 {
674 while( elements.size() > maxSize )
675 {
676 removeElementAt( 0 );
677 }
678 }
679 }
680
681 public Object getElementAt( int index )
682 {
683 synchronized( this )
684 {
685 return elements.get( index );
686 }
687 }
688
689 public void removeElementAt( int index )
690 {
691 elements.remove( index );
692 fireIntervalRemoved( this, index, index );
693 }
694
695 public void clear()
696 {
697 synchronized( this )
698 {
699 int sz = elements.size();
700 if( sz > 0 )
701 {
702 elements.clear();
703 fireIntervalRemoved( this, 0, sz - 1 );
704 }
705 }
706 }
707
708 public int getSize()
709 {
710 return elements.size();
711 }
712
713 public long getMaxSize()
714 {
715 return maxSize;
716 }
717
718 public synchronized void setMaxSize( long l )
719 {
720 this.maxSize = l;
721
722 while( elements.size() > 0 && elements.size() > maxSize )
723 {
724 removeElementAt( 0 );
725 }
726
727 getModelItem().getSettings().setLong( LogListModel.class.getName() + "@maxSize", maxSize );
728 }
729 }
730
731 private class SetLogOptionsAction extends AbstractAction
732 {
733 public SetLogOptionsAction()
734 {
735 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/options.gif" ) );
736 putValue( Action.SHORT_DESCRIPTION, "Sets MockService Log Options" );
737 }
738
739 public void actionPerformed( ActionEvent e )
740 {
741 String s = UISupport.prompt( "Enter maximum number of rows for MockService Log", "Log Options", String.valueOf( logListModel.getMaxSize() ) );
742 if( s != null )
743 {
744 try
745 {
746 long newMaxSize = Long.parseLong( s );
747 if( newMaxSize > 0 )
748 setMaxLogSize( newMaxSize );
749 }
750 catch( NumberFormatException e1 )
751 {
752 }
753 }
754 }
755 }
756
757 private class ClearLogAction extends AbstractAction
758 {
759 public ClearLogAction()
760 {
761 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/clear_loadtest.gif" ) );
762 putValue( Action.SHORT_DESCRIPTION, "Clears the MockService Log" );
763 }
764
765 public void actionPerformed( ActionEvent e )
766 {
767 logListModel.clear();
768 if( mockRunner != null )
769 mockRunner.clearResults();
770 }
771 }
772
773 /***
774 * Mouse Listener for triggering default action and showing popup for log list items
775 *
776 * @author Ole.Matzura
777 */
778
779 private final class LogListMouseListener extends AbstractListMouseListener
780 {
781 @Override
782 protected ActionList getActionsForRow( JList list, int row )
783 {
784 MockResult result = (MockResult) logListModel.getElementAt( row );
785 return result == null ? null : result.getActions();
786 }
787 }
788
789 private class StartScriptGroovyEditorModel extends AbstractGroovyEditorModel
790 {
791 public StartScriptGroovyEditorModel()
792 {
793 super( new String[]{"log", "context", "mockRunner"}, getModelItem().getSettings(), "Start" );
794 }
795
796 public String getScript()
797 {
798 return getModelItem().getStartScript();
799 }
800
801 public void setScript( String text )
802 {
803 getModelItem().setStartScript( text );
804 }
805
806 @Override
807 public Action createRunAction()
808 {
809 return new AbstractAction()
810 {
811
812 public void actionPerformed( ActionEvent e )
813 {
814 try
815 {
816 WsdlMockRunContext context = mockRunner == null ? new WsdlMockRunContext( getModelItem(), null ) : mockRunner.getMockContext();
817 getModelItem().runStartScript( context, mockRunner );
818 }
819 catch( Exception e1 )
820 {
821 UISupport.showErrorMessage( e1 );
822 }
823 }
824 };
825 }
826 }
827
828 private class StopScriptGroovyEditorModel extends AbstractGroovyEditorModel
829 {
830 public StopScriptGroovyEditorModel()
831 {
832 super( new String[]{"log", "context", "mockRunner"}, getModelItem().getSettings(), "Stop" );
833 }
834
835 public String getScript()
836 {
837 return getModelItem().getStopScript();
838 }
839
840 public void setScript( String text )
841 {
842 getModelItem().setStopScript( text );
843 }
844
845 @Override
846 public Action createRunAction()
847 {
848 return new AbstractAction()
849 {
850
851 public void actionPerformed( ActionEvent e )
852 {
853 try
854 {
855 WsdlMockRunContext context = mockRunner == null ? new WsdlMockRunContext( getModelItem(), null ) : mockRunner.getMockContext();
856 getModelItem().runStopScript( context, mockRunner );
857 }
858 catch( Exception e1 )
859 {
860 UISupport.showErrorMessage( e1 );
861 }
862 }
863 };
864 }
865 }
866
867 private class OnRequestScriptGroovyEditorModel extends AbstractGroovyEditorModel
868 {
869 public OnRequestScriptGroovyEditorModel()
870 {
871 super( new String[]{"log", "context", "mockRequest", "mockRunner"}, getModelItem().getSettings(), "OnRequest" );
872 }
873
874 public String getScript()
875 {
876 return getModelItem().getOnRequestScript();
877 }
878
879 public void setScript( String text )
880 {
881 getModelItem().setOnRequestScript( text );
882 }
883
884 @Override
885 public Action createRunAction()
886 {
887 return new AbstractAction()
888 {
889
890 public void actionPerformed( ActionEvent e )
891 {
892 try
893 {
894 WsdlMockRunContext context = mockRunner == null ? new WsdlMockRunContext( getModelItem(), null ) : mockRunner.getMockContext();
895 getModelItem().runOnRequestScript( context, mockRunner, null );
896 }
897 catch( Exception e1 )
898 {
899 UISupport.showErrorMessage( e1 );
900 }
901 }
902 };
903 }
904 }
905
906 private class AfterRequestScriptGroovyEditorModel extends AbstractGroovyEditorModel
907 {
908 public AfterRequestScriptGroovyEditorModel()
909 {
910 super( new String[]{"log", "context", "mockResult", "mockRunner"}, getModelItem().getSettings(), "AfterRequest" );
911 }
912
913 public String getScript()
914 {
915 return getModelItem().getAfterRequestScript();
916 }
917
918 public void setScript( String text )
919 {
920 getModelItem().setAfterRequestScript( text );
921 }
922
923 @Override
924 public Action createRunAction()
925 {
926 return new AbstractAction()
927 {
928
929 public void actionPerformed( ActionEvent e )
930 {
931 try
932 {
933 WsdlMockRunContext context = mockRunner == null ? new WsdlMockRunContext( getModelItem(), null ) : mockRunner.getMockContext();
934 getModelItem().runAfterRequestScript( context, mockRunner, null );
935 }
936 catch( Exception e1 )
937 {
938 UISupport.showErrorMessage( e1 );
939 }
940 }
941 };
942 }
943 }
944 }