Add FineractClientTest for Fineract SDK REST Client (FINERACT-1216)

and introduce handy Calls utilitiy
This commit is contained in:
Michael Vorburger
2020-10-18 22:04:08 +02:00
committed by Aleksandar Vidakovic
parent 00166d4543
commit 19f2a38095
6 changed files with 207 additions and 1 deletions
@@ -0,0 +1,58 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.client.test;
import static com.google.common.truth.Truth.assertThat;
import static org.apache.fineract.client.util.Calls.ok;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import org.apache.fineract.client.services.ClientApi;
import org.apache.fineract.client.util.FineractClient;
import org.junit.jupiter.api.Test;
/**
* Illustrates use of Fineract SDK REST Client.
*
* @author Michael Vorburger.ch
*/
public class FineractClientTest {
@Test
void testRetrieveAllClients() throws IOException {
FineractClient client = FineractClient.builder().baseURL("https://demo.fineract.dev/fineract-provider/api/v1/").tenant("default")
.basicAuth("mifos", "password").build();
ClientApi clientApi = client.createService(ClientApi.class);
assertThat(ok(clientApi.retrieveAll20(null, null, null, null, null, null, null, null, 0, 100, null, null, null))
.getTotalFilteredRecords()).isAtLeast(3);
}
@Test
void testFineractClientBuilder() throws IOException {
assertThrows(IllegalStateException.class, () -> {
FineractClient.builder().build();
});
assertThrows(IllegalStateException.class, () -> {
FineractClient.builder().baseURL("https://server/").build();
});
assertThrows(IllegalStateException.class, () -> {
FineractClient.builder().baseURL("https://server/").tenant("default").build();
});
}
}