Search in sources :

Example 46 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class VariableTableModelTest method testVarTableLoadFileSimple.

// Check can read simple file
public void testVarTableLoadFileSimple() throws Exception {
    String[] args = { "CV", "Name" };
    VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null);
    // create a JDOM tree from file
    XmlFile file = new XmlFile() {
    };
    Element root = file.rootFromName("xml/decoders/0NMRA.xml");
    // add the contents
    Element el0 = root.getChild("decoder").getChild("variables");
    int i = 0;
    for (Element v : el0.getChildren("variable")) {
        t.setRow(i++, v);
    }
// fault is failure to reach the end, e.g. throw message or exception
}
Also used : XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element)

Example 47 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class VariableTableModelTest method testVarTableLoadBogus.

// Check creating bogus XML (unknown variable type)
public void testVarTableLoadBogus() {
    String[] args = { "CV", "Name" };
    VariableTableModel t = new VariableTableModel(null, args, new CvTableModel(null, p), null) {

        @Override
        void reportBogus() {
        }
    };
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    // add some elements
    Element el0;
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(el0 = new Element("variable").setAttribute("CV", "17").setAttribute("mask", "VVVVVVVV").setAttribute("readOnly", "no").setAttribute("label", "long").addContent(new Element("bogusVal")))));
    // end of adding contents
    // print JDOM tree, to check
    //OutputStream o = System.out;
    //XMLOutputter fmt = new XMLOutputter();
    //fmt.setNewlines(true);   // pretty printing
    //fmt.setIndent(true);
    //try {
    //	 fmt.output(doc, o);
    //} catch (Exception e) { System.out.println("error writing XML: "+e);}
    // and test reading this
    t.setRow(0, el0);
    Assert.assertTrue(t.getRowCount() == 0);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 48 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class PaneProgFrameTest method setupDoc.

// provide a test document in the above static variables
void setupDoc() {
    // create a JDOM tree with just some elements
    root = new Element("programmer-config");
    doc = new Document(root);
    doc.setDocType(new DocType("programmer-config", "programmer-config.dtd"));
    // add some elements
    root.addContent(new Element("programmer").setAttribute("showFnLanelPane", "yes").setAttribute("showRosterMediaPane", "yes").addContent(new Element("pane").setAttribute("name", "Basic").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Start voltage")).addContent(new Element("display").setAttribute("item", "Normal direction of motion"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "checkbox")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "radiobuttons")))).addContent(new Element("pane").setAttribute("name", "CV").addContent(new Element("column").addContent(new Element("cvtable")))).addContent(new Element("pane").setAttribute("name", "Other").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")))));
    return;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 49 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class QualifierAdderTest method testExistsProtectsEq.

public void testExistsProtectsEq() {
    Element e = new Element("variable").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("none")).addContent(new Element("relation").addContent("exists")).addContent(new Element("value").addContent("1"))).addContent(new Element("qualifier").addContent(new Element("variableref").addContent("none")).addContent(new Element("relation").addContent("eq")).addContent(new Element("value").addContent("3")));
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(e)));
    // test Exists
    processModifierElements(e, v2);
    Assert.assertFalse(v2.getAvailable());
    jmri.util.JUnitAppender.assertErrorMessage("Arithmetic EQ operation when watched value doesn't exist");
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 50 with Element

use of org.eclipse.xtext.parsetree.reconstr.bug302128.Element in project JMRI by JMRI.

the class QualifierAdderTest method testNotExistsOk0.

public void testNotExistsOk0() {
    Element e = new Element("variable").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("one")).addContent(new Element("relation").addContent("exists")).addContent(new Element("value").addContent("0")));
    // create a JDOM tree with just some elements
    Element root = new Element("decoder-config");
    Document doc = new Document(root);
    doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
    root.addContent(// the sites information here lists all relevant
    new Element("decoder").addContent(new Element("variables").addContent(e)));
    // test Exists
    processModifierElements(e, v2);
    Assert.assertFalse(v2.getAvailable());
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Aggregations

Element (org.jdom2.Element)829 Attribute (org.jdom2.Attribute)76 Document (org.jdom2.Document)75 Test (org.junit.Test)70 File (java.io.File)53 ArrayList (java.util.ArrayList)45 JDOMException (org.jdom2.JDOMException)37 IOException (java.io.IOException)34 HashMap (java.util.HashMap)28 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 List (java.util.List)26 XmlFile (jmri.jmrit.XmlFile)24 SAXBuilder (org.jdom2.input.SAXBuilder)21 Turnout (jmri.Turnout)20 DataConversionException (org.jdom2.DataConversionException)20 DocType (org.jdom2.DocType)19 Editor (jmri.jmrit.display.Editor)18 XMLOutputter (org.jdom2.output.XMLOutputter)18 Namespace (org.jdom2.Namespace)17 Point (java.awt.Point)15