|
14 | 14 |
|
15 | 15 | package com.fasterxml.jackson.dataformat.ion;
|
16 | 16 |
|
17 |
| -import com.fasterxml.jackson.core.JsonParser; |
18 |
| -import com.fasterxml.jackson.core.JsonToken; |
19 |
| -import com.fasterxml.jackson.core.StreamReadCapability; |
| 17 | +import com.fasterxml.jackson.core.*; |
20 | 18 |
|
21 | 19 | import org.junit.Assert;
|
22 | 20 |
|
|
28 | 26 | import java.io.IOException;
|
29 | 27 | import java.math.BigDecimal;
|
30 | 28 | import java.math.BigInteger;
|
| 29 | +import java.util.List; |
31 | 30 | import org.junit.Test;
|
32 | 31 |
|
33 | 32 | @SuppressWarnings("resource")
|
@@ -125,4 +124,54 @@ public void testParserCapabilities() throws Exception {
|
125 | 124 | }
|
126 | 125 | }
|
127 | 126 |
|
| 127 | + |
| 128 | + @Test(expected = JsonParseException.class) |
| 129 | + public void testIonExceptionIsWrapped() throws IOException { |
| 130 | + IonFactory f = new IonFactory(); |
| 131 | + try (IonParser parser = (IonParser) f.createParser("[ 12, true ) ]")) { |
| 132 | + Assert.assertEquals(JsonToken.START_ARRAY, parser.nextToken()); |
| 133 | + Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue()); |
| 134 | + Assert.assertEquals(12, parser.getIntValue()); |
| 135 | + Assert.assertEquals(JsonToken.VALUE_TRUE, parser.nextValue()); |
| 136 | + parser.nextValue(); |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + @Test(expected = JsonParseException.class) |
| 141 | + public void testUnknownSymbolExceptionForValueIsWrapped() throws IOException { |
| 142 | + IonFactory f = new IonFactory(); |
| 143 | + try (IonParser parser = (IonParser) f.createParser("[ 12, $99 ]")) { |
| 144 | + Assert.assertEquals(JsonToken.START_ARRAY, parser.nextToken()); |
| 145 | + Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue()); |
| 146 | + Assert.assertEquals(12, parser.getIntValue()); |
| 147 | + Assert.assertEquals(JsonToken.VALUE_STRING, parser.nextValue()); |
| 148 | + parser.getValueAsString(); // Should encounter unknown symbol and fail |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + @Test(expected = JsonParseException.class) |
| 153 | + public void testUnknownSymbolExceptionForFieldNameIsWrapped() throws IOException { |
| 154 | + IonFactory f = new IonFactory(); |
| 155 | + try (IonParser parser = (IonParser) f.createParser("{ a: 1, $99: 2 }")) { |
| 156 | + Assert.assertEquals(JsonToken.START_OBJECT, parser.nextToken()); |
| 157 | + Assert.assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); |
| 158 | + Assert.assertEquals("a", parser.getCurrentName()); |
| 159 | + Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue()); |
| 160 | + Assert.assertEquals(1, parser.getIntValue()); |
| 161 | + parser.nextValue(); // Should encounter unknown symbol and fail |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + @Test(expected = JsonParseException.class) |
| 166 | + public void testUnknownSymbolExceptionForAnnotationIsWrapped() throws IOException { |
| 167 | + IonFactory f = new IonFactory(); |
| 168 | + try (IonParser parser = (IonParser) f.createParser("{ a: $99::1 }")) { |
| 169 | + Assert.assertEquals(JsonToken.START_OBJECT, parser.nextToken()); |
| 170 | + Assert.assertEquals(JsonToken.FIELD_NAME, parser.nextToken()); |
| 171 | + Assert.assertEquals("a", parser.getCurrentName()); |
| 172 | + Assert.assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue()); |
| 173 | + Assert.assertEquals(1, parser.getIntValue()); |
| 174 | + parser.getTypeAnnotations(); // Should encounter unknown symbol and fail |
| 175 | + } |
| 176 | + } |
128 | 177 | }
|
0 commit comments