Skip to content

Commit

Permalink
Migrate tests jaxb (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim authored Jan 19, 2025
1 parent fef36bb commit a30ebe5
Show file tree
Hide file tree
Showing 42 changed files with 267 additions and 16 deletions.
9 changes: 7 additions & 2 deletions jaxb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ for configuring data-binding.
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;

public abstract class BaseJaxbTest
extends junit.framework.TestCase
{
public static class NoCheckSubTypeValidator
extends PolymorphicTypeValidator.Base
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.fasterxml.jackson.module.jaxb;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;

import com.fasterxml.jackson.databind.type.TypeFactory;

import static org.junit.jupiter.api.Assertions.*;

public class TestVersions extends BaseJaxbTest
{
@Test
public void testVersions()
{
assertVersion(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
Expand All @@ -21,7 +26,7 @@ public void testVersions()
private void assertVersion(Versioned vers)
{
Version v = vers.version();
assertFalse("Should find version information (got "+v+")", v.isUnknownVersion());
assertFalse(v.isUnknownVersion(), "Should find version information (got "+v+")");
Version exp = PackageVersion.VERSION;
assertEquals(exp.toFullString(), v.toFullString());
assertEquals(exp, v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
/**
* @author Ryan Heaton
*/
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class EntryType<K, V> {

private K key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class MapAdapter<K, V> extends XmlAdapter<MapType<K, V>, Map<K, V>>
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
/**
* @author Ryan Heaton
*/
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class MapType<K,V> {

public List<EntryType<K, V>> entries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;

import static org.junit.jupiter.api.Assertions.*;

/**
* Tests for verifying JAXB adapter handling for {@link java.util.Map}
* types.
Expand Down Expand Up @@ -64,6 +68,7 @@ public Map<String, String> unmarshal(Map<String, String> input)
/**********************************************************
*/

@Test
public void testJacksonAdaptedMapType() throws IOException
{
ObjectContainingAMap obj = new ObjectContainingAMap();
Expand All @@ -83,6 +88,7 @@ public void testJacksonAdaptedMapType() throws IOException
assertEquals("here", map.get("how"));
}

@Test
public void testStringMaps() throws IOException
{
ObjectMapper mapper = getJaxbMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;

import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests for checking that JAXB type adapters work (to some
* degree, anyway).
Expand Down Expand Up @@ -164,12 +168,14 @@ public IdentityAdapterPropertyBean() { }
/**********************************************************
*/

@Test
public void testSimpleAdapterSerialization() throws Exception
{
Bean bean = new Bean(123L);
assertEquals("{\"value\":\"XXX\"}", getJaxbMapper().writeValueAsString(bean));
}

@Test
public void testSimpleAdapterDeserialization() throws Exception
{
Bean bean = getJaxbMapper().readValue("{\"value\":\"abc\"}", Bean.class);
Expand All @@ -178,6 +184,7 @@ public void testSimpleAdapterDeserialization() throws Exception
}

// [JACKSON-288]
@Test
public void testDateAdapter() throws Exception
{
Bean288 input = new Bean288("test");
Expand All @@ -189,6 +196,7 @@ public void testDateAdapter() throws Exception

// [JACKSON-656]

@Test
public void testJackson656() throws Exception
{
Bean656 bean = new Bean656();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;
import com.fasterxml.jackson.module.jaxb.introspect.TestJaxbAnnotationIntrospector.KeyValuePair;

import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests to check that {@link XmlAdapter}s also work with
* container types (Lists, Maps)
Expand Down Expand Up @@ -112,12 +116,14 @@ public void setValues(List<Date> values) {
/**********************************************************
*/

@Test
public void testAdapterForList() throws Exception
{
Wrapper w = new Wrapper(123L);
assertEquals("{\"values\":[\"XXX\"]}", getJaxbMapper().writeValueAsString(w));
}

@Test
public void testSimpleAdapterDeserialization() throws Exception
{
Wrapper w = getJaxbMapper().readValue("{\"values\":[\"abc\"]}", Wrapper.class);
Expand All @@ -127,12 +133,14 @@ public void testSimpleAdapterDeserialization() throws Exception
assertEquals(29L, w.values.get(0).getTime());
}

@Test
public void testAdapterOnGetterSerialization() throws Exception
{
WrapperWithGetterAndSetter w = new WrapperWithGetterAndSetter(123L);
assertEquals("{\"values\":[\"XXX\"]}", getJaxbMapper().writeValueAsString(w));
}

@Test
public void testAdapterOnGetterDeserialization() throws Exception
{
WrapperWithGetterAndSetter w = getJaxbMapper().readValue("{\"values\":[\"abc\"]}",
Expand All @@ -149,6 +157,7 @@ public void testAdapterOnGetterDeserialization() throws Exception
/**********************************************************
*/

@Test
public void testAdapterForBeanWithMap() throws Exception
{
ObjectMapper mapper = getJaxbMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;

import static org.junit.jupiter.api.Assertions.*;

/**
* Failing unit tests related to Adapter handling.
*/
Expand Down Expand Up @@ -60,6 +64,7 @@ public IdentityAdapterPropertyBean() { }
*/

// [Issue-10]
@Test
public void testIdentityAdapterForClass() throws Exception
{
IdentityAdapterBean input = new IdentityAdapterBean("A");
Expand All @@ -73,6 +78,7 @@ public void testIdentityAdapterForClass() throws Exception
}

// [Issue-10]
@Test
public void testIdentityAdapterForProperty() throws Exception
{
IdentityAdapterPropertyBean input = new IdentityAdapterPropertyBean("B");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;

import static org.junit.jupiter.api.Assertions.*;

public class TestEnums256 extends BaseJaxbTest
{
// [modules-base#256]
Expand Down Expand Up @@ -40,6 +44,7 @@ public enum Code {
private final ObjectMapper MAPPER = getJaxbMapper();

// [modules-base#256]
@Test
public void testEnumSerialize256() throws Exception
{
final Document256 document = new Document256(Code.RED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import javax.xml.bind.annotation.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;

import static org.junit.jupiter.api.Assertions.*;

public class TestUnwrapping extends BaseJaxbTest
{
@XmlRootElement
Expand Down Expand Up @@ -51,6 +55,7 @@ public B(String type) {
*/

// not asserting anything
@Test
public void testXmlElementAndXmlElementRefs() throws Exception
{
Bean<A> bean = new Bean<A>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;

import static org.junit.jupiter.api.Assertions.*;

// for [modules-base#46]: XmlId semantics can not be supported by Jackson/JAXB-annotation-mapper
public class TestXmlID3 extends BaseJaxbTest
{
Expand Down Expand Up @@ -45,6 +49,7 @@ static class HasIDList
public HasID getParent() { return parent; }
}

@Test
public void testIssue46() throws Exception
{
ObjectMapper mapper = getJaxbAndJacksonMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import javax.xml.bind.annotation.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;

import static org.junit.jupiter.api.Assertions.*;

/**
* Simple testing to verify that XmlID and XMLIDREF handling works
* to degree we can make it work.
Expand Down Expand Up @@ -55,6 +59,7 @@ public Employee() {
/**********************************************************
*/

@Test
public void testSimpleRefs() throws Exception
{
final ObjectMapper mapper = getJaxbMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import javax.xml.bind.annotation.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
Expand All @@ -12,6 +14,8 @@
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;

import static org.junit.jupiter.api.Assertions.*;

// Reproduction of [Issue-9]
public class TestXmlID2 extends BaseJaxbTest
{
Expand Down Expand Up @@ -113,6 +117,7 @@ private List<User> getUserList()
return resultList;
}

@Test
public void testIdWithJacksonRules() throws Exception
{
ObjectMapper mapper = JsonMapper.builder()
Expand Down Expand Up @@ -144,6 +149,7 @@ public void testIdWithJacksonRules() throws Exception
assertEquals(null, result.get(2).department);
}

@Test
public void testIdWithJaxbRules() throws Exception
{
// but then also variant where ID is ALWAYS used for XmlID / XmlIDREF
Expand Down
Loading

0 comments on commit a30ebe5

Please sign in to comment.