Skip to content

Commit

Permalink
Merge branch 'feature/BT-4418-utf8faunareader_read_boolean' into feat…
Browse files Browse the repository at this point in the history
…ure/BT-4418-utf8faunareader_read_date_and_time
  • Loading branch information
pchitolina-fauna committed Jan 25, 2024
2 parents 783d5d2 + 991e28f commit eef6eae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 37 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/gradle-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run Gradle Tests

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: corretto

- name: Run Gradle test
run: ./gradlew test
47 changes: 10 additions & 37 deletions faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public boolean read() throws IOException {
case VALUE_STRING:
currentFaunaTokenType = FaunaTokenType.STRING;
break;
case NOT_AVAILABLE:
case START_OBJECT:
handleStartObject();
break;
Expand All @@ -121,44 +120,20 @@ private void handleStartObject() throws IOException {
switch (jsonParser.currentToken()) {
case FIELD_NAME:
switch (jsonParser.getText()) {
case DATE_TAG:
handleTaggedString(FaunaTokenType.DATE);
break;
case DOC_TAG:
advance();
currentFaunaTokenType = FaunaTokenType.START_DOCUMENT;
tokenStack.push(FaunaTokenType.START_DOCUMENT);
break;
case DOUBLE_TAG:
handleTaggedString(FaunaTokenType.DOUBLE);
break;
case INT_TAG:
handleTaggedString(FaunaTokenType.INT);
break;
case DATE_TAG:
case DOC_TAG:
case DOUBLE_TAG:
case LONG_TAG:
handleTaggedString(FaunaTokenType.LONG);
break;
case MOD_TAG:
handleTaggedString(FaunaTokenType.MODULE);
break;
case OBJECT_TAG:
advance();
currentFaunaTokenType = FaunaTokenType.START_OBJECT;
tokenStack.push(TokenTypeInternal.START_ESCAPED_OBJECT);
break;
case REF_TAG:
advance();
currentFaunaTokenType = FaunaTokenType.START_REF;
tokenStack.push(FaunaTokenType.START_REF);
break;
case SET_TAG:
advance();
currentFaunaTokenType = FaunaTokenType.START_PAGE;
tokenStack.push(FaunaTokenType.START_PAGE);
break;
case TIME_TAG:
handleTaggedString(FaunaTokenType.TIME);
break;
throw new SerializationException(
"Token not implemented: " + jsonParser.currentToken());
default:
bufferedFaunaTokenType = FaunaTokenType.FIELD_NAME;
tokenStack.push(FaunaTokenType.START_OBJECT);
Expand All @@ -167,10 +142,8 @@ private void handleStartObject() throws IOException {
}
break;
case END_OBJECT:
bufferedFaunaTokenType = FaunaTokenType.END_OBJECT;
tokenStack.push(FaunaTokenType.START_OBJECT);
currentFaunaTokenType = FaunaTokenType.START_OBJECT;
break;
throw new SerializationException(
"Token not implemented: " + jsonParser.currentToken());
default:
throw new SerializationException(
"Unexpected token following StartObject: " + jsonParser.currentToken());
Expand Down Expand Up @@ -211,7 +184,7 @@ public String getValueAsString() {
try {
return jsonParser.getValueAsString();
} catch (IOException e) {
throw new RuntimeException("Error reading current token as String", e);
throw new RuntimeException("Error getting the current token as String", e);
}
}

Expand All @@ -220,15 +193,15 @@ public Integer getValueAsInt() {
try {
return Integer.parseInt(taggedTokenValue);
} catch (NumberFormatException e) {
throw new RuntimeException("Error parsing the current token as Integer", e);
throw new RuntimeException("Error getting the current token as Integer", e);
}
}

public Boolean getValueAsBoolean() {
try {
return jsonParser.getValueAsBoolean();
} catch (IOException e) {
throw new RuntimeException("Error reading current token as Boolean", e);
throw new RuntimeException("Error getting the current token as Boolean", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.fauna.common.enums.FaunaTokenType;
import com.fauna.exception.SerializationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -41,6 +43,22 @@ public void testGetValueAsInt() throws IOException {
);

assertReader(reader, expectedTokens);

String invalidJson = "{\"@int\": \"abc\"}";
InputStream invalidInputStream = new ByteArrayInputStream(invalidJson.getBytes());
FaunaParser invalidReader = new FaunaParser(invalidInputStream);

assertThrows(RuntimeException.class, invalidReader::getValueAsInt);
}

@Test
public void testUnexpectedEndDuringAdvance() throws IOException {

String json = "{\"@int\": \"123\"";
InputStream inputStream = new ByteArrayInputStream(json.getBytes());
FaunaParser reader = new FaunaParser(inputStream);

assertThrows(SerializationException.class, reader::read);
}

@Test
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.

0 comments on commit eef6eae

Please sign in to comment.