Add new DocumentTest (FINERACT-1218)
This commit is contained in:
committed by
Petri Tuomola
parent
6992102035
commit
20daf59a3e
+72
@@ -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.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();
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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() throws IOException {
|
||||
assertThat(ok(fineract().documents.retrieveAllDocuments("clients", clientId))).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createDocument() throws IOException {
|
||||
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() throws IOException {
|
||||
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() + 385);
|
||||
// TODO huh?! MIME is always text/plain instead of image/jpeg... :(
|
||||
assertThat(doc.getType()).isEqualTo("text/plain");
|
||||
// TODO doc.getStorageType() shouldn't be exposed by the API?!
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void downloadFile() throws IOException {
|
||||
ResponseBody r = ok(fineract().documents.downloadFile("clients", clientId, documentId));
|
||||
assertThat(r.contentType()).isEqualTo(MediaType.get("text/plain")); // TODO wrong, bug; needs to be "image/jpeg"
|
||||
// (as above)
|
||||
assertThat(r.bytes().length).isEqualTo(testFile.length());
|
||||
// NOK: assertThat(r.contentLength()).isEqualTo(testFile.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void updateDocument() throws IOException {
|
||||
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() throws IOException {
|
||||
ok(fineract().documents.deleteDocument("clients", clientId, documentId));
|
||||
assertThat(fineract().documents.getDocument("clients", clientId, documentId)).hasHttpStatus(404);
|
||||
}
|
||||
|
||||
@Order(9999)
|
||||
@Test // FINERACT-1036
|
||||
void createDocumentBadArgs() throws IOException {
|
||||
assertThat(fineract().documents.createDocument("clients", 123L, null, "test.pdf", null)).hasHttpStatus(400);
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -39,6 +39,8 @@ 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;
|
||||
|
||||
@@ -47,6 +49,8 @@ import retrofit2.Call;
|
||||
*
|
||||
* @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 {
|
||||
@@ -60,7 +64,7 @@ public abstract class IntegrationTest {
|
||||
// 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.BODY).build();
|
||||
.logging(Level.NONE).build();
|
||||
}
|
||||
return fineract;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
Reference in New Issue
Block a user