Move all SDK client tests into integrationtests (FINERACT-1209)

And run the against localhost instead of https://fineract.dev
This commit is contained in:
Michael Vorburger
2020-11-07 22:29:49 +01:00
committed by Aleksandar Vidakovic
parent 6f2fdaefdf
commit 73e330a58e
17 changed files with 134 additions and 278 deletions
@@ -1,102 +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;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import org.apache.fineract.integrationtests.common.ImageHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@Deprecated // replaced by new ImageTest, can be deleted as FINERACT-1209 is fully implemented
public class StaffImageApiTest {
private RequestSpecification requestSpec;
private ResponseSpecification responseSpec;
private ResponseSpecification responseSpec404;
@BeforeEach
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.responseSpec404 = new ResponseSpecBuilder().expectStatusCode(404).build();
}
@Test
public void createStaffImage() {
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
assertNotNull(imageId, "Image id should not be null");
}
@Test
public void getStaffImage() {
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
assertNotNull(imageId, "Image id should not be null");
String imageAsText = ImageHelper.getStaffImageAsText(this.requestSpec, this.responseSpec, staffId);
assertNotNull("Image id should not be null", imageAsText);
assertEquals(ImageHelper.generateImageAsText(), imageAsText);
}
@Test
public void getStaffImageAsBinary() {
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
assertNotNull(imageId, "Image id should not be null");
byte[] imageAsBytes = ImageHelper.getStaffImageAsBinary(this.requestSpec, this.responseSpec, staffId);
assertNotNull(imageAsBytes, "Image content should not be null");
assertEquals(251, imageAsBytes.length);
}
@Test
public void updateImage() {
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
assertNotNull(imageId, "Image id should not be null");
imageId = ImageHelper.updateImageForStaff(this.requestSpec, this.responseSpec, staffId);
assertNotNull(imageId, "Image id should not be null");
}
@Test
public void deleteStaffImage() {
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
assertNotNull(imageId, "Image id should not be null");
imageId = ImageHelper.deleteStaffImage(this.requestSpec, this.responseSpec, staffId);
assertNotNull(imageId, "Image id should not be null");
ImageHelper.getStaffImageAsBinary(this.requestSpec, this.responseSpec404, staffId);
// No additional Assertion required, the point is the responseSpec404
}
}
@@ -33,6 +33,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@Deprecated // TODO move this into new org.apache.fineract.integrationtests.client.StaffTest
public class StaffTest {
private RequestSpecification requestSpec;
@@ -61,7 +62,6 @@ public class StaffTest {
@Test
public void testStaffCreateValidationError() {
final String noOfficeJson = StaffHelper.createStaffWithJSONFields("firstname", "lastname");
final String noFirstnameJson = StaffHelper.createStaffWithJSONFields("officeId", "lastname");
final String noLastnameJson = StaffHelper.createStaffWithJSONFields("officeId", "firstname");
@@ -0,0 +1,55 @@
/**
* 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.client;
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);
}
}
@@ -0,0 +1,72 @@
/**
* 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.client;
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 retrieveAnyExisting() {
assertThat(retrieveFirst()).isPresent();
}
// The following are not tests, but helpful utilities for other tests
public Long getClientId() {
return retrieveFirst().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
.create6(new PostClientsRequest().officeId(1).fullname("TestClient").dateFormat(dateFormat()).locale("en_US")))
.getClientId();
}
Optional<Long> retrieveFirst() {
GetClientsResponse clients = ok(
fineract().clients.retrieveAll21(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();
}
}
@@ -0,0 +1,114 @@
/**
* 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.client;
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.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;
var 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);
}
}
@@ -0,0 +1,154 @@
/**
* 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.client;
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.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
*/
public class ImageTest extends IntegrationTest {
final File testImage = new File(getClass().getResource("/michael.vorburger-crepes.jpg").getFile());
Long clientId = new ClientTest().getClientId();
Long staffId = new StaffTest().getStaffId();
@Test
@Order(1)
void create() {
ok(fineract().images.create("staff", staffId, 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", staffId, 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", staffId, 128, 128, null));
assertThat(r.string()).hasLength(6591);
}
@Test
@Order(4)
void getBiggerSize() throws IOException {
ResponseBody r = ok(fineract().images.get("staff", staffId, 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", staffId, 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());
}
var staff = ok(fineract().staff.retrieveOne8(staffId));
String expectedFileName = staff.getDisplayName() + "JPEG"; // without dot!
assertThat(Parts.fileName(r)).hasValue(expectedFileName);
}
@Test
@Order(6)
void getOctetOutput() throws IOException {
ResponseBody r = ok(fineract().images.get("staff", staffId, 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", staffId, 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", staffId, 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", staffId, 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", staffId, Parts.fromFile(testImage)));
}
@Test
@Order(99)
void delete() {
ok(fineract().images.delete("staff", staffId));
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);
}
}
@@ -0,0 +1,142 @@
/**
* 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.client;
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.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) {
String url = System.getProperty("fineract.it.url", "https://localhost:8443/fineract-provider/api/v1/");
// insecure(true) should *ONLY* ever be used for https://localhost:8443, NOT in real clients!!
fineract = FineractClient.builder().insecure(true).baseURL(url).tenant("default").basicAuth("mifos", "password")
.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);
}
}
@@ -0,0 +1,53 @@
/**
* 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.client;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;
import org.apache.fineract.client.models.GetOfficesResponse;
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(ZoneId.of("UTC"))).dateFormat(dateFormat()).locale("en_US"))).getOfficeId()).isGreaterThan(0);
}
@Test
@Order(2)
void retrieveOneExistingInclDateFormat() { // see FINERACT-1220 re. what this tests re. Date Format
List<GetOfficesResponse> response = ok(fineract().offices.retrieveOffices(true, null, null));
assertThat(response.size()).isAtLeast(1);
assertThat(response.get(0).getOpeningDate()).isNotNull();
}
}
@@ -0,0 +1,67 @@
/**
* 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.client;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Optional;
import org.apache.fineract.client.models.PostStaffRequest;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
/**
* Integration Test for /staff API.
*
* @author Michael Vorburger.ch
*/
public class StaffTest extends IntegrationTest {
@Test
@Order(1)
void createOne() {
assertThat(create()).isGreaterThan(0);
}
@Test
@Order(2)
void retrieveAnyExisting() {
assertThat(retrieveFirst()).isPresent();
}
// The following are not tests, but helpful utilities for other tests
public Long getStaffId() {
return retrieveFirst().orElseGet(this::create);
}
Long create() {
return ok(fineract().staff
.create3(new PostStaffRequest().officeId(1L).firstname("StaffTest " + random()).lastname("Staffer " + random())
.externalId(random()).joiningDate(LocalDate.now(ZoneId.of("UTC"))).dateFormat(dateFormat()).locale("en_US")))
.getResourceId();
}
Optional<Long> retrieveFirst() {
var staff = ok(fineract().staff.retrieveAll16(1L, true, false, "ACTIVE"));
if (staff.size() > 0) {
return Optional.of((long) staff.get(0).getId());
}
return Optional.empty();
}
}
@@ -1,81 +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.common;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import org.apache.http.HttpHeaders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Deprecated // replaced by new ImageTest, can be deleted as FINERACT-1209 is fully implemented
public final class ImageHelper {
private ImageHelper() {
}
private static final Logger LOG = LoggerFactory.getLogger(ImageHelper.class);
private static final String STAFF_IMAGE_URL = "/fineract-provider/api/v1/staff/";
private static final String IMAGES_URI = "/images";
public static Integer createImageForStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
Integer staffId) {
LOG.info("---------------------------------CREATING AN IMAGE FOR STAFF---------------------------------------------");
final String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, URL, generateImageAsText(), "resourceId");
}
public static Integer updateImageForStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
Integer staffId) {
LOG.info("---------------------------------UPDATING AN IMAGE FOR STAFF---------------------------------------------");
final String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPut(requestSpec, responseSpec, URL, generateImageAsText(), "resourceId");
}
public static String getStaffImageAsText(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
Integer staffId) {
LOG.info("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
final String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
requestSpec.header(HttpHeaders.ACCEPT, "text/plain");
return Utils.performGetTextResponse(requestSpec, responseSpec, URL);
}
public static byte[] getStaffImageAsBinary(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
Integer staffId) {
LOG.info("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
final String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
requestSpec.header(HttpHeaders.ACCEPT, "application/octet-stream");
return Utils.performGetBinaryResponse(requestSpec, responseSpec, URL);
}
public static Integer deleteStaffImage(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
Integer staffId) {
LOG.info("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
final String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerDelete(requestSpec, responseSpec, URL, "resourceId");
}
public static String generateImageAsText() {
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\r\n"
+ "bWFnZVJlYWR5ccllPAAAAJ1JREFUeNpi+P//PwMIA4E9EG8E4idQDGLbw+WhiiqA+D8OXAFVAzbp\r\n"
+ "DxBvB2JLIGaGYkuoGEjOhhFIHAbij0BdPgxYACMj42ogJQpifwBiXSDeC8JIbt4LxSC5DyxQjTeB\r\n"
+ "+BeaYb+Q5EBOAVutCzMJHUNNPADzzDokiYdAfAmJvwLkGeTgWQfyKZICS6hYBTwc0QL8ORSjBDhA\r\n" + "gAEAOg13B6R/SAgAAAAASUVORK5CYII=";
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB