Search in sources :

Example 21 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncSimpleNestedTest method _testMismatchedObject.

private void _testMismatchedObject(JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    try {
        r.nextToken();
        fail("Should not pass");
    } catch (JsonParseException e) {
        verifyException(e, "Unexpected close marker ']': expected '}'");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 22 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncSimpleNestedTest method _testStuffInObject.

private void _testStuffInObject(JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertFalse(r.parser().hasTextCharacters());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("foobar", r.currentName());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    assertEquals("[", r.currentText());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(1, r.getIntValue());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(2, r.getIntValue());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(-999, r.getIntValue());
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("emptyObject", r.currentName());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("emptyArray", r.currentName());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("other", r.currentName());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("", r.currentName());
    assertToken(JsonToken.VALUE_NULL, r.nextToken());
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    // another twist: close in the middle, verify
    r = asyncForBytes(f, readSize, data, offset);
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    r.parser().close();
    assertTrue(r.parser().isClosed());
    assertNull(r.parser().nextToken());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 23 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncSimpleNestedTest method _testMismatchedArray.

private void _testMismatchedArray(JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    try {
        r.nextToken();
        fail("Should not pass");
    } catch (JsonParseException e) {
        verifyException(e, "Unexpected close marker '}': expected ']'");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 24 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncSimpleNestedTest method _testStuffInArray2.

private void _testStuffInArray2(JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals(SHORT_NAME, r.currentName());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals(LONG_NAME, r.currentName());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals(LONG_NAME, r.currentName());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    assertToken(JsonToken.START_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals(SHORT_NAME, r.currentName());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertToken(JsonToken.END_OBJECT, r.nextToken());
    assertToken(JsonToken.END_ARRAY, r.nextToken());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 25 with AsyncReaderWrapper

use of com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper in project jackson-core by FasterXML.

the class AsyncStringArrayTest method _testStrings.

private void _testStrings(JsonFactory f, String[] values, byte[] data, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    for (int i = 0; i < values.length; ++i) {
        assertToken(JsonToken.VALUE_STRING, r.nextToken());
        assertEquals(values[i], r.currentText());
    // 13-May-2017, tatu: Rules of whether efficient char[] does or does not
    // exist vary... So let's NOT try to determine at this point.
    // assertTrue(r.parser().hasTextCharacters());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Aggregations

AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)87 Test (org.junit.Test)10 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)5 BigDecimal (java.math.BigDecimal)4 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 NonBlockingJsonParserBase (com.fasterxml.jackson.core.json.async.NonBlockingJsonParserBase)2 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2