Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.ibm.soatf.gui; import com.ibm.soatf.config.ConfigConsistencyResult; import com.ibm.soatf.config.ConfigurationManager; import com.ibm.soatf.config.DirectoryStructureManager; import com.ibm.soatf.config.FrameworkConfigurationException; import com.ibm.soatf.config.InterfaceConfiguration; import com.ibm.soatf.config.InterfaceConfigurationException; import com.ibm.soatf.config.MasterConfiguration; import com.ibm.soatf.config.MasterConfigurationException; import com.ibm.soatf.config.UserProperties; import com.ibm.soatf.config.iface.IfaceExecBlock; import com.ibm.soatf.config.iface.IfaceFlowPattern; import com.ibm.soatf.config.iface.IfaceTestScenario; import com.ibm.soatf.config.master.ExecutionBlock; import com.ibm.soatf.config.master.Interface; import com.ibm.soatf.config.master.Operation; import com.ibm.soatf.config.master.Project; import com.ibm.soatf.config.master.TestScenarioPreOrPostExecutionBlock; import com.ibm.soatf.flow.FlowExecutionEvent; import com.ibm.soatf.flow.FlowExecutionListener; import com.ibm.soatf.flow.FlowExecutor; import com.ibm.soatf.flow.FrameworkExecutionException; import com.ibm.soatf.gui.logging.JTextAreaAppender; import static com.ibm.soatf.tool.Utils.isEmpty; import foxtrot.AsyncTask; import foxtrot.AsyncWorker; import java.awt.event.ItemEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; import java.io.IOException; import java.util.List; import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListModel; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.event.ListSelectionEvent; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * Master object for Graphical User Interface <code>initialisation</code> * * @author Ladislav Jech <archenroot@gmail.com> */ public class SOATestingFrameworkGUI extends javax.swing.JFrame { /** * Called by: SOATestingFramework * Calls : initComponents,setJTextArea,additionalInit * Description: * Constructor for SOATestingFrameworkGUI which creates new form SOATestingFrameworkGUI. initComponents * is used to load all GUI related components like JFrame,JSplitPannel,JPanel,JScrollPane,JList,JTable. * setJTextArea is used to link Text area from GUI page with log4j framework and write all execution logs * there. * additionalInit is used to load Interface, Interface details and Results page for each and every interface * configured. */ public SOATestingFrameworkGUI() { //Create all GUI related Components initComponents(); //The MOST important part for the logging - the JTextArea where the messages will appear JTextAreaAppender.setJTextArea(jtaLogging); logger.info("GUI created successfully"); //center the frame on screen setLocationRelativeTo(null); setupGUIComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. * only modification is added here is * <code> * jlInterfaces.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { jlInterfacesValueChanged(evt); *</code> * this is used to display interface details when a particular interface is clicked. */ @SuppressWarnings({ "unchecked", "Convert2Diamond" }) // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { btnClearLog = new javax.swing.JButton(); btnExecute = new javax.swing.JButton(); cbEnvironment = new javax.swing.JComboBox(); jLabel1 = new javax.swing.JLabel(); jSplitPane3 = new javax.swing.JSplitPane(); jSplitPane5 = new javax.swing.JSplitPane(); jSplitPane6 = new javax.swing.JSplitPane(); jPanel2 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jlInterfaces = new javax.swing.JList<GUIObjects.Interface>(); jPanel3 = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); jtInterfaceDetails = new javax.swing.JTree(new DefaultTreeModel(null)); jPanel4 = new javax.swing.JPanel(); jScrollPane3 = new javax.swing.JScrollPane(); jtResults = new javax.swing.JTable(); jPanel6 = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); jScrollPane6 = new javax.swing.JScrollPane(); jtaLogging = new javax.swing.JTextArea(); btnReloadXMLConfiguration = new javax.swing.JButton(); btnExportLog = new javax.swing.JButton(); btnValidateConfig = new javax.swing.JButton(); btnStopExecution = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("SOA Testing Framework"); btnClearLog.setText("Clear Log"); btnClearLog.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearLogActionPerformed(evt); } }); btnExecute.setText("Execute"); btnExecute.setEnabled(false); btnExecute.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnExecuteActionPerformed(evt); } }); cbEnvironment.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { cbEnvironmentItemStateChanged(evt); } }); jLabel1.setText("Environment:"); jSplitPane3.setDividerSize(3); jSplitPane3.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); jSplitPane5.setDividerSize(3); jSplitPane6.setDividerLocation(300); jSplitPane6.setDividerSize(3); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Interfaces")); jlInterfaces.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jlInterfaces.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { jlInterfacesValueChanged(evt); } }); jScrollPane1.setViewportView(jlInterfaces); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)); jSplitPane6.setLeftComponent(jPanel2); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Interface Details")); javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root"); jtInterfaceDetails.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1)); jtInterfaceDetails.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { jtInterfaceDetailsValueChanged(evt); } }); jScrollPane2.setViewportView(jtInterfaceDetails); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout .setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE) .addGap(0, 0, 0))); jSplitPane6.setRightComponent(jPanel3); jSplitPane5.setLeftComponent(jSplitPane6); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Results")); jtResults.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Operation", "Message", "Status" }) { boolean[] canEdit = new boolean[] { false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jtResults.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { jtResultsComponentResized(evt); } }); jScrollPane3.setViewportView(jtResults); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout .setHorizontalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(operationProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup() .addComponent(operationProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 1, Short.MAX_VALUE))); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout .setHorizontalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE) .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))); jSplitPane5.setRightComponent(jPanel4); jSplitPane3.setLeftComponent(jSplitPane5); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Log")); jtaLogging.setColumns(20); jtaLogging.setRows(5); jScrollPane6.setViewportView(jtaLogging); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 1137, Short.MAX_VALUE)); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)); jSplitPane3.setRightComponent(jPanel1); btnReloadXMLConfiguration.setText("Reload XML Configuration"); btnReloadXMLConfiguration.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnReloadXMLConfigurationActionPerformed(evt); } }); btnExportLog.setText("Export LOG"); btnExportLog.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnExportLogActionPerformed(evt); } }); btnValidateConfig.setText("Validate Config"); btnValidateConfig.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnValidateConfigActionPerformed(evt); } }); btnStopExecution.setText("STOP"); btnStopExecution.setEnabled(false); btnStopExecution.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnStopExecutionActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(btnClearLog) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnReloadXMLConfiguration) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnExportLog) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnValidateConfig) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnStopExecution) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cbEnvironment, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnExecute)) .addComponent(jSplitPane3, javax.swing.GroupLayout.Alignment.TRAILING)) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addComponent(jSplitPane3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnExecute) .addComponent(cbEnvironment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1).addComponent(btnClearLog) .addComponent(btnReloadXMLConfiguration).addComponent(btnExportLog) .addComponent(btnValidateConfig).addComponent(btnStopExecution)) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void jlInterfacesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jlInterfacesValueChanged if (evt.getValueIsAdjusting()) { return; } interfaceSelection(evt); }//GEN-LAST:event_jlInterfacesValueChanged private void btnClearLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearLogActionPerformed clearLogs(); }//GEN-LAST:event_btnClearLogActionPerformed private void jtInterfaceDetailsValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jtInterfaceDetailsValueChanged // DefaultMutableTreeNode root = (DefaultMutableTreeNode) details.getModel().getRoot(); // GUIObjects.Interface iface = (GUIObjects.Interface) root.getUserObject(); // for (GUIObjects.Interface i : Collections.list(jlInterfacesModel.elements())) { // if(i.getWrappedObject().getName().equals(iface.getWrappedObject().getName())) { // jlInterfaces.setSelectedValue(i, true); // } // } }//GEN-LAST:event_jtInterfaceDetailsValueChanged private void btnReloadXMLConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReloadXMLConfigurationActionPerformed AsyncWorker.post(new AdditionalInitAsyncTask()); }//GEN-LAST:event_btnReloadXMLConfigurationActionPerformed private void btnValidateConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnValidateConfigActionPerformed validateConfig(); }//GEN-LAST:event_btnValidateConfigActionPerformed private void btnExportLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportLogActionPerformed exportLog(); }//GEN-LAST:event_btnExportLogActionPerformed private void jtResultsComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jtResultsComponentResized jtResults.scrollRectToVisible(jtResults.getCellRect(jtResults.getRowCount() - 1, 0, true)); }//GEN-LAST:event_jtResultsComponentResized private void btnStopExecutionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopExecutionActionPerformed stopExecution(); }//GEN-LAST:event_btnStopExecutionActionPerformed private void btnExecuteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExecuteActionPerformed executeFramework(); }//GEN-LAST:event_btnExecuteActionPerformed private void cbEnvironmentItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbEnvironmentItemStateChanged if (evt.getStateChange() == ItemEvent.SELECTED) { String env = cbEnvironment.getSelectedItem().toString(); UserProperties.setLastEnv(env); UserProperties.save(); } }//GEN-LAST:event_cbEnvironmentItemStateChanged // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnClearLog; private javax.swing.JButton btnExecute; private javax.swing.JButton btnExportLog; private javax.swing.JButton btnReloadXMLConfiguration; private javax.swing.JButton btnStopExecution; private javax.swing.JButton btnValidateConfig; private javax.swing.JComboBox cbEnvironment; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel6; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane6; private javax.swing.JSplitPane jSplitPane3; private javax.swing.JSplitPane jSplitPane5; private javax.swing.JSplitPane jSplitPane6; private javax.swing.JList<GUIObjects.Interface> jlInterfaces; private javax.swing.JTree jtInterfaceDetails; private javax.swing.JTable jtResults; private javax.swing.JTextArea jtaLogging; static final javax.swing.JProgressBar operationProgressBar = new javax.swing.JProgressBar(); // End of variables declaration//GEN-END:variables private MasterConfiguration MCFG; private static final Logger logger = LogManager.getLogger(SOATestingFrameworkGUI.class.getName()); private final DefaultListModel<GUIObjects.Interface> jlInterfacesModel = new DefaultListModel<>(); private final TableModelResults jtResultsModel = new TableModelResults(); private FlowExecutor flowExecutor; private final FlowExecutionListener execListener = //<editor-fold defaultstate="collapsed" desc="anonymous inner class definition"> new FlowExecutionListener() { @Override public void operationStarted(FlowExecutionEvent evt) { addRow(evt); } @Override public void operationFinished(FlowExecutionEvent evt) { updateLastRow(evt); jtResults.getColumnModel().getColumn(0).setCellRenderer(new ResultColumnRenderer()); jtResults.getColumnModel().getColumn(1).setCellRenderer(new ResultColumnRenderer()); jtResults.getColumnModel().getColumn(2).setCellRenderer(new ResultColumnRenderer(true)); } @Override public void blockChanged(String message) { addInfoRow(message); jtResults.getColumnModel().getColumn(0).setCellRenderer(new ResultColumnRenderer()); jtResults.getColumnModel().getColumn(1).setCellRenderer(new ResultColumnRenderer()); jtResults.getColumnModel().getColumn(2).setCellRenderer(new ResultColumnRenderer(true)); } }; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="initialization stuff like models, listeners, ..."> /** * initialization stuff like models, listeners, ... for GUI components and configuration initialization */ private void setupGUIComponents() { //called asynchronuously so that the GUI shows up much sooner while the initialization is going on in background //why is it in the AWT invokeLater? because AsyncWorker tasks have to be called from within the EventDispatch thread java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { AsyncWorker.post(new AdditionalInitAsyncTask()); } }); //table with operation results jtResults.setModel(jtResultsModel); jtResults.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 1) { displayResultDetails(); } } }); //middle panel, with the interface details (tree) jtInterfaceDetails.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); } //</editor-fold> /** * * loop through each interface defined in <code>master-config</code> file and add it to GUI. * First add it to interfaceModel and then add that model to <code>jlInterfaces</code> object. * <br></br><br></br> * <code>Interface </code> used here is an object of * <code>SOATestingFrameworkMasterConfiguration.Interfaces.Interface</code> * */ private void initInterfaces() { for (Interface iface : MCFG.getInterfaces()) { jlInterfacesModel.addElement(new GUIObjects.Interface(iface)); } jlInterfaces.setModel(jlInterfacesModel); } private void clearInterfaces() { jlInterfacesModel.clear(); } private String[] getListOfEnvironments() { try { return MCFG.getAllEnvironments().toArray(new String[0]); } catch (MasterConfigurationException ex) { logger.error("Can't get list of environments from configuration", ex); return new String[0]; } } private void executeFramework() { clearAll(); try { flowExecutor = buildFlowExecutor(); } catch (FrameworkConfigurationException ex) { logger.error("Can't build flow executor: ", ex); return; } flowExecutor.addFlowExecutionListener(execListener); btnExecute.setEnabled(false); btnReloadXMLConfiguration.setEnabled(false); jlInterfaces.setEnabled(false); btnStopExecution.setEnabled(true); AsyncWorker.post(new ExecuteTask(flowExecutor)); } /** * Called by <code>SOATestingFrameWork.initComponents</code> method. This method checks whether * any Interface in the left most JPannel was selected or not . * <br></br> * If selected then pass the * selected <code>jLInterface</code> reference to <code>SOATestingFrameWork.updateDetails</code> method and then enable * the <code>Execute</code> button in GUI * */ private void interfaceSelection(ListSelectionEvent evt) { if (jlInterfaces.getSelectedValue() != null) { Interface iface = jlInterfaces.getSelectedValue().getWrappedObject(); logger.info( "interfaceSelection.Message: Interface selected" + jlInterfaces.getSelectedValue().toString()); updateDetails(new GUIObjects.Interface(iface)); checkExecuteButton(); } else { resetInterfaceDetails(); checkExecuteButton(); } } /** * * @param iface */ private void updateDetails(GUIObjects.Interface iface) { final Interface ifaceMasterXML = iface.getWrappedObject(); String name = ifaceMasterXML.getName(); final InterfaceConfiguration ICFG; try { ICFG = MCFG.getInterfaceConfig(name); } catch (MasterConfigurationException ex) { logger.error("Can't load interface details.", ex); resetInterfaceDetails(); return; } DefaultMutableTreeNode nodeInterface = new DefaultMutableTreeNode(iface); DefaultMutableTreeNode nodeProjects = new DefaultMutableTreeNode("SOA Projects"); //Loop through all project defined in //SOATestingFrameworkMasterConfiguration.Interfaces.Interface for (Project project : ifaceMasterXML.getProjects().getProject()) { DefaultMutableTreeNode nodeProject = new DefaultMutableTreeNode(new GUIObjects.Project(project)); nodeProjects.add(nodeProject); } nodeInterface.add(nodeProjects); DefaultMutableTreeNode nodePatterns = new DefaultMutableTreeNode("Flow Patterns"); /*for (Interface.Patterns.ReferencedFlowPattern refPattern : ifaceMasterXML.getPatterns().getReferencedFlowPattern()) { for (int i = 0; i < refPattern.getOccurrence(); i++) { String flowPatternId = refPattern.getIdentificator(); FlowPattern flowPattern = MCFG.getFlowPattern(flowPatternId); DefaultMutableTreeNode nodeFlowPattern = new DefaultMutableTreeNode(new GUIObjects.FlowPattern(flowPattern)); ICFG.getInterfaceFlowPattern(flowPatternId); for (TestScenario testScenario : flowPattern.getTestScenario()) { DefaultMutableTreeNode nodeTestScenario = new DefaultMutableTreeNode(new GUIObjects.TestScenario(testScenario)); for (ExecutionBlock executionBlock : testScenario.getExecutionBlock()) { DefaultMutableTreeNode nodeExecutionBlock = new DefaultMutableTreeNode(new GUIObjects.ExecutionBlock(executionBlock)); for (Operation operation : executionBlock.getOperation()) { DefaultMutableTreeNode nodeOperation = new DefaultMutableTreeNode(new GUIObjects.Operation(operation)); nodeExecutionBlock.add(nodeOperation); } nodeTestScenario.add(nodeExecutionBlock); } nodeFlowPattern.add(nodeTestScenario); } nodePatterns.add(nodeFlowPattern); } }*/ List<IfaceFlowPattern> ifaceFlowPatterns; try { ifaceFlowPatterns = ICFG.getIfaceFlowPatterns(); } catch (InterfaceConfigurationException ex) { logger.error("Can't load interface flow patterns.", ex); resetInterfaceDetails(); return; } for (IfaceFlowPattern iFlowPattern : ifaceFlowPatterns) { DefaultMutableTreeNode nodeInterfaceFlowPattern = new DefaultMutableTreeNode( new GUIObjects.IfaceFlowPattern(iFlowPattern)); for (IfaceTestScenario iTestScenario : iFlowPattern.getIfaceTestScenario()) { DefaultMutableTreeNode nodeInterfaceTestScenario = new DefaultMutableTreeNode( new GUIObjects.InterfaceTestScenario(iTestScenario)); for (IfaceExecBlock iExecutionBlock : iTestScenario.getIfaceExecBlock()) { DefaultMutableTreeNode nodeInterfaceExecutionBlock = new DefaultMutableTreeNode( new GUIObjects.InterfaceExecutionBlock(iExecutionBlock)); ExecutionBlock executionBlock; try { executionBlock = MCFG.getExecutionBlock(iFlowPattern.getRefId(), iTestScenario.getRefId(), iExecutionBlock.getRefId()); } catch (MasterConfigurationException ex) { logger.error("Can't load execution block", ex); resetInterfaceDetails(); return; } for (Operation operation : executionBlock.getOperation()) { DefaultMutableTreeNode nodeOperation = new DefaultMutableTreeNode( new GUIObjects.Operation(operation)); nodeInterfaceExecutionBlock.add(nodeOperation); } nodeInterfaceTestScenario.add(nodeInterfaceExecutionBlock); } TestScenarioPreOrPostExecutionBlock postExecBlock = null; try { postExecBlock = MCFG.getPostExecutionBlock(iFlowPattern.getRefId(), iTestScenario.getRefId()); } catch (MasterConfigurationException ex) { ; } if (postExecBlock != null) { //TODO KROKY } nodeInterfaceFlowPattern.add(nodeInterfaceTestScenario); } nodePatterns.add(nodeInterfaceFlowPattern); } nodeInterface.add(nodePatterns); DefaultTreeModel defaultTreeModel = new DefaultTreeModel(nodeInterface); jtInterfaceDetails.setModel(defaultTreeModel); } private void resetInterfaceDetails() { jtInterfaceDetails.setModel(new DefaultTreeModel(null)); } private void initEnvironments() { String[] environments = getListOfEnvironments(); if (isEmpty(environments)) { return; } final DefaultComboBoxModel model = new DefaultComboBoxModel(environments); cbEnvironment.setModel(model); final String lastEnv = UserProperties.getLastEnv(); if (isEmpty(lastEnv)) { cbEnvironment.setSelectedIndex(0); } else { cbEnvironment.setSelectedItem(lastEnv); } } private void updateLastRow(FlowExecutionEvent evt) { Result result = new Result(evt.getOperationName()); result.setMessages(evt.getOperationResult().getMessages()); result.setCommonResult(evt.getOperationResult().getCommmonResult()); result.setPrePostOperation(evt.isPrePostOperation()); result.setInfoRow(false); jtResultsModel.updateLastRow(result); } private void addRow(FlowExecutionEvent evt) { Result result = new Result(evt.getOperationName()); result.setPrePostOperation(evt.isPrePostOperation()); jtResultsModel.addRow(result); } private void addInfoRow(String message) { Result result = new Result(message); result.setInfoRow(true); jtResultsModel.addRow(result); } private FlowExecutor buildFlowExecutor() throws FrameworkConfigurationException { String interfaceId = jlInterfaces.getSelectedValue().getWrappedObject().getName(); logger.info("Interface ID : " + interfaceId); String envName = cbEnvironment.getSelectedItem().toString(); //boolean ignoreFailures = chkBoxIgnoreFailures.isSelected(); FlowExecutor flowExecutor = new FlowExecutor(envName, interfaceId); TreePath selectionPath = jtInterfaceDetails.getSelectionPath(); if (selectionPath == null) { return flowExecutor; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); while (node != null) { Object userObject = node.getUserObject(); if (userObject instanceof GUIObjects.Project) { boolean inboundOnly = "INBOUND" .equalsIgnoreCase(((GUIObjects.Project) userObject).getWrappedObject().getDirection()); flowExecutor = new FlowExecutor(inboundOnly, envName, interfaceId); break; } else if (userObject instanceof GUIObjects.Operation) { flowExecutor.setOperation(((GUIObjects.Operation) userObject).getWrappedObject()); } else if (userObject instanceof GUIObjects.InterfaceExecutionBlock) { flowExecutor.setIfaceExecutionBlock( ((GUIObjects.InterfaceExecutionBlock) userObject).getWrappedObject()); } else if (userObject instanceof GUIObjects.InterfaceTestScenario) { flowExecutor .setIfaceTestScenario(((GUIObjects.InterfaceTestScenario) userObject).getWrappedObject()); } else if (userObject instanceof GUIObjects.IfaceFlowPattern) { flowExecutor.setIfaceFlowPattern(((GUIObjects.IfaceFlowPattern) userObject).getWrappedObject()); } node = (DefaultMutableTreeNode) node.getParent(); } return flowExecutor; } private void clearAll() { clearLogs(); clearResults(); } private void clearLogs() { jtaLogging.setText(""); } private void clearResults() { jtResultsModel.clear(); } private void displayResultDetails() { int rowIdx = jtResults.getSelectedRow(); Result result = jtResultsModel.getRow(rowIdx); JDialog dialog = new ResultsDetailDialog(this, true, result); dialog.setVisible(true); } private void validateConfig() { try { ConfigConsistencyResult ccr = ConfigurationManager.getInstance().checkConfigConsistency(); JDialog dialog = new ConfigConsistencyCheckResultDialog(this, true, ccr); dialog.setVisible(true); } catch (FrameworkConfigurationException ex) { logger.warn(ex); } } private void exportLog() { final Object[] options = { "OK" }; try { final String fileName = "current.log"; final String text = jtaLogging.getText(); FileUtils.writeStringToFile(new File(fileName), text); JOptionPane.showOptionDialog(this, "Log exported successfully into \"" + fileName + "\"", "Success", JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } catch (IOException ex) { JOptionPane.showOptionDialog(this, "Failed to export log. Reason:\n" + ex.getMessage(), "Failure", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE, null, options, options[0]); } } private void stopExecution() { btnStopExecution.setEnabled(false); if (flowExecutor != null) { flowExecutor.setStopped(true); } } private void checkExecuteButton() { btnExecute.setEnabled(jlInterfaces.getSelectedIndex() != -1 && cbEnvironment.getSelectedIndex() != -1); } private class ExecuteTask extends AsyncTask { private final Logger logger = LogManager.getLogger(ExecuteTask.class); private final FlowExecutor flowExecutor; public ExecuteTask(FlowExecutor flowExecutor) { this.flowExecutor = flowExecutor; } @Override public void success(Object o) { logger.info("Execution finished"); } @Override public void failure(Throwable thrwbl) { logger.info("Execution finished with following exception: ", thrwbl); } @Override public Object run() throws Exception { try { flowExecutor.execute(); } catch (Throwable e) { throw new FrameworkExecutionException(e); } finally { checkExecuteButton(); btnStopExecution.setEnabled(false); btnReloadXMLConfiguration.setEnabled(true); jlInterfaces.setEnabled(true); } return null; } } private class AdditionalInitAsyncTask extends AsyncTask { private final Logger logger = LogManager.getLogger(AdditionalInitAsyncTask.class); @Override public void success(Object o) { logger.info("Initialization complete"); } @Override public void failure(Throwable thrwbl) { logger.info("Initialization failed: ", thrwbl); } @Override public Object run() throws Exception { resetInterfaceDetails(); btnExecute.setEnabled(false); btnReloadXMLConfiguration.setEnabled(false); btnValidateConfig.setEnabled(false); clearInterfaces(); jlInterfaces.setEnabled(false); ConfigurationManager cfgMgr = ConfigurationManager.getInstance(); try { cfgMgr.init(); MCFG = cfgMgr.getMasterConfig(); DirectoryStructureManager.checkFrameworkDirectoryStructure(); //Interfaces list initInterfaces(); //Environment combobox initEnvironments(); } finally { btnReloadXMLConfiguration.setEnabled(true); btnValidateConfig.setEnabled(true); } jlInterfaces.setEnabled(true); return null; } } }