JMeterUtils.loadJMeterProperties("/path/to/jmeter.properties"); JMeterUtils.setJMeterHome("/path/to/jmeter"); JMeterUtils.initLogging(); JMeterUtils.initLocale(); SaveService.loadProperties(); StandardJMeterEngine jmeter = new StandardJMeterEngine(); HashTree testPlanTree = SaveService.loadTree(new File("/path/to/test.jmx")); JMeterTreeModel treeModel = new JMeterTreeModel(new Object()); JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot(); treeModel.addSubTree(testPlanTree, root); SearchByClass<ThreadGroup> threadGroups = new SearchByClass<>(ThreadGroup.class); testPlanTree.traverse(threadGroups); Collection<ThreadGroup> threadGroupsRes = threadGroups.getSearchResults(); for (ThreadGroup threadGroup : threadGroupsRes) { System.out.println(threadGroup.getProperty("ThreadGroup.num_threads")); }
/** * Finds the first enabled node of a given type in the tree. * * @param type * class of the node to be found * * @return the first node of the given type in the test component tree, or * <code>null</code> if none was found. */ private JMeterTreeNode findFirstNodeOfType(Class<?> type) { JMeterTreeModel treeModel = getJmeterTreeModel(); List<JMeterTreeNode> nodes = treeModel.getNodesOfType(type); for (JMeterTreeNode node : nodes) { if (node.isEnabled()) { return node; } } return null; }
/** * Find if there is any AuthManager in JMeterTreeModel * If there is no one, create and add it to tree * Add authorization object to AuthManager * @param authorization {@link Authorization} * @param target {@link JMeterTreeNode} */ private void setAuthorization(Authorization authorization, JMeterTreeNode target) { JMeterTreeModel jmeterTreeModel = getJmeterTreeModel(); List<JMeterTreeNode> authManagerNodes = jmeterTreeModel.getNodesOfType(AuthManager.class); if (authManagerNodes.isEmpty()) { try { log.debug("Creating HTTP Authentication manager for authorization: {}", authorization); AuthManager authManager = newAuthorizationManager(authorization); jmeterTreeModel.addComponent(authManager, target); } catch (IllegalUserActionException e) { log.error("Failed to add Authorization Manager to target node: {}", target.getName(), e); } } else{ AuthManager authManager=(AuthManager)authManagerNodes.get(0).getTestElement(); authManager.addAuth(authorization); } }
/** * Get the node for a given TestElement object. * @param userObject The object to be found in this tree * @return the node corresponding to the <code>userObject</code> */ public JMeterTreeNode getNodeOf(TestElement userObject) { return traverseAndFind(userObject, (JMeterTreeNode) getRoot()); }
/** * Initialize the model with nodes for testplan. * * @param tp the element to use as testplan */ private void initTree(TestElement tp) { // Insert the test plan node insertNodeInto(new JMeterTreeNode(tp, this), (JMeterTreeNode) getRoot(), 0); // Let others know that the tree content has changed. // This should not be necessary, but without it, nodes are not shown when the user // uses the Close menu item nodeStructureChanged((JMeterTreeNode)getRoot()); }
/** * Clear the test plan, and use specified node for test plan * * N.B. Should only be called by {@link GuiPackage#clearTestPlan(TestElement)} * * @param testPlan the node to use as the testplan top node */ public void clearTestPlan(TestElement testPlan) { // Remove testplan nodes int children = getChildCount(getRoot()); while (children > 0) { JMeterTreeNode child = (JMeterTreeNode)getChild(getRoot(), 0); super.removeNodeFromParent(child); children = getChildCount(getRoot()); } // Init the tree initTree(testPlan); // Assumes this is only called from GUI mode }
/** * Gets the CurrentNode attribute of the JMeterTreeListener object. * * @return the CurrentNode value */ public JMeterTreeNode getCurrentNode() { if (currentPath != null) { if (currentPath.getLastPathComponent() != null) { return (JMeterTreeNode) currentPath.getLastPathComponent(); } return (JMeterTreeNode) currentPath.getParentPath().getLastPathComponent(); } return (JMeterTreeNode) model.getRoot(); }
if (item instanceof TestPlan) { TestPlan tp = (TestPlan) item; current = (JMeterTreeNode) ((JMeterTreeNode) getRoot()).getChildAt(0); final TestPlan userObject = (TestPlan) current.getUserObject(); userObject.addTestElement(item); userObject.setFunctionalMode(tp.isFunctionalMode()); userObject.setSerialized(tp.isSerialized()); addSubTree(subTree.getTree(item), current); } else if (item instanceof WorkBench) { moveWorkBenchToTestPlan(current, workbenchTree); addSubTree(subTree.getTree(item), addComponent(item, current)); return getCurrentSubTree(current);
/** * Get the {@link TestPlan} from the root of this tree * @return The {@link TestPlan} found at the root of this tree */ public HashTree getTestPlan() { return getCurrentSubTree((JMeterTreeNode) ((JMeterTreeNode) this.getRoot()).getChildAt(0)); }
private static void moveAndSelectNode( JMeterTreeNode currentNode, JMeterTreeNode parentNode, int newIndx) { GuiPackage guiInstance = GuiPackage.getInstance(); guiInstance.getTreeModel().removeNodeFromParent(currentNode); guiInstance.getTreeModel().insertNodeInto(currentNode, parentNode, newIndx); // select the node TreeNode[] nodes = guiInstance.getTreeModel() .getPathToRoot(currentNode); JTree jTree = guiInstance.getMainFrame().getTree(); jTree.setSelectionPath(new TreePath(nodes)); }
PluginManager.install(this, true); JMeterTreeModel treeModel = new JMeterTreeModel(); splash.setProgress(30); JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
private void safelyAddComponent( final JMeterTreeModel model, final JMeterTreeNode node, final GenericController controller) { JMeterUtils.runSafe(true, () -> { try { model.addComponent(controller, node); } catch (IllegalUserActionException e) { log.error("Program error", e); throw new Error(e); } }); }
/** * Find the JMeterTreeNode for a certain TestElement object. * * @param userObject * the test element to search for * @return the tree node associated with the test element */ public JMeterTreeNode getNodeOf(TestElement userObject) { return treeModel.getNodeOf(userObject); }
variables.addParameter("T", Long.toString(deltaT)); // $NON-NLS-1$ ValueReplacer replacer = new ValueReplacer(variables); JMeterTreeNode mySelf = model.getNodeOf(this); if(mySelf != null) { Enumeration<?> children = mySelf.children(); timer.setComment("Recorded:"+Long.toString(deltaT)+"ms"); replacer.undoReverseReplace(timer); model.addComponent(timer, node); } catch (InvalidVariableException | IllegalUserActionException e) {
} else if (action.equals(ActionNames.ADD_ALL)) { previousGuiItems.clear(); GuiPackage.getInstance().getTreeModel().getTestPlan().traverse(this); } else if (action.equals(ActionNames.CHECK_REMOVE) || action.equals(ActionNames.CHECK_CUT)) { try { for (int i = nodes.length - 1; i >= 0; i--) { guiPackage.getTreeModel().getCurrentSubTree(nodes[i]).traverse(this); GuiPackage.getInstance().getTreeModel().getTestPlan().traverse(this); checkMode = true; try { HashTree wholeTree = GuiPackage.getInstance().getTreeModel().getTestPlan(); wholeTree.traverse(this);
/** * @see Command#doAction(ActionEvent) */ @Override public void doAction(ActionEvent e) { HashTree wholeTree = GuiPackage.getInstance().getTreeModel().getTestPlan(); SamplerAndTransactionNameVisitor visitor = new SamplerAndTransactionNameVisitor(); wholeTree.traverse(visitor); Set<String> sampleNames = visitor.getListOfTransactions(); if(sampleNames.isEmpty()) { log.warn("No transaction exported using regexp '{}', modify property '{}' to fix this problem", TRANSACTIONS_REGEX_PATTERN, "report_transactions_pattern"); showResult("No transaction exported using regexp '" +TRANSACTIONS_REGEX_PATTERN +"', modify property 'report_transactions_pattern' to fix this problem"); } else { StringBuilder builder = new StringBuilder(); for (String sampleName : sampleNames) { builder.append(sampleName).append('|'); } builder.setLength(builder.length()-1); String result = builder.toString(); log.info("Exported transactions: jmeter.reportgenerator.exporter.html.series_filter=^({})(-success|-failure)?$", result); showResult("jmeter.reportgenerator.exporter.html.series_filter=^(" +result +")(-success|-failure)?$"); } }
@Override protected void exportDone(JComponent source, Transferable data, int action) { if(this.nodesForRemoval != null && ((action & MOVE) == MOVE)) { GuiPackage guiInstance = GuiPackage.getInstance(); for (JMeterTreeNode jMeterTreeNode : nodesForRemoval) { guiInstance.getTreeModel().removeNodeFromParent(jMeterTreeNode); } nodesForRemoval = null; } }
private void moveNode(GuiPackage guiPackage, JMeterTreeNode node, JMeterTreeNode newParentNode) { guiPackage.getTreeModel().removeNodeFromParent(node); guiPackage.getTreeModel().insertNodeInto(node, newParentNode, newParentNode.getChildCount()); } }
if (GuiPackage.getInstance() != null) { for (Object node : workbenchTreeArray) { if (isNonTestElement(node)) { HashTree subtree = workbenchTree.getTree(node); workbenchTree.remove(node); tree.add(node, subtree); ((TestElement) node).setProperty(TestElement.ENABLED, false); addSubTree(tree, current); testFragmentTree.add(testFragmentController); testFragmentTree.add(testFragmentController, workbenchTree); addSubTree(testFragmentTree, current);
/** * Add a subtree to the currently selected node. * * @param subTree * the subtree to add. * * @return the resulting subtree starting with the currently selected node * * @throws IllegalUserActionException * if a subtree cannot be added to the currently selected node */ public HashTree addSubTree(HashTree subTree) throws IllegalUserActionException { HashTree hashTree = treeModel.addSubTree(subTree, treeListener.getCurrentNode()); undoHistory.clear(); undoHistory.add(this.treeModel, "Loaded tree"); return hashTree; }