Examples of ODOMXPath


Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

    /**
     * Tests multi-step path creation where the path is absolute and the
     * context is not valid for the absolute path given.
     */
    public void testCreateWithAbsolutePathBadContext() throws Exception {
        ODOMXPath path = new ODOMXPath("/catalog/cd[6]/title/text()");

        // This will demonstrate invalid application of an absolute path
        // (the context is not appropriate to the absolute path because its
        // name doesn't match the first step in the absolute path)
        try {
            ODOMElement cd = (ODOMElement) root.getChild("cd");
            path.create(cd, factory);

            fail("Should have received an XPathException");
        } catch (XPathException e) {
            // Expected condition
        }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

     * Test the creation of an ODOMXPath.
     */
    public void testCreateSimple() throws Exception {
        // Check when element does not exist.
        String elementName = "newElement";
        ODOMXPath path = new ODOMXPath(elementName);
        ODOMObservable result = path.create((ODOMElement) root, factory);
        assertNotNull("Result should not be null", result);
        assertTrue("Type should match", result instanceof Element);
        assertEquals("Value should match", elementName,
                     ((Element) result).getName());

        // Check when attribute does not exist.
        path = new ODOMXPath("newElement/@attribute");
        result = path.create((ODOMElement) root, factory);
        assertNotNull("Result should not be null", result);
        assertTrue("Type should match", result instanceof Attribute);
        assertEquals("Value should match", "attribute",
                     ((Attribute) result).getName());
        assertEquals("Value should match", "",
                     ((Attribute) result).getValue());

        // Check when text does not exist.
        path = new ODOMXPath("newElement/text()");
        result = path.create((ODOMElement) root, factory);

        assertNotNull("Result should not be null", result);
        assertTrue("Type should match", result instanceof Text);
        assertEquals("Value should match", "",
                     ((Text) result).getText());
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

     * Test the creation of an ODOMXPath.
     */
    public void testCreateWithNamespace() throws Exception {
        // Check when element does not exist.
        String elementName = "ns1:newElement/notNamespaced/ns1:namespaced";
        ODOMXPath path = new ODOMXPath(elementName);
        ODOMObservable result = null;
        try {
            result = path.create((ODOMElement) root, factory);
            fail("Expected IllegalStateException (no namespaces set)");
        } catch (IllegalStateException e) {
        }
        path = new ODOMXPath(elementName, NAMESPACES);
        result = path.create((ODOMElement) root, factory);
        assertNotNull("Result should not be null", result);
        assertTrue("Type should match", result instanceof Element);
        assertEquals("Value should match", "namespaced",
                     ((Element) result).getName());
        assertEquals("Value should match", "ns1",
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

     * Test the creation of an ODOMXPath.
     */
    public void testCreateWithNamespaceExists() throws Exception {
        // Check when element does not exist.
        String elementName = "ns1:newElement";
        ODOMXPath path = new ODOMXPath(elementName);
        ODOMObservable result = null;
        try {
            result = path.create((ODOMElement) root, factory);
            fail("Expected IllegalStateException (no namespaces set)");
        } catch (IllegalStateException e) {
        }
        path = new ODOMXPath(elementName, NAMESPACES);
        result = path.create((ODOMElement) root, factory);
        assertNull("Result should be null", result);
    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

     * Test the creation of an ODOMXPath.
     */
    public void testCreateWithPredicateNoneExist() throws Exception {
        // Check when element does not exist.
        String elementName = "predicateElement[4]";
        ODOMXPath path = new ODOMXPath(elementName);
        ODOMObservable result = null;
        result = path.create((ODOMElement) root, factory);
        assertNotNull("Result should not be null", result);
        assertTrue("Type should match", result instanceof Element);
        assertEquals("Value should match", "predicateElement",
                     ((Element) result).getName());

        assertNotNull("Should now be in the ODOM",
                      path.selectSingleNode((ODOMElement) root));


    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

     * Test the creation of an ODOMXPath.
     */
    public void testCreateWithPredicateForText() throws Exception {
        // Check when element does not exist.
        String path = "cd[1]/title/text()[2]";
        ODOMXPath xpath = new ODOMXPath(path);
        ODOMObservable result = xpath.create((ODOMElement) root, factory);

        assertNotNull("Result should not be null", result);
        assertTrue("Type should match", result instanceof Text);
        ((Text) result).setText("Garbage");
        //showDocument();
        assertNotNull("Should now be in the ODOM",
                      xpath.selectSingleNode((ODOMElement) root));

    }
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

     */
    public void testSelectSingleNodeWithNamespaces() throws Exception {

        // select the newElement node in the
        // http://www.w3.org/2001/XMLSchema namespace.
        ODOMXPath xpath = new ODOMXPath("ns1:newElement", NAMESPACES);
        ODOMObservable node = xpath.selectSingleNode((ODOMObservable) root);

        // ensure the node is not null
        assertNotNull("node selected was null", node);

        // should have returned a ODOMElement
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

        // select the newElement node in the
        // http://www.w3.org/2001/XMLSchema namespace.

        // use a different prefix (same URI) to that in the DOM
        ODOMXPath xpath = new ODOMXPath("p:newElement", new Namespace[]{
            Namespace.getNamespace("p", "http://www.w3.org/2001/XMLSchema")
        });

        ODOMObservable node = xpath.selectSingleNode((ODOMObservable) root);

        // ensure the node is not null
        assertNotNull("node selected was null", node);

        // should have returned a ODOMElement
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

     *
     * @throws Exception if an error occurs
     */
    public void testSelectElementNode() throws Exception {

        ODOMXPath xpath = new ODOMXPath("cd[1]");
        // select the first cd element
        Element element = xpath.selectSingleElement(root);

        // ensure the node is not null
        assertNotNull("node selected was null", element);

        // check the name of the element
View Full Code Here

Examples of com.volantis.mcs.eclipse.common.odom.xpath.ODOMXPath

     * @throws Exception if an error occurs
     */
    public void testSelectElementNodeNoElement() throws Exception {

        // xpath to an attribute
        ODOMXPath xpath = new ODOMXPath("cd[1]/@country");

        try {
            // select the xpath. We expect an element
            xpath.selectSingleElement(root);
            fail("Expected an excpetion as xpath is to an attribute");
        } catch (XPathException e) {
            // expected
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.