Skip to content

Commit

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

This is currently only tested via REST tests.

Closes elastic#37450
  • Loading branch information
jpountz authored and Gurkan Kaymak committed May 27, 2019
1 parent 5eba372 commit 9f0265c
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 9f0265c

Please sign in to comment.