From d1498c0ca64bb6ed57a6d97c05101fc8dc04d9cf Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Thu, 14 Nov 2024 18:27:46 +0100 Subject: [PATCH] Add test to encode a URL as Base64 as default Complements 9014b018fe3a13dba4cad2c9b737890e211da0e1. --- .../metafacture/metafix/MetafixMethodTest.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java index 9f58ecce..7166e7b1 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java @@ -36,6 +36,7 @@ @ExtendWith(MetafixToDo.Extension.class) public class MetafixMethodTest { + private static final String YOUTUBE_URL = "https://www.youtube.com/watch?v=daLgsPSvD9A"; @Mock private StreamReceiver streamReceiver; @@ -4085,21 +4086,30 @@ public void shouldTransformStringToBase64() { } @Test - public void shouldTransformUrlToBase64() { + public void shouldTransformUrlSafeToBase64() { + urlToBase64(",url_safe:'true'", "aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj1kYUxnc1BTdkQ5QQ=="); + } + + @Test + public void shouldTransformNotUrlSafeToBase64AsDefault() { + urlToBase64("", "aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kYUxnc1BTdkQ5QQ=="); + } + + private void urlToBase64(final String option, final String expected) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "to_base64('data.title', url_safe:'true')" + "to_base64('data.title'" + option + ")" ), i -> { i.startRecord("1"); i.startEntity("data"); - i.literal("title", "https://www.youtube.com/watch?v=daLgsPSvD9A"); + i.literal("title", YOUTUBE_URL); i.endEntity(); i.endRecord(); }, o -> { o.get().startRecord("1"); o.get().startEntity("data"); - o.get().literal("title", "aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj1kYUxnc1BTdkQ5QQ=="); + o.get().literal("title", expected); o.get().endEntity(); o.get().endRecord(); }