Skip to content
Snippets Groups Projects
Commit e8b84fab authored by Martin Vogel's avatar Martin Vogel
Browse files

Merge branch 'refactor/1308-remove-from-string-attachment' into 'main'

#1308 Remove fromString() method in attachments

See merge request !248
parents a48aa4d9 0f3ebc48
No related branches found
No related tags found
1 merge request!248#1308 Remove fromString() method in attachments
......@@ -81,7 +81,7 @@ class CommandLineClientTest {
// Given
final var submissionId = UUID.randomUUID();
final Attachment attachment = Attachment.fromString("attachment text", "text/plain", "testAttachment.txt", "test");
final Attachment attachment = Attachment.fromByteArray("attachment text".getBytes(), "text/plain", "testAttachment.txt", "test");
final var expectedSubmission = new Submission();
final var data = new ReceivedData("{ \"test\" : \"data\"", MimeType.APPLICATION_JSON);
......
......@@ -11,7 +11,8 @@ import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
public class Attachment {
public final class Attachment {
private final byte[] data;
private final String fileName;
private final String description;
......@@ -92,7 +93,10 @@ public class Attachment {
*
* @param content data of the attachment as byte[]
* @param mimeType mime type of the provided attachment data
* @deprecated This method is no longer acceptable since it can lead to character encoding issues when used incorrectly, e.g. when an entire file is passed as string.
* <p> Use {@link Attachment#fromByteArray(byte[], String)}} instead.
*/
@Deprecated(since = "1.2.0", forRemoval = true)
public static Attachment fromString(final String content, final String mimeType) {
return fromString(content, mimeType, null, null);
}
......@@ -105,7 +109,10 @@ public class Attachment {
* @param fileName name of the attachment file
* @param mimeType mime type of the provided attachment data
* @param description description of the attachment file
* @deprecated This method is no longer acceptable since it can lead to character encoding issues when used incorrectly, e.g. when an entire file is passed as string.
* <p> Use {@link Attachment#fromByteArray(byte[], String)}} instead.
*/
@Deprecated(since = "1.2.0", forRemoval = true)
public static Attachment fromString(final String content, final String mimeType, final String fileName, final String description) {
return new Attachment(content.getBytes(StandardCharsets.UTF_8), mimeType, fileName, description);
}
......@@ -140,6 +147,7 @@ public class Attachment {
/**
* Filename of the attachment. This filed is optional so it might be null.
*
* @return filename as string, null if not present
*/
public String getFileName() {
......@@ -148,6 +156,7 @@ public class Attachment {
/**
* Description of the attachment. This filed is optional so it might be null.
*
* @return description as string, null if not present
*/
public String getDescription() {
......@@ -156,6 +165,7 @@ public class Attachment {
/**
* Mimetype of the attachments content.
*
* @return mimetype as string.
*/
public String getMimeType() {
......
......@@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@EnableIfEnvironmentVariablesAreSet
public class CallbackIT extends IntegrationTestBase {
private final String callbackRequestUrl = "https://webhook.site/token/14efa049-f720-45d5-8088-ecbff3f625dd/request/latest";
private final String callbackRequestUrl = "https://webhook.site/token/41cc8f7f-23fc-48fb-8323-99def074dfdf/request/latest";
private final ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
......
......@@ -75,7 +75,6 @@ public class SenderClientIT extends IntegrationTestBase {
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "text/plain"))
.addAttachment(Attachment.fromByteArray("attachment data".getBytes(), "text/plain"))
.addAttachment(Attachment.fromString("attachment data", "text/plain"))
.setReplyChannel(ReplyChannel.fromDeMail("test@mail.org"))
.build();
......@@ -94,7 +93,7 @@ public class SenderClientIT extends IntegrationTestBase {
assertThat(receivedSubmission.getDataSchemaUri(), is(URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json")));
assertThat(receivedSubmission.getDataMimeType(), is("application/json"));
assertThat(receivedSubmission.getServiceType().getIdentifier(), is("urn:de:fim:leika:leistung:99400048079000"));
assertThat(receivedSubmission.getAttachments(), hasSize(3));
assertThat(receivedSubmission.getAttachments(), hasSize(2));
assertThat(receivedSubmission.getMetadata().getReplyChannel(), is(ReplyChannel.fromDeMail("test@mail.org")));
assertThat(new String(receivedSubmission.getAttachments().get(0).getDataAsBytes()), is("Test attachment"));
assertThat(receivedSubmission.getAttachments().get(0).getMimeType(), is("text/plain"));
......@@ -114,7 +113,6 @@ public class SenderClientIT extends IntegrationTestBase {
.setXmlData(submissionData, URI.create("urn:de:fim:leika:leistung:99400048079000"))
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "text/plain"))
.addAttachment(Attachment.fromByteArray("attachment data".getBytes(), "text/plain"))
.addAttachment(Attachment.fromString("attachment data", "text/plain"))
.setReplyChannel(ReplyChannel.fromDeMail("test@mail.org"))
.build();
......@@ -132,7 +130,7 @@ public class SenderClientIT extends IntegrationTestBase {
assertThat(receivedSubmission.getDataAsString(), is(submissionData));
assertThat(receivedSubmission.getDataSchemaUri(), is(URI.create("urn:de:fim:leika:leistung:99400048079000")));
assertThat(receivedSubmission.getDataMimeType(), is("application/xml"));
assertThat(receivedSubmission.getAttachments(), hasSize(3));
assertThat(receivedSubmission.getAttachments(), hasSize(2));
assertThat(receivedSubmission.getMetadata().getReplyChannel(), is(ReplyChannel.fromDeMail("test@mail.org")));
assertThat(new String(receivedSubmission.getAttachments().get(0).getDataAsBytes()), is("Test attachment"));
}
......@@ -158,7 +156,6 @@ public class SenderClientIT extends IntegrationTestBase {
.setJsonData(submissionData, submissionDataSchemaUri)
.addAttachment(Attachment.fromPath(Path.of("src/test/resources/attachment.txt"), "text/plain"))
.addAttachment(Attachment.fromByteArray("attachment data".getBytes(), "text/plain"))
.addAttachment(Attachment.fromString("attachment data", "text/plain"))
.setReplyChannel(ReplyChannel.fromDeMail("test@mail.org"))
.build();
......
......@@ -121,7 +121,7 @@ public class SubscriberClientIT extends IntegrationTestBase {
.setDestination(destinationId)
.setServiceType(leikaKey, serviceName)
.setJsonData(submissionData, URI.create("https://schema.fitko.de/fim/s00000114_1.1.schema.json"))
.addAttachment(Attachment.fromString("foo", "plain/text"))
.addAttachment(Attachment.fromByteArray("foo".getBytes(), "plain/text"))
.build();
final var sentSubmission = senderClient.send(submission);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment