Skip to content

Commit

Permalink
Add test to encode a URL as Base64 as default
Browse files Browse the repository at this point in the history
Complements 9014b01.
  • Loading branch information
dr0i committed Nov 14, 2024
1 parent e49cdd7 commit 5bebf35
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import org.metafacture.framework.StreamReceiver;

import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.exceptions.base.MockitoAssertionError;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Arrays;
Expand All @@ -36,6 +38,9 @@
@ExtendWith(MetafixToDo.Extension.class)
public class MetafixMethodTest {

private static final String YOUTUBE_URL = "https://www.youtube.com/watch?v=daLgsPSvD9A";

private static final String YOUTUBE_URL_AS_URL_URL_BASE64 = "aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g_dj1kYUxnc1BTdkQ5QQ==";
@Mock
private StreamReceiver streamReceiver;

Expand Down Expand Up @@ -4086,20 +4091,31 @@ public void shouldTransformStringToBase64() {

@Test
public void shouldTransformUrlToBase64() {
urlToBase64(",url_safe:'true'");
}

@Test
public void shouldFailTransformUrlToBase64AsDefault() {
Assertions.assertThrows(MockitoAssertionError.class, () -> {
urlToBase64("");
});
}

private void urlToBase64(final String option) {
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", YOUTUBE_URL_AS_URL_URL_BASE64);
o.get().endEntity();
o.get().endRecord();
}
Expand Down

0 comments on commit 5bebf35

Please sign in to comment.