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


Java NamespaceContext类代码示例

本文整理汇总了Java中org.custommonkey.xmlunit.NamespaceContext的典型用法代码示例。如果您正苦于以下问题:Java NamespaceContext类的具体用法?Java NamespaceContext怎么用?Java NamespaceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setUp

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:26,代码来源:ReferenceTypeHintTest.java

示例2: testLoanRequestAccepted

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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

示例3: testLoanRequestUnableToHandle

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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

示例4: testDeployment

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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

示例5: testLoanRequestAccepted

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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

示例6: testLoanRequestUnableToHandle

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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

示例7: testSayHello

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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

示例8: turnIntoMap

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的package包/类
static Map<String, String> turnIntoMap(NamespaceContext ctx) {
    Map<String, String> m = new HashMap<String, String>();
    for (Iterator i = ctx.getPrefixes(); i.hasNext(); ) {
        String prefix = (String) i.next();
        String uri = ctx.getNamespaceURI(prefix);
        // according to the Javadocs only the constants defined in
        // XMLConstants are allowed as prefixes for the following
        // two URIs
        if (!XMLConstants.XML_NS_URI.equals(uri)
            && !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(uri)) {
            m.put(prefix, uri);
        }
    }
    m.put(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI);
    m.put(XMLConstants.XMLNS_ATTRIBUTE,
          XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
    return m;
}
 
开发者ID:xmlunit,项目名称:xmlunit,代码行数:19,代码来源:XMLUnitNamespaceContext2Jaxp13.java

示例9: setUp

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
  super.setUp();
  Injector injector = Guice.createInjector(new SocialApiTestsGuiceModule());

  servlet = new DataServiceServlet();

  HandlerRegistry dispatcher = injector.getInstance(HandlerRegistry.class);
  dispatcher.addHandlers(injector.getInstance(Key.get(new TypeLiteral<Set<Object>>(){},
      Names.named("org.apache.shindig.social.handlers"))));
  servlet.setHandlerRegistry(dispatcher);
  servlet.setBeanConverters(new BeanJsonConverter(injector),
      new BeanXStreamConverter(new XStream081Configuration(injector)),
      new BeanXStreamAtomConverter(new XStream081Configuration(injector)));

  res = EasyMock.createMock(HttpServletResponse.class);
  NamespaceContext ns = new SimpleNamespaceContext(ImmutableMap.of("", "http://ns.opensocial.org/2008/opensocial"));
  XMLUnit.setXpathNamespaceContext(ns);
  xp = XMLUnit.newXpathEngine();
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:21,代码来源:AbstractLargeRestfulTests.java

示例10: assertXpathEvaluatesTo

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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

示例11: initializeXmlUnit

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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: writeValidMetadata

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的package包/类
@Test
public void writeValidMetadata() throws Exception {
  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  annotationElements.add(new AnnotationElement().setName("test").setText("hallo"));
  Schema schema = new Schema().setAnnotationElements(annotationElements);
  schema.setNamespace("http://namespace.com");
  schemas.add(schema);

  DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
  OutputStreamWriter writer = null;
  CircleStreamBuffer csb = new CircleStreamBuffer();
  writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
  XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
  XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  String metadata = StringHelper.inputStreamToString(csb.getInputStream());
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/a:test", metadata);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:28,代码来源:XmlMetadataProducerTest.java

示例13: writeValidMetadata4

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的package包/类
@Test
public void writeValidMetadata4() throws Exception {

  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
  attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self"));
  attributesElement1.add(new AnnotationAttribute().setName("href").setText("link"));

  List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
  schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
  schemaElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));

  Schema schema = new Schema().setAnnotationElements(schemaElements);
  schema.setNamespace("http://namespace.com");
  schemas.add(schema);

  DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
  OutputStreamWriter writer = null;
  CircleStreamBuffer csb = new CircleStreamBuffer();
  writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
  XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
  XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
  String metadata = StringHelper.inputStreamToString(csb.getInputStream());

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
  prefixMap.put("atom", "http://www.w3.org/2005/Atom");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest2", metadata);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:39,代码来源:XmlMetadataProducerTest.java

示例14: writeValidMetadata5

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的package包/类
@Test
public void writeValidMetadata5() throws Exception {

  List<Schema> schemas = new ArrayList<Schema>();

  List<AnnotationAttribute> attributesElement1 = new ArrayList<AnnotationAttribute>();
  attributesElement1.add(new AnnotationAttribute().setName("rel").setText("self").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom"));
  attributesElement1.add(new AnnotationAttribute().setName("href").setText("link").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom"));

  List<AnnotationElement> schemaElements = new ArrayList<AnnotationElement>();
  schemaElements.add(new AnnotationElement().setName("schemaElementTest1").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));
  schemaElements.add(new AnnotationElement().setName("schemaElementTest2").setPrefix("atom").setNamespace(
      "http://www.w3.org/2005/Atom").setAttributes(attributesElement1));

  Schema schema = new Schema().setAnnotationElements(schemaElements);
  schema.setNamespace("http://namespace.com");
  schemas.add(schema);

  DataServices data = new DataServices().setSchemas(schemas).setDataServiceVersion(ODataServiceVersion.V20);
  OutputStreamWriter writer = null;
  CircleStreamBuffer csb = new CircleStreamBuffer();
  writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8");
  XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer);
  XmlMetadataProducer.writeMetadata(data, xmlStreamWriter, null);
  String metadata = StringHelper.inputStreamToString(csb.getInputStream());

  Map<String, String> prefixMap = new HashMap<String, String>();
  prefixMap.put("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
  prefixMap.put("a", "http://schemas.microsoft.com/ado/2008/09/edm");
  prefixMap.put("atom", "http://www.w3.org/2005/Atom");

  NamespaceContext ctx = new SimpleNamespaceContext(prefixMap);
  XMLUnit.setXpathNamespaceContext(ctx);

  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest1", metadata);
  assertXpathExists("/edmx:Edmx/edmx:DataServices/a:Schema/atom:schemaElementTest2", metadata);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:41,代码来源:XmlMetadataProducerTest.java

示例15: assertXpathEvaluatesTo

import org.custommonkey.xmlunit.NamespaceContext; //导入依赖的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


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