Skip to content

Commit

Permalink
more validation unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhmaurya committed Nov 17, 2023
1 parent fe33157 commit f9fc10f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,35 @@ public void testPositionIncrementGap() throws IOException {}
public void testDefaultPositionIncrementGap() throws IOException {}

@Override
public void testIndexPrefixMapping() throws IOException {}
public void testIndexPrefixMapping() throws IOException {
MapperParsingException e = expectThrows(
MapperParsingException.class,
() -> createDocumentMapper(
fieldMapping(
b -> b.field("type", textFieldName)
.field("analyzer", "standard")
.startObject("index_prefixes")
.field("min_chars", 2)
.field("max_chars", 10)
.endObject()
)
)
);
assertEquals(
"Failed to parse mapping [_doc]: Index prefixes cannot be enabled on for match_only_text field. Use text field instead",
e.getMessage()
);
}

@Override
public void testIndexPrefixIndexTypes() throws IOException {}
public void testIndexPrefixIndexTypes() throws IOException {
// not supported and asserted the expected behavior in testIndexPrefixMapping
}

@Override
public void testFastPhrasePrefixes() throws IOException {}
public void testFastPhrasePrefixes() throws IOException {
// not supported and asserted the expected behavior in testIndexPrefixMapping
}

public void testPhrasePrefixes() throws IOException {
MapperService mapperService = createMapperService(mapping(b -> {
Expand Down Expand Up @@ -351,7 +373,21 @@ public void testPhrasePrefixes() throws IOException {
}

@Override
public void testFastPhraseMapping() throws IOException {}
public void testFastPhraseMapping() throws IOException {
MapperParsingException e = expectThrows(MapperParsingException.class, () -> createMapperService(mapping(b -> {
b.startObject("field")
.field("type", textFieldName)
.field("analyzer", "my_stop_analyzer")
.field("index_phrases", true)
.endObject();
// "standard" will be replaced with MockSynonymAnalyzer
b.startObject("synfield").field("type", textFieldName).field("analyzer", "standard").field("index_phrases", true).endObject();
})));
assertEquals(
"Failed to parse mapping [_doc]: Index phrases cannot be enabled on for match_only_text field. Use text field instead",
e.getMessage()
);
}

@Override
public void testSimpleMerge() throws IOException {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ protected QueryShardContext createQueryShardContext(MapperService mapperService)
when(queryShardContext.lookup()).thenReturn(new SearchLookup(mapperService, (ft, s) -> {
throw new UnsupportedOperationException("search lookup not available");
}));
when(queryShardContext.getFieldType(any())).thenAnswer(
inv -> mapperService.fieldType(inv.getArguments()[0].toString())
);
when(queryShardContext.getFieldType(any())).thenAnswer(inv -> mapperService.fieldType(inv.getArguments()[0].toString()));
return queryShardContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ public void testSupportedFieldTypes() throws IOException {
source.put("type", mappedType.getKey());

// Text is the only field that doesn't support DVs, instead FD
if (mappedType.getKey().equals(TextFieldMapper.CONTENT_TYPE) == false && mappedType.getKey().equals(MatchOnlyTextFieldMapper.CONTENT_TYPE) == false) {
if (mappedType.getKey().equals(TextFieldMapper.CONTENT_TYPE) == false
&& mappedType.getKey().equals(MatchOnlyTextFieldMapper.CONTENT_TYPE) == false) {
source.put("doc_values", "true");
}

Expand Down

0 comments on commit f9fc10f

Please sign in to comment.