本文整理了Java中org.assertj.core.api.AbstractCharSequenceAssert.isXmlEqualTo()
方法的一些代码示例,展示了AbstractCharSequenceAssert.isXmlEqualTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractCharSequenceAssert.isXmlEqualTo()
方法的具体详情如下:
包路径:org.assertj.core.api.AbstractCharSequenceAssert
类名称:AbstractCharSequenceAssert
方法名:isXmlEqualTo
[英]Verifies that the actual CharSequence is equal to the given XML CharSequence after both have been formatted the same way.
Example :
String expectedXml =
"<rings>\n" +
" <bearer>\n" +
" <name>Frodo</name>\n" +
" <ring>\n" +
" <name>one ring</name>\n" +
" <createdBy>Sauron</createdBy>\n" +
" </ring>\n" +
" </bearer>\n" +
"</rings>";
// No matter how your xml string is formated, isXmlEqualTo is able to compare it's content with another xml String.
String oneLineXml = "<rings><bearer><name>Frodo</name><ring><name>one ring</name><createdBy>Sauron</createdBy></ring></bearer></rings>";
assertThat(oneLineXml).isXmlEqualTo(expectedXml);
String xmlWithNewLine =
"<rings>\n" +
"<bearer> \n" +
" <name>Frodo</name>\n" +
" <ring>\n" +
" <name>one ring</name>\n" +
" <createdBy>Sauron</createdBy>\n" +
" </ring>\n" +
"</bearer>\n" +
"</rings>";
assertThat(xmlWithNewLine).isXmlEqualTo(expectedXml);
// You can compare it with oneLineXml
assertThat(xmlWithNewLine).isXmlEqualTo(oneLineXml);
// Tip : use isXmlEqualToContentOf assertion to compare your XML String with the content of an XML file :
assertThat(oneLineXml).isXmlEqualToContentOf(new File("src/test/resources/formatted.xml"));
[中]以相同的方式格式化后,验证实际的CharSequence是否等于给定的XML CharSequence。
例子:
String expectedXml =
"<rings>\n" +
" <bearer>\n" +
" <name>Frodo</name>\n" +
" <ring>\n" +
" <name>one ring</name>\n" +
" <createdBy>Sauron</createdBy>\n" +
" </ring>\n" +
" </bearer>\n" +
"</rings>";
// No matter how your xml string is formated, isXmlEqualTo is able to compare it's content with another xml String.
String oneLineXml = "<rings><bearer><name>Frodo</name><ring><name>one ring</name><createdBy>Sauron</createdBy></ring></bearer></rings>";
assertThat(oneLineXml).isXmlEqualTo(expectedXml);
String xmlWithNewLine =
"<rings>\n" +
"<bearer> \n" +
" <name>Frodo</name>\n" +
" <ring>\n" +
" <name>one ring</name>\n" +
" <createdBy>Sauron</createdBy>\n" +
" </ring>\n" +
"</bearer>\n" +
"</rings>";
assertThat(xmlWithNewLine).isXmlEqualTo(expectedXml);
// You can compare it with oneLineXml
assertThat(xmlWithNewLine).isXmlEqualTo(oneLineXml);
// Tip : use isXmlEqualToContentOf assertion to compare your XML String with the content of an XML file :
assertThat(oneLineXml).isXmlEqualToContentOf(new File("src/test/resources/formatted.xml"));
代码示例来源:origin: org.assertj/assertj-core
/**
* Verifies that the actual {@code CharSequence} is equal to the content of the given file.
* <p>
* This is an handy shortcut that calls : {@code isXmlEqualTo(contentOf(xmlFile))}
* </p>
* Example :
* <pre><code class='java'> // You can easily compare your XML String to the content of an XML file, whatever how formatted they are.
* String oneLineXml = "<rings><bearer><name>Frodo</name><ring><name>one ring</name><createdBy>Sauron</createdBy></ring></bearer></rings>";
* assertThat(oneLineXml).isXmlEqualToContentOf(new File("src/test/resources/formatted.xml"));</code></pre>
*
* @param xmlFile the file to read the expected XML String to compare with actual {@code CharSequence}
* @return {@code this} assertion object to chain other assertions.
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws AssertionError if the actual {@code CharSequence} is {@code null} or is not the same XML as the content of
* given {@code File}.
*/
public SELF isXmlEqualToContentOf(File xmlFile) {
isXmlEqualTo(contentOf(xmlFile));
return myself;
}
代码示例来源:origin: joel-costigliola/assertj-core
/**
* Verifies that the actual {@code CharSequence} is equal to the content of the given file.
* <p>
* This is an handy shortcut that calls : {@code isXmlEqualTo(contentOf(xmlFile))}
* </p>
* Example :
* <pre><code class='java'> // You can easily compare your XML String to the content of an XML file, whatever how formatted they are.
* String oneLineXml = "<rings><bearer><name>Frodo</name><ring><name>one ring</name><createdBy>Sauron</createdBy></ring></bearer></rings>";
* assertThat(oneLineXml).isXmlEqualToContentOf(new File("src/test/resources/formatted.xml"));</code></pre>
*
* @param xmlFile the file to read the expected XML String to compare with actual {@code CharSequence}
* @return {@code this} assertion object to chain other assertions.
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws AssertionError if the actual {@code CharSequence} is {@code null} or is not the same XML as the content of
* given {@code File}.
*/
public SELF isXmlEqualToContentOf(File xmlFile) {
isXmlEqualTo(contentOf(xmlFile));
return myself;
}
代码示例来源:origin: SonarSource/sonarqube
private void assertSimilarXml(String fileWithExpectedXml, String xml) throws IOException, SAXException {
String pathToExpectedXml = "XMLProfileSerializerTest/" + fileWithExpectedXml;
assertThat(xml).isXmlEqualTo(IOUtils.toString(getClass().getResource(pathToExpectedXml)));
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void returns_backup_of_profile_with_specified_key() {
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
TestResponse response = tester.newRequest().setParam(PARAM_KEY, profile.getKee()).execute();
assertThat(response.getMediaType()).isEqualTo("application/xml");
assertThat(response.getInput()).isXmlEqualTo(xmlForProfileWithoutRules(profile));
assertThat(response.getHeader("Content-Disposition")).isEqualTo("attachment; filename=" + profile.getKee() + ".xml");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void export_xml() throws Exception {
List<RuleDebt> rules = newArrayList(
new RuleDebt().setRuleKey(RuleKey.of("checkstyle", "Regexp"))
.setFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()).setCoefficient("3d").setOffset("15min")
);
assertThat(underTest.export(rules)).isXmlEqualTo(getFileContent("export_xml.xml"));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void returns_backup_of_profile_with_specified_name_on_default_organization() {
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
.setParam("language", profile.getLanguage())
.setParam("qualityProfile", profile.getName())
.execute();
assertThat(response.getInput()).isXmlEqualTo(xmlForProfileWithoutRules(profile));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void returns_backup_of_profile_with_specified_name_and_organization() {
OrganizationDto org = db.organizations().insert();
QProfileDto profile = db.qualityProfiles().insert(org, p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
.setParam("organization", org.getKey())
.setParam("language", profile.getLanguage())
.setParam("qualityProfile", profile.getName())
.execute();
assertThat(response.getInput()).isXmlEqualTo(xmlForProfileWithoutRules(profile));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void returns_backup_of_profile_on_free_organization() {
OrganizationDto organization = db.organizations().insert(o -> o.setSubscription(FREE));
QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
.setParam("organization", organization.getKey())
.setParam("language", profile.getLanguage())
.setParam("qualityProfile", profile.getName())
.execute();
assertThat(response.getInput()).isXmlEqualTo(xmlForProfileWithoutRules(profile));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void returns_backup_of_profile_on_paid_organization() {
OrganizationDto organization = db.organizations().insert(o -> o.setSubscription(PAID));
QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
UserDto user = db.users().insertUser();
userSession.logIn(user).addMembership(organization);
TestResponse response = tester.newRequest()
.setParam("organization", organization.getKey())
.setParam("language", profile.getLanguage())
.setParam("qualityProfile", profile.getName())
.execute();
assertThat(response.getInput()).isXmlEqualTo(xmlForProfileWithoutRules(profile));
}
代码示例来源:origin: org.assertj/assertj-core-java8
/**
* Verifies that the actual {@code CharSequence} is equal to the content of the given file.
* <p/>
* This is an handy shortcut that calls : {@code isXmlEqualTo(contentOf(xmlFile))}
* </p>
* <p>
* Example :
* </p>
*
* <pre><code class='java'>
* // You can easily compare your XML String to the content of an XML file, whatever how formatted thay are.
* String oneLineXml = "<rings><bearer><name>Frodo</name><ring><name>one ring</name><createdBy>Sauron</createdBy></ring></bearer></rings>";
* assertThat(oneLineXml).isXmlEqualToContentOf(new File("src/test/resources/formatted.xml"));
* </code></pre>
*
* @param xmlFile the file to read the expected XML String to compare with actual {@code CharSequence}
* @return {@code this} assertion object to chain other assertions.
* @throws NullPointerException if the given {@code File} is {@code null}.
* @throws AssertionError if the actual {@code CharSequence} is {@code null} or is not the same XML as the content of
* given {@code File}.
*/
public S isXmlEqualToContentOf(File xmlFile) {
isXmlEqualTo(contentOf(xmlFile));
return myself;
}
代码示例来源:origin: io.syndesis.rest/rest-connector-generator
@Test
public void shouldCreateArrayFromExamples() {
final Map<String, ArrayProperty> namedPropertyMap = propertyFrom(jsonSchemaSnippet);
final Entry<String, ArrayProperty> namedProperty = namedPropertyMap.entrySet().iterator().next();
final String propertyName = namedProperty.getKey();
final ArrayProperty array = namedProperty.getValue();
final Document document = DocumentHelper.createDocument();
final Element parent = document.addElement("xsd:sequence", XmlSchemaHelper.XML_SCHEMA_NS);
assertThat(UnifiedXmlDataShapeGenerator.determineArrayItemName(propertyName, array)).isEqualTo(arrayItemName);
assertThat(UnifiedXmlDataShapeGenerator.determineArrayElementName(propertyName, array)).isEqualTo(arrayElementName);
UnifiedXmlDataShapeGenerator.defineArrayElement(array, propertyName, parent, NO_SWAGGER, NO_MORE_SCHEMAS);
assertThat(XmlSchemaHelper.serialize(document)).isXmlEqualTo(schema(xmlSchemaSnippet));
}
代码示例来源:origin: io.syndesis.server/server-connector-generator
@Test
public void shouldCreateArrayFromExamples() {
final Map<String, ArrayProperty> namedPropertyMap = propertyFrom(jsonSchemaSnippet);
final Entry<String, ArrayProperty> namedProperty = namedPropertyMap.entrySet().iterator().next();
final String propertyName = namedProperty.getKey();
final ArrayProperty array = namedProperty.getValue();
final Document document = DocumentHelper.createDocument();
final Element parent = document.addElement("xsd:sequence", XmlSchemaHelper.XML_SCHEMA_NS);
assertThat(UnifiedXmlDataShapeGenerator.determineArrayItemName(propertyName, array)).isEqualTo(arrayItemName);
assertThat(UnifiedXmlDataShapeGenerator.determineArrayElementName(propertyName, array)).isEqualTo(arrayElementName);
UnifiedXmlDataShapeGenerator.defineArrayElement(array, propertyName, parent, NO_SWAGGER, NO_MORE_SCHEMAS);
assertThat(XmlSchemaHelper.serialize(document)).isXmlEqualTo(schema(xmlSchemaSnippet));
}
代码示例来源:origin: io.syndesis.rest/rest-connector-generator
@Test
public void shouldGenerateAtlasmapSchemaSetForUpdatePetRequest() throws IOException {
final Operation swaggerOperation = swagger.getPaths().get(path).getOperationMap().get(operation);
final DataShape shape = generator.createShapeFromRequest(swaggerSpecification, swagger, swaggerOperation);
final SoftAssertions softly = new SoftAssertions();
softly.assertThat(shape.getKind()).isEqualTo(DataShapeKinds.XML_SCHEMA);
softly.assertThat(shape.getName()).isEqualTo("Request");
softly.assertThat(shape.getDescription()).isEqualTo("API request payload");
softly.assertThat(shape.getExemplar()).isNotPresent();
softly.assertAll();
final String expectedSpecification;
try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/" + schemaset)) {
expectedSpecification = IOUtils.toString(in, StandardCharsets.UTF_8);
}
final String specification = shape.getSpecification();
assertThat(specification).isXmlEqualTo(expectedSpecification);
}
代码示例来源:origin: io.syndesis.server/server-connector-generator
@Test
public void shouldGenerateAtlasmapSchemaSetForUpdatePetRequest() throws IOException {
final Operation swaggerOperation = swagger.getPaths().get(path).getOperationMap().get(operation);
final DataShape shape = generator.createShapeFromRequest(json, swagger, swaggerOperation);
final SoftAssertions softly = new SoftAssertions();
softly.assertThat(shape.getKind()).isEqualTo(DataShapeKinds.XML_SCHEMA);
softly.assertThat(shape.getName()).isEqualTo("Request");
softly.assertThat(shape.getDescription()).isEqualTo("API request payload");
softly.assertThat(shape.getExemplar()).isNotPresent();
softly.assertAll();
final String expectedSpecification;
try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/" + schemaset)) {
expectedSpecification = IOUtils.toString(in, StandardCharsets.UTF_8);
}
final String specification = shape.getSpecification();
assertThat(specification).isXmlEqualTo(expectedSpecification);
}
内容来源于网络,如有侵权,请联系作者删除!