Search in sources :

Example 11 with AsyncReaderWrapper

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

the class AsyncRootValuesTest method _testTokenRootTokens.

private void _testTokenRootTokens(JsonToken expToken, JsonFactory f, byte[] data, int offset, int readSize) throws IOException {
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    assertNull(r.currentToken());
    assertToken(expToken, r.nextToken());
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 12 with AsyncReaderWrapper

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

the class AsyncScopeMatchingTest method testMisssingColon.

public void testMisssingColon(int mode) throws Exception {
    final String JSON = "{ \"a\" \"b\" }";
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        // can be either here, or with next one...
        assertToken(JsonToken.FIELD_NAME, p.nextToken());
        p.nextToken();
        fail("Expected an exception for missing semicolon");
    } catch (JsonParseException pe) {
        verifyException(pe, "was expecting a colon");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 13 with AsyncReaderWrapper

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

the class AsyncScopeMatchingTest method testUnclosedObject.

public void testUnclosedObject(int mode) throws Exception {
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc("{ \"key\" : 3  "), 0);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertToken(JsonToken.FIELD_NAME, p.nextToken());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    try {
        p.nextToken();
        fail("Expected an exception for unclosed OBJECT (mode: " + mode + ")");
    } catch (JsonParseException pe) {
        verifyException(pe, "expected close marker for OBJECT");
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 14 with AsyncReaderWrapper

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

the class AsyncScopeMatchingTest method testMismatchObjectToArray.

public void testMismatchObjectToArray() throws Exception {
    final String JSON = "{ ]";
    AsyncReaderWrapper p = asyncForBytes(JSON_F, 3, _jsonDoc(JSON), 0);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    try {
        p.nextToken();
        fail("Expected an exception for incorrectly closed OBJECT");
    } catch (JsonParseException pe) {
        verifyException(pe, "Unexpected close marker ']': expected '}'");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)

Example 15 with AsyncReaderWrapper

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

the class AsyncSimpleObjectTest method _testBooleans.

private void _testBooleans(JsonFactory f, 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_OBJECT, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("a", r.currentText());
    // by default no cheap access to char[] version:
    assertFalse(r.parser().hasTextCharacters());
    // but...
    char[] ch = r.parser().getTextCharacters();
    assertEquals(0, r.parser().getTextOffset());
    assertEquals(1, r.parser().getTextLength());
    assertEquals("a", new String(ch, 0, 1));
    assertTrue(r.parser().hasTextCharacters());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("b", r.currentText());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("acdc", r.currentText());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals(UNICODE_SHORT_NAME, r.currentText());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("a1234567", r.currentText());
    assertToken(JsonToken.VALUE_FALSE, r.nextToken());
    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals(UNICODE_LONG_NAME, r.currentText());
    assertToken(JsonToken.VALUE_TRUE, r.nextToken());
    // and for fun let's verify can't access this as number or binary
    try {
        r.getDoubleValue();
        fail("Should not pass");
    } catch (JsonProcessingException e) {
        verifyException(e, "Current token (VALUE_TRUE) not numeric");
    }
    try {
        r.parser().getBinaryValue();
        fail("Should not pass");
    } catch (JsonProcessingException e) {
        verifyException(e, "Current token (VALUE_TRUE) not");
        verifyException(e, "can not access as binary");
    }
    assertToken(JsonToken.END_OBJECT, 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