Skip to content

Commit f5895f8

Browse files
committed
review: add test for network error
1 parent 6236a80 commit f5895f8

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/test/java/dev/openfga/sdk/api/OpenFgaApiTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,4 +1928,27 @@ DEFAULT_STORE_ID, DEFAULT_AUTH_MODEL_ID, new WriteAssertionsRequest())
19281928
assertEquals(
19291929
"{\"code\":\"internal_error\",\"message\":\"Internal Server Error\"}", exception.getResponseData());
19301930
}
1931+
1932+
@Test
1933+
public void writeAssertions_networkError() throws Exception {
1934+
// Given - Mock network failure by throwing IOException
1935+
String putUrl =
1936+
"https://api.fga.example/stores/01YCP46JKYM8FJCQ37NMBYHE5X/assertions/01G5JAVJ41T49E9TT3SKVS7X1J";
1937+
1938+
// Configure mock to throw IOException to simulate network error (connection timeout, DNS failure, etc.)
1939+
mockHttpClient.onPut(putUrl).doThrowException(new java.io.IOException("Connection timeout"));
1940+
1941+
// When
1942+
ExecutionException execException = assertThrows(ExecutionException.class, () -> fga.writeAssertions(
1943+
DEFAULT_STORE_ID, DEFAULT_AUTH_MODEL_ID, new WriteAssertionsRequest())
1944+
.get());
1945+
1946+
// Then
1947+
// Network errors should be retried (1 initial + 3 retries = 4 total attempts)
1948+
mockHttpClient.verify().put(putUrl).called(4);
1949+
var exception = assertInstanceOf(ApiException.class, execException.getCause());
1950+
assertNotNull(exception.getCause()); // Should have underlying network error
1951+
assertTrue(exception.getCause() instanceof java.io.IOException);
1952+
assertEquals("Connection timeout", exception.getCause().getMessage());
1953+
}
19311954
}

0 commit comments

Comments
 (0)