Skip to content

Commit

Permalink
Add unit test for MetaDataMappingService with typeless put mapping. (#…
Browse files Browse the repository at this point in the history
…40578) (#40720)

This is currently only tested via REST tests.

Closes #37450
  • Loading branch information
jpountz authored Apr 4, 2019
1 parent 4296ff2 commit f5f5c3e
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
Expand Down Expand Up @@ -114,4 +115,23 @@ public void testMappingVersionUnchanged() throws Exception {
assertThat(result.resultingState.metaData().index("test").getMappingVersion(), equalTo(previousVersion));
}

public void testMappingUpdateAccepts_docAsType() throws Exception {
final IndexService indexService = createIndex("test",
client().admin().indices().prepareCreate("test").addMapping("my_type"));
final MetaDataMappingService mappingService = getInstanceFromNode(MetaDataMappingService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest()
.type(MapperService.SINGLE_MAPPING_NAME);
request.indices(new Index[] {indexService.index()});
request.source("{ \"properties\": { \"foo\": { \"type\": \"keyword\" } }}");
final ClusterStateTaskExecutor.ClusterTasksResult<PutMappingClusterStateUpdateRequest> result =
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request));
assertThat(result.executionResults.size(), equalTo(1));
assertTrue(result.executionResults.values().iterator().next().isSuccess());
MappingMetaData mappingMetaData = result.resultingState.metaData().index("test").mapping();
assertEquals("my_type", mappingMetaData.type());
assertEquals(Collections.singletonMap("properties",
Collections.singletonMap("foo",
Collections.singletonMap("type", "keyword"))), mappingMetaData.sourceAsMap());
}
}

0 comments on commit f5f5c3e

Please sign in to comment.