Skip to content

Commit

Permalink
Merge pull request #146 from fauna/pr145-feedback
Browse files Browse the repository at this point in the history
[pr145-feedback] Move RELEASING.md and fix some imports.
  • Loading branch information
findgriffin authored Sep 20, 2024
2 parents b468a2a + 1d1c3a8 commit e355a20
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
File renamed without changes.
13 changes: 12 additions & 1 deletion src/main/java/com/fauna/codec/UTF8FaunaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@
import java.util.Set;
import java.util.Stack;

import static com.fauna.codec.FaunaTokenType.*;
import static com.fauna.codec.FaunaTokenType.BYTES;
import static com.fauna.codec.FaunaTokenType.DATE;
import static com.fauna.codec.FaunaTokenType.DOUBLE;
import static com.fauna.codec.FaunaTokenType.END_ARRAY;
import static com.fauna.codec.FaunaTokenType.END_DOCUMENT;
import static com.fauna.codec.FaunaTokenType.END_OBJECT;
import static com.fauna.codec.FaunaTokenType.END_PAGE;
import static com.fauna.codec.FaunaTokenType.END_REF;
import static com.fauna.codec.FaunaTokenType.INT;
import static com.fauna.codec.FaunaTokenType.LONG;
import static com.fauna.codec.FaunaTokenType.NONE;
import static com.fauna.codec.FaunaTokenType.TIME;

/**
* Represents a reader that provides fast, non-cached, forward-only access to serialized data.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/fauna/codec/codecs/BaseRefCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.fauna.codec.UTF8FaunaGenerator;
import com.fauna.codec.UTF8FaunaParser;
import com.fauna.exception.CodecException;
import com.fauna.types.*;
import com.fauna.types.BaseRef;
import com.fauna.types.DocumentRef;
import com.fauna.types.NamedDocumentRef;

public class BaseRefCodec extends BaseCodec<BaseRef> {

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/fauna/codec/codecs/DynamicCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.fauna.codec.UTF8FaunaParser;
import com.fauna.exception.CodecException;
import com.fauna.query.StreamTokenResponse;
import com.fauna.types.*;
import com.fauna.types.Document;
import com.fauna.types.DocumentRef;
import com.fauna.types.Page;

import java.util.List;
import java.util.Map;
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/fauna/codec/codecs/InternalDocument.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.fauna.codec.codecs;

import com.fauna.codec.FaunaTokenType;
import com.fauna.exception.NullDocumentException;
import com.fauna.codec.UTF8FaunaParser;
import com.fauna.types.*;
import com.fauna.exception.NullDocumentException;
import com.fauna.types.Document;
import com.fauna.types.DocumentRef;
import com.fauna.types.Module;
import com.fauna.types.NamedDocument;
import com.fauna.types.NamedDocumentRef;

import java.time.Instant;
import java.util.HashMap;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/fauna/query/template/FaunaTemplate.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.fauna.query.template;

import com.fauna.query.builder.*;
import com.fauna.query.builder.QueryFragment;
import com.fauna.query.builder.QueryLiteral;
import com.fauna.query.builder.QueryVal;

import java.util.Iterator;
import java.util.Map;
Expand Down
32 changes: 13 additions & 19 deletions src/test/java/com/fauna/response/QueryResponseTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.fauna.response;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -62,7 +64,7 @@ public void getFromResponseBody_Success() throws IOException {
}

@Test
public void handleResponseWithInvalidJsonThrowsProtocolException() {
public void handleResponseWithInvalidJsonThrowsClientResponseException() {
HttpResponse resp = mockResponse("{\"not valid json\"");
when(resp.statusCode()).thenReturn(400);

Expand All @@ -71,23 +73,15 @@ public void handleResponseWithInvalidJsonThrowsProtocolException() {
}

@Test
public void handleResponseWithMissingStatsThrowsProtocolException() {
HttpResponse resp = mockResponse("{\"not valid json\"");
assertThrows(ClientResponseException.class, () -> QueryResponse.parseResponse(resp, codecProvider.get(Object.class)));
public void handleResponseWithEmptyFieldsDoesNotThrow() {
HttpResponse resp = mockResponse("{}");
QuerySuccess<Object> response = QueryResponse.parseResponse(resp, codecProvider.get(Object.class));
assertEquals(QuerySuccess.class, response.getClass());
assertNull(response.getSchemaVersion());
assertNull(response.getSummary());
assertNull(response.getLastSeenTxn());
assertNull(response.getQueryTags());
assertNull(response.getData());
assertNull(response.getStats());
}

@Test
void getFromResponseBody_Exception() {
String body = "Invalid JSON";

// TODO call FaunaClient.handleResponse here.
CodecException exception = assertThrows(CodecException.class, () -> {
throw new CodecException("Error occurred while parsing the response body");
});

assertEquals("Error occurred while parsing the response body", exception.getMessage());
// assertTrue(exception.getCause().getMessage().contains(
// "Unrecognized token 'Invalid': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')"));
}

}

0 comments on commit e355a20

Please sign in to comment.