Search in sources :

Example 1 with SimpleNamespaceContext

use of org.custommonkey.xmlunit.SimpleNamespaceContext in project jersey by jersey.

the class WadlBeanParamTest method testBeanParamConstructorInitializedBean.

private void testBeanParamConstructorInitializedBean(String resource) throws Exception {
    final Response response = target("/application.wadl").request().get();
    final Document d = WadlResourceTest.extractWadlAsDocument(response);
    final XPath xp = XPathFactory.newInstance().newXPath();
    final SimpleNamespaceResolver nsContext = new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02");
    xp.setNamespaceContext(nsContext);
    final Diff diff = XMLUnit.compareXML(nodeAsString(xp.evaluate("//wadl:resource[@path='wadlBeanParamReference']/wadl:resource", d, XPathConstants.NODE)), nodeAsString(xp.evaluate("//wadl:resource[@path='" + resource + "']/wadl:resource", d, XPathConstants.NODE)));
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(ImmutableMap.of("wadl", "http://wadl.dev.java.net/2009/02")));
    diff.overrideElementQualifier(elementQualifier);
    XMLAssert.assertXMLEqual(diff, true);
}
Also used : Response(javax.ws.rs.core.Response) XPath(javax.xml.xpath.XPath) Diff(org.custommonkey.xmlunit.Diff) SimpleNamespaceResolver(org.glassfish.jersey.internal.util.SimpleNamespaceResolver) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) Document(org.w3c.dom.Document)

Example 2 with SimpleNamespaceContext

use of org.custommonkey.xmlunit.SimpleNamespaceContext in project camel by apache.

the class Utils method evaluate.

/**
     * Evaluate an XPATH expression.
     *
     * @param xpath
     * @param xml
     * @return
     */
public static String evaluate(final String xpath, final String xml) {
    Map<String, Object> m = new HashMap<String, Object>();
    m.put("svrl", Constants.HTTP_PURL_OCLC_ORG_DSDL_SVRL);
    XpathEngine xpathEngine = XMLUnit.newXpathEngine();
    xpathEngine.setNamespaceContext(new SimpleNamespaceContext(m));
    try {
        return xpathEngine.evaluate(xpath, XMLUnit.buildControlDocument(xml));
    } catch (Exception e) {
        LOG.error("Failed to apply xpath {} on xml {}", xpath, xml);
        throw new RuntimeCamelException(e);
    }
}
Also used : HashMap(java.util.HashMap) XpathEngine(org.custommonkey.xmlunit.XpathEngine) RuntimeCamelException(org.apache.camel.RuntimeCamelException) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 3 with SimpleNamespaceContext

use of org.custommonkey.xmlunit.SimpleNamespaceContext in project sling by apache.

the class ReferenceTypeHintTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();
    Map<String, String> m = new HashMap<String, String>();
    m.put("sv", "http://www.jcp.org/jcr/sv/1.0");
    NamespaceContext ctx = new SimpleNamespaceContext(m);
    XMLUnit.setXpathNamespaceContext(ctx);
    final NameValuePairList props = new NameValuePairList();
    props.add("a", "");
    props.add("jcr:mixinTypes", "mix:referenceable");
    firstCreatedNodeUrl = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props, null, false);
    firstUuid = getProperty(firstCreatedNodeUrl, "jcr:uuid");
    firstPath = getPath(firstCreatedNodeUrl);
    secondCreatedNodeUrl = testClient.createNode(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, props, null, false);
    secondUuid = getProperty(secondCreatedNodeUrl, "jcr:uuid");
    secondPath = getPath(secondCreatedNodeUrl);
}
Also used : HashMap(java.util.HashMap) NamespaceContext(org.custommonkey.xmlunit.NamespaceContext) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) NameValuePairList(org.apache.sling.commons.testing.integration.NameValuePairList)

Example 4 with SimpleNamespaceContext

use of org.custommonkey.xmlunit.SimpleNamespaceContext in project ddf by codice.

the class AbstractTestCompositeGeometry method setupTestClass.

@BeforeClass
public static void setupTestClass() {
    HashMap map = new HashMap();
    map.put("gml", "http://www.opengis.net/gml");
    map.put("georss", "http://www.georss.org/georss");
    NamespaceContext ctx = new SimpleNamespaceContext(map);
    XMLUnit.setXpathNamespaceContext(ctx);
    XMLUnit.setIgnoreWhitespace(true);
}
Also used : HashMap(java.util.HashMap) NamespaceContext(org.custommonkey.xmlunit.NamespaceContext) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) BeforeClass(org.junit.BeforeClass)

Example 5 with SimpleNamespaceContext

use of org.custommonkey.xmlunit.SimpleNamespaceContext in project ddf by codice.

the class TestCswFilterDelegate method setupTestClass.

@BeforeClass
public static void setupTestClass() throws JAXBException, ParseException {
    XMLUnit.setIgnoreWhitespace(true);
    marshaller = JAXB_CONTEXT.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    POS_LIST_GEO_FILTER_PROP_MAP.put(USE_POS_LIST_GEO_FILTER_PROP_MAP_KEY, "true");
    SAMPLE_DISTANCE_GEO_FILTER_PROP_MAP.put(DISTANCE_GEO_FILTER_PROP_MAP_KEY, Double.toString(SAMPLE_DISTANCE));
    SAMPLE_DISTANCE_POS_LIST_GEO_FILTER_PROP_MAP.put(USE_POS_LIST_GEO_FILTER_PROP_MAP_KEY, "true");
    SAMPLE_DISTANCE_POS_LIST_GEO_FILTER_PROP_MAP.put(DISTANCE_GEO_FILTER_PROP_MAP_KEY, Double.toString(SAMPLE_DISTANCE));
    THOUSAND_METER_DISTANCE_GEO_FILTER_PROP_MAP.put(DISTANCE_GEO_FILTER_PROP_MAP_KEY, "1000.0");
    // XPath query support.
    HashMap<String, String> map = new HashMap<>();
    map.put("", "http://www.opengis.net/cat/csw/2.0.2");
    map.put("ogc", "http://www.opengis.net/ogc");
    NamespaceContext ctx = new SimpleNamespaceContext(map);
    XMLUnit.setXpathNamespaceContext(ctx);
}
Also used : HashMap(java.util.HashMap) NamespaceContext(org.custommonkey.xmlunit.NamespaceContext) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) BeforeClass(org.junit.BeforeClass)

Aggregations

SimpleNamespaceContext (org.custommonkey.xmlunit.SimpleNamespaceContext)8 HashMap (java.util.HashMap)7 NamespaceContext (org.custommonkey.xmlunit.NamespaceContext)6 BeforeClass (org.junit.BeforeClass)4 Response (javax.ws.rs.core.Response)1 XPath (javax.xml.xpath.XPath)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 NameValuePairList (org.apache.sling.commons.testing.integration.NameValuePairList)1 Diff (org.custommonkey.xmlunit.Diff)1 XpathEngine (org.custommonkey.xmlunit.XpathEngine)1 SimpleNamespaceResolver (org.glassfish.jersey.internal.util.SimpleNamespaceResolver)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Document (org.w3c.dom.Document)1