diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestUtil.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestUtil.java new file mode 100644 index 000000000..94dacb2c2 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestUtil.java @@ -0,0 +1,384 @@ +package com.fasterxml.jackson.dataformat.xml; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.type.TypeFactory; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationIntrospector; + +import static org.junit.jupiter.api.Assertions.*; + +public abstract class XmlTestUtil +{ + + protected static final String DEFAULT_NEW_LINE; + + static { + String newLine = System.getProperty("line.separator"); + DEFAULT_NEW_LINE = newLine == null ? "\n" : newLine; + } + + @JsonPropertyOrder({ "first", "last", "id" }) + protected static class NameBean { + @JacksonXmlProperty(isAttribute=true) + public int age; + public String last, first; + + public NameBean() { } + public NameBean(int age, String f, String l) { + this.age = age; + first = f; + last = l; + } + } + + /** + * Sample class from Jackson tutorial ("JacksonInFiveMinutes") + */ + public static class FiveMinuteUser { + public enum Gender { MALE, FEMALE }; + + public static class Name + { + private String _first, _last; + + public Name() { } + public Name(String f, String l) { + _first = f; + _last = l; + } + + public String getFirst() { return _first; } + public String getLast() { return _last; } + + public void setFirst(String s) { _first = s; } + public void setLast(String s) { _last = s; } + + @Override + public boolean equals(Object o) + { + if (o == this) return true; + if (o == null || o.getClass() != getClass()) return false; + Name other = (Name) o; + return _first.equals(other._first) && _last.equals(other._last); + } + } + + private Gender _gender; + private Name _name; + private boolean _isVerified; + private byte[] _userImage; + + public FiveMinuteUser() { } + + public FiveMinuteUser(String first, String last, boolean verified, Gender g, byte[] data) + { + _name = new Name(first, last); + _isVerified = verified; + _gender = g; + _userImage = data; + } + + public Name getName() { return _name; } + public boolean isVerified() { return _isVerified; } + public Gender getGender() { return _gender; } + public byte[] getUserImage() { return _userImage; } + + public void setName(Name n) { _name = n; } + public void setVerified(boolean b) { _isVerified = b; } + public void setGender(Gender g) { _gender = g; } + public void setUserImage(byte[] b) { _userImage = b; } + + @Override + public boolean equals(Object o) + { + if (o == this) return true; + if (o == null || o.getClass() != getClass()) return false; + FiveMinuteUser other = (FiveMinuteUser) o; + if (_isVerified != other._isVerified) return false; + if (_gender != other._gender) return false; + if (!_name.equals(other._name)) return false; + byte[] otherImage = other._userImage; + if (otherImage.length != _userImage.length) return false; + for (int i = 0, len = _userImage.length; i < len; ++i) { + if (_userImage[i] != otherImage[i]) { + return false; + } + } + return true; + } + } + + protected static class StringBean + { + public String text; + + public StringBean() { this("foobar"); } + public StringBean(String s) { text = s; } + + @Override + public String toString() { + if (text == null) return "NULL"; + return "\""+text+"\""; + } + } + + /** + * Simple wrapper around String type, usually to test value + * conversions or wrapping + */ + protected static class StringWrapper { + public String str; + + public StringWrapper() { } + public StringWrapper(String value) { + str = value; + } + } + + protected static class IntWrapper { + public int i; + + public IntWrapper() { } + public IntWrapper(int value) { + i = value; + } + } + + public static class Point { + public int x, y; + + protected Point() { } // for deser + public Point(int x0, int y0) { + x = x0; + y = y0; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Point)) { + return false; + } + Point other = (Point) o; + return (other.x == x) && (other.y == y); + } + + @Override + public String toString() { + return String.format("[x=%d, y=%d]", x, y); + } + } + + /* + /********************************************************** + /* Some sample documents: + /********************************************************** + */ + + protected final static int SAMPLE_SPEC_VALUE_WIDTH = 800; + protected final static int SAMPLE_SPEC_VALUE_HEIGHT = 600; + protected final static String SAMPLE_SPEC_VALUE_TITLE = "View from 15th Floor"; + protected final static String SAMPLE_SPEC_VALUE_TN_URL = "http://www.example.com/image/481989943"; + protected final static int SAMPLE_SPEC_VALUE_TN_HEIGHT = 125; + protected final static String SAMPLE_SPEC_VALUE_TN_WIDTH = "100"; + protected final static int SAMPLE_SPEC_VALUE_TN_ID1 = 116; + protected final static int SAMPLE_SPEC_VALUE_TN_ID2 = 943; + protected final static int SAMPLE_SPEC_VALUE_TN_ID3 = 234; + protected final static int SAMPLE_SPEC_VALUE_TN_ID4 = 38793; + + protected final static String SAMPLE_DOC_JSON_SPEC = + "{\n" + +" \"Image\" : {\n" + +" \"Width\" : "+SAMPLE_SPEC_VALUE_WIDTH+",\n" + +" \"Height\" : "+SAMPLE_SPEC_VALUE_HEIGHT+"," + +"\"Title\" : \""+SAMPLE_SPEC_VALUE_TITLE+"\",\n" + +" \"Thumbnail\" : {\n" + +" \"Url\" : \""+SAMPLE_SPEC_VALUE_TN_URL+"\",\n" + +"\"Height\" : "+SAMPLE_SPEC_VALUE_TN_HEIGHT+",\n" + +" \"Width\" : \""+SAMPLE_SPEC_VALUE_TN_WIDTH+"\"\n" + +" },\n" + +" \"IDs\" : ["+SAMPLE_SPEC_VALUE_TN_ID1+","+SAMPLE_SPEC_VALUE_TN_ID2+","+SAMPLE_SPEC_VALUE_TN_ID3+","+SAMPLE_SPEC_VALUE_TN_ID4+"]\n" + +" }" + +"}" + ; + + /* + /********************************************************** + /* Construction, factory methods + /********************************************************** + */ + + protected XmlTestUtil() { + super(); + } + + protected XmlFactoryBuilder streamFactoryBuilder() { + return XmlFactory.builder(); + } + + protected static XmlMapper newMapper() { + return new XmlMapper(); + } + + protected static XmlMapper.Builder mapperBuilder() { + return XmlMapper.builder(); + } + + protected static XmlMapper.Builder mapperBuilder(XmlFactory f) { + return XmlMapper.builder(f); + } + + protected XmlMapper xmlMapper(boolean useListWrapping) + { + JacksonXmlModule module = new JacksonXmlModule(); + module.setDefaultUseWrapper(useListWrapping); + return new XmlMapper(module); + } + + protected AnnotationIntrospector jakartaXMLBindAnnotationIntrospector() { + return new JakartaXmlBindAnnotationIntrospector(TypeFactory.defaultInstance()); + } + + /* + /********************************************************** + /* Additional assertion methods + /********************************************************** + */ + + protected void assertToken(JsonToken expToken, JsonToken actToken) + { + if (actToken != expToken) { + fail("Expected token "+expToken+", current token "+actToken); + } + } + + protected void assertToken(JsonToken expToken, JsonParser jp) + { + assertToken(expToken, jp.getCurrentToken()); + } + + /** + * Method that gets textual contents of the current token using + * available methods, and ensures results are consistent, before + * returning them + */ + protected String getAndVerifyText(JsonParser jp) + throws IOException, JsonParseException + { + // Ok, let's verify other accessors + int actLen = jp.getTextLength(); + char[] ch = jp.getTextCharacters(); + String str2 = new String(ch, jp.getTextOffset(), actLen); + String str = jp.getText(); + + if (str.length() != actLen) { + fail("Internal problem (jp.token == "+jp.getCurrentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen); + } + assertEquals("String access via getText(), getTextXxx() must be the same", str, str2); + + return str; + } + + protected void verifyFieldName(JsonParser jp, String expName) + throws IOException + { + assertEquals(expName, jp.getText()); + assertEquals(expName, jp.currentName()); + } + + protected void verifyException(Throwable e, String... matches) + { + String msg = e.getMessage(); + String lmsg = (msg == null) ? "" : msg.toLowerCase(); + for (String match : matches) { + String lmatch = match.toLowerCase(); + if (lmsg.indexOf(lmatch) >= 0) { + return; + } + } + fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one ("+ + e.getClass().getName()+") with message \""+msg+"\""); + } + + /* + /********************************************************** + /* Helper methods, other + /********************************************************** + */ + + protected static String a2q(String content) { + return content.replace("'", "\""); + } + + protected byte[] utf8Bytes(String str) { + return str.getBytes(StandardCharsets.UTF_8); + } + + /** + * Helper method that tries to remove unnecessary namespace + * declaration that default JDK XML parser (SJSXP) sees fit + * to add. + */ + protected static String removeSjsxpNamespace(String xml) + { + final String match = " xmlns=\"\""; + int ix = xml.indexOf(match); + if (ix > 0) { + xml = xml.substring(0, ix) + xml.substring(ix+match.length()); + } + return xml; + } + + protected String readAll(File f) throws IOException + { + StringBuilder sb = new StringBuilder(); + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8")); + String line; + + while ((line = br.readLine()) != null) { + sb.append(line).append("\n"); + } + br.close(); + return sb.toString(); + } + + protected byte[] readResource(String ref) + { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + final byte[] buf = new byte[4000]; + + InputStream in = getClass().getResourceAsStream(ref); + if (in != null) { + try { + int len; + while ((len = in.read(buf)) > 0) { + bytes.write(buf, 0, len); + } + in.close(); + } catch (IOException e) { + throw new RuntimeException("Failed to read resource '"+ref+"': "+e); + } + } + if (bytes.size() == 0) { + throw new IllegalArgumentException("Failed to read resource '"+ref+"': empty resource?"); + } + return bytes.toByteArray(); + } + + public String jaxbSerialized(Object ob, Class<?>... classes) throws Exception + { + StringWriter sw = new StringWriter(); + if (classes.length == 0) { + jakarta.xml.bind.JAXB.marshal(ob, sw); + } else { + jakarta.xml.bind.JAXBContext.newInstance(classes).createMarshaller().marshal(ob, sw); + } + sw.close(); + return sw.toString(); + } +} diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/adapters/TestIssue47Attribute.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/adapters/TestIssue47Attribute.java index 8c01e8e78..0e6655010 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/adapters/TestIssue47Attribute.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/adapters/TestIssue47Attribute.java @@ -2,10 +2,14 @@ import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -public class TestIssue47Attribute extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + +public class TestIssue47Attribute extends XmlTestUtil { public static class Response { @@ -20,6 +24,7 @@ public static class Item public String b; } + @Test public void testEmptyStringFromElemAndAttr() throws Exception { final XmlMapper MAPPER = new XmlMapper(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java index 06839f6dd..072d88b3d 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java @@ -2,18 +2,22 @@ import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class CaseInsensitiveDeserTest extends XmlTestBase +public class CaseInsensitiveDeserTest extends XmlTestUtil { static class BaseResponse { public int errorCode; @@ -80,6 +84,7 @@ public void setName(String n) { .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) .build(); + @Test public void testCaseInsensitive1036() throws Exception { final String DOC = @@ -100,6 +105,7 @@ public void testCaseInsensitive1036() throws Exception } // [dataformat-xml#273] + @Test public void testCaseInsensitiveComplex() throws Exception { final String DOC = diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CoerceFromEmptyStringTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CoerceFromEmptyStringTest.java index 96377db26..01e357bb5 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CoerceFromEmptyStringTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CoerceFromEmptyStringTest.java @@ -3,13 +3,16 @@ import java.util.List; import java.util.Map; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // Note: copied from coercion tests of `jackson-databind` -public class CoerceFromEmptyStringTest extends XmlTestBase +public class CoerceFromEmptyStringTest extends XmlTestUtil { static class PointWrapper { public Point p; @@ -46,6 +49,7 @@ public NoCtorPOJO(boolean b) { } private final static String EMPTY_XML = "<GeneralEmpty><value /></GeneralEmpty>"; + @Test public void testNullsToEmptyPojo() throws Exception { PointWrapper pw = MAPPER.readValue("<PointWrapper><p /></PointWrapper>", @@ -56,6 +60,7 @@ public void testNullsToEmptyPojo() throws Exception assertEquals(0, pw.p.y); } + @Test public void testNullsToGenericPojo() throws Exception { // String xml = MAPPER.writeValueAsString(new GeneralEmpty<Point>(new Point(1, 2))); @@ -67,6 +72,7 @@ public void testNullsToGenericPojo() throws Exception assertEquals(0, p.y); } + @Test public void testNullsToEmptyCollection() throws Exception { GeneralEmpty<List<String>> result = MAPPER.readValue(EMPTY_XML, @@ -81,6 +87,7 @@ public void testNullsToEmptyCollection() throws Exception assertEquals(0, result2.value.size()); } + @Test public void testNullsToEmptyMap() throws Exception { GeneralEmpty<Map<String,String>> result = MAPPER.readValue(EMPTY_XML, @@ -89,6 +96,7 @@ public void testNullsToEmptyMap() throws Exception assertEquals(0, result.value.size()); } + @Test public void testNullsToEmptyArrays() throws Exception { final String doc = EMPTY_XML; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DefaultTyping325Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DefaultTyping325Test.java index 6ae3267fe..8eb839927 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DefaultTyping325Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DefaultTyping325Test.java @@ -2,13 +2,17 @@ import java.io.IOException; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.testutil.NoCheckSubTypeValidator; -public class DefaultTyping325Test extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + +public class DefaultTyping325Test extends XmlTestUtil { static class Simple325 { protected String[] list; @@ -18,6 +22,7 @@ static class Simple325 { } // [dataformat-xml#325] + @Test public void testDefaultTypingWithInnerClass() throws IOException { ObjectMapper mapper = mapperBuilder() diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DelegatingCreator254Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DelegatingCreator254Test.java index 63f472d4e..4a93be9d5 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DelegatingCreator254Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DelegatingCreator254Test.java @@ -1,10 +1,13 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class DelegatingCreator254Test extends XmlTestBase +public class DelegatingCreator254Test extends XmlTestUtil { static class Foo { public Bar bar; @@ -29,6 +32,7 @@ public Bar(int i) { // [dataformat-xml#254]: Coercion needed for int-taking creator (as XML can // not natively detect scalars other than Strings) + @Test public void testIntDelegatingCreator() throws Exception { Foo foo = MAPPER.readValue( diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DeserErrorHandling236Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DeserErrorHandling236Test.java index 44485ad96..27ee8809f 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DeserErrorHandling236Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/DeserErrorHandling236Test.java @@ -1,9 +1,13 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.dataformat.xml.*; -public class DeserErrorHandling236Test extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + +public class DeserErrorHandling236Test extends XmlTestUtil { static class Employee { public String name; @@ -18,6 +22,7 @@ static class Employee { protected XmlMapper MAPPER = new XmlMapper(); // [dataformat-xml#236] + @Test public void testExceptionWrapping() throws Exception { final String XML = "<name>monica&</name>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/ElementWithScalarAndAttr412Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/ElementWithScalarAndAttr412Test.java index 7514ff354..26b8dcd88 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/ElementWithScalarAndAttr412Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/ElementWithScalarAndAttr412Test.java @@ -4,13 +4,17 @@ import java.util.Date; import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonRootName; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class ElementWithScalarAndAttr412Test extends XmlTestBase +public class ElementWithScalarAndAttr412Test extends XmlTestUtil { @JsonRootName("container") static class Bean412 { @@ -100,6 +104,7 @@ static class TaggedDate412 { private final ObjectMapper MAPPER = newMapper(); // [dataformat-xml#412] + @Test public void testIntFromElemAndAttrInList() throws Exception { String XML = "<container>\n" @@ -124,6 +129,7 @@ public void testIntFromElemAndAttrInList() throws Exception assertEquals(42, many.v.get(1).count); } + @Test public void testIntFromElemAndAttr() throws Exception { TaggedInt412 result; @@ -151,6 +157,7 @@ public void testIntFromElemAndAttr() throws Exception /********************************************************** */ + @Test public void testBooleanFromElemAndAttr() throws Exception { final String XML = "<tagged><truthy bar='baz'>true</truthy><count>3</count></tagged>"; @@ -166,6 +173,7 @@ public void testBooleanFromElemAndAttr() throws Exception } } + @Test public void testDoubleFromElemAndAttr() throws Exception { final String XML = "<tagged><count>28</count><value bar='baz'> 0.25 </value></tagged>"; @@ -182,6 +190,7 @@ public void testDoubleFromElemAndAttr() throws Exception } } + @Test public void testStringFromElemAndAttr() throws Exception { TaggedString412 result = MAPPER.readValue( @@ -191,6 +200,7 @@ public void testStringFromElemAndAttr() throws Exception assertEquals(7, result.count); } + @Test public void testURIFromElemAndAttr() throws Exception { TaggedURI412 result = MAPPER.readValue( @@ -202,6 +212,7 @@ public void testURIFromElemAndAttr() throws Exception assertEquals(11, result.count); } + @Test public void testDateFromElemAndAttr() throws Exception { TaggedDate412 result = MAPPER.readValue( diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyBeanDeser318Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyBeanDeser318Test.java index dd30204b0..0599e0d99 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyBeanDeser318Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyBeanDeser318Test.java @@ -1,12 +1,17 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; -public class EmptyBeanDeser318Test extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + +public class EmptyBeanDeser318Test extends XmlTestUtil { static class Wrapper { @JacksonXmlProperty(localName = "id") @@ -40,6 +45,7 @@ static class Bean579 { private final XmlMapper MAPPER = newMapper(); + @Test public void testEmptyString() throws Exception { String s = "<wrapper>" + " <id>id</id>" @@ -52,6 +58,7 @@ public void testEmptyString() throws Exception { assertNull(value.nested.nested2); } + @Test public void testBlankString() throws Exception { String s = "<wrapper>" + " <id>id</id>" @@ -67,6 +74,7 @@ public void testBlankString() throws Exception { assertNull(value.nested.nested2); } + @Test public void testBlankString2() throws Exception { String s = "<wrapper>" + " <id>id</id>" @@ -80,6 +88,7 @@ public void testBlankString2() throws Exception { assertNull(value.nested.nested2); } + @Test public void testMissing() throws Exception { String s = "<wrapper>" + " <id>id</id>" @@ -90,6 +99,7 @@ public void testMissing() throws Exception { assertNull(value.nested); } + @Test public void testValidStructure() throws Exception { String s = "<wrapper>" + " <id>id</id>" @@ -105,6 +115,7 @@ public void testValidStructure() throws Exception { } // [dataformat-xml#579] + @Test public void testEmptyRootElem579() throws Exception { Bean579 bean; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyStringValueTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyStringValueTest.java index 79f729719..33b6da833 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyStringValueTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyStringValueTest.java @@ -3,13 +3,16 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -public class EmptyStringValueTest extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + +public class EmptyStringValueTest extends XmlTestUtil { static class Name { public String first; @@ -56,6 +59,7 @@ static class Product427 { private final XmlMapper MAPPER = newMapper(); + @Test public void testEmptyString162() throws Exception { Name name = MAPPER.readValue("<name><first>Ryan</first><last></last></name>", @@ -65,6 +69,7 @@ public void testEmptyString162() throws Exception assertEquals("", name.last); } + @Test public void testEmptyElement() throws Exception { final String XML = "<name><first/><last></last></name>"; @@ -85,6 +90,7 @@ public void testEmptyElement() throws Exception assertEquals("", name.last); } + @Test public void testEmptyStringElement() throws Exception { // then with empty element @@ -97,6 +103,7 @@ public void testEmptyStringElement() throws Exception } // [dataformat-xml#25] + @Test public void testEmptyStringFromElemAndAttr() throws Exception { EmptyStrings25 ob = MAPPER.readValue("<EmptyString a=''><b /></EmptyString>", @@ -107,6 +114,7 @@ public void testEmptyStringFromElemAndAttr() throws Exception } // [dataformat-xml#427] + @Test public void testEmptyIssue427() throws Exception { String xml = "<product><stuff></stuff></product>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyWithScalarsTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyWithScalarsTest.java index 6a15de23a..47d36124a 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyWithScalarsTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EmptyWithScalarsTest.java @@ -3,17 +3,20 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.exc.MismatchedInputException; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import static org.junit.jupiter.api.Assertions.*; + // [dataformat-xml#473]: 2.11 -> 2.12 coercion of empty to "default" // [dataformat-xml#474]: no failure for primitives, no null -public class EmptyWithScalarsTest extends XmlTestBase +public class EmptyWithScalarsTest extends XmlTestUtil { @JacksonXmlRootElement(localName = "w") static class NumbersPrimitive { @@ -52,6 +55,7 @@ static class MiscOther { /********************************************************************** */ + @Test public void testPrimitiveIntsWithEmpty() throws Exception { NumbersPrimitive p = MAPPER.readValue(_emptyWrapped("i"), @@ -62,6 +66,7 @@ public void testPrimitiveIntsWithEmpty() throws Exception assertEquals(0L, p.l); } + @Test public void testPrimitiveFPsWithEmpty() throws Exception { NumbersPrimitive p = MAPPER.readValue(_emptyWrapped("d"), @@ -74,6 +79,7 @@ public void testPrimitiveFPsWithEmpty() throws Exception // [dataformat-xml#474]: no failure for primitives, no null // (will try to fix in 2.13, but not 2.12) + @Test public void testPrimitivesNoNulls() throws Exception { ObjectReader r = MAPPER @@ -101,6 +107,7 @@ private void _testPrimitivesNoNulls(ObjectReader r, String doc) throws Exception /********************************************************************** */ + @Test public void testIntegralsWithEmpty() throws Exception { NumbersWrapper w = MAPPER.readValue(_emptyWrapped("I"), @@ -115,6 +122,7 @@ public void testIntegralsWithEmpty() throws Exception assertNull(o.bi); } + @Test public void testFPWithEmpty() throws Exception { NumbersWrapper w = MAPPER.readValue(_emptyWrapped("D"), @@ -135,6 +143,7 @@ public void testFPWithEmpty() throws Exception /********************************************************************** */ + @Test public void testOtherScalarWithEmpty() throws Exception { MiscOther o = MAPPER.readValue(_emptyWrapped("B"), diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeserTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeserTest.java index 308fa3742..fc75b4611 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/EnumDeserTest.java @@ -1,11 +1,15 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.dataformat.xml.*; -public class EnumDeserTest extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + +public class EnumDeserTest extends XmlTestUtil { static enum TestEnum { A, B, C; } @@ -48,6 +52,7 @@ public static Country682 fromValue(String value) { private final XmlMapper MAPPER = new XmlMapper(); + @Test public void testEnumInBean() throws Exception { String xml = MAPPER.writeValueAsString(new EnumBean(TestEnum.B)); @@ -57,6 +62,7 @@ public void testEnumInBean() throws Exception } // [dataformat-xml#121] + @Test public void testRootEnum() throws Exception { String xml = MAPPER.writeValueAsString(TestEnum.B); @@ -66,6 +72,7 @@ public void testRootEnum() throws Exception } // [dataformat-xml#682] + @Test public void testEnumDeser682() throws Exception { String xml = MAPPER.writeValueAsString(Country682.ITALY); assertEquals("<Country682>Italy</Country682>", xml); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/ExceptionDeserializationTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/ExceptionDeserializationTest.java index 04b5b9a5f..8713d52b5 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/ExceptionDeserializationTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/ExceptionDeserializationTest.java @@ -2,10 +2,13 @@ import java.io.IOException; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import org.junit.jupiter.api.Test; -public class ExceptionDeserializationTest extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + +public class ExceptionDeserializationTest extends XmlTestUtil { /* /********************************************************** @@ -16,6 +19,7 @@ public class ExceptionDeserializationTest extends XmlTestBase private final XmlMapper MAPPER = new XmlMapper(); // [dataformat-xml#250] + @Test public void testEmptyString162() throws Exception { IOException src = new IOException("test"); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/Issue274PropertyNameTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/Issue274PropertyNameTest.java index 6c07c0b6f..bdcea77ef 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/Issue274PropertyNameTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/Issue274PropertyNameTest.java @@ -1,13 +1,17 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonRootName; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import static org.junit.jupiter.api.Assertions.*; + // [dataformat-xml#274]: Actually passes... can not reproduce failure -public class Issue274PropertyNameTest extends XmlTestBase +public class Issue274PropertyNameTest extends XmlTestUtil { private static final String XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + @@ -46,6 +50,7 @@ static class RootObject { */ // [dataformat-xml#274] + @Test public void testIssue274() throws Exception { final ObjectMapper xm = mapperBuilder() diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapDeserializationTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapDeserializationTest.java index 301d57388..e87096aeb 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapDeserializationTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapDeserializationTest.java @@ -4,10 +4,13 @@ import java.util.LinkedHashMap; import java.util.Map; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import org.junit.jupiter.api.Test; -public class MapDeserializationTest extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + +public class MapDeserializationTest extends XmlTestUtil { /* /********************************************************** @@ -18,6 +21,7 @@ public class MapDeserializationTest extends XmlTestBase private final XmlMapper XML_MAPPER = newMapper(); // [dataformat-xml#14] + @Test public void testMapWithAttr() throws Exception { final String xml = "<order><person lang='en'>John Smith</person></order>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapWithDupsDeser498Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapWithDupsDeser498Test.java index 10fd105e0..3e2a32e46 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapWithDupsDeser498Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/MapWithDupsDeser498Test.java @@ -2,13 +2,16 @@ import java.util.Map; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class MapWithDupsDeser498Test extends XmlTestBase +public class MapWithDupsDeser498Test extends XmlTestUtil { /* /********************************************************************** @@ -21,6 +24,7 @@ public class MapWithDupsDeser498Test extends XmlTestBase private final ObjectMapper JSON_MAPPER = new JsonMapper(); // [dataformat-xml#498] + @Test public void testRootLevelMap() throws Exception { final String xml = "<result>\n" diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsSkipTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsSkipTest.java index 318d2addd..fa15b36a2 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsSkipTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsSkipTest.java @@ -1,13 +1,16 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // for [databind#1402]; configurable null handling, specifically with SKIP -public class NullConversionsSkipTest extends XmlTestBase +public class NullConversionsSkipTest extends XmlTestUtil { static class NullSkipField { public String nullsOk = "a"; @@ -48,6 +51,7 @@ public void setValue(String v) { .enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL) .build(); + @Test public void testSkipNullField1() throws Exception { // first, ok if assigning non-null to not-nullable, null for nullable @@ -59,6 +63,7 @@ public void testSkipNullField1() throws Exception assertNull(result.nullsOk); } + @Test public void testSkipNullField2() throws Exception { // and then see that nulls are not ok for non-nullable @@ -68,6 +73,7 @@ public void testSkipNullField2() throws Exception assertEquals("a", result.nullsOk); } + @Test public void testSkipNullMethod1() throws Exception { NullSkipMethod result = NULL_EXPOSING_MAPPER.readValue( @@ -78,6 +84,7 @@ public void testSkipNullMethod1() throws Exception assertNull(result._nullsOk); } + @Test public void testSkipNullMethod2() throws Exception { NullSkipMethod result = NULL_EXPOSING_MAPPER.readValue("<NullSkipMethod><noNulls /></NullSkipMethod>", @@ -92,6 +99,7 @@ public void testSkipNullMethod2() throws Exception /********************************************************** */ + @Test public void testSkipNullWithDefaults() throws Exception { // String doc = "<StringValue><value></value></StringValue>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NumberDeserWithXMLTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NumberDeserWithXMLTest.java index da5b5173b..96840ce75 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NumberDeserWithXMLTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NumberDeserWithXMLTest.java @@ -2,6 +2,8 @@ import java.math.BigDecimal; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; import com.fasterxml.jackson.annotation.JsonSubTypes; @@ -13,10 +15,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlFactory; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; + +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // Tests copied from databind "JDKNumberDeserTest" (only a small subset) -public class NumberDeserWithXMLTest extends XmlTestBase +public class NumberDeserWithXMLTest extends XmlTestUtil { // [databind#2644] @JsonRootName("Root") @@ -85,6 +90,7 @@ static class NestedFloatHolder2784 { private final XmlMapper MAPPER = newMapper(); // [databind#2644] + @Test public void testBigDecimalSubtypes() throws Exception { ObjectMapper mapper = mapperBuilder() @@ -101,6 +107,7 @@ public void testBigDecimalSubtypes() throws Exception } // [databind#2784] + @Test public void testBigDecimalUnwrapped() throws Exception { // mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); @@ -109,6 +116,7 @@ public void testBigDecimalUnwrapped() throws Exception assertEquals(new BigDecimal("5.00"), result.holder.value); } + @Test public void testDoubleUnwrapped() throws Exception { final String DOC = "<Nested><value>125.123456789</value></Nested>"; @@ -116,6 +124,7 @@ public void testDoubleUnwrapped() throws Exception assertEquals(Double.parseDouble("125.123456789"), result.holder.value); } + @Test public void testFloatUnwrapped() throws Exception { final String DOC = "<Nested><value>125.123</value></Nested>"; @@ -123,6 +132,7 @@ public void testFloatUnwrapped() throws Exception assertEquals(Float.parseFloat("125.123"), result.holder.value); } + @Test public void testVeryBigDecimalUnwrapped() throws Exception { final int len = 1200; @@ -136,11 +146,12 @@ public void testVeryBigDecimalUnwrapped() throws Exception MAPPER.readValue(DOC, NestedBigDecimalHolder2784.class); fail("expected JsonMappingException"); } catch (JsonMappingException jme) { - assertTrue("unexpected exception message: " + jme.getMessage(), - jme.getMessage().startsWith("Number value length (1200) exceeds the maximum allowed")); + assertTrue(jme.getMessage().startsWith("Number value length (1200) exceeds the maximum allowed"), + "unexpected exception message: " + jme.getMessage()); } } + @Test public void testVeryBigDecimalUnwrappedWithUnlimitedNumLength() throws Exception { final int len = 1200; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/RootValueDeserTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/RootValueDeserTest.java index 2c1ff7298..e66521964 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/RootValueDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/RootValueDeserTest.java @@ -3,11 +3,14 @@ import java.math.BigDecimal; import java.math.BigInteger; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // New tests (2.12) for root-level values -public class RootValueDeserTest extends XmlTestBase +public class RootValueDeserTest extends XmlTestUtil { private final XmlMapper MAPPER = newMapper(); @@ -17,6 +20,7 @@ public class RootValueDeserTest extends XmlTestBase /********************************************************** */ + @Test public void testNumbers() throws Exception { _testScalar(Integer.valueOf(42), "<Integer>42</Integer>"); @@ -25,6 +29,7 @@ public void testNumbers() throws Exception _testScalar(BigInteger.valueOf(31337), "<BigInteger>31337</BigInteger>"); } + @Test public void testNumbersWithENotation() throws Exception { BigInteger bigInteger = new BigDecimal("2e308").toBigInteger(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/SimpleStringValuesTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/SimpleStringValuesTest.java index 2e29d9f70..b52be808b 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/SimpleStringValuesTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/SimpleStringValuesTest.java @@ -1,11 +1,16 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.deser.EmptyStringValueTest.Name; import com.fasterxml.jackson.dataformat.xml.deser.EmptyStringValueTest.Names; -public class SimpleStringValuesTest extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + +public class SimpleStringValuesTest extends XmlTestUtil { protected static class Bean2 { @@ -29,6 +34,7 @@ static class Issue167Bean { private final XmlMapper MAPPER = newMapper(); + @Test public void testSimpleStringElement() throws Exception { // first, simple one to verify baseline @@ -43,6 +49,7 @@ public void testSimpleStringElement() throws Exception // build Bean, but with gets empty String, passed via String-creator. // 06-Sep-2022, tatu: With 2.14 behavior should become closer to 2.11 in // this respect. + @Test public void testMissingString() throws Exception { StringBean bean = MAPPER.readValue("<StringBean />", StringBean.class); @@ -56,6 +63,7 @@ public void testMissingString() throws Exception /********************************************************** */ + @Test public void testStringWithAttribute() throws Exception { // and then the money shot: with 'standard' attribute... @@ -64,6 +72,7 @@ public void testStringWithAttribute() throws Exception assertEquals("Pulla", bean.text); } + @Test public void testStringsWithAttribute() throws Exception { Bean2 bean = MAPPER.readValue( @@ -78,6 +87,7 @@ public void testStringsWithAttribute() throws Exception assertEquals("def", bean.b); } + @Test public void testStringArrayWithAttribute() throws Exception { // should even work for arrays of those @@ -95,6 +105,7 @@ public void testStringArrayWithAttribute() throws Exception assertEquals("Good stuff", beans[2].text); } + @Test public void testEmptyElementToString() throws Exception { final String XML = @@ -115,6 +126,7 @@ public void testEmptyElementToString() throws Exception /********************************************************** */ + @Test public void testStringsInList() throws Exception { Names input = new Names(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestBinaryData.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestBinaryData.java index 6336c0639..8013a4788 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestBinaryData.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestBinaryData.java @@ -1,10 +1,13 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class TestBinaryData extends XmlTestBase +public class TestBinaryData extends XmlTestUtil { public static class Data { public byte[] bytes; @@ -24,6 +27,7 @@ public static class TwoData { // private final XmlMapper MAPPER = new XmlMapper(); // for [https://github.com/FasterXML/jackson-dataformat-xml/issues/29] + @Test public void testTwoBinaryProps() throws Exception { /* Hmmh. Looks like XmlMapper has some issues with convertValue: diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestViews.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestViews.java index ee344c1f3..30c9868ee 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestViews.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestViews.java @@ -2,20 +2,24 @@ import java.io.IOException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import static org.junit.jupiter.api.Assertions.*; + /* * Tests for ('JSON') Views, other filtering. */ -public class TestViews extends XmlTestBase +public class TestViews extends XmlTestUtil { static class RestrictedView { }; @@ -61,9 +65,8 @@ public class Issue44Bean { protected XmlMapper _xmlMapper; // let's actually reuse XmlMapper to make things bit faster - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); _xmlMapper = new XmlMapper(); } @@ -73,6 +76,7 @@ public void setUp() throws Exception { /********************************************************** */ + @Test public void testIssue7() throws Exception { Foo foo = new Foo(); @@ -104,12 +108,14 @@ public void testIssue7() throws Exception assertEquals(11, result.bars[1].restrictedBarProperty); } + @Test public void testNullSuppression() throws Exception { String xml = _xmlMapper.writeValueAsString(new NonNullBean()); assertEquals("<NonNullBean><name>Bob</name></NonNullBean>", xml); } + @Test public void testIssue44() throws IOException { String exp = "<Issue44Bean first=\"abc\"><second>13</second></Issue44Bean>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TypeAttributeOrder242Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TypeAttributeOrder242Test.java index 656225c22..23d9aa733 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TypeAttributeOrder242Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TypeAttributeOrder242Test.java @@ -2,14 +2,17 @@ import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -public class TypeAttributeOrder242Test extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + +public class TypeAttributeOrder242Test extends XmlTestUtil { @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = B.class) @JsonSubTypes({ @@ -41,6 +44,7 @@ static class B extends A { private final XmlMapper MAPPER = new XmlMapper(); + @Test public void testAttributeOrder() throws Exception { String content1 = "<A type='B' id='1'><attr><param name='1'/><param name='2'/></attr></A>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UnexpectedNonWhitespaceText509Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UnexpectedNonWhitespaceText509Test.java index 1d7f2c037..1555badd8 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UnexpectedNonWhitespaceText509Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UnexpectedNonWhitespaceText509Test.java @@ -2,15 +2,15 @@ import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; // For [dataformat-xml#509] public class UnexpectedNonWhitespaceText509Test { @@ -57,7 +57,7 @@ public String toString() { @Test public void testDeSerData() throws Exception { Data value = deSer("<data key=\"MadeWith\">Text Editor</data>", Data.class); - assertEquals("\"key\" attribute not correctly deserialized", value.getKey(), "MadeWith"); + assertEquals(value.getKey(), "MadeWith", "\"key\" attribute not correctly deserialized"); } @Test @@ -67,11 +67,11 @@ public void testDeSerMetaData() throws Exception { + " <data key=\"Version\">1.0.0</data>\n" // + "</metaData>", MetaData.class); List<Data> entries = value.getData(); - assertEquals("\"data\" not correctly deserialized", entries.size(), 2); + assertEquals(2, entries.size(), "\"data\" not correctly deserialized"); Data entry = entries.get(0); - assertEquals("\"key\" attribute not correctly deserialized", entry.getKey(), "MadeWith"); + assertEquals(entry.getKey(), "MadeWith", "\"key\" attribute not correctly deserialized"); entry = entries.get(1); - assertEquals("\"key\" attribute not correctly deserialized", entry.getKey(), "Version"); + assertEquals(entry.getKey(), "Version", "\"key\" attribute not correctly deserialized"); } private <T> T deSer(String xmlString, Class<T> clazz) throws Exception { diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UntypedObjectDeserTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UntypedObjectDeserTest.java index 64fbfb56c..bf36e83d2 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UntypedObjectDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/UntypedObjectDeserTest.java @@ -4,20 +4,25 @@ import java.util.List; import java.util.Map; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class UntypedObjectDeserTest extends XmlTestBase +public class UntypedObjectDeserTest extends XmlTestUtil { private final ObjectMapper XML_MAPPER = newMapper(); // for [dataformat-xml#205], handling "untyped" ({@code java.lang.Object}-targeted) // deserialization, including handling of element sequences + @Test public void testRepeatingElements() throws Exception { final String XML = @@ -68,6 +73,7 @@ public void testRepeatingElements() throws Exception } // [dataformat-xml#405]: support mixed content + @Test public void testMixedContent() throws Exception { final String XML = "<root>first<a>123</a>second<b>abc</b>last</root>"; @@ -88,6 +94,7 @@ public void testMixedContent() throws Exception // [dataformat-xml#445]: problem with earlier #205 implementation (from 2.12.0), // fixed in 2.12.2 + @Test public void testDuplicateListDeser445() throws Exception { final String XML = diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XmlWrapperClass517Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XmlWrapperClass517Test.java index 92267c022..2ddd586a9 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XmlWrapperClass517Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XmlWrapperClass517Test.java @@ -4,17 +4,20 @@ import java.util.List; import java.util.Objects; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; + +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import static org.junit.jupiter.api.Assertions.*; + // [databind#517] XML wrapper doesn't work with java records // Equivalent to on in jdk17/.../records/XmlWrapperRecord517Test.java public class XmlWrapperClass517Test - extends XmlTestBase + extends XmlTestUtil { public static final class Request { @JacksonXmlElementWrapper(localName = "messages") diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilBasicTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilBasicTest.java index c6ea26b3a..e32a0ccff 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilBasicTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilBasicTest.java @@ -1,11 +1,14 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectReader; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class XsiNilBasicTest extends XmlTestBase +public class XsiNilBasicTest extends XmlTestUtil { private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"; @@ -27,6 +30,7 @@ public DoubleWrapper2() { } private final XmlMapper MAPPER = newMapper(); + @Test public void testWithDoubleAsNull() throws Exception { DoubleWrapper bean = MAPPER.readValue( @@ -44,6 +48,7 @@ public void testWithDoubleAsNull() throws Exception // actually we should perhaps also verify there is no content but... for now, let's leave it. } + @Test public void testWithDoubleAsNonNull() throws Exception { DoubleWrapper bean = MAPPER.readValue( @@ -53,6 +58,7 @@ public void testWithDoubleAsNonNull() throws Exception assertEquals(Double.valueOf(0.25), bean.d); } + @Test public void testWithDoubleAsMixed() throws Exception { DoubleWrapper2 bean = MAPPER.readValue( @@ -87,6 +93,7 @@ public void testWithDoubleAsMixed() throws Exception assertEquals(defaultValue.b, bean.b); } + @Test public void testRootPojoAsNull() throws Exception { Point bean = MAPPER.readValue( @@ -95,6 +102,7 @@ public void testRootPojoAsNull() throws Exception assertNull(bean); } + @Test public void testRootPojoAsNonNull() throws Exception { Point bean = MAPPER.readValue( @@ -104,6 +112,7 @@ public void testRootPojoAsNonNull() throws Exception } // [dataformat-xml#467]: Ok to have contents within "xsi:nil" element + @Test public void testXsiNilWithNonEmptyElement() throws Exception { JsonNode node = MAPPER.readTree( @@ -116,6 +125,7 @@ public void testXsiNilWithNonEmptyElement() throws Exception } // [dataformat-xml#468]: Allow disabling xsi:nil special handling + @Test public void testDisableXsiNilLeafProcessing() throws Exception { final ObjectReader r = MAPPER.readerFor(JsonNode.class); @@ -131,6 +141,7 @@ public void testDisableXsiNilLeafProcessing() throws Exception // [dataformat-xml#468]: Allow disabling xsi:nil special handling + @Test public void testDisableXsiNilRootProcessing() throws Exception { final ObjectReader r = MAPPER.readerFor(JsonNode.class); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilForStringsTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilForStringsTest.java index f4ca4ac9a..a0e210571 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilForStringsTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilForStringsTest.java @@ -1,9 +1,14 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; -public class XsiNilForStringsTest extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + +public class XsiNilForStringsTest extends XmlTestUtil { private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"; @@ -14,6 +19,7 @@ protected static class StringPair { private final XmlMapper MAPPER = newMapper(); // [dataformat-xml#378] + @Test public void testWithStringAsNull() throws Exception { StringPair bean; @@ -27,6 +33,7 @@ public void testWithStringAsNull() throws Exception } // [dataformat-xml#378] + @Test public void testWithStringAsNull2() throws Exception { StringPair bean; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilNestingTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilNestingTest.java index fe5ccea9f..9acfef3a4 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilNestingTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNilNestingTest.java @@ -1,9 +1,14 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; -public class XsiNilNestingTest extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + +public class XsiNilNestingTest extends XmlTestUtil { // for [dataformat-xml#366] protected static class Parent366 { @@ -22,6 +27,7 @@ protected static class Level2 { private final XmlMapper MAPPER = newMapper(); // for [dataformat-xml#366] + @Test public void testDoesNotAffectHierarchy() throws Exception { String xml = "<Parent xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiTypeReadTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiTypeReadTest.java index beb1fdebb..6f77d8749 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiTypeReadTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiTypeReadTest.java @@ -1,16 +1,19 @@ package com.fasterxml.jackson.dataformat.xml.deser; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo.As; import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; +import static org.junit.jupiter.api.Assertions.*; + // [dataformat-xml#634] -public class XsiTypeReadTest extends XmlTestBase +public class XsiTypeReadTest extends XmlTestUtil { @JsonRootName("Typed") static class TypeBean { @@ -37,6 +40,7 @@ protected PolyBean() { } .configure(FromXmlParser.Feature.AUTO_DETECT_XSI_TYPE, true) .build(); + @Test public void testExplicitXsiTypeReadEnabled() throws Exception { final String XML = XSI_ENABLED_MAPPER.writeValueAsString(new TypeBean("type0")); @@ -44,6 +48,7 @@ public void testExplicitXsiTypeReadEnabled() throws Exception assertEquals("type0", result.typeId); } + @Test public void testXsiTypeAsTypeReadeEnabled() throws Exception { final String XML = XSI_ENABLED_MAPPER.writeValueAsString(new PolyBean(42)); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java index 821368919..91d0da61c 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.dataformat.xml.deser.builder; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.core.Version; @@ -9,10 +11,11 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class BuilderSimpleTest extends XmlTestBase +public class BuilderSimpleTest extends XmlTestUtil { // // Simple 2-property value class, builder with standard naming @@ -253,6 +256,7 @@ public Version version() { private final XmlMapper MAPPER = newMapper(); + @Test public void testSimple() throws Exception { String doc = "<ValueClassXY><x>1</x><y>2</y></ValueClassXY>"; @@ -266,6 +270,7 @@ public void testSimple() throws Exception } // related to [databind#1214] + @Test public void testSimpleWithIgnores() throws Exception { // 'z' is unknown, and would fail by default: @@ -293,6 +298,7 @@ public void testSimpleWithIgnores() throws Exception assertEquals(value._y, 3); } + @Test public void testMultiAccess() throws Exception { String doc = "<ValueClassABC><c>3</c> <a>2</a> <b>-9</b></ValueClassABC>"; @@ -313,6 +319,7 @@ public void testMultiAccess() throws Exception } // test for Immutable builder, to ensure return value is used + @Test public void testImmutable() throws Exception { ValueImmutable value = MAPPER.readValue("<ValueImmutable><value>13</value></ValueImmutable>", @@ -321,6 +328,7 @@ public void testImmutable() throws Exception } // test with custom 'with-prefix' + @Test public void testCustomWith() throws Exception { ValueFoo value = MAPPER.readValue("<ValueFoo><value>1</value></ValueFoo>", ValueFoo.class); @@ -329,12 +337,14 @@ public void testCustomWith() throws Exception // for [databind#761] + @Test public void testBuilderMethodReturnMoreGeneral() throws Exception { ValueInterface value = MAPPER.readValue("<ValueInterface><x>1</x></ValueInterface>", ValueInterface.class); assertEquals(2, value.getX()); } + @Test public void testBuilderMethodReturnMoreSpecific() throws Exception { final String json = "<ValueInterface2><x>1</x></ValueInterface2>}"; @@ -342,6 +352,7 @@ public void testBuilderMethodReturnMoreSpecific() throws Exception assertEquals(2, value.getX()); } + @Test public void testSelfBuilder777() throws Exception { SelfBuilder777 result = MAPPER.readValue("<SelfBuilder777><x>3</x></SelfBuilder777>'", @@ -353,6 +364,7 @@ public void testSelfBuilder777() throws Exception // Won't work well with XML, omit: // public void testWithAnySetter822() throws Exception + @Test public void testPOJOConfigResolution1557() throws Exception { final String json = "<ValueFoo><value>1</value></ValueFoo>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderWithXmlText345Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderWithXmlText345Test.java index 710a0b9ee..f14984ad6 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderWithXmlText345Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderWithXmlText345Test.java @@ -1,14 +1,18 @@ package com.fasterxml.jackson.dataformat.xml.deser.builder; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonRootName; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class BuilderWithXmlText345Test extends XmlTestBase +public class BuilderWithXmlText345Test extends XmlTestUtil { @JsonRootName("example") @JsonDeserialize(builder = Example345.ExampleBuilder.class) @@ -67,6 +71,7 @@ public ExampleBuilder value(String value) { private final ObjectMapper MAPPER = newMapper(); // [dataformat-xml#345] + @Test public void testXmlTextViaBuilder345() throws Exception { Example345 in = Example345.builder() diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/convert/CoerceStringToIntsTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/convert/CoerceStringToIntsTest.java index 0045833f8..915dc0c20 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/convert/CoerceStringToIntsTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/convert/CoerceStringToIntsTest.java @@ -3,19 +3,22 @@ import java.math.BigInteger; import java.util.concurrent.atomic.AtomicLong; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.cfg.CoercionAction; import com.fasterxml.jackson.databind.cfg.CoercionInputShape; import com.fasterxml.jackson.databind.type.LogicalType; +import com.fasterxml.jackson.dataformat.xml.*; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import static org.junit.jupiter.api.Assertions.*; // 2020-12-18, tatu: Modified from "jackson-databind" version: XML // backend MUST NOT prevent coercion from String since XML has no // native number representation (although TBH JsonParser.isExpectedNumberInt() // can work around that in many cases) public class CoerceStringToIntsTest - extends XmlTestBase + extends XmlTestUtil { private final ObjectMapper DEFAULT_MAPPER = newMapper(); private final ObjectMapper MAPPER_LEGACY_FAIL = mapperBuilder() @@ -84,10 +87,12 @@ public DoubleWrapper() { } // even if seemingly prevented -- this because XML has no native // number type and Strings present all scalar values, essentially + @Test public void testDefaultStringToIntCoercion() throws Exception { _verifyLegacyFromStringSucceeds(DEFAULT_MAPPER); } + @Test public void testLegacyFailStringToInt() throws Exception { _verifyLegacyFromStringSucceeds(MAPPER_LEGACY_FAIL); } @@ -129,6 +134,7 @@ private void _verifyLegacyFromStringSucceeds(ObjectMapper mapper) throws Excepti // When explicitly enabled, should pass + @Test public void testCoerceConfigStringToNull() throws Exception { _verifyCoercionFromStringSucceeds(MAPPER_TO_NULL); } @@ -136,14 +142,17 @@ public void testCoerceConfigStringToNull() throws Exception { // But even if blocked, or changed to null, should pass since with // XML, "String" is a native representation of numbers + @Test public void testCoerceConfigStringToEmpty() throws Exception { _verifyCoercionFromStringSucceeds(MAPPER_TO_EMPTY); } + @Test public void testCoerceConfigStringConvert() throws Exception { _verifyCoercionFromStringSucceeds(MAPPER_TRY_CONVERT); } + @Test public void testCoerceConfigFailFromString() throws Exception { _verifyCoercionFromStringSucceeds(MAPPER_TO_FAIL); } diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/convert/CoerceToBooleanTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/convert/CoerceToBooleanTest.java index cdd446ead..d34b7e366 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/convert/CoerceToBooleanTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/convert/CoerceToBooleanTest.java @@ -3,18 +3,21 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.cfg.CoercionAction; import com.fasterxml.jackson.databind.cfg.CoercionInputShape; import com.fasterxml.jackson.databind.type.LogicalType; +import com.fasterxml.jackson.dataformat.xml.*; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import static org.junit.jupiter.api.Assertions.*; // 2020-12-18, tatu: Modified from "jackson-databind" version: XML // backend MUST NOT prevent coercion from String since XML has no // native boolean representation public class CoerceToBooleanTest - extends XmlTestBase + extends XmlTestUtil { static class BooleanPOJO { public boolean value; @@ -43,6 +46,7 @@ static class BooleanPOJO { */ // for [databind#403] + @Test public void testEmptyStringFailForBooleanPrimitive() throws IOException { final ObjectReader reader = MAPPER_EMPTY_TO_BOOLEAN_FAIL @@ -56,6 +60,7 @@ public void testEmptyStringFailForBooleanPrimitive() throws IOException } } + @Test public void testDefaultStringToBooleanCoercionOk() throws Exception { _verifyStringToBooleanOk(DEFAULT_MAPPER); } @@ -66,6 +71,7 @@ public void testDefaultStringToBooleanCoercionOk() throws Exception { /********************************************************** */ + @Test public void testStringToBooleanOkDespiteCoercionConfig() throws Exception { _verifyStringToBooleanOk(MAPPER_STRING_TO_BOOLEAN_FAIL); } diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/ImplicitParamsForCreatorTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/ImplicitParamsForCreatorTest.java index 5ed510b40..1b6389943 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/ImplicitParamsForCreatorTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/ImplicitParamsForCreatorTest.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.dataformat.xml.deser.creator; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; @@ -8,13 +10,14 @@ import com.fasterxml.jackson.databind.introspect.AnnotatedMember; import com.fasterxml.jackson.databind.introspect.AnnotatedParameter; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; - -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // copied form [jackson-databind] public class ImplicitParamsForCreatorTest - extends XmlTestBase + extends XmlTestUtil { @SuppressWarnings("serial") static class MyParamIntrospector extends JacksonAnnotationIntrospector @@ -80,6 +83,7 @@ public int serializedAs() { .annotationIntrospector(new MyParamIntrospector()) .build(); + @Test public void testNonSingleArgCreator() throws Exception { XY value = MAPPER.readValue( @@ -91,6 +95,7 @@ public void testNonSingleArgCreator() throws Exception } // [databind#2932] + @Test public void testJsonCreatorWithOtherAnnotations() throws Exception { Bean2932 bean = MAPPER.readValue( @@ -105,6 +110,7 @@ public void testJsonCreatorWithOtherAnnotations() throws Exception // 04-Feb-2024, tatu: XML does not have type information wrt Integer so this // can't work /* + @Test public void testDelegatingInferFromJsonValue() throws Exception { // First verify serialization via `@JsonValue` diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/NestedSingleArgCtors547Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/NestedSingleArgCtors547Test.java index b19552807..b8fa8731a 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/NestedSingleArgCtors547Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/NestedSingleArgCtors547Test.java @@ -1,12 +1,17 @@ package com.fasterxml.jackson.dataformat.xml.deser.creator; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; -public class NestedSingleArgCtors547Test extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + +public class NestedSingleArgCtors547Test extends XmlTestUtil { private static final XmlMapper XML_MAPPER = newMapper(); @@ -38,6 +43,7 @@ public Inner547Props(@JsonProperty("value") String v) { } // [dataformat-xml#547] + @Test public void testNested1ArgCtorsDelegating() throws Exception { String xml = "<outer><inner></inner></outer>"; @@ -47,6 +53,7 @@ public void testNested1ArgCtorsDelegating() throws Exception } // [dataformat-xml#547] + @Test public void testNested1ArgCtorsProps() throws Exception { String xml = "<outer><inner></inner></outer>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/NoArgCtorDeser491Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/NoArgCtorDeser491Test.java index bcc1d0ff2..c2619c8c4 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/NoArgCtorDeser491Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/NoArgCtorDeser491Test.java @@ -1,12 +1,15 @@ package com.fasterxml.jackson.dataformat.xml.deser.creator; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; /** * Reproduces <i>no default no-arg ctor found</i> deserialization regression @@ -24,7 +27,7 @@ * Use cases where (non-empty) element needs to map to Scalar types is now handled * with mechanism introduced in 2.13. */ -public class NoArgCtorDeser491Test extends XmlTestBase +public class NoArgCtorDeser491Test extends XmlTestUtil { @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, @@ -83,6 +86,7 @@ public int getStatus() { /** * Passes on 2.11.4 and 2.12.{0..4}. */ + @Test public void test_empty_Problem_JSON_deserialization() throws Exception { Problem problem = JSON_MAPPER.readValue("{}", Problem.class); @@ -93,6 +97,7 @@ public void test_empty_Problem_JSON_deserialization() throws Exception /** * Passes on 2.11.4, but fails on 2.12.{0..4}. */ + @Test public void test_empty_Problem_XML_deserialization() throws Exception { Problem problem = XML_MAPPER.readValue( diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/PojoWithCreatorRequired538Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/PojoWithCreatorRequired538Test.java index a3e7f3a33..0e2571b84 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/PojoWithCreatorRequired538Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/creator/PojoWithCreatorRequired538Test.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.dataformat.xml.deser.creator; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; @@ -8,7 +10,9 @@ import com.fasterxml.jackson.databind.exc.MismatchedInputException; import com.fasterxml.jackson.dataformat.xml.*; -public class PojoWithCreatorRequired538Test extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + +public class PojoWithCreatorRequired538Test extends XmlTestUtil { @JsonRootName(value = "bar") static class Bar538 @@ -35,6 +39,7 @@ public Bar538(@JsonProperty(value = "foo", required = true) final int foo) .build(); // [dataformat-xml#538] + @Test public void testPojoWithRequiredFromEmpty() throws Exception { // Should fail diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ConflictingGetters27Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ConflictingGetters27Test.java index 035252168..640695f5d 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ConflictingGetters27Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ConflictingGetters27Test.java @@ -1,13 +1,16 @@ package com.fasterxml.jackson.dataformat.xml.failing; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import static org.junit.jupiter.api.Assertions.*; + // For [dataformat-xml#27] -public class ConflictingGetters27Test extends XmlTestBase +public class ConflictingGetters27Test extends XmlTestUtil { // [dataformat-xml#27] @JsonRootName("output") @@ -49,6 +52,7 @@ public BeanInfo() { } */ // [dataformat-xml#27] + @Test public void testIssue27() throws Exception { XmlMapper mapper = new XmlMapper(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ElementWrapperViaCreator149Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ElementWrapperViaCreator149Test.java index 7477515b0..d53c0f2f0 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ElementWrapperViaCreator149Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ElementWrapperViaCreator149Test.java @@ -3,18 +3,23 @@ import java.util.Arrays; import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonRootName; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + // 13-Nov-2020, tatu: Not quite sure how to configure test to pass; // seems like it should work but does not. Leaving for future generations // to figure out... -public class ElementWrapperViaCreator149Test extends XmlTestBase +public class ElementWrapperViaCreator149Test extends XmlTestUtil { @JsonRootName("body") static class Body149 { @@ -44,6 +49,7 @@ public Body149(@JacksonXmlProperty(localName="type") private final ObjectMapper MAPPER = newMapper(); // [dataformat-xml#149] + @Test public void testElementWrapper149() throws Exception { final String XML = "<body>\n" + diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/EnumIssue9Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/EnumIssue9Test.java index c7988819c..87f496fde 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/EnumIssue9Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/EnumIssue9Test.java @@ -1,12 +1,15 @@ package com.fasterxml.jackson.dataformat.xml.failing; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.xml.*; + import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import static org.junit.jupiter.api.Assertions.*; // related to [dataformat-xml#9] (and possibly others) -public class EnumIssue9Test extends XmlTestBase +public class EnumIssue9Test extends XmlTestUtil { static enum TestEnum { A, B, C; } @@ -29,6 +32,7 @@ public UntypedEnumBean() { } private final XmlMapper MAPPER = newMapper(); + @Test public void testUntypedEnum() throws Exception { String xml = MAPPER.writeValueAsString(new UntypedEnumBean(TestEnum.B)); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue37AdapterTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue37AdapterTest.java index 64ee7f673..88cdf7e42 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue37AdapterTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue37AdapterTest.java @@ -7,14 +7,19 @@ import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.adapters.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.dataformat.xml.*; +import static org.junit.jupiter.api.Assertions.*; + // 30-Jun-2020, tatu: This is deferred and possibly won't be fixed // at all. But leaving failing test here just in case future brings // alternate approach to do something. -public class Issue37AdapterTest extends XmlTestBase +public class Issue37AdapterTest extends XmlTestUtil { @XmlJavaTypeAdapter(URLEncoderMapDataAdapter.class) public static class MapData @@ -100,10 +105,9 @@ private Map<String,String> singletonMap(String a, String b) { protected XmlMapper _nonJaxbMapper; - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); _jaxbMapper = new XmlMapper(); _nonJaxbMapper = new XmlMapper(); // Use JAXB-then-Jackson annotation introspector @@ -119,6 +123,7 @@ public void setUp() throws Exception /********************************************************************** */ + @Test public void testSimpleKeyMap() throws Exception { DocWithMapData bean = new DocWithMapData(); @@ -128,6 +133,7 @@ public void testSimpleKeyMap() throws Exception _jaxbMapper.writeValueAsString(bean)); } + @Test public void testNeedEncodingKeyMap() throws Exception { DocWithMapData bean = new DocWithMapData(); @@ -139,6 +145,7 @@ public void testNeedEncodingKeyMap() throws Exception xml); } + @Test public void testSimpleKeyMapSimpleAnnotation() throws Exception { DocWithMapDataSimpleAnnotation bean = new DocWithMapDataSimpleAnnotation(); @@ -149,6 +156,7 @@ public void testSimpleKeyMapSimpleAnnotation() throws Exception _jaxbMapper.writeValueAsString(bean)); } + @Test public void testNeedEncodingKeyMapSimpleAnnotation() throws Exception { DocWithMapDataSimpleAnnotation bean = new DocWithMapDataSimpleAnnotation(); @@ -159,6 +167,7 @@ public void testNeedEncodingKeyMapSimpleAnnotation() throws Exception _jaxbMapper.writeValueAsString(bean)); } + @Test public void testNeedEncodingKeyMap_nonJaxb() throws Exception { DocWithMapData bean = new DocWithMapData(); @@ -169,6 +178,7 @@ public void testNeedEncodingKeyMap_nonJaxb() throws Exception _nonJaxbMapper.writeValueAsString(bean)); } + @Test public void testNeedEncodingKeyMapSimpleAnnotation_nonJaxb() throws Exception { DocWithMapDataSimpleAnnotation bean = new DocWithMapDataSimpleAnnotation(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PojoAsAttributeSer128Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PojoAsAttributeSer128Test.java index 6d1717c61..8d9549001 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PojoAsAttributeSer128Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PojoAsAttributeSer128Test.java @@ -1,15 +1,17 @@ package com.fasterxml.jackson.dataformat.xml.failing; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import static org.junit.jupiter.api.Assertions.*; // [dataformat-xml#128]: Should ignore "as-attribute" setting for POJO -public class PojoAsAttributeSer128Test extends XmlTestBase +public class PojoAsAttributeSer128Test extends XmlTestUtil { static class Bean { public int value = 42; @@ -36,6 +38,7 @@ static class Container { private final XmlMapper MAPPER = newMapper(); + @Test public void testAttributeDeser128() throws Exception { final String output = MAPPER.writeValueAsString(new Container()).trim(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicIssue4Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicIssue4Test.java index 075ba3acb..191803fe3 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicIssue4Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicIssue4Test.java @@ -1,15 +1,18 @@ package com.fasterxml.jackson.dataformat.xml.failing; +import org.junit.jupiter.api.Test; + + import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // for: // // [dataformat-xml#4] // [dataformat-xml#9] (enums) - -public class PolymorphicIssue4Test extends XmlTestBase +public class PolymorphicIssue4Test extends XmlTestUtil { /* /********************************************************** @@ -72,6 +75,7 @@ public ClassArrayWrapper() { } */ // Does not work since array wrapping is not explicitly forced (unlike with collection // property of a bean + @Test public void testAsClassArray() throws Exception { String xml = MAPPER.writeValueAsString(new SubTypeWithClassArray("Foobar")); @@ -83,6 +87,7 @@ public void testAsClassArray() throws Exception // Hmmh. Does not yet quite work either, since we do not properly force // array context when writing... + @Test public void testAsWrappedClassArray() throws Exception { String xml = MAPPER.writeValueAsString(new ClassArrayWrapper("Foobar")); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicList426Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicList426Test.java index 41306aefa..99a1e5586 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicList426Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicList426Test.java @@ -3,17 +3,21 @@ import java.io.IOException; import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver; import com.fasterxml.jackson.databind.jsontype.impl.TypeIdResolverBase; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class PolymorphicList426Test extends XmlTestBase +public class PolymorphicList426Test extends XmlTestUtil { static class Auto { @JacksonXmlProperty(localName = "Object") @@ -84,6 +88,7 @@ public JsonTypeInfo.Id getMechanism() { private final ObjectMapper MAPPER = newMapper(); // [dataformat-xml#426] + @Test public void testPolymorphicList426() throws Exception { String xml = "" + diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicList576Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicList576Test.java index f3f2cca0b..fd59cdcd5 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicList576Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicList576Test.java @@ -4,15 +4,19 @@ import java.util.Arrays; import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class PolymorphicList576Test extends XmlTestBase +public class PolymorphicList576Test extends XmlTestUtil { @JacksonXmlRootElement(localName = "wrapper") static class Wrapper extends Base { @@ -91,6 +95,7 @@ static class Base { private final ObjectMapper XML_MAPPER = newMapper(); + @Test public void test_3itemsInXml_expect_3itemsInDeserializedObject() throws Exception { String xmlString = "<?xml version='1.0' encoding='UTF-8'?>\n" @@ -104,6 +109,7 @@ public void test_3itemsInXml_expect_3itemsInDeserializedObject() throws Exceptio assertEquals(3, ((Wrapper)base).getItems().size()); } + @Test public void test_2itemsInObject_expect_2itemsInObjectAfterRoundTripDeserializationToBaseClass() throws Exception { Wrapper wrapper = new Wrapper(); Item item1 = new Item("1"); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TypeInfoOrder525Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TypeInfoOrder525Test.java index b0bc306f8..28fc032a9 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TypeInfoOrder525Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TypeInfoOrder525Test.java @@ -2,17 +2,20 @@ import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.xml.*; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import static org.junit.jupiter.api.Assertions.*; // Tests for [dataformat-xml#525], related to relative order of "type" // property (as attribute) compared to other properties -public class TypeInfoOrder525Test extends XmlTestBase +public class TypeInfoOrder525Test extends XmlTestUtil { @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @JsonSubTypes({ @@ -46,6 +49,7 @@ static class BindingInfo525 { .defaultUseWrapper(false) .build(); + @Test public void testTypeAfterOtherProperties() throws Exception { String xml = " <typeInfo name=\"MyName\" type=\"ClassInfo\">\n" + @@ -59,6 +63,7 @@ public void testTypeAfterOtherProperties() throws Exception { assertEquals("Test", ((ClassInfo525)m).element.get(0).binding.description); } + @Test public void testTypeBeforeOtherProperties() throws Exception { String xml = " <typeInfo type=\"ClassInfo\" name=\"MyName\">\n" + diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UntypedListSerialization8Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UntypedListSerialization8Test.java index f0d1863b7..2fca3c546 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UntypedListSerialization8Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UntypedListSerialization8Test.java @@ -4,11 +4,15 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Test; + + import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class UntypedListSerialization8Test extends XmlTestBase +public class UntypedListSerialization8Test extends XmlTestUtil { @JsonRootName("L") static class UntypedListBean @@ -48,6 +52,7 @@ public TypedListBean() { * For [dataformat-xml#8] -- Will not use wrapping, if type is not statically known * to be a Collection */ + @Test public void testListAsObject() throws IOException { String xmlForUntyped = MAPPER.writeValueAsString(new UntypedListBean()); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnwrappedAndList299DeserTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnwrappedAndList299DeserTest.java index 7304db20d..d1e07a898 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnwrappedAndList299DeserTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/UnwrappedAndList299DeserTest.java @@ -2,13 +2,17 @@ import java.util.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class UnwrappedAndList299DeserTest extends XmlTestBase +public class UnwrappedAndList299DeserTest extends XmlTestUtil { static class Request { @JsonUnwrapped @@ -29,6 +33,7 @@ static class Header { private final ObjectMapper MAPPER = newMapper(); + @Test public void testXmlMarshallingAndUnmarshalling() throws Exception { final Request request = new Request(); request.composite.messageId = "ABC"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/VerifyRootLocalName247Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/VerifyRootLocalName247Test.java index e9f4d2308..c6f4c327b 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/VerifyRootLocalName247Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/VerifyRootLocalName247Test.java @@ -1,10 +1,15 @@ package com.fasterxml.jackson.dataformat.xml.failing; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; -public class VerifyRootLocalName247Test extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; + +public class VerifyRootLocalName247Test extends XmlTestUtil { // [dataformat-xml#247] static class Root { @@ -20,6 +25,7 @@ static class Root { private final ObjectMapper MAPPER = newMapper(); // [dataformat-xml#247] + @Test public void testRootNameValidation247() throws Exception { Root root = MAPPER diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XmlTextViaCreator306Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XmlTextViaCreator306Test.java index e5d9b60bf..228175f31 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XmlTextViaCreator306Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XmlTextViaCreator306Test.java @@ -2,17 +2,20 @@ import java.beans.ConstructorProperties; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; +import static org.junit.jupiter.api.Assertions.*; + // [dataformat-xml#306]: Problem is that `@XmlText` has no nominal property name // of empty String (""), and that is not properly bound. Worse, empty String has // special meaning so that annotation CANNOT specify it, either. -public class XmlTextViaCreator306Test extends XmlTestBase +public class XmlTextViaCreator306Test extends XmlTestUtil { // [dataformat-xml#306] @JsonRootName("ROOT") @@ -90,6 +93,7 @@ public Sample423(@JacksonXmlText String text, private final XmlMapper MAPPER = newMapper(); // [dataformat-xml#306] + @Test public void testIssue306WithCtor() throws Exception { final String XML = "<ROOT><CHILD attr='attr_value'>text</CHILD></ROOT>"; @@ -97,6 +101,7 @@ public void testIssue306WithCtor() throws Exception assertNotNull(root); } + @Test public void testIssue306NoCtor() throws Exception { final String XML = "<ROOT><CHILD attr='attr_value'>text</CHILD></ROOT>"; @@ -105,6 +110,7 @@ public void testIssue306NoCtor() throws Exception } // [dataformat-xml#423] + @Test public void testXmlTextViaCtor423() throws Exception { final String XML = "<Sample423 attribute='attrValue'>text value</Sample423>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XmlTextWithEmpty449Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XmlTextWithEmpty449Test.java index 1a55fabf3..c3c3d1809 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XmlTextWithEmpty449Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/XmlTextWithEmpty449Test.java @@ -2,14 +2,17 @@ import java.util.List; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.ObjectReader; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; -public class XmlTextWithEmpty449Test extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + +public class XmlTextWithEmpty449Test extends XmlTestUtil { static class Project449 { public Text449 text; @@ -29,6 +32,7 @@ static class Text449 { private final XmlMapper MAPPER = newMapper(); // [dataformat-xml#449] + @Test public void testXmlText449ItemWithAttr() throws Exception { final ObjectReader r = MAPPER.readerFor(Project449.class); @@ -46,6 +50,7 @@ public void testXmlText449ItemWithAttr() throws Exception } // [dataformat-xml#449] + @Test public void testXmlText449ItemWithList() throws Exception { final ObjectReader r = MAPPER.readerFor(Project449WithList.class); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz463_32872_XmlDeclTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz463_32872_XmlDeclTest.java index c88f50a92..d8c73682f 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz463_32872_XmlDeclTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz463_32872_XmlDeclTest.java @@ -2,16 +2,20 @@ import java.nio.charset.StandardCharsets; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.exc.StreamReadException; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // [dataformat-xml#463] // (but root cause of https://github.com/FasterXML/woodstox/issues/123) -public class Fuzz463_32872_XmlDeclTest extends XmlTestBase +public class Fuzz463_32872_XmlDeclTest extends XmlTestUtil { private final XmlMapper MAPPER = newMapper(); + @Test public void testInvalidXmlDecl() throws Exception { final byte[] doc = "<?xml version=\"1.1\" encoding=\"U\"?>".getBytes(StandardCharsets.UTF_8); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz465_32906_CDataReadTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz465_32906_CDataReadTest.java index 82250565c..56fd457c9 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz465_32906_CDataReadTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz465_32906_CDataReadTest.java @@ -1,14 +1,18 @@ package com.fasterxml.jackson.dataformat.xml.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class Fuzz465_32906_CDataReadTest extends XmlTestBase +public class Fuzz465_32906_CDataReadTest extends XmlTestUtil { private final XmlMapper MAPPER = newMapper(); + @Test public void testIssue465() throws Exception { byte[] doc = readResource("/data/fuzz-32906.xml"); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz618_64655_InvalidXMLTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz618_64655_InvalidXMLTest.java index 0e3d66f8a..48e1af0d1 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz618_64655_InvalidXMLTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/Fuzz618_64655_InvalidXMLTest.java @@ -1,26 +1,30 @@ package com.fasterxml.jackson.dataformat.xml.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.exc.StreamReadException; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; -public class Fuzz618_64655_InvalidXMLTest extends XmlTestBase +public class Fuzz618_64655_InvalidXMLTest extends XmlTestUtil { private final XmlMapper MAPPER = newMapper(); + @Test public void testWithInvalidXml1() throws Exception { _testWithInvalidXml(1, "Unexpected end of input", // Woodstox "Internal processing error by `XMLStreamReader` of type" // SJSXP ); } + @Test public void testWithInvalidXml2() throws Exception { _testWithInvalidXml(2, "Unexpected character 'a'", // Woodstox "Internal processing error by `XMLInputFactory` of type " // SJSXP ); } + @Test public void testWithInvalidXml3() throws Exception { _testWithInvalidXml(3, "Unexpected EOF; was expecting a close tag", // Woodstox "XML document structures must start and end" // SJSXP diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/FuzzXXX_32969_UTF32Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/FuzzXXX_32969_UTF32Test.java index 8cf44a36a..60b122ba2 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/FuzzXXX_32969_UTF32Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/fuzz/FuzzXXX_32969_UTF32Test.java @@ -1,18 +1,22 @@ package com.fasterxml.jackson.dataformat.xml.fuzz; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.exc.StreamReadException; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // [dataformat-xml#???] // (but root cause of https://github.com/FasterXML/woodstox/issues/125) // // NOTE! Not reproducible for some reason with these settings (probably // has different buffer sizes or... something -public class FuzzXXX_32969_UTF32Test extends XmlTestBase +public class FuzzXXX_32969_UTF32Test extends XmlTestUtil { private final XmlMapper MAPPER = newMapper(); + @Test public void testUTF32() throws Exception { final byte[] doc = readResource("/data/fuzz-32906.xml"); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/IncrementalWritingTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/IncrementalWritingTest.java index 94d561560..8eade6d3b 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/IncrementalWritingTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/IncrementalWritingTest.java @@ -5,14 +5,19 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamWriter; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.xml.*; import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; -public class IncrementalWritingTest extends XmlTestBase +import static org.junit.jupiter.api.Assertions.*; + + +public class IncrementalWritingTest extends XmlTestUtil { private final XmlMapper MAPPER = xmlMapper(true); + @Test public void testSimple() throws Exception { StringWriter strw = new StringWriter(); @@ -35,6 +40,7 @@ public void testSimple() throws Exception } // @since 2.17 + @Test public void testWriteUsingXMLStreamWriter() throws Exception { XMLOutputFactory staxF = MAPPER.getFactory().getXMLOutputFactory(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/PartialReadTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/PartialReadTest.java index 1d787a2d3..06a1cc01f 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/PartialReadTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/incr/PartialReadTest.java @@ -3,14 +3,18 @@ import java.io.*; import javax.xml.stream.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class PartialReadTest extends XmlTestBase +public class PartialReadTest extends XmlTestUtil { private final XmlMapper MAPPER = xmlMapper(true); + @Test public void testSimpleRead() throws Exception { final String XML = "<?xml version='1.0'?><root>" @@ -46,6 +50,7 @@ public void testSimpleRead() throws Exception } // @since 2.17 + @Test public void testReadUsingXMLStreamReader() throws Exception { final String DOC = "<Point><x>1</x><y>2</y></Point>"; diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/interop/NonWoodstoxStaxImpl482Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/interop/NonWoodstoxStaxImpl482Test.java index b55b9abcb..4ada863d6 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/interop/NonWoodstoxStaxImpl482Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/interop/NonWoodstoxStaxImpl482Test.java @@ -2,14 +2,17 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectReader; -import com.fasterxml.jackson.dataformat.xml.XmlFactory; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import org.junit.jupiter.api.Test; + import com.sun.xml.stream.ZephyrParserFactory; import com.sun.xml.stream.ZephyrWriterFactory; +import static org.junit.jupiter.api.Assertions.*; + // to verify issue behind [dataformat-xml#482] -public class NonWoodstoxStaxImpl482Test extends XmlTestBase +public class NonWoodstoxStaxImpl482Test extends XmlTestUtil { static class Root { public int value = 3; @@ -23,6 +26,7 @@ static class Root { .build(); // [dataformat-xml#482] + @Test public void testSjsxpFromByteArray() throws Exception { byte[] xml0 = SJSXP_MAPPER.writeValueAsBytes(new Root()); @@ -34,6 +38,7 @@ public void testSjsxpFromByteArray() throws Exception } // [dataformat-xml#482] + @Test public void testSjsxpFromCharArray() throws Exception { char[] xml0 = SJSXP_MAPPER.writeValueAsString(new Root()).toCharArray(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/AttributesWithJAXBTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/AttributesWithJAXBTest.java index 113860043..d0dc936ed 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/AttributesWithJAXBTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/AttributesWithJAXBTest.java @@ -4,11 +4,15 @@ import jakarta.xml.bind.annotation.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.dataformat.xml.XmlTestUtil; + +import static org.junit.jupiter.api.Assertions.*; -public class AttributesWithJAXBTest extends XmlTestBase +public class AttributesWithJAXBTest extends XmlTestUtil { @XmlAccessorType(value = XmlAccessType.FIELD) public class Jurisdiction { @@ -38,6 +42,7 @@ public Problem(String id, String description) { /********************************************************** */ + @Test public void testTwoAttributes() throws IOException { XmlMapper mapper = XmlMapper.builder() @@ -48,6 +53,7 @@ public void testTwoAttributes() throws IOException assertEquals("<Jurisdiction name=\"Foo\" value=\"13\"/>", xml); } + @Test public void testAttributeAndElement() throws IOException { XmlMapper mapper = XmlMapper.builder() diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/BuilderWithJAXB291Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/BuilderWithJAXB291Test.java index 381f8372c..542434362 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/BuilderWithJAXB291Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/BuilderWithJAXB291Test.java @@ -5,18 +5,20 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.AnnotationIntrospector; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; -import com.fasterxml.jackson.dataformat.xml.XmlAnnotationIntrospector; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; // Test for [dataformat-xml#291]: works via field, not constructor // (name mismatch to fix in test case) -public class BuilderWithJAXB291Test extends XmlTestBase +public class BuilderWithJAXB291Test extends XmlTestUtil { @JsonDeserialize(builder = Address.AddressBuilder.class) static class Address @@ -108,6 +110,7 @@ public Address build() { /********************************************************************** */ + @Test public void testBuilder291() throws Exception { final String DOC = "<Address>\n" + diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/ElementWrapperTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/ElementWrapperTest.java index 1017d25ee..0eb40db97 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/ElementWrapperTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/ElementWrapperTest.java @@ -7,14 +7,16 @@ import jakarta.xml.bind.annotation.XmlElementWrapper; import jakarta.xml.bind.annotation.XmlRootElement; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.AnnotationIntrospector; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; -import com.fasterxml.jackson.dataformat.xml.XmlAnnotationIntrospector; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.*; + +import static org.junit.jupiter.api.Assertions.*; -public class ElementWrapperTest extends XmlTestBase +public class ElementWrapperTest extends XmlTestUtil { @XmlRootElement(name = "Individual") static class MyPerson { @@ -38,6 +40,7 @@ static class MyPerson2 { /********************************************************************** */ + @Test public void testElementWrapper() throws Exception { XmlMapper _jaxbMapper = new XmlMapper(); @@ -63,6 +66,7 @@ public void testElementWrapper() throws Exception } // And with JAXB, default should be "no wrapper" + @Test public void testNoElementWrapper() throws Exception { XmlMapper jaxbMapper = mapperBuilder() diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/JAXBObjectId170Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/JAXBObjectId170Test.java index 08568096f..ff77a994d 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/JAXBObjectId170Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/JAXBObjectId170Test.java @@ -5,6 +5,8 @@ import jakarta.xml.bind.annotation.*; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.AnnotationIntrospector; @@ -12,9 +14,12 @@ import com.fasterxml.jackson.dataformat.xml.XmlAnnotationIntrospector; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; -public class JAXBObjectId170Test extends XmlTestBase +import com.fasterxml.jackson.dataformat.xml.XmlTestUtil; + +import static org.junit.jupiter.api.Assertions.*; + +public class JAXBObjectId170Test extends XmlTestUtil { static class Company { @@ -85,6 +90,7 @@ static class LaptopComputer extends Computer { */ // for [dataformat-xml#178] + @Test public void testPolyIdList178() throws Exception { final String XML = diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/JaxbXmlValue418Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/JaxbXmlValue418Test.java index fcf3d1220..3590a8f96 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/JaxbXmlValue418Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/JaxbXmlValue418Test.java @@ -4,15 +4,19 @@ import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlValue; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonRootName; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.XmlTestUtil; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; +import static org.junit.jupiter.api.Assertions.*; + // Problem with handling of `@XmlValue` via JAXBAnnotationIntrospector // is that by default it gives implicit name of `value` for virtual // property. Although accessor itself will be specially processed, this @@ -23,7 +27,7 @@ // binding can not be relied on) // 2. Override default implicit name to be `null`, which should allow // combination of accessors -public class JaxbXmlValue418Test extends XmlTestBase +public class JaxbXmlValue418Test extends XmlTestUtil { // [dataformat-xml#418] @XmlRootElement(name = "ROOT") @@ -98,6 +102,7 @@ public void setEl(String el) { private static final String EXPECTED_418 = "<ROOT><CHILD attr=\"attr_value\">text</CHILD></ROOT>"; // [dataformat-xml#418] + @Test public void testWithJaxbAnnotations() throws Exception { final RootWithJaxbAnnotations value = new RootWithJaxbAnnotations(); @@ -113,6 +118,7 @@ public void testWithJaxbAnnotations() throws Exception { assertEquals(EXPECTED_418, xml); } + @Test public void testWithJacksonAnnotations() throws Exception { final RootWithJacksonAnnotations value = new RootWithJacksonAnnotations(); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/NamespaceViaJAXB18Test.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/NamespaceViaJAXB18Test.java index 663c6786a..2742a67ec 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/NamespaceViaJAXB18Test.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/NamespaceViaJAXB18Test.java @@ -1,12 +1,16 @@ package com.fasterxml.jackson.dataformat.xml.jaxb; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; - import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlRootElement; -public class NamespaceViaJAXB18Test extends XmlTestBase +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.XmlTestUtil; + +import static org.junit.jupiter.api.Assertions.*; + +public class NamespaceViaJAXB18Test extends XmlTestUtil { final static String TEST_NAMESPACE = "http://namespace-base"; @@ -36,6 +40,7 @@ static class HouseWithNoNamespace2 implements Facility { .build(); // [dataformat-xml#18] + @Test public void testNamespaceViaJAXB() throws Exception { String xml = MAPPER.writeValueAsString(new House()); diff --git a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/WithJAXBAnnotationsTest.java b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/WithJAXBAnnotationsTest.java index 67604b01f..14325ad8b 100644 --- a/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/WithJAXBAnnotationsTest.java +++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/WithJAXBAnnotationsTest.java @@ -4,20 +4,25 @@ import jakarta.xml.bind.annotation.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.AnnotationIntrospector; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.dataformat.xml.XmlAnnotationIntrospector; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.XmlTestBase; +import com.fasterxml.jackson.dataformat.xml.XmlTestUtil; + +import static org.junit.jupiter.api.Assertions.*; /** * Although XML-backed data binding does not rely (or directly build) on JAXB * annotations, it should be possible to use them similar to how they are used * with default Jackson JSON data binding. Let's verify this is the case. */ -public class WithJAXBAnnotationsTest extends XmlTestBase +public class WithJAXBAnnotationsTest extends XmlTestUtil { /* /********************************************************************** @@ -91,9 +96,8 @@ public void setLastName(final String lastName) { protected XmlMapper _nonJaxbMapper; // let's actually reuse XmlMapper to make things bit faster - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); _jaxbMapper = new XmlMapper(); _nonJaxbMapper = new XmlMapper(); // Use JAXB-then-Jackson annotation introspector @@ -112,6 +116,7 @@ public void setUp() throws Exception { * Unit test for verifying that root element name can be overridden * with {@link XmlRootElement} annotation. */ + @Test public void testRootName() throws Exception { RootBean bean = new RootBean(); @@ -124,6 +129,7 @@ public void testRootName() throws Exception * Unit test for verifying that a property defaults to being written as * element, but can be redefined with {@link XmlAttribute} annotation. */ + @Test public void testSerializeAsAttr() throws Exception { AttrBean bean = new AttrBean(); @@ -135,6 +141,7 @@ public void testSerializeAsAttr() throws Exception * Unit test for verifying correct handling of * {@link XmlValue} annotation. */ + @Test public void testAsTextWithJAXB() throws IOException { // first: serialize @@ -148,6 +155,7 @@ public void testAsTextWithJAXB() throws IOException assertEquals("else", result.text); } + @Test public void testPersonAsXml() throws Exception { MyPerson person = new MyPerson(); person.id = Long.valueOf(1L);