|
36 | 36 |
|
37 | 37 | import org.junit.jupiter.api.BeforeEach;
|
38 | 38 | import org.junit.jupiter.api.Test;
|
| 39 | +import org.junit.jupiter.params.ParameterizedTest; |
| 40 | +import org.junit.jupiter.params.provider.ValueSource; |
39 | 41 |
|
40 | 42 | import java.io.File;
|
41 | 43 | import java.io.IOException;
|
@@ -980,37 +982,52 @@ public void testVersionRetrievedFromAppInfoParser() {
|
980 | 982 |
|
981 | 983 | @Test
|
982 | 984 | public void testSchemaContentIsNull() {
|
983 |
| - converter.configure(Collections.singletonMap(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, null), false); |
| 985 | + converter.configure(Map.of(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, null), false); |
984 | 986 | assertEquals(new SchemaAndValue(Schema.STRING_SCHEMA, "foo-bar-baz"), converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"string\" }, \"payload\": \"foo-bar-baz\" }".getBytes()));
|
985 | 987 | }
|
986 | 988 |
|
987 | 989 | @Test
|
988 | 990 | public void testSchemaContentIsEmptyString() {
|
989 |
| - converter.configure(Collections.singletonMap(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, ""), false); |
| 991 | + converter.configure(Map.of(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, ""), false); |
990 | 992 | assertEquals(new SchemaAndValue(Schema.STRING_SCHEMA, "foo-bar-baz"), converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"string\" }, \"payload\": \"foo-bar-baz\" }".getBytes()));
|
991 | 993 | }
|
992 | 994 |
|
993 | 995 | @Test
|
994 | 996 | public void testSchemaContentValidSchema() {
|
995 |
| - converter.configure(Collections.singletonMap(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, "{ \"type\": \"string\" }"), false); |
| 997 | + converter.configure(Map.of(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, "{ \"type\": \"string\" }"), false); |
996 | 998 | assertEquals(new SchemaAndValue(Schema.STRING_SCHEMA, "foo-bar-baz"), converter.toConnectData(TOPIC, "\"foo-bar-baz\"".getBytes()));
|
997 | 999 | }
|
998 | 1000 |
|
999 | 1001 | @Test
|
1000 | 1002 | public void testSchemaContentInValidSchema() {
|
1001 | 1003 | assertThrows(
|
1002 | 1004 | DataException.class,
|
1003 |
| - () -> converter.configure(Collections.singletonMap(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, "{ \"string\" }"), false), |
| 1005 | + () -> converter.configure(Map.of(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, "{ \"string\" }"), false), |
1004 | 1006 | " Provided schema is invalid , please recheck the schema you have provided");
|
1005 | 1007 | }
|
1006 | 1008 |
|
1007 | 1009 | @Test
|
1008 | 1010 | public void testSchemaContentLooksLikeSchema() {
|
1009 |
| - converter.configure(Collections.singletonMap(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, "{ \"type\": \"struct\", \"fields\": [{\"field\": \"schema\", \"type\": \"struct\",\"fields\": [{\"field\": \"type\", \"type\": \"string\" }]}, {\"field\": \"payload\", \"type\": \"string\"}]}"), false); |
| 1011 | + converter.configure(Map.of(JsonConverterConfig.SCHEMA_CONTENT_CONFIG, "{ \"type\": \"struct\", \"fields\": [{\"field\": \"schema\", \"type\": \"struct\",\"fields\": [{\"field\": \"type\", \"type\": \"string\" }]}, {\"field\": \"payload\", \"type\": \"string\"}]}"), false); |
1010 | 1012 | SchemaAndValue connectData = converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"string\" }, \"payload\": \"foo-bar-baz\" }".getBytes());
|
1011 | 1013 | assertEquals("foo-bar-baz", ((Struct) connectData.value()).getString("payload"));
|
1012 | 1014 | }
|
1013 | 1015 |
|
| 1016 | + @ParameterizedTest |
| 1017 | + @ValueSource(strings = { |
| 1018 | + "{ }", |
| 1019 | + "{ \"wrong\": \"schema\" }", |
| 1020 | + "{ \"schema\": { \"type\": \"string\" } }", |
| 1021 | + "{ \"payload\": \"foo-bar-baz\" }", |
| 1022 | + "{ \"schema\": { \"type\": \"string\" }, \"payload\": \"foo-bar-baz\", \"extra\": \"field\" }", |
| 1023 | + }) |
| 1024 | + public void testNullSchemaContentWithWrongConnectDataValue(String value) { |
| 1025 | + converter.configure(Map.of(), false); |
| 1026 | + assertThrows( |
| 1027 | + DataException.class, |
| 1028 | + () -> converter.toConnectData(TOPIC, value.getBytes())); |
| 1029 | + } |
| 1030 | + |
1014 | 1031 | private JsonNode parse(byte[] json) {
|
1015 | 1032 | try {
|
1016 | 1033 | return objectMapper.readTree(json);
|
|
0 commit comments