This is an automated email from the ASF dual-hosted git repository.
vorburger pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new db4d2ae Add FineractClientTest.testInvalidOperations (FINERACT-1221)
db4d2ae is described below
commit db4d2ae0061b585fd44cfb1eab8ef2e7985da128
Author: Michael Vorburger <[email protected]>
AuthorDate: Sun Oct 18 18:03:34 2020 +0200
Add FineractClientTest.testInvalidOperations (FINERACT-1221)
---
.../fineract/client/util/FineractClient.java | 42 ++++++++++++++++------
.../fineract/client/test/FineractClientTest.java | 9 +++++
2 files changed, 40 insertions(+), 11 deletions(-)
diff --git
a/fineract-client/src/main/java/org/apache/fineract/client/util/FineractClient.java
b/fineract-client/src/main/java/org/apache/fineract/client/util/FineractClient.java
index 4ad6e7e..6252b01 100644
---
a/fineract-client/src/main/java/org/apache/fineract/client/util/FineractClient.java
+++
b/fineract-client/src/main/java/org/apache/fineract/client/util/FineractClient.java
@@ -20,6 +20,7 @@ package org.apache.fineract.client.util;
import org.apache.fineract.client.ApiClient;
import org.apache.fineract.client.auth.ApiKeyAuth;
+import org.apache.fineract.client.auth.HttpBasicAuth;
import org.apache.fineract.client.services.*;
/**
@@ -243,48 +244,67 @@ public class FineractClient {
workingDays = apiClient.createService(WorkingDaysApi.class);
}
- public static FineractClientBuilder builder() {
- return new FineractClientBuilder();
+ public static Builder builder() {
+ return new Builder();
}
protected <S> S createService(Class<S> serviceClass) {
return api.createService(serviceClass);
}
- public static class FineractClientBuilder {
+ public static class Builder {
+ private final ApiClient apiClient = new ApiClient();
private String baseURL;
private String tenant;
private String username;
private String password;
- private FineractClientBuilder() {}
+ private Builder() {}
- public FineractClientBuilder baseURL(String baseURL) {
+ public Builder baseURL(String baseURL) {
this.baseURL = baseURL;
return this;
}
- public FineractClientBuilder tenant(String tenant) {
+ public Builder tenant(String tenant) {
this.tenant = tenant;
return this;
}
- public FineractClientBuilder basicAuth(String username, String
password) {
+ public Builder basicAuth(String username, String password) {
this.username = username;
this.password = password;
return this;
}
public FineractClient build() {
- ApiClient apiClient = new ApiClient("basicAuth", has("username",
username), has("password", password));
+ // URL
apiClient.getAdapterBuilder().baseUrl(has("baseURL", baseURL));
- ApiKeyAuth authorization = new ApiKeyAuth("header",
"fineract-platform-tenantid");
- authorization.setApiKey(has("tenant", tenant));
- apiClient.addAuthorization("tenantid", authorization);
+
+ // Tenant
+ ApiKeyAuth tenantAuth = new ApiKeyAuth("header",
"fineract-platform-tenantid");
+ tenantAuth.setApiKey(has("tenant", tenant));
+ apiClient.addAuthorization("tenantid", tenantAuth);
+
+ // BASIC Auth
+ HttpBasicAuth basicAuth = new HttpBasicAuth();
+ basicAuth.setCredentials(has("username", username),
has("password", password));
+ apiClient.addAuthorization("basicAuth", basicAuth);
+
return new FineractClient(apiClient);
}
+ /**
+ * Obtain the internal Retrofit ApiClient. This method is typically
not required to be invoked for simple API
+ * usages, but can be a handy back door for non-trivial advanced
customizations of the API client.
+ *
+ * @return the {@link ApiClient} which {@link #build()} will use.
+ */
+ public ApiClient getApiClient() {
+ return apiClient;
+ }
+
private <T> T has(String propertyName, T value) throws
IllegalStateException {
if (value == null) {
throw new IllegalStateException("Must call " + propertyName +
"(...) to create valid Builder");
diff --git
a/fineract-client/src/test/java/org/apache/fineract/client/test/FineractClientTest.java
b/fineract-client/src/test/java/org/apache/fineract/client/test/FineractClientTest.java
index 74eeeef..a6c9f78 100644
---
a/fineract-client/src/test/java/org/apache/fineract/client/test/FineractClientTest.java
+++
b/fineract-client/src/test/java/org/apache/fineract/client/test/FineractClientTest.java
@@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import org.apache.fineract.client.util.FineractClient;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
@@ -42,6 +43,14 @@ public class FineractClientTest {
}
@Test
+ @Disabled // TODO remove Ignore once
https://issues.apache.org/jira/browse/FINERACT-1221 is fixed
+ void testInvalidOperations() throws IOException {
+ FineractClient.Builder builder =
FineractClient.builder().baseURL("http://test/").tenant("default").basicAuth("mifos",
"password");
+ builder.getApiClient().getAdapterBuilder().validateEagerly(true); //
see FINERACT-1221
+ builder.build();
+ }
+
+ @Test
void testFineractClientBuilder() throws IOException {
assertThrows(IllegalStateException.class, () -> {
FineractClient.builder().build();