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
+5 -1
View File
@@ -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();
@@ -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
@@ -115,9 +115,8 @@ public class StaffApiResource {
+ "and for status=ALL, it Returns both ACTIVE and INACTIVE Staff.\n" + "\n" + "Example Requests:\n" + "\n"
+ "staff?status=active")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = StaffApiResourceSwagger.GetStaffResponse.class)))),
@ApiResponse(responseCode = "200", description = "GET https://DomainName/api/v1/staff?status={ACTIVE|INACTIVE|ALL}", content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.GetStaffResponse.class))) })
public String retrieveStaff(@Context final UriInfo uriInfo,
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = StaffApiResourceSwagger.RetrieveOneResponse.class)))) })
public String retrieveAll(@Context final UriInfo uriInfo,
@QueryParam("officeId") @Parameter(description = "officeId") final Long officeId,
@DefaultValue("false") @QueryParam("staffInOfficeHierarchy") @Parameter(description = "staffInOfficeHierarchy") final boolean staffInOfficeHierarchy,
@DefaultValue("false") @QueryParam("loanOfficersOnly") @Parameter(description = "loanOfficersOnly") final boolean loanOfficersOnly,
@@ -143,8 +142,8 @@ public class StaffApiResource {
+ "officeId, firstname, lastname\n" + "\n" + "Optional Fields: \n" + "isLoanOfficer, isActive")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.PostStaffRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.PostStaffResponse.class))) })
public String createStaff(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.CreateStaffResponse.class))) })
public String create(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createStaff().withJson(apiRequestBodyAsJson).build();
@@ -160,8 +159,8 @@ public class StaffApiResource {
@Operation(summary = "Retrieve a Staff Member", description = "Returns the details of a Staff Member.\n" + "\n" + "Example Requests:\n"
+ "\n" + "staff/1")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.GetStaffResponse.class))) })
public String retreiveStaff(@PathParam("staffId") @Parameter(description = "staffId") final Long staffId,
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.RetrieveOneResponse.class))) })
public String retrieveOne(@PathParam("staffId") @Parameter(description = "staffId") final Long staffId,
@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
@@ -183,8 +182,8 @@ public class StaffApiResource {
@Operation(summary = "Update a Staff Member", description = "Updates the details of a staff member.")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.PutStaffRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.PutStaffResponse.class))) })
public String updateStaff(@PathParam("staffId") @Parameter(description = "staffId") final Long staffId,
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StaffApiResourceSwagger.UpdateStaffResponse.class))) })
public String update(@PathParam("staffId") @Parameter(description = "staffId") final Long staffId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateStaff(staffId).withJson(apiRequestBodyAsJson).build();
@@ -197,14 +196,14 @@ public class StaffApiResource {
@GET
@Path("downloadtemplate")
@Produces("application/vnd.ms-excel")
public Response getStaffTemplate(@QueryParam("officeId") final Long officeId, @QueryParam("dateFormat") final String dateFormat) {
public Response getTemplate(@QueryParam("officeId") final Long officeId, @QueryParam("dateFormat") final String dateFormat) {
return bulkImportWorkbookPopulatorService.getTemplate(GlobalEntityType.STAFF.toString(), officeId, null, dateFormat);
}
@POST
@Path("uploadtemplate")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String postStaffTemplate(@FormDataParam("file") InputStream uploadedInputStream,
public String postTemplate(@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("locale") final String locale,
@FormDataParam("dateFormat") final String dateFormat) {
final Long importDocumentId = this.bulkImportWorkbookService.importWorkbook(GlobalEntityType.STAFF.toString(), uploadedInputStream,
@@ -39,7 +39,7 @@ final class StaffApiResourceSwagger {
}
@Schema(example = "1")
public Long id;
public Long officeId;
@Schema(example = "John")
public String firstname;
@Schema(example = "Doe")
@@ -62,9 +62,9 @@ final class StaffApiResourceSwagger {
}
@Schema(description = "PostStaffResponse")
public static final class PostStaffResponse {
public static final class CreateStaffResponse {
private PostStaffResponse() {
private CreateStaffResponse() {
}
@@ -75,9 +75,9 @@ final class StaffApiResourceSwagger {
}
@Schema(description = "GetStaffResponse")
public static final class GetStaffResponse {
public static final class RetrieveOneResponse {
private GetStaffResponse() {
private RetrieveOneResponse() {
}
@@ -119,9 +119,9 @@ final class StaffApiResourceSwagger {
}
@Schema(description = "PutStaffResponse")
public static final class PutStaffResponse {
public static final class UpdateStaffResponse {
private PutStaffResponse() {
private UpdateStaffResponse() {
}
+1
View File
@@ -23,6 +23,7 @@ dependencies {
tomcat 'org.apache.tomcat:tomcat:9.0.39@zip'
testImplementation( files("$rootDir/fineract-provider/build/classes/java/main/"),
project(path: ':fineract-provider', configuration: 'runtimeElements'),
project(path: ':fineract-client', configuration: 'runtimeElements'),
'org.junit.jupiter:junit-jupiter-api:5.7.0',
'com.google.truth:truth:1.0.1',
'com.google.truth.extensions:truth-java8-extension:1.0.1',
@@ -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");
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.client.testutil;
package org.apache.fineract.integrationtests.client;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.newstyle;
package org.apache.fineract.integrationtests.client;
import java.util.Optional;
import org.apache.fineract.client.models.GetClientsResponse;
@@ -39,14 +39,14 @@ public class ClientTest extends IntegrationTest {
@Test
@Order(2)
void retrieveOneExisting() {
assertThat(retrieveOne()).isPresent();
void retrieveAnyExisting() {
assertThat(retrieveFirst()).isPresent();
}
// The following are not tests, but helpful utilities for other tests
public Long getClientId() {
return retrieveOne().orElseGet(this::create);
return retrieveFirst().orElseGet(this::create);
}
Long create() {
@@ -56,13 +56,13 @@ public class ClientTest extends IntegrationTest {
// 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")))
.create6(new PostClientsRequest().officeId(1).fullname("TestClient").dateFormat(dateFormat()).locale("en_US")))
.getClientId();
}
Optional<Long> retrieveOne() {
Optional<Long> retrieveFirst() {
GetClientsResponse clients = ok(
fineract().clients.retrieveAll20(null, null, null, null, null, null, null, null, 0, 1, null, null, false));
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());
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.newstyle;
package org.apache.fineract.integrationtests.client;
import java.io.File;
import java.io.IOException;
@@ -24,7 +24,6 @@ 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;
@@ -54,9 +53,7 @@ public class DocumentTest extends IntegrationTest {
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));
var response = ok(fineract().documents.createDocument("clients", clientId, part, name, description));
assertThat(response.getResourceId()).isNotNull();
assertThat(response.getResourceIdentifier()).isNotEmpty();
documentId = response.getResourceId();
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.newstyle;
package org.apache.fineract.integrationtests.client;
import java.io.File;
import java.io.IOException;
@@ -24,7 +24,6 @@ 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;
@@ -37,28 +36,24 @@ import retrofit2.http.Headers;
*
* @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
Long staffId = new StaffTest().getStaffId();
@Test
@Order(1)
void create() {
ok(fineract().images.create("staff", 1L, Parts.fromFile(testImage)));
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", 1L, 3505, 1972, null));
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,");
@@ -69,14 +64,14 @@ public class ImageTest extends IntegrationTest {
@Test
@Order(3)
void getSmallerSize() throws IOException {
ResponseBody r = ok(fineract().images.get("staff", 1L, 128, 128, null));
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", 1L, 9000, 6000, null));
ResponseBody r = ok(fineract().images.get("staff", staffId, 9000, 6000, null));
assertThat(r.string()).hasLength(2846549);
}
@@ -84,21 +79,22 @@ public class ImageTest extends IntegrationTest {
@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"));
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());
}
String expectedFileName = "test, testJPEG"; // without dot!
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", 1L, 3505, 1972, "octet"));
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());
@@ -107,7 +103,7 @@ public class ImageTest extends IntegrationTest {
@Test
@Order(7)
void getAnotherOutput() throws IOException {
ResponseBody r = ok(fineract().images.get("staff", 1L, 3505, 1972, "abcd"));
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,");
}
@@ -115,7 +111,7 @@ public class ImageTest extends IntegrationTest {
@Test
@Order(8)
void getText() throws IOException {
ResponseBody r = ok(fineract().createService(ImagesApiWithHeadersForTest.class).getText("staff", 1L, 3505, 1972, null));
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,");
}
@@ -123,7 +119,7 @@ public class ImageTest extends IntegrationTest {
@Test
@Order(9)
void getBytes() throws IOException {
ResponseBody r = ok(fineract().createService(ImagesApiWithHeadersForTest.class).getBytes("staff", 1L, 3505, 1972, null));
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());
}
@@ -131,13 +127,13 @@ public class ImageTest extends IntegrationTest {
@Test
@Order(50)
void update() {
ok(fineract().images.update("staff", 1L, Parts.fromFile(testImage)));
ok(fineract().images.update("staff", staffId, Parts.fromFile(testImage)));
}
@Test
@Order(99)
void delete() {
ok(fineract().images.delete("staff", 1L));
ok(fineract().images.delete("staff", staffId));
ok(fineract().images.delete("clients", clientId));
}
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.newstyle;
package org.apache.fineract.integrationtests.client;
import com.google.common.truth.BigDecimalSubject;
import com.google.common.truth.BooleanSubject;
@@ -35,7 +35,6 @@ 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;
@@ -62,9 +61,9 @@ public abstract class IntegrationTest {
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)
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;
@@ -16,9 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.integrationtests.newstyle;
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;
@@ -36,13 +39,15 @@ public class OfficeTest extends IntegrationTest {
// 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);
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 retrieveOneExisting() {
assertThat(ok(fineract().offices.retrieveOffices(true, null, null)).size()).isAtLeast(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=";
}
}

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 2.0 MiB