client: Fix mediaType MIME code (FINERACT-1218)

This commit is contained in:
Michael Vorburger
2020-10-24 21:01:32 +03:00
committed by Petri Tuomola
parent 20daf59a3e
commit 5f42112278
3 changed files with 60 additions and 14 deletions
@@ -0,0 +1,46 @@
/**
* 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.util;
import com.google.common.truth.Truth;
import okhttp3.MediaType;
import org.junit.jupiter.api.Test;
public class PartsTest {
@Test
void validMediaType() {
Truth.assertThat(Parts.mediaType("test.jpg")).isEqualTo(MediaType.get("image/jpeg"));
}
@Test
void dotMediaType() {
Truth.assertThat(Parts.mediaType("test.")).isNull();
}
@Test
void emptyMediaType() {
Truth.assertThat(Parts.mediaType("")).isNull();
}
@Test
void nullMediaType() {
Truth.assertThat(Parts.mediaType(null)).isNull();
}
}
@@ -49,7 +49,7 @@ public class DocumentTest extends IntegrationTest {
@Test
@Order(2)
void createDocument() throws IOException {
void createDocument() {
String name = "Test";
Part part = Parts.fromFile(testFile);
String description = null;
@@ -63,7 +63,7 @@ public class DocumentTest extends IntegrationTest {
@Test
@Order(3)
void getDocument() throws IOException {
void getDocument() {
GetEntityTypeEntityIdDocumentsResponse doc = ok(fineract().documents.getDocument("clients", clientId, documentId));
assertThat(doc.getName()).isEqualTo("Test");
assertThat(doc.getFileName()).isEqualTo(testFile.getName());
@@ -72,9 +72,8 @@ public class DocumentTest extends IntegrationTest {
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");
assertThat(doc.getSize()).isEqualTo(testFile.length() + 411);
assertThat(doc.getType()).isEqualTo("image/jpeg");
// TODO doc.getStorageType() shouldn't be exposed by the API?!
}
@@ -82,15 +81,14 @@ public class DocumentTest extends IntegrationTest {
@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.contentType()).isEqualTo(MediaType.get("image/jpeg"));
assertThat(r.bytes().length).isEqualTo(testFile.length());
// NOK: assertThat(r.contentLength()).isEqualTo(testFile.length());
}
@Test
@Order(10)
void updateDocument() throws IOException {
void updateDocument() {
String newName = "Test changed name";
String newDescription = getClass().getName();
ok(fineract().documents.updateDocument("clients", clientId, documentId, null, newName, newDescription));