当前位置: 首页>>代码示例>>Java>>正文


Java XpathEngine.setNamespaceContext方法代码示例

本文整理汇总了Java中org.custommonkey.xmlunit.XpathEngine.setNamespaceContext方法的典型用法代码示例。如果您正苦于以下问题:Java XpathEngine.setNamespaceContext方法的具体用法?Java XpathEngine.setNamespaceContext怎么用?Java XpathEngine.setNamespaceContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.custommonkey.xmlunit.XpathEngine的用法示例。


在下文中一共展示了XpathEngine.setNamespaceContext方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testLoanRequestAccepted

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testLoanRequestAccepted() throws Exception {
    HTTPMixIn httpMixIn = new HTTPMixIn();
    httpMixIn.initialize();
    try {
        String port = System.getProperty("org.switchyard.component.soap.standalone.port", "8181/cxf");
        String response = httpMixIn.postString("http://localhost:" + port + "/loanService/loanService", SOAP_REQUEST_1);

        org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
        java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
        m.put("tns", "http://example.com/loan-approval/loanService/");
        NamespaceContext ctx = new SimpleNamespaceContext(m);
        XpathEngine engine = XMLUnit.newXpathEngine();
        engine.setNamespaceContext(ctx);

        NodeList l = engine.getMatchingNodes("//tns:accept", d);
        assertEquals(1, l.getLength());
        assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
        
        if (!l.item(0).getTextContent().equals("yes")) {
            fail("Expecting 'yes'");
        }
    } finally {
        httpMixIn.uninitialize();
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:27,代码来源:BpelServiceLoanApprovalQuickstartTest.java

示例2: testLoanRequestUnableToHandle

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testLoanRequestUnableToHandle() throws Exception {
    HTTPMixIn httpMixIn = new HTTPMixIn();
    httpMixIn.initialize();
    try {
        String response = httpMixIn.postString("http://localhost:" + getSoapClientPort() + "/loanService/loanService", SOAP_REQUEST_2);

        org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
        java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
        //m.put("tns", "http://example.com/loan-approval/loanService/");
        NamespaceContext ctx = new SimpleNamespaceContext(m);
        XpathEngine engine = XMLUnit.newXpathEngine();
        engine.setNamespaceContext(ctx);

        NodeList l = engine.getMatchingNodes("//faultcode", d);
        assertEquals(1, l.getLength());
        assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
        
        if (!l.item(0).getTextContent().endsWith(":unableToHandleRequest")) {
            fail("Expecting 'unableToHandleRequest' fault code");
        }
    } finally {
        httpMixIn.uninitialize();
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:26,代码来源:BpelServiceLoanApprovalQuickstartTest.java

示例3: testDeployment

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Override
@Test
public void testDeployment() throws Exception {
    HTTPMixIn httpMixIn = new HTTPMixIn();
    httpMixIn.initialize();
    try {
        String response = httpMixIn.postString("http://localhost:" + getSoapClientPort() + "/SayHelloService/SayHelloService", SOAP_REQUEST);

        org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
        java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
        m.put("tns", "http://www.jboss.org/bpel/examples");
        NamespaceContext ctx = new SimpleNamespaceContext(m);
        XpathEngine engine = XMLUnit.newXpathEngine();
        engine.setNamespaceContext(ctx);

        NodeList l = engine.getMatchingNodes("//tns:result", d);
        assertEquals(1, l.getLength());
        assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
        
        if (!l.item(0).getTextContent().equals("Hello Fred")) {
            fail("Expecting 'Hello Fred'");
        }
    } finally {
        httpMixIn.uninitialize();
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:27,代码来源:BpelServiceSayHelloQuickstartTest.java

示例4: testLoanRequestAccepted

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testLoanRequestAccepted() throws Exception {
    HTTPMixIn httpMixIn = new HTTPMixIn();
    httpMixIn.initialize();
    try {
        String response = httpMixIn.postString("http://localhost:8080/loanService/loanService", SOAP_REQUEST_1);

        org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
        java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
        m.put("tns", "http://example.com/loan-approval/loanService/");
        NamespaceContext ctx = new SimpleNamespaceContext(m);
        XpathEngine engine = XMLUnit.newXpathEngine();
        engine.setNamespaceContext(ctx);

        NodeList l = engine.getMatchingNodes("//tns:accept", d);
        assertEquals(1, l.getLength());
        assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
        
        if (!l.item(0).getTextContent().equals("yes")) {
            fail("Expecting 'yes'");
        }
    } finally {
        httpMixIn.uninitialize();
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:26,代码来源:BpelServiceLoanApprovalQuickstartTest.java

示例5: testLoanRequestUnableToHandle

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testLoanRequestUnableToHandle() throws Exception {
    HTTPMixIn httpMixIn = new HTTPMixIn();
    httpMixIn.initialize();
    try {
        String response = httpMixIn.postString("http://localhost:8080/loanService/loanService", SOAP_REQUEST_2);

        org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
        java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
        //m.put("tns", "http://example.com/loan-approval/loanService/");
        NamespaceContext ctx = new SimpleNamespaceContext(m);
        XpathEngine engine = XMLUnit.newXpathEngine();
        engine.setNamespaceContext(ctx);

        NodeList l = engine.getMatchingNodes("//faultcode", d);
        assertEquals(1, l.getLength());
        assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
        
        if (!l.item(0).getTextContent().endsWith(":unableToHandleRequest")) {
            fail("Expecting 'unableToHandleRequest' fault code");
        }
    } finally {
        httpMixIn.uninitialize();
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:26,代码来源:BpelServiceLoanApprovalQuickstartTest.java

示例6: testSayHello

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void testSayHello() throws Exception {
	HTTPMixIn httpMixIn = new HTTPMixIn();
	httpMixIn.initialize();
	try {
		String response = httpMixIn.postString("http://localhost:8080/SayHelloService/SayHelloService", SOAP_REQUEST);

		org.w3c.dom.Document d = XMLUnit.buildControlDocument(response);
        java.util.HashMap<String,String> m = new java.util.HashMap<String,String>();
        m.put("tns", "http://www.jboss.org/bpel/examples");
	    NamespaceContext ctx = new SimpleNamespaceContext(m);
	    XpathEngine engine = XMLUnit.newXpathEngine();
	    engine.setNamespaceContext(ctx);

	    NodeList l = engine.getMatchingNodes("//tns:result", d);
	    assertEquals(1, l.getLength());
	    assertEquals(org.w3c.dom.Node.ELEMENT_NODE, l.item(0).getNodeType());
	    
	    if (!l.item(0).getTextContent().equals("Hello Fred")) {
	        fail("Expecting 'Hello Fred'");
	    }
	} finally {
		httpMixIn.uninitialize();
	}
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:26,代码来源:BpelServiceSayHelloQuickstartTest.java

示例7: assertXpathEvaluatesTo

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
/**
 * Assert the values of xpath expression evaluation is exactly the same as expected value.
 * <p>The xpath may contain the xml namespace prefixes, since namespaces from flight example
 * are being registered.
 * @param msg the error message that will be used in case of test failure
 * @param expected the expected value
 * @param xpath the xpath to evaluate
 * @param xmlDoc the xml to use
 * @throws Exception if any error occurs during xpath evaluation
 */
private void assertXpathEvaluatesTo(String msg, String expected, String xpath, String xmlDoc) throws Exception {
	Map<String, String> namespaces = new HashMap<String, String>();
	namespaces.put("tns", "http://samples.springframework.org/flight");
	namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");

	NamespaceContext ctx = new SimpleNamespaceContext(namespaces);
	XpathEngine engine = XMLUnit.newXpathEngine();
	engine.setNamespaceContext(ctx);

	Document doc = XMLUnit.buildControlDocument(xmlDoc);
	NodeList node = engine.getMatchingNodes(xpath, doc);
	assertEquals(msg, expected, node.item(0).getNodeValue());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:CastorMarshallerTests.java

示例8: evaluate

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:Utils.java

示例9: initializeXmlUnit

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
private static void initializeXmlUnit() {
  HashMap<String, String> m = new HashMap<String, String>();
  m.put("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
  m.put("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
  m.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  m.put("g", "http://www.w3.org/2005/Atom"); // 'g' is a dummy for global namespace

  NamespaceContext ctx = new SimpleNamespaceContext(m);
  XMLUnit.setXpathNamespaceContext(ctx);
  XpathEngine engine = XMLUnit.newXpathEngine();
  engine.setNamespaceContext(ctx);
}
 
开发者ID:teiid,项目名称:oreva,代码行数:13,代码来源:ServiceOperationsTest.java

示例10: assertXpathEvaluatesTo

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
/**
 * Asserts the values of xpath expression evaluation is exactly the same as expected value. </p> The xpath may contain
 * the xml namespace prefixes, since namespaces from flight example are being registered.
 *
 * @param msg the error message that will be used in case of test failure
 * @param expected the expected value
 * @param xpath the xpath to evaluate
 * @param xmlDoc the xml to use
 * @throws Exception if any error occurs during xpath evaluation
 */
private void assertXpathEvaluatesTo(String msg, String expected, String xpath, String xmlDoc) throws Exception {
	Map<String, String> namespaces = new HashMap<String, String>();
	namespaces.put("tns", "http://samples.springframework.org/flight");
	namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");

	NamespaceContext ctx = new SimpleNamespaceContext(namespaces);
	XpathEngine engine = XMLUnit.newXpathEngine();
	engine.setNamespaceContext(ctx);

	Document doc = XMLUnit.buildControlDocument(xmlDoc);
	NodeList node = engine.getMatchingNodes(xpath, doc);
	assertEquals(msg, expected, node.item(0).getNodeValue());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:CastorMarshallerTests.java

示例11: validateQueryUsingIdAttribute

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
protected void validateQueryUsingIdAttribute(InputStream query, InputStream expectedResults) {
String actualResults = executeQuery(query) ;
String xpath = "//ns1:Attribute[@name='id']/@value" ;
Map<String, String> ns = new HashMap<String, String>() ;
ns.put("ns1", "http://CQL.caBIG/1/gov.nih.nci.cagrid.CQLResultSet") ;
NamespaceContext ctx = new SimpleNamespaceContext(ns) ;
XpathEngine engine = XMLUnit.newXpathEngine() ;
engine.setNamespaceContext(ctx) ;
try { 
    NodeList controlList = engine.getMatchingNodes(xpath, XMLUnit.buildControlDocument(asString(expectedResults))) ;
    Set<String> controlIds = new HashSet<String>() ;
    for (int i = 0; i < controlList.getLength(); i++) {
	controlIds.add(controlList.item(i).getNodeValue()) ;
    }
    
    NodeList testList = engine.getMatchingNodes(xpath, XMLUnit.buildControlDocument(actualResults)) ;
    Set<String> testIds = new HashSet<String>() ;
    for (int i = 0; i < testList.getLength(); i++) {
	testIds.add(testList.item(i).getNodeValue()) ;
    }

    assertTrue(controlIds.containsAll(testIds)) ;
    assertTrue(testIds.containsAll(controlIds)) ;
} catch (Exception e) {
    throw new RuntimeException("Exception while comparing ID attributes.", e) ;
}
   }
 
开发者ID:NCIP,项目名称:digital-model-repository,代码行数:28,代码来源:CvitDataServiceTests.java

示例12: getXpathEngine

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
public static XpathEngine getXpathEngine() {
    final NamespaceContext context = new SimpleNamespaceContext(Collections.singletonMap("itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd"));
    final XpathEngine engine = XMLUnit.newXpathEngine();
    engine.setNamespaceContext(context);
    return engine;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:7,代码来源:XmlUtils.java

示例13: test_createFromClass

import org.custommonkey.xmlunit.XpathEngine; //导入方法依赖的package包/类
@Test
public void test_createFromClass() throws Exception {
    JAXBUnmarshalTransformer unmarshalTransformer = new JAXBUnmarshalTransformer(
            new QName("purchaseOrder"), JavaTypes.toMessageType(POType.class), null, true);

    JAXBMarshalTransformer marshalTransformer = new JAXBMarshalTransformer(
            JavaTypes.toMessageType(POType.class), new QName("purchaseOrder"), null, true, true);

    DefaultMessage message = new DefaultMessage();
    message.setContent(new StreamSource(new StringReader(PO_XML)));
    message.addAttachment("cid:coverphoto.jpg", new DataSource() {
        @Override
        public InputStream getInputStream() throws IOException {
            return Classes.getResourceAsStream(IMG_FILE_PATH);
        }
        @Override
        public OutputStream getOutputStream() throws IOException {
            throw new IOException("Not supported");
        }
        @Override
        public String getContentType() {
            return "application/octet-stream";
        }
        @Override
        public String getName() {
            return "cid:coverphoto.jpg";
        }
    });

    // Transform XML to Java POType
    unmarshalTransformer.transform(message);
    
    // Check if the attachment is successfully mapped into JAXB object
    Object unmarshalledPOType = message.getContent();
    Assert.assertEquals(POType.class, unmarshalledPOType.getClass());
    for (Item i : ((POType)unmarshalledPOType).getItems().getItem()) {
        if (i.getPartNumber().equals("242-GZ")) {
            Assert.assertNotNull("A coverPhoto for 242-GZ must not be null", i.getCoverPhoto());
            compareCoverPhoto(Classes.getResourceAsStream(IMG_FILE_PATH), i.getCoverPhoto().getInputStream());
        } else {
            Assert.assertNull("A coverPhoto for " + i.getPartNumber() + " must be null, but was :" + i.getCoverPhoto(), i.getCoverPhoto());
        }
    }
    
    // Transform Java POType back to XML
    logger.info("Attempting JAVA2XML transformation with attachment enabled");
    marshalTransformer.transform(message);
    String resultXML = message.getContent(String.class);
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.compareXML(PO_XML, resultXML);
    //logger.info(String.format("Response:[\n%s]", resultXML));
    XpathEngine xpath = XMLUnit.newXpathEngine();
    HashMap<String,String> ncm = new HashMap<String,String>();
    ncm.put("xop", "http://www.w3.org/2004/08/xop/include");
    xpath.setNamespaceContext(new SimpleNamespaceContext(ncm));
    String href = xpath.evaluate("//purchaseOrder/items/item[@partNum=\"242-GZ\"]/coverPhoto/xop:Include/@href", XMLUnit.buildControlDocument(resultXML));
    DataSource attachment = message.getAttachment(href);
    Assert.assertNotNull(String.format("Attachment '%s' must not be null", href), attachment);
    logger.info(String.format("Found an attachment '%s'", href));
    compareCoverPhoto(Classes.getResourceAsStream(IMG_FILE_PATH), attachment.getInputStream());
    
    // Try POType > XML again with attachment disabled - coverPhoto should be inlined
    message.removeAttachment(href);
    message.setContent(unmarshalledPOType);
    JAXBMarshalTransformer marshalTransformerInline = new JAXBMarshalTransformer(
            JavaTypes.toMessageType(POType.class), new QName("purchaseOrder"), null, false, true);
    logger.info("Attempting JAVA2XML transformation with attachment disabled");
    marshalTransformerInline.transform(message);
    resultXML = message.getContent(String.class);
    //logger.info(String.format("Response:[\n%s]", resultXML));
    Document resultDoc = XMLUnit.buildControlDocument(resultXML);
    href = xpath.evaluate("//purchaseOrder/items/item[@partNum=\"242-GZ\"]/coverPhoto/xop:Include", resultDoc);
    Assert.assertTrue(String.format("xop:Include should not appear, but got [%s]", href), href.trim().isEmpty());
    String coverPhotoB64 = xpath.evaluate("//purchaseOrder/items/item[@partNum=\"242-GZ\"]/coverPhoto", resultDoc);
    Assert.assertTrue(String.format("Inlined coverPhoto data is invalid:[%s]", coverPhotoB64), coverPhotoB64 != null && !coverPhotoB64.trim().isEmpty());
    logger.info(String.format("Found inlined coverPhoto:[%s]", coverPhotoB64));
    compareCoverPhoto(Classes.getResourceAsStream(IMG_FILE_PATH), new ByteArrayInputStream(Base64.decode(coverPhotoB64)));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:79,代码来源:JAXBTransformerTest.java


注:本文中的org.custommonkey.xmlunit.XpathEngine.setNamespaceContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。