Skip to content

Commit 0130a8e

Browse files
committed
Add basic Avro test
1 parent 09d6a18 commit 0130a8e

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

pom.xml

+6-4
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,13 @@
171171

172172
<!-- JSONP/JSR-353 datatype modules will need actual JSON-P provider impls:
173173
-->
174-
<!-- "new" jakarta jsonp: -->
174+
175+
<!-- "new" jakarta jsonp: API transitively exposed but need impl -->
175176
<dependency>
176-
<groupId>jakarta.json</groupId>
177-
<artifactId>jakarta.json-api</artifactId>
178-
<version>2.1.3</version>
177+
<groupId>org.eclipse.parsson</groupId>
178+
<artifactId>parsson</artifactId>
179+
<version>1.1.7</version>
180+
<scope>test</scope>
179181
</dependency>
180182

181183
<!-- Some general modules -->

src/test/java/tools/jackson/integtest/df/basic/BasicReadWriteAvroTest.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
import org.junit.jupiter.api.Test;
44

5-
import tools.jackson.databind.ObjectMapper;
6-
5+
import tools.jackson.dataformat.avro.AvroMapper;
6+
import tools.jackson.dataformat.avro.AvroSchema;
77
import tools.jackson.integtest.BaseTest;
88

9-
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
1010

1111
public class BasicReadWriteAvroTest extends BaseTest
1212
{
1313
@Test
14-
public void testSimple() throws Exception
14+
public void testBasicReadWrite() throws Exception
1515
{
16-
ObjectMapper mapper = avroMapper();
16+
AvroMapper mapper = avroMapper();
17+
18+
AvroSchema schema = mapper.schemaFor(PointXYZ.class);
19+
20+
PointXYZ input = new PointXYZ(1, 2, 3);
21+
byte[] encoded = mapper.writer(schema).writeValueAsBytes(input);
22+
23+
PointXYZ output = mapper.readerFor(PointXYZ.class)
24+
.with(schema).readValue(encoded);
1725

18-
// !!! 23-Feb-2016, tatu: Trivial to avoid using any Schema
19-
assertNotNull(mapper);
26+
assertEquals(input, output);
2027
}
2128
}

src/test/java/tools/jackson/integtest/dt/jsonp/JakartaNewJsonpTest.java

+11-19
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,16 @@ public class JakartaNewJsonpTest extends BaseTest
2626
@Test
2727
public void testSimpleDeser() throws Exception
2828
{
29-
if (false) {
30-
ObjectMapper mapper;
31-
try {
32-
mapper = jsonMapperBuilder()
33-
.addModule(new JSONPModule())
34-
.build();
35-
} catch (Throwable t) {
36-
t.printStackTrace();
37-
mapper = null;
38-
}
39-
final String JSON = "[1,true,\"foo\"]";
40-
JsonValue v = mapper.readValue(JSON, JsonValue.class);
41-
assertTrue(v instanceof JsonArray);
42-
JsonArray a = (JsonArray) v;
43-
assertEquals(3, a.size());
44-
assertTrue(a.get(0) instanceof JsonNumber);
45-
assertSame(JsonValue.TRUE, a.get(1));
46-
assertTrue(a.get(2) instanceof JsonString);
47-
}
29+
ObjectMapper mapper = jsonMapperBuilder()
30+
.addModule(new JSONPModule())
31+
.build();
32+
final String JSON = "[1,true,\"foo\"]";
33+
JsonValue v = mapper.readValue(JSON, JsonValue.class);
34+
assertTrue(v instanceof JsonArray);
35+
JsonArray a = (JsonArray) v;
36+
assertEquals(3, a.size());
37+
assertTrue(a.get(0) instanceof JsonNumber);
38+
assertSame(JsonValue.TRUE, a.get(1));
39+
assertTrue(a.get(2) instanceof JsonString);
4840
}
4941
}

0 commit comments

Comments
 (0)