From dcb47eefdc7a9cde7f19f249d71401013431d4a8 Mon Sep 17 00:00:00 2001 From: Darren Cunningham Date: Fri, 10 Nov 2023 15:31:15 -0500 Subject: [PATCH 1/4] gradlew executable --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From 85ec90acc3a49963c78a9ff31968c3bb37a019fd Mon Sep 17 00:00:00 2001 From: Darren Cunningham Date: Fri, 10 Nov 2023 15:34:20 -0500 Subject: [PATCH 2/4] gradle test workflow --- .github/workflows/gradle-test.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/gradle-test.yml diff --git a/.github/workflows/gradle-test.yml b/.github/workflows/gradle-test.yml new file mode 100644 index 00000000..917c4028 --- /dev/null +++ b/.github/workflows/gradle-test.yml @@ -0,0 +1,22 @@ +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' + + + - name: Run Gradle test + run: ./gradlew test + From 2d4a46976a89dfbdde1dacb03e03cdb726133732 Mon Sep 17 00:00:00 2001 From: Darren Cunningham Date: Fri, 10 Nov 2023 15:35:56 -0500 Subject: [PATCH 3/4] distribution --- .github/workflows/gradle-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/gradle-test.yml b/.github/workflows/gradle-test.yml index 917c4028..1125c710 100644 --- a/.github/workflows/gradle-test.yml +++ b/.github/workflows/gradle-test.yml @@ -15,8 +15,7 @@ jobs: uses: actions/setup-java@v3 with: java-version: '17' - + distribution: corretto - name: Run Gradle test run: ./gradlew test - From acf57b59efa99c0cdfe9e06d312d1c27b86e804d Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Thu, 25 Jan 2024 14:24:46 -0300 Subject: [PATCH 4/4] Resolved PR comments. --- .../com/fauna/serialization/FaunaParser.java | 58 ++++++------------- .../fauna/serialization/FaunaParserTest.java | 18 ++++++ 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java index 8d66713e..492c89ab 100644 --- a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java +++ b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java @@ -90,7 +90,6 @@ public boolean read() throws IOException { case VALUE_STRING: currentFaunaTokenType = FaunaTokenType.STRING; break; - case NOT_AVAILABLE: case START_OBJECT: handleStartObject(); break; @@ -111,44 +110,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); @@ -157,12 +132,11 @@ 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()); + throw new SerializationException( + "Unexpected token following StartObject: " + jsonParser.currentToken()); } } @@ -174,8 +148,7 @@ private void handleTaggedString(FaunaTokenType token) throws IOException { } private void advanceTrue() { - if (!advance()) - { + if (!advance()) { throw new SerializationException("Unexpected end of underlying JSON reader."); } } @@ -189,8 +162,10 @@ private boolean advance() { } private void validateTaggedType(FaunaTokenType type) { - if (currentFaunaTokenType != type || taggedTokenValue == null || !(taggedTokenValue instanceof String)) { - throw new IllegalStateException("CurrentTokenType is a " + currentFaunaTokenType.toString() + + if (currentFaunaTokenType != type || taggedTokenValue == null + || !(taggedTokenValue instanceof String)) { + throw new IllegalStateException( + "CurrentTokenType is a " + currentFaunaTokenType.toString() + ", not a " + type.toString() + "."); } } @@ -199,15 +174,16 @@ 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); } } + public Integer getValueAsInt() { validateTaggedType(FaunaTokenType.INT); 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); } } } \ No newline at end of file diff --git a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java index cca73833..eba77d26 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -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; @@ -39,6 +41,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); } private static void assertReader(FaunaParser reader,