|
1 | | -package seko.kafka.connect.transformer.python; |
| 1 | +package seko.kafka.connect.transformer.script; |
2 | 2 |
|
| 3 | +import org.apache.kafka.common.config.ConfigException; |
3 | 4 | import org.apache.kafka.connect.source.SourceRecord; |
4 | 5 | import org.apache.kafka.connect.transforms.util.Requirements; |
5 | 6 | import org.junit.Assert; |
@@ -79,6 +80,35 @@ public void applyWithoutSchemaRuby() { |
79 | 80 | Assert.assertEquals("key___123", transformed.key()); |
80 | 81 | } |
81 | 82 |
|
| 83 | + |
| 84 | + @Test(expected = ConfigException.class) |
| 85 | + public void applyWithoutSchemaJsConfigFail() { |
| 86 | + config.put(Configuration.SCRIP_ENGINE_NAME, "JavaScript"); |
| 87 | + config.put(Configuration.KEY_SCRIPT_CONFIG, "java.lang.System.exit(9);function keyTransform(source){ return source + '123'; }"); |
| 88 | + config.put(Configuration.VALUE_SCRIPT_CONFIG, "function valueTransform(source){ source.qweqweq = 12312312; return source;}"); |
| 89 | + transformer.configure(config); |
| 90 | + |
| 91 | + SourceRecord transformed = transformer.apply(record); |
| 92 | + Map<String, Object> stringObjectMap = Requirements.requireMapOrNull(transformed.value(), ""); |
| 93 | + Assert.assertEquals(12312312, stringObjectMap.get("qweqweq")); |
| 94 | + Assert.assertEquals(2, stringObjectMap.size()); |
| 95 | + Assert.assertEquals("key___123", transformed.key()); |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + public void applyWithoutSchemaJsFail() { |
| 100 | + config.put(Configuration.SCRIP_ENGINE_NAME, "JavaScript"); |
| 101 | + config.put(Configuration.KEY_SCRIPT_CONFIG, "function keyTransform(source){ java.lang.System.exit(9); return source + '123'; }"); |
| 102 | + config.put(Configuration.VALUE_SCRIPT_CONFIG, "function valueTransform(source){ source.qweqweq = 12312312; return source;}"); |
| 103 | + transformer.configure(config); |
| 104 | + |
| 105 | + SourceRecord transformed = transformer.apply(record); |
| 106 | + Map<String, Object> stringObjectMap = Requirements.requireMapOrNull(transformed.value(), ""); |
| 107 | + Assert.assertEquals(12312312, stringObjectMap.get("qweqweq")); |
| 108 | + Assert.assertEquals(2, stringObjectMap.size()); |
| 109 | + Assert.assertEquals("key___", transformed.key()); |
| 110 | + } |
| 111 | + |
82 | 112 | /*@Test(expected = ConfigException.class) |
83 | 113 | public void testSFConfigEmpty() { |
84 | 114 | config.put(Configuration.KEY_SCRIPT_CONFIG, ""); |
|
0 commit comments