Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e - Added tests to show discrepancies when handling XML output by Jackson. #473

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions approvaltests-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xstream</artifactId>
Expand Down
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this file is showing as changed, please ignore for the purposes of showing the issue I'm seeing in handling XML.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void testWithTypesTransformersAndBoth()
""";
ParseInput.from(expected).withTypes(Integer.class).verifyAll(Integer::toBinaryString);
ParseInput.from(expected).transformTo(Integer::parseInt).verifyAll(Integer::toBinaryString);
ParseInput.from(expected).withTypes(String.class).transformTo(Integer::parseInt).verifyAll(Integer::toBinaryString);
ParseInput.from(expected).withTypes(String.class).transformTo(Integer::parseInt)
.verifyAll(Integer::toBinaryString);
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this file is showing as changed, please ignore for the purposes of showing the issue I'm seeing in handling XML.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public class Parse2InputTest
void testWithTypesTransformersAndBoth()
{
var expected = """
1,2.2 -> 2.2
1,3.3 -> 3.3
""";
1,2.2 -> 2.2
1,3.3 -> 3.3
""";
ParseInput.from(expected).withTypes(Integer.class, Double.class).verifyAll(t -> t.getFirst() * t.getSecond());
// TODO: continue here
// ParseInput.from(expected).transformTo(Integer::parseInt).verifyAll(Integer::toBinaryString);
// ParseInput.from(expected).withTypes(String.class).transformTo(Integer::parseInt).verifyAll(Integer::toBinaryString);
// ParseInput.from(expected).transformTo(Integer::parseInt).verifyAll(Integer::toBinaryString);
// ParseInput.from(expected).withTypes(String.class).transformTo(Integer::parseInt).verifyAll(Integer::toBinaryString);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package org.approvaltests.writers;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.approvaltests.Approvals;
import org.approvaltests.core.Options;
import org.approvaltests.scrubbers.RegExScrubber;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature.WRITE_XML_DECLARATION;

public class ApprovalXmlWriterTest
{
@Test
Expand Down Expand Up @@ -36,4 +42,36 @@ public void invalidXml()
Approvals.verifyXml("<xml><hello/><start>hi</xml>");
System.err.println("Note: The previous xml error (</start>) is expected ");
}
@Test
void xmlOutputByJacksonIsHandledCorrectly() throws JsonProcessingException
{
ObjectWriter objectWriter = new XmlMapper().configure(WRITE_XML_DECLARATION, true).writer();
String jacksonXml = objectWriter.writeValueAsString(new JacksonTestPOJO());
String approvalsWriterXml = ApprovalXmlWriter.prettyPrint(jacksonXml, 2);
Assertions.assertEquals(jacksonXml, approvalsWriterXml);
}
@Test
void xmlOutputByJacksonIsHandledCorrectlyWhenPrettyPrintingIsEnabled() throws JsonProcessingException
{
ObjectWriter objectWriter = new XmlMapper().configure(WRITE_XML_DECLARATION, true)
.writerWithDefaultPrettyPrinter();
String jacksonXml = objectWriter.writeValueAsString(new JacksonTestPOJO());
String approvalsWriterXml = ApprovalXmlWriter.prettyPrint(jacksonXml, 2);
Assertions.assertEquals(jacksonXml, approvalsWriterXml);
}
private static class JacksonTestPOJO
{
public String getSomeText()
{
return "Some text";
}
public String getSomeTextWithAmpersand()
{
return "Some more text & some more";
}
public String getEmoji()
{
return "😸";
}
}
}