本文整理汇总了Java中org.custommonkey.xmlunit.XMLUnit.buildControlDocument方法的典型用法代码示例。如果您正苦于以下问题:Java XMLUnit.buildControlDocument方法的具体用法?Java XMLUnit.buildControlDocument怎么用?Java XMLUnit.buildControlDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.custommonkey.xmlunit.XMLUnit
的用法示例。
在下文中一共展示了XMLUnit.buildControlDocument方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEntityType
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
@Test
public void testEntityType() throws XpathException, IOException, SAXException {
EdmEntityType.Builder productBuilder = EdmEntityType.newBuilder();
productBuilder = productBuilder.setName("Product").setOpenType(OPENTYPE_TRUE).addKeys("ProductId");
EdmSchema.Builder schema = EdmSchema.newBuilder().setNamespace(SCHEMA);
schema.addEntityTypes(productBuilder);
EdmDataServices.Builder serviceBuilder = EdmDataServices.newBuilder().addSchemas(schema);
EdmDataServices edmService = serviceBuilder.build();
StringWriter writer = new StringWriter();
EdmxFormatWriter.write(edmService, writer);
String xml2 = writer.toString();
assertThat(xml2, containsString("<EntityType OpenType=\"true\" Name=\"Product\">"));
Document inDocument = XMLUnit.buildControlDocument(xml2);
assertXpathExists("//edm:Schema/edm:EntityType/@OpenType", xml2);
}
示例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));
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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());
}
示例10: assertXmlEqual
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
/**
* Parse the expected and actual content strings as XML and assert that the
* two are "similar" -- i.e. they contain the same elements and attributes
* regardless of order.
* <p>Use of this method assumes the
* <a href="http://xmlunit.sourceforge.net/">XMLUnit<a/> library is available.
* @param expected the expected XML content
* @param actual the actual XML content
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Object...)
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Map, Object...)
*/
public void assertXmlEqual(String expected, String actual) throws Exception {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
Document control = XMLUnit.buildControlDocument(expected);
Document test = XMLUnit.buildTestDocument(actual);
Diff diff = new Diff(control, test);
if (!diff.similar()) {
AssertionErrors.fail("Body content " + diff.toString());
}
}
示例11: invoke
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
@Override
public String invoke(CallingContext ctx) {
try {
XMLUnit.buildControlDocument("<x></x>");
} catch (SAXException | IOException e) {
e.printStackTrace();
}
return String.valueOf(++x1);
}
示例12: toDoc
import org.custommonkey.xmlunit.XMLUnit; //导入方法依赖的package包/类
public static Document toDoc(String aXmlString) throws Exception {
return XMLUnit.buildControlDocument(aXmlString);
}
示例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)));
}