當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLUnit.newXpathEngine方法代碼示例

本文整理匯總了Java中org.custommonkey.xmlunit.XMLUnit.newXpathEngine方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLUnit.newXpathEngine方法的具體用法?Java XMLUnit.newXpathEngine怎麽用?Java XMLUnit.newXpathEngine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.custommonkey.xmlunit.XMLUnit的用法示例。


在下文中一共展示了XMLUnit.newXpathEngine方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: removeIgnoredBranches

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的package包/類
public Document removeIgnoredBranches(Document document) {
	for (String branch : getIgnoredBranches()) {
        XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine();
        
        NodeList nodeList;
		try {
			nodeList = simpleXpathEngine.getMatchingNodes(branch, document);
			for (int i = 0; i < nodeList.getLength(); i++) {
				Node parentNode = nodeList.item(i).getParentNode();
				parentNode.removeChild(nodeList.item(i));
			}
		} catch (XpathException e) {
			e.printStackTrace(); // FIXME : remove printStackTrace()
		}
	}
	return document;
}
 
開發者ID:fastconnect,項目名稱:tibco-fcunit,代碼行數:18,代碼來源:FCDiff.java

示例2: forTopics

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的package包/類
@Test
public void forTopics() throws Exception {
	Forum forum = new Forum(); forum.setId(1); forum.setName("forum x"); forum.setDescription("forum description");

	when(forumRepository.get(forum.getId())).thenReturn(forum);
	when(config.getInt(ConfigKeys.TOPICS_PER_PAGE)).thenReturn(10);
	when(rssRepository.getForumTopics(forum, 10)).thenReturn(Arrays.asList(newTopic(1, "topic 1", 1, "post text 1")));
	when(i18n.params("forum x")).thenReturn(new Object[] { "forum x" });
	when(i18n.getFormattedMessage("RSS.ForumTopics.title", new Object[] { "forum x" })).thenReturn("channel title");
	when(config.getValue(ConfigKeys.RSS_DATE_TIME_FORMAT)).thenReturn("EEE, d MMM yyyy HH:mm:ss");
	when(config.getString(ConfigKeys.FORUM_LINK)).thenReturn("http://site.link/");
	String result = service.forForum(1);

	XpathEngine xpath = XMLUnit.newXpathEngine();
	Document document = XMLUnit.buildControlDocument(result);

	assertEquals("forum description", xpath.evaluate("//channel/description", document));
	assertEquals("http://site.link/forums/show/1.page", xpath.evaluate("//channel/link", document));
	assertEquals("channel title", xpath.evaluate("//channel/title", document));
	assertEquals("post text 1", xpath.evaluate("//channel/item/description", document));
	assertEquals("http://site.link/topics/preList/1/1.page", xpath.evaluate("//channel/item/link", document));
	assertEquals("topic 1", xpath.evaluate("//channel/item/title", document));
}
 
開發者ID:eclipse123,項目名稱:JForum,代碼行數:24,代碼來源:RSSServiceTestCase.java

示例3: testLoanRequestAccepted

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例4: testLoanRequestUnableToHandle

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例5: testDeployment

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例6: testLoanRequestAccepted

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例7: testLoanRequestUnableToHandle

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例8: testSayHello

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例9: assertXpathEvaluatesTo

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例10: evaluate

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例11: initializeXmlUnit

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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

示例12: getXpathEngine

import org.custommonkey.xmlunit.XMLUnit; //導入方法依賴的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.XMLUnit; //導入方法依賴的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.XMLUnit.newXpathEngine方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。