|
19 | 19 | import com.fasterxml.jackson.databind.node.NumericNode; |
20 | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | 21 | import com.fasterxml.jackson.databind.node.TextNode; |
| 22 | +import com.fasterxml.jackson.databind.JsonNode; |
22 | 23 | import com.google.gson.JsonObject; |
23 | 24 |
|
24 | 25 | import org.apache.kafka.connect.data.Date; |
|
35 | 36 | import static io.confluent.connect.elasticsearch.DataConverter.BehaviorOnNullValues; |
36 | 37 | import static io.confluent.connect.elasticsearch.ElasticsearchSinkConnectorConstants.KEYWORD_TYPE; |
37 | 38 | import static io.confluent.connect.elasticsearch.ElasticsearchSinkConnectorConstants.TEXT_TYPE; |
38 | | -import static org.junit.Assert.assertEquals; |
39 | 39 | import static org.mockito.Mockito.mock; |
40 | 40 | import static org.mockito.Mockito.when; |
41 | 41 |
|
@@ -82,6 +82,29 @@ public void testStringMappingForES6() throws Exception { |
82 | 82 | assertEquals(256, ignoreAbove.asInt()); |
83 | 83 | } |
84 | 84 |
|
| 85 | + @Test |
| 86 | + public void testInferMapping() throws Exception { |
| 87 | + |
| 88 | + Schema stringSchema = SchemaBuilder |
| 89 | + .struct() |
| 90 | + .name("record") |
| 91 | + .field("foo", SchemaBuilder.string().defaultValue("0").build()) |
| 92 | + .build(); |
| 93 | + JsonNode stringMapping = Mapping.inferMapping(client, stringSchema); |
| 94 | + |
| 95 | + assertNull(stringMapping.get("properties").get("foo").get("null_value")); |
| 96 | + |
| 97 | + Schema intSchema =SchemaBuilder |
| 98 | + .struct() |
| 99 | + .name("record") |
| 100 | + .field("foo", SchemaBuilder.int32().defaultValue(0).build()) |
| 101 | + .build(); |
| 102 | + |
| 103 | + JsonNode intMapping = Mapping.inferMapping(client, intSchema); |
| 104 | + assertNotNull(intMapping.get("properties").get("foo").get("null_value")); |
| 105 | + assertEquals(0, intMapping.get("properties").get("foo").get("null_value").asInt()); |
| 106 | + } |
| 107 | + |
85 | 108 | protected Schema createSchema() { |
86 | 109 | Schema structSchema = createInnerSchema(); |
87 | 110 | return SchemaBuilder.struct().name("record") |
@@ -127,7 +150,6 @@ private Schema createInnerSchema() { |
127 | 150 | @SuppressWarnings("unchecked") |
128 | 151 | private void verifyMapping(Schema schema, JsonObject mapping) throws Exception { |
129 | 152 | String schemaName = schema.name(); |
130 | | - |
131 | 153 | Object type = mapping.get("type"); |
132 | 154 | if (schemaName != null) { |
133 | 155 | switch (schemaName) { |
|
0 commit comments