Search in sources :

Example 11 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class UndoHistory method add.

/**
     * Add tree model copy to the history
     * <p>
     * This method relies on the rule that the record in history made AFTER
     * change has been made to test plan
     *
     * @param treeModel JMeterTreeModel
     * @param comment   String
     */
public void add(JMeterTreeModel treeModel, String comment) {
    if (!isEnabled()) {
        log.debug("undo.history.size is set to 0, undo/redo feature is disabled");
        return;
    }
    // don't add element if we are in the middle of undo/redo or a big loading
    if (working) {
        log.debug("Not adding history because of noop");
        return;
    }
    JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
    if (root.getChildCount() < 1) {
        log.debug("Not adding history because of no children");
        return;
    }
    String name = root.getName();
    log.debug("Adding history element {}: {}", name, comment);
    working = true;
    // get test plan tree
    HashTree tree = treeModel.getCurrentSubTree((JMeterTreeNode) treeModel.getRoot());
    // first clone to not convert original tree
    tree = (HashTree) tree.getTree(tree.getArray()[0]).clone();
    position++;
    while (history.size() > position) {
        if (log.isDebugEnabled()) {
            log.debug("Removing further record, position: {}, size: {}", position, history.size());
        }
        history.remove(history.size() - 1);
    }
    // cloning is required because we need to immute stored data
    HashTree copy = UndoCommand.convertAndCloneSubTree(tree);
    history.add(new UndoHistoryItem(copy, comment));
    log.debug("Added history element, position: {}, size: {}", position, history.size());
    working = false;
    notifyListeners();
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 12 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class TestLoad method checkTestFile.

public void checkTestFile() throws Exception {
    HashTree tree = null;
    try {
        tree = getTree(testFile);
    } catch (Exception e) {
        fail(parent + ": " + testFile.getName() + " caused " + e);
    }
    assertTree(tree);
}
Also used : HashTree(org.apache.jorphan.collections.HashTree)

Example 13 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class TestSave method testTreeConversion.

@Test
public void testTreeConversion() throws Exception {
    HashTree tree = new ListedHashTree();
    JMeterTreeNode root = new JMeterTreeNode(new Arguments(), null);
    tree.add(root, root);
    tree.getTree(root).add(root, root);
    save.convertSubTree(tree);
    assertEquals(tree.getArray()[0].getClass().getName(), root.getTestElement().getClass().getName());
    tree = tree.getTree(tree.getArray()[0]);
    assertEquals(tree.getArray()[0].getClass().getName(), root.getTestElement().getClass().getName());
    assertEquals(tree.getTree(tree.getArray()[0]).getArray()[0].getClass().getName(), root.getTestElement().getClass().getName());
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) HashTree(org.apache.jorphan.collections.HashTree) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) Arguments(org.apache.jmeter.config.Arguments) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Test(org.junit.Test)

Example 14 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class TestSaveService method testLoad.

@Test
public void testLoad() throws Exception {
    for (String fileName : FILES_LOAD_ONLY) {
        File file = findTestFile("testfiles/" + fileName);
        try {
            HashTree tree = SaveService.loadTree(file);
            assertNotNull(tree);
        } catch (IllegalArgumentException ex) {
            fail("Exception loading " + file.getAbsolutePath());
        }
    }
}
Also used : HashTree(org.apache.jorphan.collections.HashTree) File(java.io.File) Test(org.junit.Test)

Example 15 with HashTree

use of org.apache.jorphan.collections.HashTree in project jmeter by apache.

the class DistributedRunnerTest method initRunner.

private void initRunner(DistributedRunnerEmul runner, List<String> hosts) {
    PrintStream origSystemOut = System.out;
    ByteArrayOutputStream catchingOut = new ByteArrayOutputStream();
    System.setOut(new PrintStream(catchingOut));
    try {
        runner.init(hosts, new HashTree());
        fail();
    } catch (RuntimeException ignored) {
    }
    System.setOut(origSystemOut);
}
Also used : PrintStream(java.io.PrintStream) HashTree(org.apache.jorphan.collections.HashTree) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

HashTree (org.apache.jorphan.collections.HashTree)24 File (java.io.File)7 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)7 IOException (java.io.IOException)5 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)5 GuiPackage (org.apache.jmeter.gui.GuiPackage)5 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)5 ActionEvent (java.awt.event.ActionEvent)4 ConversionException (com.thoughtworks.xstream.converters.ConversionException)3 FileNotFoundException (java.io.FileNotFoundException)3 MalformedURLException (java.net.MalformedURLException)3 TestElement (org.apache.jmeter.testelement.TestElement)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 SocketException (java.net.SocketException)2 LinkedList (java.util.LinkedList)2 JTree (javax.swing.JTree)2 TreePath (javax.swing.tree.TreePath)2 ReplaceableController (org.apache.jmeter.control.ReplaceableController)2