org.apache.jmeter.gui.tree.JMeterTreeModel Java Examples

The following examples show how to use org.apache.jmeter.gui.tree.JMeterTreeModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
private TreePath getTreePathFor(TestElement te) {
    List<Object> nodes = new ArrayList<>();
    JMeterTreeModel model = (JMeterTreeModel) tree.getModel();

    TreeNode treeNode = model.getNodeOf(te);
    if (treeNode != null) {
        nodes.add(treeNode);
        treeNode = treeNode.getParent();
        while (treeNode != null) {
            nodes.add(0, treeNode);
            treeNode = treeNode.getParent();
        }
    }

    return nodes.isEmpty() ? null : new TreePath(nodes.toArray());
}
 
Example #2
Source File: WeightedSwitchControllerGui.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void fillGridFromTree(WeightedSwitchController wsc, CollectionProperty oldData) {
    JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
    JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();

    Map<JMeterTreeNode, Boolean> childItems = getChildItems(root, wsc);
    for (JMeterTreeNode node : childItems.keySet()) {
        String w = "100";
        JMeterProperty row = getRowByName(node.getTestElement().getName(), oldData);
        if (row != null) {
            w = ((CollectionProperty) row).get(1).getStringValue();
        }
        grid.getModel().addRow(new String[]{node.getTestElement().getName(), w, childItems.get(node).toString()});
    }
}
 
Example #3
Source File: TestUtilities.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
public static void createJmeterEnv() {
  	
      JMeterUtils.setJMeterHome("src/test/resources");
      JMeterUtils.setLocale(Locale.ENGLISH);
      JMeterUtils.loadJMeterProperties("src/test/resources/bin/jmeter.properties");
      
      try {
	SaveService.loadProperties();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

      JMeterTreeModel jMeterTreeModel = new JMeterTreeModel();
      JMeterTreeListener jMeterTreeListener = new JMeterTreeListener();
      jMeterTreeListener.setModel(jMeterTreeModel);
      
      JMeterContextService.getContext().setVariables(new JMeterVariables());
      StandardJMeterEngine engine = new StandardJMeterEngine();
      JMeterContextService.getContext().setEngine(engine);
      
      JMeterThreadMonitor monitor = new NOOPThreadMonitor();
      
      
      HashTree hashtree = new HashTree();
      hashtree.add(new LoopController());
      
      JMeterThread thread = new JMeterThread(hashtree, monitor, null);
      thread.setThreadName("test thread");
      JMeterContextService.getContext().setThread(thread);
      
      
      ThreadGroup tg1 = new ThreadGroup();
      tg1.setName("tg1");
      JMeterContextService.getContext().setThreadGroup(tg1);
      
  }
 
Example #4
Source File: DebuggerDialogBase.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private JTree getTreeView() {
    treeModel = new JMeterTreeModel();
    tree = new JTree(treeModel);
    tree.setCellRenderer(new FixedJMeterTreeCellRenderer(this));
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.addTreeSelectionListener(this);
    tree.addMouseListener(new TreeMouseListener());
    return tree;
}
 
Example #5
Source File: DebuggerDialogTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void testGui() throws Exception {
    if (GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
        return;
    }
    String actions = ActionRouter.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    String renderers = RenderAsHTML.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    JMeterUtils.setProperty("search_paths", actions + ";" + renderers);
    TestProvider prov = new TestProvider();
    JMeterTreeModel mdl = prov.getTreeModel();
    JMeterTreeListener a = new JMeterTreeListener();
    a.setActionHandler(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            log.debug("Action " + actionEvent);
        }
    });
    a.setModel(mdl);
    GuiPackage.getInstance(a, mdl);

    DebuggerDialog obj = new DebuggerDialogMock(prov.getTreeModel());
    obj.componentShown(null);
    obj.started();
    obj.statusRefresh(JMeterContextService.getContext());
    obj.frozenAt(new SamplerDebug());
    obj.continuing();
    obj.stopped();
    obj.componentHidden(null);
}
 
Example #6
Source File: TestJMeterUtils.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static void createJmeterEnv() {
    JMeterUtils.setJMeterHome(getTempDir());

    File dst = new File(JMeterUtils.getJMeterHome() + "/ss.props");
    InputStream src = DirectoryAnchor.class.getResourceAsStream("/kg/apc/jmeter/bin/saveservice.properties");
    try {
        Files.copy(src, dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        throw new RuntimeException("Failed to copy file " + src + " to " + dst, e);
    }

    JMeterUtils.loadJMeterProperties(dst.getAbsolutePath());
    JMeterUtils.setLocale(new Locale("ignoreResources"));

    JMeterTreeModel jMeterTreeModel = new JMeterTreeModel();
    JMeterTreeListener jMeterTreeListener = new JMeterTreeListener();
    jMeterTreeListener.setModel(jMeterTreeModel);
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    StandardJMeterEngine engine = new EmulatorJmeterEngine();
    JMeterThreadMonitor monitor = new EmulatorThreadMonitor();
    JMeterContextService.getContext().setEngine(engine);
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, monitor, null);
    thread.setThreadName("test thread");
    JMeterContextService.getContext().setThread(thread);
    ThreadGroup threadGroup = new org.apache.jmeter.threads.ThreadGroup();
    threadGroup.setName("test thread group");
    JMeterContextService.getContext().setThreadGroup(threadGroup);
    JMeterUtils.setProperty("sample_variables", "TEST1,TEST2,TEST3"); // for Flexible File Writer Test
    JMeterUtils.setProperty("saveservice_properties", "/ss.props");
    JMeterUtils.setProperty("upgrade_properties", "/ss.props");
    JMeterUtils.setProperty("sampleresult.default.encoding", "UTF-8"); // enable multibyte
}
 
Example #7
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void addRowToCompositeModels(String rowName, AbstractGraphRow row) {
    GuiPackage gui = GuiPackage.getInstance();
    if (gui == null) {
        log.debug("No GUI Package present, ignored adding to composite");
        return;
    }

    JMeterTreeModel testTree = gui.getTreeModel();

    for (JMeterTreeNode obj : testTree.getNodesOfType(CompositeResultCollector.class)) {
        CompositeResultCollector compositeResultCollector = (CompositeResultCollector) obj.getTestElement();
        compositeResultCollector.getCompositeModel().addRow(rowName, row);
    }
}
 
Example #8
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void clearRowsFromCompositeModels(String vizualizerName) {
    GuiPackage gui = GuiPackage.getInstance();
    if (gui == null) {
        log.debug("No GUI Package present, ignored removing from composite");
        return;
    }
    JMeterTreeModel testTree = gui.getTreeModel();

    for (JMeterTreeNode obj : testTree.getNodesOfType(CompositeResultCollector.class)) {
        //System.out.println("obj");
        CompositeResultCollector compositeResultCollector = (CompositeResultCollector) obj.getTestElement();
        compositeResultCollector.getCompositeModel().clearRows(vizualizerName);
    }
}
 
Example #9
Source File: TestProvider.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
public JMeterTreeModel getTreeModel() {
    return mdl;
}
 
Example #10
Source File: DebuggerDialogTest.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Test
public void displayGUI() throws InterruptedException, IOException, IllegalUserActionException {
    if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
        TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/vars.jmx", "vars.jmx");
        JMeterTreeModel mdl = prov.getTreeModel();
        JMeterTreeListener a = new JMeterTreeListener();
        a.setActionHandler(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                log.debug("Action " + actionEvent);
            }
        });
        a.setModel(mdl);

        GuiPackage.getInstance(a, mdl);
        String actions = ActionRouter.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        String renderers = RenderAsHTML.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        JMeterUtils.setProperty("search_paths", actions + ";" + renderers);
        MainFrame mf = new MainFrame(mdl, a); // does important stuff inside
        ComponentFinder<JMeterToolBar> finder = new ComponentFinder<>(JMeterToolBar.class);
        JMeterToolBar tb = finder.findComponentIn(mf);
        tb.add(new JButton("test"));

        new TimeFunction();
        long now = System.currentTimeMillis();
        JMeterUtils.setProperty("START.MS", Long.toString(now));
        Date today = new Date(now);
        JMeterUtils.setProperty("START.YMD", new SimpleDateFormat("yyyyMMdd").format(today));
        JMeterUtils.setProperty("START.HMS", new SimpleDateFormat("HHmmss").format(today));

        DebuggerDialogMock frame = new DebuggerDialogMock(mdl);

        frame.setPreferredSize(new Dimension(800, 600));
        frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        while (frame.isVisible()) {
            Thread.sleep(1000);
        }
    }
}
 
Example #11
Source File: DebuggerDialogTest.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
public DebuggerDialogMock(JMeterTreeModel b) {
    mdl = b;
}