-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure aliases can be accessed through 'doc'.
- Loading branch information
1 parent
2041ca6
commit 4145db5
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
server/src/test/java/org/elasticsearch/search/lookup/LeafDocLookupTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.search.lookup; | ||
|
||
import org.elasticsearch.index.fielddata.AtomicFieldData; | ||
import org.elasticsearch.index.fielddata.IndexFieldData; | ||
import org.elasticsearch.index.fielddata.ScriptDocValues; | ||
import org.elasticsearch.index.mapper.MappedFieldType; | ||
import org.elasticsearch.index.mapper.MapperService; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.junit.Before; | ||
|
||
import static org.mockito.AdditionalAnswers.returnsFirstArg; | ||
import static org.mockito.Matchers.anyObject; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class LeafDocLookupTests extends ESTestCase { | ||
private ScriptDocValues<?> docValues; | ||
private LeafDocLookup docLookup; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
|
||
MappedFieldType fieldType = mock(MappedFieldType.class); | ||
when(fieldType.name()).thenReturn("field"); | ||
when(fieldType.valueForDisplay(anyObject())).then(returnsFirstArg()); | ||
|
||
MapperService mapperService = mock(MapperService.class); | ||
when(mapperService.fullName("field")).thenReturn(fieldType); | ||
when(mapperService.fullName("alias")).thenReturn(fieldType); | ||
|
||
docValues = mock(ScriptDocValues.class); | ||
|
||
AtomicFieldData atomicFieldData = mock(AtomicFieldData.class); | ||
doReturn(docValues).when(atomicFieldData).getScriptValues(); | ||
|
||
IndexFieldData<?> fieldData = mock(IndexFieldData.class); | ||
when(fieldData.getFieldName()).thenReturn("field"); | ||
doReturn(atomicFieldData).when(fieldData).load(anyObject()); | ||
|
||
docLookup = new LeafDocLookup(mapperService, | ||
ignored -> fieldData, | ||
new String[] { "type" }, | ||
null); | ||
} | ||
|
||
public void testBasicLookup() { | ||
ScriptDocValues<?> fetchedDocValues = docLookup.get("field"); | ||
assertEquals(docValues, fetchedDocValues); | ||
} | ||
|
||
public void testLookupWithFieldAlias() { | ||
ScriptDocValues<?> fetchedDocValues = docLookup.get("alias"); | ||
assertEquals(docValues, fetchedDocValues); | ||
} | ||
} |