Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java-sdk calling the server without content when submitting empty deletes and writes #307

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ public class OpenFgaClient {
var deleteTransactions = chunksOf(chunkSize, request.getDeletes()).map(ClientWriteRequest::ofDeletes);

var transactions = Stream.concat(writeTransactions, deleteTransactions).collect(Collectors.toList());

if(transactions.isEmpty()) {
var emptyTransaction = new ClientWriteRequest().writes(null).deletes(null);
return this.writeNonTransaction(storeId, emptyTransaction, writeOptions);
}

var futureResponse = this.writeNonTransaction(storeId, transactions.get(0), options);

for (int i = 1; i < transactions.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.pgssoft.httpclient.HttpClientMock;
import {{clientPackage}}.model.*;
Expand All @@ -16,6 +15,7 @@ import {{invokerPackage}}.*;
import {{modelPackage}}.*;
import java.net.http.HttpClient;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -1361,6 +1361,23 @@ public class OpenFgaClientTest {
assertEquals(200, response.getStatusCode());
}

@Test
public void write_nothingSentWhenWritesAndDeletesAreEmpty() throws FgaInvalidParameterException, ExecutionException, InterruptedException {
// Given
String postPath = String.format("https://localhost/stores/%s/write", DEFAULT_STORE_ID);
String expectedBody = String.format(
"{\"writes\":null,\"deletes\":null,\"authorization_model_id\":\"%s\"}", DEFAULT_AUTH_MODEL_ID);
mockHttpClient.onPost(postPath).withBody(is(expectedBody)).doReturn(200, EMPTY_RESPONSE_BODY);

// When
var clientWriteRequest = new ClientWriteRequest().writes(Collections.emptyList()).deletes(Collections.emptyList());
var response = fga.write(clientWriteRequest).get();

// Then
mockHttpClient.verify().post(postPath).called(1);
assertEquals(200, response.getStatusCode());
}

@Test
public void write_storeIdRequired() {
// Given
Expand Down
Loading