Skip to content

Commit 57e63b1

Browse files
committed
Serialization-deserialization tests moved into BigDecimal_serialization_and_deserializationTest.java
1 parent 997ad53 commit 57e63b1

File tree

1 file changed

+1
-92
lines changed

1 file changed

+1
-92
lines changed

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/BigDecimalTest.java renamed to avro/src/test/java/com/fasterxml/jackson/dataformat/avro/BigDecimal_serialization_and_deserializationTest.java

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,105 +2,14 @@
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.fasterxml.jackson.databind.JsonMappingException;
6-
import com.fasterxml.jackson.dataformat.avro.annotation.Decimal;
7-
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;
8-
import org.apache.avro.LogicalTypes;
9-
import org.apache.avro.Schema;
10-
import org.junit.Test;
115

126
import java.math.BigDecimal;
137

148
import static org.assertj.core.api.Assertions.assertThat;
159

16-
public class BigDecimalTest extends AvroTestBase {
10+
public class BigDecimal_serialization_and_deserializationTest extends AvroTestBase {
1711
private static final AvroMapper MAPPER = new AvroMapper();
1812

19-
static class BigDecimalWithDecimalAnnotationWrapper {
20-
@JsonProperty(required = true) // field is required to have simpler avro schema
21-
@Decimal(precision = 10, scale = 2)
22-
public final BigDecimal bigDecimalValue;
23-
24-
public BigDecimalWithDecimalAnnotationWrapper(BigDecimal bigDecimalValue) {
25-
this.bigDecimalValue = bigDecimalValue;
26-
}
27-
}
28-
29-
@Test
30-
public void testSchemaCreation_withLogicalTypesDisabled_onBigDecimalWithDecimalAnnotation() throws JsonMappingException {
31-
// GIVEN
32-
AvroSchemaGenerator gen = new AvroSchemaGenerator()
33-
.disableLogicalTypes();
34-
35-
// WHEN
36-
MAPPER.acceptJsonFormatVisitor(BigDecimalWithDecimalAnnotationWrapper.class, gen);
37-
// actualSchema = MAPPER.schemaFor(BigDecimalWithDecimalAnnotationWrapper.class) would be enough in this case
38-
// because logical types are disabled by default.
39-
final Schema actualSchema = gen.getGeneratedSchema().getAvroSchema();
40-
41-
System.out.println(BigDecimalWithDecimalAnnotationWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));
42-
43-
// THEN
44-
assertThat(actualSchema.getField("bigDecimalValue")).isNotNull();
45-
Schema bigDecimalValue = actualSchema.getField("bigDecimalValue").schema();
46-
assertThat(bigDecimalValue.getType()).isEqualTo(Schema.Type.STRING);
47-
assertThat(bigDecimalValue.getLogicalType()).isNull();
48-
assertThat(bigDecimalValue.getProp("java-class")).isEqualTo("java.math.BigDecimal");
49-
}
50-
51-
@Test
52-
public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithDecimalAnnotation() throws JsonMappingException {
53-
// GIVEN
54-
AvroSchemaGenerator gen = new AvroSchemaGenerator()
55-
.enableLogicalTypes();
56-
57-
// WHEN
58-
MAPPER.acceptJsonFormatVisitor(BigDecimalWithDecimalAnnotationWrapper.class, gen);
59-
final Schema actualSchema = gen.getGeneratedSchema().getAvroSchema();
60-
61-
System.out.println(BigDecimalWithDecimalAnnotationWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));
62-
63-
// THEN
64-
assertThat(actualSchema.getField("bigDecimalValue")).isNotNull();
65-
Schema bigDecimalValue = actualSchema.getField("bigDecimalValue").schema();
66-
assertThat(bigDecimalValue.getType()).isEqualTo(Schema.Type.BYTES);
67-
assertThat(bigDecimalValue.getLogicalType()).isEqualTo(LogicalTypes.decimal(10, 2));
68-
assertThat(bigDecimalValue.getProp("java-class")).isNull();
69-
}
70-
71-
static class BigDecimalWithDecimalAnnotationToFixedWrapper {
72-
@JsonProperty(required = true) // field is required to have simpler avro schema
73-
@AvroFixedSize(typeName = "BigDecimalWithDecimalAnnotationToFixedWrapper", size = 10)
74-
@Decimal(precision = 6, scale = 3)
75-
public final BigDecimal bigDecimalValue;
76-
77-
public BigDecimalWithDecimalAnnotationToFixedWrapper(BigDecimal bigDecimalValue) {
78-
this.bigDecimalValue = bigDecimalValue;
79-
}
80-
}
81-
82-
@Test
83-
public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithDecimalAnnotationToFixed() throws JsonMappingException {
84-
// GIVEN
85-
AvroSchemaGenerator gen = new AvroSchemaGenerator()
86-
.enableLogicalTypes();
87-
88-
// WHEN
89-
MAPPER.acceptJsonFormatVisitor(BigDecimalWithDecimalAnnotationToFixedWrapper.class, gen);
90-
final Schema actualSchema = gen.getGeneratedSchema().getAvroSchema();
91-
92-
System.out.println(BigDecimalWithDecimalAnnotationToFixedWrapper.class.getSimpleName() + " schema:" + actualSchema.toString(true));
93-
94-
// THEN
95-
assertThat(actualSchema.getField("bigDecimalValue")).isNotNull();
96-
97-
Schema bigDecimalValue = actualSchema.getField("bigDecimalValue").schema();
98-
assertThat(bigDecimalValue.getType()).isEqualTo(Schema.Type.FIXED);
99-
assertThat(bigDecimalValue.getFixedSize()).isEqualTo(10);
100-
assertThat(bigDecimalValue.getLogicalType()).isEqualTo(LogicalTypes.decimal(6, 3));
101-
assertThat(bigDecimalValue.getProp("java-class")).isNull();
102-
}
103-
10413
static class BigDecimalAndName {
10514
public final BigDecimal bigDecimalValue;
10615
public final String name;

0 commit comments

Comments
 (0)