forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relates to elastic#10217 Closes elastic#12035 This PR is against the query-refactoring branch.
- Loading branch information
1 parent
b315e48
commit 7281f01
Showing
4 changed files
with
154 additions
and
41 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
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
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
58 changes: 58 additions & 0 deletions
58
core/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTest.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,58 @@ | ||
/* | ||
* 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.index.query; | ||
|
||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.lucene.search.TermQuery; | ||
import org.elasticsearch.index.mapper.DocumentMapper; | ||
import org.elasticsearch.index.mapper.internal.TypeFieldMapper; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
public class TypeQueryBuilderTest extends BaseQueryTestCase<TypeQueryBuilder> { | ||
|
||
@Override | ||
protected TypeQueryBuilder doCreateTestQueryBuilder() { | ||
return new TypeQueryBuilder(getRandomType()); | ||
} | ||
|
||
@Override | ||
protected Query doCreateExpectedQuery(TypeQueryBuilder queryBuilder, QueryParseContext context) throws IOException { | ||
Query expectedQuery; | ||
//LUCENE 4 UPGRADE document mapper should use bytesref as well? | ||
DocumentMapper documentMapper = context.mapperService().documentMapper(queryBuilder.type().utf8ToString()); | ||
if (documentMapper == null) { | ||
expectedQuery = new TermQuery(new Term(TypeFieldMapper.NAME, queryBuilder.type())); | ||
} else { | ||
expectedQuery = documentMapper.typeFilter(); | ||
} | ||
return expectedQuery; | ||
} | ||
|
||
@Test | ||
public void testValidate() { | ||
TypeQueryBuilder typeQueryBuilder = new TypeQueryBuilder((String) null); | ||
assertThat(typeQueryBuilder.validate().validationErrors().size(), is(1)); | ||
} | ||
} |