All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.centurylink.mdw.xml.XmlPathTest Maven / Gradle / Ivy

There is a newer version: 6.1.39
Show newest version
/*
 * Copyright (C) 2017 CenturyLink, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.centurylink.mdw.xml;

import org.apache.xmlbeans.XmlObject;

import junit.framework.TestCase;

public class XmlPathTest extends TestCase {
    
    private static String xml1 = 
        " asf\nSTART";
    private static String xml2 = "" +
    "" +
    "   " +
    "     " +
    "  " +
    "";
    
    private void runCase(String xml, String xpath, String expected)
        throws Exception {
        XmlObject xmlBean = XmlObject.Factory.parse(xml);
        XmlPath path = new XmlPath(xpath);
        String actual = path.evaluate(xmlBean);
        assertEquals(expected, actual);
    }

    public void testCase1() throws Exception {
        
        String xpath = "//G[H=asf]";
        String expected = " asf\n";
        runCase(xml1, xpath, expected);
    }
    
    public void testCase2() throws Exception {
        String xpath = "/Ping/@id";
        String expected = "MyId";
        runCase(xml1, xpath, expected);
    }
    
    public void testCase3() throws Exception {
        String xpath = "//@id";
        String expected = "MyId";
        runCase(xml1, xpath, expected);
    }
    
    public void testCase4() throws Exception {
        String xpath = "ActivationMessage/@activationId";
        String expected = "567834";
        runCase(xml2, xpath, expected);
    }
    
    public void testCase5() throws Exception {
        String xpath = "/ActivationMessage/@activationId";
        String expected = "567834";
        runCase(xml2, xpath, expected);
    }
    
    public void testCase6() throws Exception {
        String xpath = "//ActivationMessage/@activationId";
        String expected = "567834";
        runCase(xml2, xpath, expected);
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy