Skip to content

Commit 68b531a

Browse files
committed
chore: cleanup tests, remove unused method, move urlEncode method
1 parent 1af5cc1 commit 68b531a

27 files changed

+692
-372
lines changed

.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,6 @@ src/test/java/dev/openfga/sdk/telemetry/HistogramsTest.java
330330
src/test/java/dev/openfga/sdk/telemetry/MetricTest.java
331331
src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java
332332
src/test/java/dev/openfga/sdk/telemetry/TelemetryTest.java
333+
src/test/java/dev/openfga/sdk/util/PairTest.java
333334
src/test/java/dev/openfga/sdk/util/StringUtilTest.java
335+
src/test/java/dev/openfga/sdk/util/ValidationTest.java

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ jacocoTestReport {
5656

5757
ext {
5858
jackson_version = "2.19.0"
59-
junit_version = "5.12.2"
6059
}
6160

6261
dependencies {
@@ -74,13 +73,13 @@ testing {
7473
suites {
7574
test {
7675
useJUnitJupiter()
77-
7876
dependencies {
79-
implementation project()
80-
implementation "org.junit.jupiter:junit-jupiter:$junit_version"
81-
implementation "org.mockito:mockito-core:5.17.0"
82-
runtimeOnly "org.junit.platform:junit-platform-launcher"
83-
implementation "org.wiremock:wiremock:3.13.0"
77+
implementation 'org.assertj:assertj-core:3.27.3'
78+
implementation 'org.mockito:mockito-core:5.17.0'
79+
implementation 'org.junit.jupiter:junit-jupiter:5.12.2'
80+
implementation 'org.wiremock:wiremock:3.13.0'
81+
82+
runtimeOnly 'org.junit.platform:junit-platform-launcher'
8483

8584
// This test-only dependency is convenient but not widely used.
8685
// Review project activity before updating the version here.
@@ -99,6 +98,7 @@ testing {
9998
}
10099
}
101100
}
101+
102102
integration(JvmTestSuite) {
103103
testType = TestSuiteType.INTEGRATION_TEST
104104
useJUnitJupiter()

src/main/java/dev/openfga/sdk/api/OpenFgaApi.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import dev.openfga.sdk.telemetry.Attributes;
4848
import dev.openfga.sdk.telemetry.Telemetry;
4949
import dev.openfga.sdk.util.Pair;
50+
import dev.openfga.sdk.util.StringUtil;
5051
import java.io.IOException;
5152
import java.net.URI;
5253
import java.net.http.HttpRequest;
@@ -127,7 +128,7 @@ private CompletableFuture<ApiResponse<BatchCheckResponse>> batchCheck(
127128

128129
assertParamExists(body, "body", "batchCheck");
129130

130-
String path = "/stores/{store_id}/batch-check".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
131+
String path = "/stores/{store_id}/batch-check".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
131132

132133
Map<String, Object> methodParameters = new HashMap<>();
133134
methodParameters.put("storeId", storeId);
@@ -183,7 +184,7 @@ private CompletableFuture<ApiResponse<CheckResponse>> check(
183184

184185
assertParamExists(body, "body", "check");
185186

186-
String path = "/stores/{store_id}/check".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
187+
String path = "/stores/{store_id}/check".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
187188

188189
Map<String, Object> methodParameters = new HashMap<>();
189190
methodParameters.put("storeId", storeId);
@@ -283,7 +284,7 @@ private CompletableFuture<ApiResponse<Void>> deleteStore(String storeId, Configu
283284

284285
assertParamExists(storeId, "storeId", "deleteStore");
285286

286-
String path = "/stores/{store_id}".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
287+
String path = "/stores/{store_id}".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
287288

288289
Map<String, Object> methodParameters = new HashMap<>();
289290
methodParameters.put("storeId", storeId);
@@ -338,7 +339,7 @@ private CompletableFuture<ApiResponse<ExpandResponse>> expand(
338339

339340
assertParamExists(body, "body", "expand");
340341

341-
String path = "/stores/{store_id}/expand".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
342+
String path = "/stores/{store_id}/expand".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
342343

343344
Map<String, Object> methodParameters = new HashMap<>();
344345
methodParameters.put("storeId", storeId);
@@ -389,7 +390,7 @@ private CompletableFuture<ApiResponse<GetStoreResponse>> getStore(String storeId
389390

390391
assertParamExists(storeId, "storeId", "getStore");
391392

392-
String path = "/stores/{store_id}".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
393+
String path = "/stores/{store_id}".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
393394

394395
Map<String, Object> methodParameters = new HashMap<>();
395396
methodParameters.put("storeId", storeId);
@@ -444,7 +445,7 @@ private CompletableFuture<ApiResponse<ListObjectsResponse>> listObjects(
444445

445446
assertParamExists(body, "body", "listObjects");
446447

447-
String path = "/stores/{store_id}/list-objects".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
448+
String path = "/stores/{store_id}/list-objects".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
448449

449450
Map<String, Object> methodParameters = new HashMap<>();
450451
methodParameters.put("storeId", storeId);
@@ -551,7 +552,7 @@ private CompletableFuture<ApiResponse<ListUsersResponse>> listUsers(
551552

552553
assertParamExists(body, "body", "listUsers");
553554

554-
String path = "/stores/{store_id}/list-users".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
555+
String path = "/stores/{store_id}/list-users".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
555556

556557
Map<String, Object> methodParameters = new HashMap<>();
557558
methodParameters.put("storeId", storeId);
@@ -607,7 +608,7 @@ private CompletableFuture<ApiResponse<ReadResponse>> read(
607608

608609
assertParamExists(body, "body", "read");
609610

610-
String path = "/stores/{store_id}/read".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
611+
String path = "/stores/{store_id}/read".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
611612

612613
Map<String, Object> methodParameters = new HashMap<>();
613614
methodParameters.put("storeId", storeId);
@@ -664,8 +665,8 @@ private CompletableFuture<ApiResponse<ReadAssertionsResponse>> readAssertions(
664665
assertParamExists(authorizationModelId, "authorizationModelId", "readAssertions");
665666

666667
String path = "/stores/{store_id}/assertions/{authorization_model_id}"
667-
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()))
668-
.replace("{authorization_model_id}", ApiClient.urlEncode(authorizationModelId.toString()));
668+
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()))
669+
.replace("{authorization_model_id}", StringUtil.urlEncode(authorizationModelId.toString()));
669670

670671
Map<String, Object> methodParameters = new HashMap<>();
671672
methodParameters.put("storeId", storeId);
@@ -722,8 +723,8 @@ private CompletableFuture<ApiResponse<ReadAuthorizationModelResponse>> readAutho
722723
assertParamExists(id, "id", "readAuthorizationModel");
723724

724725
String path = "/stores/{store_id}/authorization-models/{id}"
725-
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()))
726-
.replace("{id}", ApiClient.urlEncode(id.toString()));
726+
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()))
727+
.replace("{id}", StringUtil.urlEncode(id.toString()));
727728

728729
Map<String, Object> methodParameters = new HashMap<>();
729730
methodParameters.put("storeId", storeId);
@@ -787,7 +788,7 @@ private CompletableFuture<ApiResponse<ReadAuthorizationModelsResponse>> readAuth
787788
assertParamExists(storeId, "storeId", "readAuthorizationModels");
788789

789790
String path = "/stores/{store_id}/authorization-models"
790-
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
791+
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
791792
path = pathWithParams(path, "page_size", pageSize, "continuation_token", continuationToken);
792793

793794
Map<String, Object> methodParameters = new HashMap<>();
@@ -869,7 +870,7 @@ private CompletableFuture<ApiResponse<ReadChangesResponse>> readChanges(
869870

870871
assertParamExists(storeId, "storeId", "readChanges");
871872

872-
String path = "/stores/{store_id}/changes".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
873+
String path = "/stores/{store_id}/changes".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
873874
path = pathWithParams(
874875
path,
875876
"type",
@@ -933,7 +934,7 @@ private CompletableFuture<ApiResponse<Object>> write(String storeId, WriteReques
933934

934935
assertParamExists(body, "body", "write");
935936

936-
String path = "/stores/{store_id}/write".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
937+
String path = "/stores/{store_id}/write".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
937938

938939
Map<String, Object> methodParameters = new HashMap<>();
939940
methodParameters.put("storeId", storeId);
@@ -998,8 +999,8 @@ private CompletableFuture<ApiResponse<Void>> writeAssertions(
998999
assertParamExists(body, "body", "writeAssertions");
9991000

10001001
String path = "/stores/{store_id}/assertions/{authorization_model_id}"
1001-
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()))
1002-
.replace("{authorization_model_id}", ApiClient.urlEncode(authorizationModelId.toString()));
1002+
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()))
1003+
.replace("{authorization_model_id}", StringUtil.urlEncode(authorizationModelId.toString()));
10031004

10041005
Map<String, Object> methodParameters = new HashMap<>();
10051006
methodParameters.put("storeId", storeId);
@@ -1057,7 +1058,7 @@ private CompletableFuture<ApiResponse<WriteAuthorizationModelResponse>> writeAut
10571058
assertParamExists(body, "body", "writeAuthorizationModel");
10581059

10591060
String path = "/stores/{store_id}/authorization-models"
1060-
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
1061+
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
10611062

10621063
Map<String, Object> methodParameters = new HashMap<>();
10631064
methodParameters.put("storeId", storeId);

src/main/java/dev/openfga/sdk/api/client/ApiClient.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
2222
import dev.openfga.sdk.api.configuration.Configuration;
2323
import dev.openfga.sdk.errors.FgaInvalidParameterException;
24+
import dev.openfga.sdk.util.StringUtil;
2425
import java.io.InputStream;
2526
import java.net.URI;
2627
import java.net.URLEncoder;
2728
import java.net.http.HttpClient;
2829
import java.net.http.HttpRequest;
2930
import java.net.http.HttpResponse;
3031
import java.time.Duration;
31-
import java.time.OffsetDateTime;
32-
import java.time.format.DateTimeFormatter;
3332
import java.util.function.Consumer;
3433
import org.openapitools.jackson.nullable.JsonNullableModule;
3534

@@ -104,16 +103,6 @@ public ApiClient(HttpClient.Builder builder, ObjectMapper mapper) {
104103
asyncResponseInterceptor = null;
105104
}
106105

107-
private static String valueToString(Object value) {
108-
if (value == null) {
109-
return "";
110-
}
111-
if (value instanceof OffsetDateTime) {
112-
return ((OffsetDateTime) value).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
113-
}
114-
return value.toString();
115-
}
116-
117106
public static HttpRequest.Builder requestBuilder(String method, String path, Configuration configuration)
118107
throws FgaInvalidParameterException {
119108
return requestBuilder(method, path, HttpRequest.BodyPublishers.noBody(), configuration);
@@ -171,7 +160,9 @@ private static HttpRequest.Builder requestBuilder(
171160
*
172161
* @param s String to encode.
173162
* @return URL-encoded representation of the input string.
163+
* @deprecated in favor of {@link StringUtil#urlEncode(String)}
174164
*/
165+
@Deprecated(forRemoval = true, since = "0.8.2")
175166
public static String urlEncode(String s) {
176167
return URLEncoder.encode(s, UTF_8).replaceAll("\\+", "%20");
177168
}

src/main/java/dev/openfga/sdk/telemetry/Attribute.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* OpenFGA
3+
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
4+
*
5+
* The version of the OpenAPI document: 1.x
6+
* Contact: community@openfga.dev
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
113
package dev.openfga.sdk.telemetry;
214

315
/**

src/main/java/dev/openfga/sdk/telemetry/Attributes.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* OpenFGA
3+
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
4+
*
5+
* The version of the OpenAPI document: 1.x
6+
* Contact: community@openfga.dev
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
113
package dev.openfga.sdk.telemetry;
214

315
import static dev.openfga.sdk.util.StringUtil.isNullOrWhitespace;
@@ -17,7 +29,6 @@
1729
* This class represents a collection of attributes used for telemetry purposes.
1830
*/
1931
public class Attributes {
20-
2132
/**
2233
* The client ID used in the request, if applicable.
2334
*/

src/main/java/dev/openfga/sdk/telemetry/Counter.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* OpenFGA
3+
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
4+
*
5+
* The version of the OpenAPI document: 1.x
6+
* Contact: community@openfga.dev
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
113
package dev.openfga.sdk.telemetry;
214

315
/**

src/main/java/dev/openfga/sdk/telemetry/Counters.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* OpenFGA
3+
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
4+
*
5+
* The version of the OpenAPI document: 1.x
6+
* Contact: community@openfga.dev
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
113
package dev.openfga.sdk.telemetry;
214

315
/**
@@ -10,4 +22,6 @@ public class Counters {
1022
public static final Counter CREDENTIALS_REQUEST = new Counter(
1123
"fga-client.credentials.request",
1224
"The total number of times new access tokens have been requested using ClientCredentials.");
25+
26+
private Counters() {} // Instantiation prevented.
1327
}

src/main/java/dev/openfga/sdk/telemetry/Histogram.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* OpenFGA
3+
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
4+
*
5+
* The version of the OpenAPI document: 1.x
6+
* Contact: community@openfga.dev
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
113
package dev.openfga.sdk.telemetry;
214

315
/**

src/main/java/dev/openfga/sdk/telemetry/Histograms.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* OpenFGA
3+
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
4+
*
5+
* The version of the OpenAPI document: 1.x
6+
* Contact: community@openfga.dev
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
113
package dev.openfga.sdk.telemetry;
214

315
/**
@@ -17,4 +29,6 @@ public class Histograms {
1729
public static final Histogram QUERY_DURATION = new Histogram(
1830
"fga-client.query.duration",
1931
"The total time it took (in milliseconds) for the FGA server to process and evaluate the request.");
32+
33+
private Histograms() {} // Instantiation prevented.
2034
}

src/main/java/dev/openfga/sdk/telemetry/Metric.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
/*
2+
* OpenFGA
3+
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
4+
*
5+
* The version of the OpenAPI document: 1.x
6+
* Contact: community@openfga.dev
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
113
package dev.openfga.sdk.telemetry;
214

315
public class Metric {
4-
protected final String name;
5-
protected final String description;
16+
private final String name;
17+
private final String description;
618

719
/**
820
* Constructs a new metric with the specified name and description.

0 commit comments

Comments
 (0)