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