Move all SDK client tests into integrationtests (FINERACT-1209)
And run the against localhost instead of https://fineract.dev
This commit is contained in:
committed by
Aleksandar Vidakovic
parent
6f2fdaefdf
commit
73e330a58e
@@ -103,7 +103,11 @@ compileJava {
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
// the generated code contains some warnings in build/generated/java/src/main/java/org/apache/fineract/client/auth/OAuthOkHttpClient.java#L71 that won't pass
|
||||
// the generated code in build/generated/java/src/main/java/org/apache/fineract/client/auth/OAuthOkHttpClient.java#L71 currently uses deprecated RequestBody.create(MediaType,String)
|
||||
// TODO FINERACT-1247 why does this not work:
|
||||
// options.compilerArgs -= ["-Xlint:deprecation"]
|
||||
// options.compilerArgs += ["-Xlint:-deprecation"]
|
||||
// So we just have to use:
|
||||
options.compilerArgs -= ["-Werror"]
|
||||
}
|
||||
|
||||
|
||||
@@ -453,7 +453,8 @@ public final class FineractClient {
|
||||
}
|
||||
};
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("SSL"); // TODO "SSL" or "TLS" as in hooks.processor.ProcessorHelper?
|
||||
// TODO "SSL" or "TLS" as in hooks.processor.ProcessorHelper?
|
||||
SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
sslContext.init(null, new TrustManager[] { insecureX509TrustManager }, new SecureRandom());
|
||||
SSLSocketFactory insecureSslSocketFactory = sslContext.getSocketFactory();
|
||||
|
||||
|
||||
+2
-32
@@ -18,48 +18,18 @@
|
||||
*/
|
||||
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 okhttp3.logging.HttpLoggingInterceptor.Level;
|
||||
import org.apache.fineract.client.util.FineractClient;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Illustrates use of Fineract SDK REST Client.
|
||||
* Tests a few technical aspect of the Fineract SDK REST Client.
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
public class FineractClientTest {
|
||||
|
||||
void checkClients(FineractClient fineract) {
|
||||
assertThat(ok(fineract.clients.retrieveAll20(null, null, null, null, null, null, null, null, 0, 100, null, null, null))
|
||||
.getTotalFilteredRecords()).isAtLeast(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRetrieveAllClientsFromFineractDev() {
|
||||
FineractClient fineract = FineractClient.builder().baseURL("https://demo.fineract.dev/fineract-provider/api/v1/").tenant("default")
|
||||
.basicAuth("mifos", "password").logging(Level.BODY).build();
|
||||
checkClients(fineract);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO remove Disabled once https://issues.apache.org/jira/browse/FINERACT-1209 is fixed
|
||||
void testRetrieveAllClientsFromLocalhostWithInsecureSelfSignedCert() {
|
||||
FineractClient fineract = FineractClient.builder().baseURL("https://localhost:8443/fineract-provider/api/v1/").tenant("default")
|
||||
.basicAuth("mifos", "password").insecure(true).build();
|
||||
checkClients(fineract);
|
||||
}
|
||||
|
||||
@Test // FINERACT-1220
|
||||
void testOfficesDateFormat() {
|
||||
FineractClient fineract = FineractClient.builder().baseURL("https://demo.fineract.dev/fineract-provider/api/v1/").tenant("default")
|
||||
.basicAuth("mifos", "password").insecure(true).logging(Level.BODY).build();
|
||||
ok(fineract.offices.retrieveOffices(true, null, null));
|
||||
}
|
||||
public class FineractClientTechnicalTest {
|
||||
|
||||
@Test
|
||||
@Disabled // TODO remove Ignore once https://issues.apache.org/jira/browse/FINERACT-1221 is fixed
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* 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.testutil;
|
||||
|
||||
import com.google.common.truth.FailureMetadata;
|
||||
import com.google.common.truth.Subject;
|
||||
import com.google.common.truth.Truth;
|
||||
import javax.annotation.Nullable;
|
||||
import org.apache.fineract.client.util.Calls;
|
||||
import retrofit2.Call;
|
||||
|
||||
/**
|
||||
* Google Truth Extension for Retrofit Call.
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
public class CallSubject extends Subject {
|
||||
|
||||
// as per https://truth.dev/extension
|
||||
|
||||
public static CallSubject assertThat(@Nullable Call<?> actual) {
|
||||
return Truth.assertAbout(calls()).that(actual);
|
||||
}
|
||||
|
||||
public static Factory<CallSubject, Call<?>> calls() {
|
||||
return CallSubject::new;
|
||||
}
|
||||
|
||||
private final Call<?> actual;
|
||||
|
||||
protected CallSubject(FailureMetadata metadata, @Nullable Call<?> actual) {
|
||||
super(metadata, actual);
|
||||
this.actual = actual;
|
||||
}
|
||||
|
||||
public void hasHttpStatus(int expectedHttpStatus) {
|
||||
check("httpStatus").that(Calls.executeU(actual).code()).isEqualTo(expectedHttpStatus);
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* 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.integrationtests.newstyle;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.apache.fineract.client.models.GetClientsResponse;
|
||||
import org.apache.fineract.client.models.PostClientsRequest;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Integration Test for /clients API.
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
public class ClientTest extends IntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createOne() {
|
||||
assertThat(create()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void retrieveOneExisting() {
|
||||
assertThat(retrieveOne()).isPresent();
|
||||
}
|
||||
|
||||
// The following are not tests, but helpful utilities for other tests
|
||||
|
||||
public Long getClientId() {
|
||||
return retrieveOne().orElseGet(this::create);
|
||||
}
|
||||
|
||||
Long create() {
|
||||
// NB officeId(1) always exists (Head Office)
|
||||
// TODO rm long cast, see https://issues.apache.org/jira/browse/FINERACT-1230
|
||||
// TODO activationDate() why String? https://issues.apache.org/jira/browse/FINERACT-1232
|
||||
// TODO why dateFormat and locale required even when no activationDate?!
|
||||
// https://issues.apache.org/jira/browse/FINERACT-1233
|
||||
return (long) ok(fineract().clients
|
||||
.create5(new PostClientsRequest().officeId(1).fullname("TestClient").dateFormat(dateFormat()).locale("en_US")))
|
||||
.getClientId();
|
||||
}
|
||||
|
||||
Optional<Long> retrieveOne() {
|
||||
GetClientsResponse clients = ok(
|
||||
fineract().clients.retrieveAll20(null, null, null, null, null, null, null, null, 0, 1, null, null, false));
|
||||
if (clients.getTotalFilteredRecords() > 0) {
|
||||
// TODO rm long cast, see https://issues.apache.org/jira/browse/FINERACT-1230
|
||||
return Optional.of((long) clients.getPageItems().get(0).getId());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
/**
|
||||
* 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.integrationtests.newstyle;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody.Part;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.apache.fineract.client.models.GetEntityTypeEntityIdDocumentsResponse;
|
||||
import org.apache.fineract.client.models.PostEntityTypeEntityIdDocumentsResponse;
|
||||
import org.apache.fineract.client.util.Parts;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Integration Test for /documents API.
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
public class DocumentTest extends IntegrationTest {
|
||||
|
||||
final File testFile = new File(getClass().getResource("/michael.vorburger-crepes.jpg").getFile());
|
||||
|
||||
Long clientId = new ClientTest().getClientId();
|
||||
Long documentId;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void retrieveAllDocuments() {
|
||||
assertThat(ok(fineract().documents.retrieveAllDocuments("clients", clientId))).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createDocument() {
|
||||
String name = "Test";
|
||||
Part part = Parts.fromFile(testFile);
|
||||
String description = null;
|
||||
// TODO used var in tests when moved from fineract-client (Java 8 only) to new module
|
||||
PostEntityTypeEntityIdDocumentsResponse response = ok(
|
||||
fineract().documents.createDocument("clients", clientId, part, name, description));
|
||||
assertThat(response.getResourceId()).isNotNull();
|
||||
assertThat(response.getResourceIdentifier()).isNotEmpty();
|
||||
documentId = response.getResourceId();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getDocument() {
|
||||
GetEntityTypeEntityIdDocumentsResponse doc = ok(fineract().documents.getDocument("clients", clientId, documentId));
|
||||
assertThat(doc.getName()).isEqualTo("Test");
|
||||
assertThat(doc.getFileName()).isEqualTo(testFile.getName());
|
||||
assertThat(doc.getDescription()).isNull();
|
||||
assertThat(doc.getId()).isEqualTo(documentId);
|
||||
assertThat(doc.getParentEntityType()).isEqualTo("clients");
|
||||
assertThat(doc.getParentEntityId()).isEqualTo(clientId);
|
||||
// TODO huh?! It's more than uploaded file; seems like a bug - it's including create body, not just file size
|
||||
assertThat(doc.getSize()).isEqualTo(testFile.length() + 411);
|
||||
assertThat(doc.getType()).isEqualTo("image/jpeg");
|
||||
// TODO doc.getStorageType() shouldn't be exposed by the API?!
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void downloadFile() throws IOException {
|
||||
Response<ResponseBody> r = okR(fineract().documents.downloadFile("clients", clientId, documentId));
|
||||
try (ResponseBody body = r.body()) {
|
||||
assertThat(body.contentType()).isEqualTo(MediaType.get("image/jpeg"));
|
||||
assertThat(body.bytes().length).isEqualTo(testFile.length());
|
||||
assertThat(body.contentLength()).isEqualTo(-1); // TODO testFile.length()
|
||||
}
|
||||
assertThat(Parts.fileName(r)).hasValue(testFile.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void updateDocumentWithoutNewUpload() {
|
||||
String newName = "Test changed name";
|
||||
String newDescription = getClass().getName();
|
||||
ok(fineract().documents.updateDocument("clients", clientId, documentId, null, newName, newDescription));
|
||||
|
||||
GetEntityTypeEntityIdDocumentsResponse doc = ok(fineract().documents.getDocument("clients", clientId, documentId));
|
||||
assertThat(doc.getName()).isEqualTo(newName);
|
||||
assertThat(doc.getDescription()).isEqualTo(newDescription);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void deleteDocument() {
|
||||
ok(fineract().documents.deleteDocument("clients", clientId, documentId));
|
||||
assertThat(fineract().documents.getDocument("clients", clientId, documentId)).hasHttpStatus(404);
|
||||
}
|
||||
|
||||
@Order(9999)
|
||||
@Test // FINERACT-1036
|
||||
void createDocumentBadArgs() {
|
||||
assertThat(fineract().documents.createDocument("clients", 123L, null, "test.pdf", null)).hasHttpStatus(400);
|
||||
}
|
||||
}
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
/**
|
||||
* 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.integrationtests.newstyle;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.apache.fineract.client.services.ImagesApi;
|
||||
import org.apache.fineract.client.util.Parts;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Headers;
|
||||
|
||||
/**
|
||||
* Integration Test for /images API.
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
@Disabled // TODO FINERACT-1247
|
||||
public class ImageTest extends IntegrationTest {
|
||||
|
||||
// TODO This "new style" test is equivalent to the old StaffImageApiTest, so we could delete that (after
|
||||
// FINERACT-1209)
|
||||
|
||||
final File testImage = new File(getClass().getResource("/michael.vorburger-crepes.jpg").getFile());
|
||||
|
||||
Long clientId = new ClientTest().getClientId();
|
||||
// staffId is hard-coded to 1L below, because that always exists
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void create() {
|
||||
ok(fineract().images.create("staff", 1L, Parts.fromFile(testImage)));
|
||||
ok(fineract().images.create("clients", clientId, Parts.fromFile(testImage)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getOriginalSize() throws IOException {
|
||||
ResponseBody r = ok(fineract().images.get("staff", 1L, 3505, 1972, null));
|
||||
assertThat(r.contentType()).isEqualTo(MediaType.get("text/plain"));
|
||||
String encodedImage = r.string();
|
||||
assertThat(encodedImage).startsWith("data:image/jpeg;base64,");
|
||||
assertThat(encodedImage).hasLength(2846549);
|
||||
assertThat(r.contentLength()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getSmallerSize() throws IOException {
|
||||
ResponseBody r = ok(fineract().images.get("staff", 1L, 128, 128, null));
|
||||
assertThat(r.string()).hasLength(6591);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getBiggerSize() throws IOException {
|
||||
ResponseBody r = ok(fineract().images.get("staff", 1L, 9000, 6000, null));
|
||||
assertThat(r.string()).hasLength(2846549);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void getInlineOctetOutput() throws IOException {
|
||||
// 3505x1972 is the exact original size of testFile
|
||||
Response<ResponseBody> r = okR(fineract().images.get("staff", 1L, 3505, 1972, "inline_octet"));
|
||||
try (ResponseBody body = r.body()) {
|
||||
assertThat(body.contentType()).isEqualTo(MediaType.get("image/jpeg"));
|
||||
assertThat(body.bytes().length).isEqualTo(testImage.length());
|
||||
assertThat(body.contentLength()).isEqualTo(testImage.length());
|
||||
}
|
||||
|
||||
String expectedFileName = "test, testJPEG"; // without dot!
|
||||
assertThat(Parts.fileName(r)).hasValue(expectedFileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void getOctetOutput() throws IOException {
|
||||
ResponseBody r = ok(fineract().images.get("staff", 1L, 3505, 1972, "octet"));
|
||||
assertThat(r.contentType()).isEqualTo(MediaType.get("image/jpeg"));
|
||||
assertThat(r.bytes().length).isEqualTo(testImage.length());
|
||||
assertThat(r.contentLength()).isEqualTo(testImage.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void getAnotherOutput() throws IOException {
|
||||
ResponseBody r = ok(fineract().images.get("staff", 1L, 3505, 1972, "abcd"));
|
||||
assertThat(r.contentType()).isEqualTo(MediaType.get("text/plain"));
|
||||
assertThat(r.string()).startsWith("data:image/jpeg;base64,");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void getText() throws IOException {
|
||||
ResponseBody r = ok(fineract().createService(ImagesApiWithHeadersForTest.class).getText("staff", 1L, 3505, 1972, null));
|
||||
assertThat(r.contentType()).isEqualTo(MediaType.get("text/plain"));
|
||||
assertThat(r.string()).startsWith("data:image/jpeg;base64,");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void getBytes() throws IOException {
|
||||
ResponseBody r = ok(fineract().createService(ImagesApiWithHeadersForTest.class).getBytes("staff", 1L, 3505, 1972, null));
|
||||
assertThat(r.contentType()).isEqualTo(MediaType.get("image/jpeg"));
|
||||
assertThat(r.bytes().length).isEqualTo(testImage.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(50)
|
||||
void update() {
|
||||
ok(fineract().images.update("staff", 1L, Parts.fromFile(testImage)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(99)
|
||||
void delete() {
|
||||
ok(fineract().images.delete("staff", 1L));
|
||||
ok(fineract().images.delete("clients", clientId));
|
||||
}
|
||||
|
||||
interface ImagesApiWithHeadersForTest extends ImagesApi {
|
||||
|
||||
@Headers("Accept: text/plain")
|
||||
@GET("{entityType}/{entityId}/images")
|
||||
Call<ResponseBody> getText(@retrofit2.http.Path("entityType") String entityType, @retrofit2.http.Path("entityId") Long entityId,
|
||||
@retrofit2.http.Query("maxWidth") Integer maxWidth, @retrofit2.http.Query("maxHeight") Integer maxHeight,
|
||||
@retrofit2.http.Query("output") String output);
|
||||
|
||||
@Headers("Accept: application/octet-stream")
|
||||
@GET("{entityType}/{entityId}/images")
|
||||
Call<ResponseBody> getBytes(@retrofit2.http.Path("entityType") String entityType, @retrofit2.http.Path("entityId") Long entityId,
|
||||
@retrofit2.http.Query("maxWidth") Integer maxWidth, @retrofit2.http.Query("maxHeight") Integer maxHeight,
|
||||
@retrofit2.http.Query("output") String output);
|
||||
}
|
||||
}
|
||||
-143
@@ -1,143 +0,0 @@
|
||||
/**
|
||||
* 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.integrationtests.newstyle;
|
||||
|
||||
import com.google.common.truth.BigDecimalSubject;
|
||||
import com.google.common.truth.BooleanSubject;
|
||||
import com.google.common.truth.ComparableSubject;
|
||||
import com.google.common.truth.DoubleSubject;
|
||||
import com.google.common.truth.FloatSubject;
|
||||
import com.google.common.truth.IntegerSubject;
|
||||
import com.google.common.truth.IterableSubject;
|
||||
import com.google.common.truth.LongSubject;
|
||||
import com.google.common.truth.OptionalSubject;
|
||||
import com.google.common.truth.StringSubject;
|
||||
import com.google.common.truth.Subject;
|
||||
import com.google.common.truth.Truth;
|
||||
import com.google.common.truth.Truth8;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import okhttp3.logging.HttpLoggingInterceptor.Level;
|
||||
import org.apache.fineract.client.testutil.CallSubject;
|
||||
import org.apache.fineract.client.util.Calls;
|
||||
import org.apache.fineract.client.util.FineractClient;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Integration Test for /documents API.
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
// Allow keeping state between tests
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
// TODO Remove @TestMethodOrder when https://github.com/junit-team/junit5/issues/1919 is available
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public abstract class IntegrationTest {
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
private FineractClient fineract;
|
||||
|
||||
protected FineractClient fineract() {
|
||||
if (fineract == null) {
|
||||
// TODO change from Fineract.dev to https://localhost:8443/fineract-provider/api/v1/ after FINERACT-1209
|
||||
String url = System.getProperty("fineract.it.url", "https://demo.fineract.dev/fineract-provider/api/v1/");
|
||||
fineract = FineractClient.builder().baseURL(url).tenant("default").basicAuth("mifos", "password").insecure(true)
|
||||
.logging(Level.NONE).build();
|
||||
}
|
||||
return fineract;
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link FineractClient#DATE_FORMAT}.
|
||||
*/
|
||||
protected String dateFormat() {
|
||||
return FineractClient.DATE_FORMAT;
|
||||
}
|
||||
|
||||
protected String random() {
|
||||
return Long.toString(random.nextLong());
|
||||
}
|
||||
|
||||
// This method just makes it easier to use Calls.ok() in tests (it avoids having to static import)
|
||||
protected <T> T ok(Call<T> call) {
|
||||
return Calls.ok(call);
|
||||
}
|
||||
|
||||
protected <T> Response<T> okR(Call<T> call) {
|
||||
return Calls.okR(call);
|
||||
}
|
||||
|
||||
// as above, avoids import static CallSubject.assertThat
|
||||
protected <T> CallSubject assertThat(Call<T> call) {
|
||||
return CallSubject.assertThat(call);
|
||||
}
|
||||
|
||||
// as above, this avoids issues with e.g. the Eclipse compiler getting confused which assertThat is which
|
||||
public static IterableSubject assertThat(Iterable<?> actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static <T extends Comparable<?>> ComparableSubject<T> assertThat(T actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static BigDecimalSubject assertThat(BigDecimal actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static Subject assertThat(Object actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static LongSubject assertThat(Long actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static DoubleSubject assertThat(Double actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static FloatSubject assertThat(Float actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static IntegerSubject assertThat(Integer actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static BooleanSubject assertThat(Boolean actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
public static StringSubject assertThat(String actual) {
|
||||
return Truth.assertThat(actual);
|
||||
}
|
||||
|
||||
// from truth-java8-extension
|
||||
public static OptionalSubject assertThat(Optional<?> actual) {
|
||||
return Truth8.assertThat(actual);
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/**
|
||||
* 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.integrationtests.newstyle;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import org.apache.fineract.client.models.PostOfficesRequest;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Integration Test for /offices API.
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
public class OfficeTest extends IntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createOne() {
|
||||
// NB parentId(1) always exists (Head Office)
|
||||
// NB name random() because Office Names have to be unique
|
||||
// TODO requiring dateFormat(..).locale(..) is dumb :( see https://issues.apache.org/jira/browse/FINERACT-1233
|
||||
assertThat(ok(fineract().offices.createOffice(new PostOfficesRequest().name("TestOffice-" + random()).parentId(1L)
|
||||
.openingDate(LocalDate.now()).dateFormat(dateFormat()).locale("en_US"))).getOfficeId()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void retrieveOneExisting() {
|
||||
assertThat(ok(fineract().offices.retrieveOffices(true, null, null)).size()).isAtLeast(2);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.0 MiB |
Reference in New Issue
Block a user