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


Java XMLAssert类代码示例

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


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

示例1: ignoresTrailingWhitespace

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
@Test
public void ignoresTrailingWhitespace() throws Exception {
    StringWriter writer = new StringWriter();
    Properties log4jProperties = new Properties();
    log4jProperties.load(getClass().getClassLoader().getResourceAsStream("log4j.issue5.properties"));

    converter.toXml(log4jProperties, writer);

    String expected = readFromStream("log4j.issue5.expected.xml");
    String actual = writer.toString();

    System.out.println(expected);
    System.out.println("=============================");
    System.out.println(actual);

    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setControlEntityResolver(new Log4JEntityResolver());
    XMLUnit.setTestEntityResolver(new Log4JEntityResolver());

    Validator validator = new Validator(actual);
    validator.assertIsValid();

    XMLAssert.assertXMLEqual(expected, actual);
}
 
开发者ID:jroyals,项目名称:log4j-properties-converter,代码行数:25,代码来源:ConvertFromPropertiesToXmlTest.java

示例2: verifyReferences

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
private void verifyReferences(final String referencingNodeUrl) throws Exception {
    final String refCreatedValue = getProperty(referencingNodeUrl, "r");
    final String weakrefCreatedValue = getProperty(referencingNodeUrl, "w");

    final String[] refCreatedValues = getPropertyArray(referencingNodeUrl, "rs");
    final String[] weakrefCreatedValues = getPropertyArray(referencingNodeUrl, "ws");

    assertEquals(firstUuid, refCreatedValue);
    assertEquals(firstUuid, weakrefCreatedValue);
    assertEquals(firstUuid, refCreatedValues[0]);
    assertEquals(firstUuid, weakrefCreatedValues[0]);
    assertEquals(secondUuid, refCreatedValues[1]);
    assertEquals(secondUuid, weakrefCreatedValues[1]);

    final String sysView = getSystemView(referencingNodeUrl);

    XMLAssert.assertXpathEvaluatesTo("Reference", "//sv:property[@sv:name='r']/@sv:type", sysView);
    XMLAssert.assertXpathEvaluatesTo("WeakReference", "//sv:property[@sv:name='w']/@sv:type", sysView);
    XMLAssert.assertXpathEvaluatesTo("Reference", "//sv:property[@sv:name='rs']/@sv:type", sysView);
    XMLAssert.assertXpathEvaluatesTo("WeakReference", "//sv:property[@sv:name='ws']/@sv:type", sysView);
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:22,代码来源:ReferenceTypeHintTest.java

示例3: testConfigurationMerging

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
public void testConfigurationMerging()
    throws Exception
{

    XMLUnit.setNormalizeWhitespace( true );

    InputStream resourceAsStream = getClass().getResourceAsStream( "/components-1.xml" );
    transformer.processResource( "components-1.xml", resourceAsStream,
                                 Collections.<Relocator> emptyList() );
    resourceAsStream.close();
    InputStream resourceAsStream1 = getClass().getResourceAsStream( "/components-2.xml" );
    transformer.processResource( "components-1.xml", resourceAsStream1,
                                 Collections.<Relocator> emptyList() );
    resourceAsStream1.close();
    final InputStream resourceAsStream2 = getClass().getResourceAsStream( "/components-expected.xml" );
    Diff diff = XMLUnit.compareXML(
        IOUtil.toString( resourceAsStream2, "UTF-8" ),
        IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ) );
    //assertEquals( IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ), "UTF-8" ),
    //              IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ).replaceAll("\r\n", "\n") );
    resourceAsStream2.close();
    XMLAssert.assertXMLIdentical( diff, true );
}
 
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:24,代码来源:ComponentsXmlResourceTransformerTest.java

示例4: testWriteSimple

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
@Test
public void testWriteSimple()
    throws Exception
{
    File defaultRepoDir = new File( "src/test/repositories/default-repository" );
    File expectedFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
    String expectedContent = FileUtils.readFileToString( expectedFile, Charset.defaultCharset() );

    ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();

    metadata.setGroupId( "org.apache.maven.shared" );
    metadata.setArtifactId( "maven-downloader" );
    metadata.setVersion( "1.0" );
    metadata.setReleasedVersion( "1.1" );
    metadata.getAvailableVersions().add( "1.0" );
    metadata.getAvailableVersions().add( "1.1" );
    metadata.setLastUpdated( "20061212214311" );

    StringWriter actual = new StringWriter();
    RepositoryMetadataWriter.write( metadata, actual );

    XMLAssert.assertXMLEqual( "XML Contents", expectedContent, actual.toString() );
}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:24,代码来源:RepositoryMetadataWriterTest.java

示例5: testConfigCommandWithDefault

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
@Test (description = "Test with default mock configuration")
public void testConfigCommandWithDefault() throws Exception {
    LOGGER.info("About to send Config command (default), total routes: {}", getProducerTemplate().getCamelContext().getRoutes().size());
    ConfigurationManager configurationManager = MockRegistry.findConfigurationManager();
    Assert.assertNotNull(configurationManager);
    Exchange response = getProducerTemplate().request("jetty:http://localhost:" + getAvailablePort() + "/mock/cmd", exchange -> {
        exchange.getIn().setHeader(Exchange.HTTP_METHOD, ConfigurationManager.HTTP_GET);
        exchange.getIn().setHeader("config", "current");
    });
    String actualConfig = response.getOut().getBody(String.class);
    LOGGER.debug("Got actual: {}", actualConfig);
    Path pathToConfigFile = Paths.get(PathSupport.getPathToTestConfigForMockResources().toString(), "config-1-for-ConfigCommandTest.xml");
    Assert.assertTrue(Files.exists(pathToConfigFile));
    String expectedConfig = new String(Files.readAllBytes(pathToConfigFile));
    LOGGER.debug("Got expected: {}", expectedConfig);
    XMLAssert.assertXMLEqual(expectedConfig, actualConfig);
}
 
开发者ID:Technolords,项目名称:microservice-mock,代码行数:18,代码来源:ConfigCommandTest.java

示例6: testConformness

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
@Test
public void testConformness() throws Exception {
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    StringWriter secStringWriter = new StringWriter();
    XMLStreamWriter secXmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(secStringWriter);
    XMLSecurityEventWriter xmlSecurityEventWriter = new XMLSecurityEventWriter(secXmlStreamWriter);

    StringWriter stdStringWriter = new StringWriter();
    XMLEventWriter stdXmlEventWriter = xmlOutputFactory.createXMLEventWriter(stdStringWriter);

    XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
    XMLStreamReader xmlStreamReader =
        xmlInputFactory.createXMLStreamReader(this.getClass().getClassLoader().getResourceAsStream(
                "org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));

    while (xmlStreamReader.hasNext()) {
        XMLEvent xmlEvent = XMLSecEventFactory.allocate(xmlStreamReader, null);
        xmlSecurityEventWriter.add(xmlEvent);
        stdXmlEventWriter.add(xmlEvent);
        xmlStreamReader.next();
    }

    xmlSecurityEventWriter.close();
    stdXmlEventWriter.close();
    XMLAssert.assertXMLEqual(stdStringWriter.toString(), secStringWriter.toString());
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:27,代码来源:XMLSecurityEventWriterTest.java

示例7: testSetEndpoints

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
public void testSetEndpoints() throws Exception {
    // Create a new Camel context and add an endpoint
    CamelContextFactoryBean camelContext = new CamelContextFactoryBean();
    List<CamelEndpointFactoryBean> endpoints = new LinkedList<CamelEndpointFactoryBean>();
    CamelEndpointFactoryBean endpoint = new CamelEndpointFactoryBean();
    endpoint.setId("endpoint1");
    endpoint.setUri("mock:end");
    endpoints.add(endpoint);
    camelContext.setEndpoints(endpoints);

    // Compare the new context with our reference context
    Reader expectedContext = null;
    try {
        expectedContext = new InputStreamReader(getClass().getResourceAsStream("/org/apache/camel/spring/context-with-endpoint.xml"));
        String createdContext = contextAsString(camelContext);
        XMLUnit.setIgnoreWhitespace(true);
        XMLAssert.assertXMLEqual(expectedContext, new StringReader(createdContext));
    } finally {
        IOHelper.close(expectedContext);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CamelContextFactoryBeanTest.java

示例8: canConvertPropertiesToXmlFormat

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
@Test
public void canConvertPropertiesToXmlFormat() throws IOException, SAXException {
    StringWriter writer = new StringWriter();
    Properties log4jProperties = new Properties();
    log4jProperties.load(getClass().getClassLoader().getResourceAsStream("log4j.issue4.properties"));

    converter.toXml(log4jProperties, writer);

    String expected = readFromStream("log4j.issue4.expected.xml");
    String actual = writer.toString();

    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setControlEntityResolver(new Log4JEntityResolver());
    XMLUnit.setTestEntityResolver(new Log4JEntityResolver());

    Validator validator = new Validator(actual);
    validator.assertIsValid();

    XMLAssert.assertXMLEqual(expected, actual);
}
 
开发者ID:jroyals,项目名称:log4j-properties-converter,代码行数:21,代码来源:ConvertFromPropertiesToXmlTest.java

示例9: testManualDocumentContentModification

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
/**
 * Tests modification of the DocumentContentVO object directly.
 */
@Test public void testManualDocumentContentModification() throws Exception {
	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TestDocumentType");
	document.saveDocumentData();
	
	// fetch it from WorkflowInfo
	DocumentContent content = KewApiServiceLocator.getWorkflowDocumentService().getDocumentContent(document.getDocumentId());
	assertTrue("Should contain default content, was " + content.getFullContent(), KewApiConstants.DEFAULT_DOCUMENT_CONTENT.equals(content.getFullContent()) ||
			KewApiConstants.DEFAULT_DOCUMENT_CONTENT2.equals(content.getFullContent()));
	
	String appContent = "<abcdefg>hijklm n o p</abcdefg>";
	DocumentContentUpdate.Builder contentUpdate = DocumentContentUpdate.Builder.create(content);
	contentUpdate.setApplicationContent(appContent);
	document.updateDocumentContent(contentUpdate.build());
    document.saveDocumentData();
	
	// test that the content on the document is the same as the content we just set
	XMLAssert.assertXMLEqual(appContent, document.getApplicationContent());
	
	// fetch the document fresh and make sure the content is correct
	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
	XMLAssert.assertXMLEqual(appContent, document.getApplicationContent());
	
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:27,代码来源:DocumentContentTest.java

示例10: testTransformation

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
@Test
public void testTransformation() throws Exception {
    ModsDefinition mods = ModsUtils.unmarshalModsType(new StreamSource(DcStreamEditorTest.class.getResource("periodical.xml").toExternalForm()));
    Transformer t = DcUtils.modsTransformer("model:periodical");
    JAXBSource jaxbSource = new JAXBSource(ModsUtils.defaultMarshaller(false),
            new ObjectFactory().createMods(mods));
    StringWriter dump = new StringWriter();
    t.transform(jaxbSource, new StreamResult(dump));
    String toXml = dump.toString();
    System.out.println(toXml);

    HashMap<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("oai_dc", DcStreamEditor.DATASTREAM_FORMAT_URI);
    namespaces.put("dc", "http://purl.org/dc/elements/1.1/");
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='main']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='key']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:title[text()='alternative']", toXml);
    XMLAssert.assertXpathEvaluatesTo("3", "count(/oai_dc:dc/dc:title)", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:creator[text()='Boleslav']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:description[text()='poznámka']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='uuid:40d13cb2-811f-468c-a6d3-1ad6b01f06f7']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='isbn:0eaa6730']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='issn-l:idIssn-l']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='idWitEmptyType']", toXml);
    XMLAssert.assertXpathExists("/oai_dc:dc/dc:identifier[text()='idWithoutType']", toXml);
    // XXX needs more test
}
 
开发者ID:proarc,项目名称:proarc,代码行数:29,代码来源:DcStreamEditorTest.java

示例11: testMarcAsMods

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
@Test
    public void testMarcAsMods() throws Exception {
        XMLUnit.setNormalizeWhitespace(true);
        InputStream goldenIS = TransformersTest.class.getResourceAsStream("alephXServerDetailResponseAsMods.xml");
        assertNotNull(goldenIS);
        InputStream xmlIS = TransformersTest.class.getResourceAsStream("alephXServerDetailResponseAsMarcXml.xml");// from test
        assertNotNull(xmlIS);
        StreamSource streamSource = new StreamSource(xmlIS);
        Transformers mt = new Transformers();

        try {
            byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3);
            assertNotNull(contents);
//            System.out.println(new String(contents, "UTF-8"));
            XMLAssert.assertXMLEqual(new InputSource(goldenIS), new InputSource(new ByteArrayInputStream(contents)));
        } finally {
            close(xmlIS);
            close(goldenIS);
        }
    }
 
开发者ID:proarc,项目名称:proarc,代码行数:21,代码来源:TransformersTest.java

示例12: testMarcAsMods_FrequencyAuthority_Issue181

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
/**
     * Tests mapping of fields 310a and 008/18 to {@code [email protected]}.
     * See issue 118 and 181.
     */
    @Test
    public void testMarcAsMods_FrequencyAuthority_Issue181() throws Exception {
        InputStream xmlIS = TransformersTest.class.getResourceAsStream("frequencyAuthority.xml");
        assertNotNull(xmlIS);
        StreamSource streamSource = new StreamSource(xmlIS);
        Transformers mt = new Transformers();

        try {
            byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3);
            assertNotNull(contents);
            String xmlResult = new String(contents, "UTF-8");
//            System.out.println(xmlResult);
            XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{
                put("m", ModsConstants.NS);
            }}));
            XMLAssert.assertXpathNotExists("/m:mods/m:originInfo/m:frequency[1]/@authority", xmlResult);
            XMLAssert.assertXpathEvaluatesTo("2x ročně", "/m:mods/m:originInfo/m:frequency[1]", xmlResult);
            XMLAssert.assertXpathEvaluatesTo("marcfrequency", "/m:mods/m:originInfo/m:frequency[2]/@authority", xmlResult);
            XMLAssert.assertXpathEvaluatesTo("Semiannual", "/m:mods/m:originInfo/m:frequency[2]", xmlResult);
            validateMods(new StreamSource(new ByteArrayInputStream(contents)));
        } finally {
            close(xmlIS);
        }
    }
 
开发者ID:proarc,项目名称:proarc,代码行数:29,代码来源:TransformersTest.java

示例13: testMarcAsMods_SubjectTopic_Issue185_Issue433

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
/**
     * Tests mapping of field 653 indicator_9 $a to {@code subject/[email protected]}.
     * See issue 185.
     * See issue 433.
     */
    @Test
    public void testMarcAsMods_SubjectTopic_Issue185_Issue433() throws Exception {
        InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_subject_65X_X9.xml");
        assertNotNull(xmlIS);
        StreamSource streamSource = new StreamSource(xmlIS);
        Transformers mt = new Transformers();

        try {
            byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3);
            assertNotNull(contents);
            String xmlResult = new String(contents, "UTF-8");
//            System.out.println(xmlResult);
            XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{
                put("m", ModsConstants.NS);
            }}));
            // 653
            XMLAssert.assertXpathExists("/m:mods/m:subject[not(@authority)]/m:topic[text()='kočky' and @lang='cze']", xmlResult);
            XMLAssert.assertXpathExists("/m:mods/m:subject[not(@authority)]/m:topic[text()='cats' and @lang='eng']", xmlResult);
            XMLAssert.assertXpathNotExists("/m:mods/m:subject/m:name/m:namePart[text()='kočky']", xmlResult);
            XMLAssert.assertXpathNotExists("/m:mods/m:subject/m:name/m:namePart[text()='cats']", xmlResult);
            validateMods(new StreamSource(new ByteArrayInputStream(contents)));
        } finally {
            close(xmlIS);
        }
    }
 
开发者ID:proarc,项目名称:proarc,代码行数:31,代码来源:TransformersTest.java

示例14: testMarcAsMods_Conspectus_Issue303

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
/**
     * Test mapping of 072#7 $x to {@code subject/topic} and $a/$9 to {@code classification}.
     * See issue 303.
     */
    @Test
    public void testMarcAsMods_Conspectus_Issue303() throws Exception {
        InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc.xml");
        assertNotNull(xmlIS);
        StreamSource streamSource = new StreamSource(xmlIS);
        Transformers mt = new Transformers();

        try {
            byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3);
            assertNotNull(contents);
            String xmlResult = new String(contents, "UTF-8");
//            System.out.println(xmlResult);
            XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{
                put("m", ModsConstants.NS);
            }}));
            XMLAssert.assertXpathEvaluatesTo("Umění", "/m:mods/m:subject[@authority='Konspekt']/m:topic", xmlResult);
            XMLAssert.assertXpathEvaluatesTo("7.01/.09", "/m:mods/m:classification[@authority='udc' and @edition='Konspekt']", xmlResult);
            XMLAssert.assertXpathEvaluatesTo("21", "/m:mods/m:classification[@authority='Konspekt']", xmlResult);
            validateMods(new StreamSource(new ByteArrayInputStream(contents)));
        } finally {
            close(xmlIS);
        }
    }
 
开发者ID:proarc,项目名称:proarc,代码行数:28,代码来源:TransformersTest.java

示例15: testMarcAsMods_AbstractLang_Issue434

import org.custommonkey.xmlunit.XMLAssert; //导入依赖的package包/类
/**
     * Tests mapping of field 520 and subfield $9 to {@code [email protected]}.
     * See issue 434.
     */
    @Test
    public void testMarcAsMods_AbstractLang_Issue434() throws Exception {
        InputStream xmlIS = TransformersTest.class.getResourceAsStream("marc_subject_65X_X9.xml");
        assertNotNull(xmlIS);
        StreamSource streamSource = new StreamSource(xmlIS);
        Transformers mt = new Transformers();

        try {
            byte[] contents = mt.transformAsBytes(streamSource, Transformers.Format.MarcxmlAsMods3);
            assertNotNull(contents);
            String xmlResult = new String(contents, "UTF-8");
//            System.out.println(xmlResult);
            XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(new HashMap() {{
                put("m", ModsConstants.NS);
            }}));
            XMLAssert.assertXpathExists("/m:mods/m:abstract[@lang='cze' and @type='Abstract' and text()='Text cze']", xmlResult);
            XMLAssert.assertXpathExists("/m:mods/m:abstract[@lang='eng' and @type='Abstract' and text()='Text eng']", xmlResult);
            XMLAssert.assertXpathExists("/m:mods/m:abstract[not(@lang) and @type='Abstract' and text()='Text no lang']", xmlResult);
            validateMods(new StreamSource(new ByteArrayInputStream(contents)));
        } finally {
            close(xmlIS);
        }
    }
 
开发者ID:proarc,项目名称:proarc,代码行数:28,代码来源:TransformersTest.java


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