[OLINGO-568] Added exception messages and some tests
This commit is contained in:
parent
1a59a5804b
commit
ae1b2754b7
|
@ -39,7 +39,9 @@ public class SearchParser {
|
|||
try {
|
||||
searchExpression = parse(tokenizer.tokenize(searchQuery));
|
||||
} catch (SearchTokenizerException e) {
|
||||
return null;
|
||||
String message = e.getMessage();
|
||||
throw new SearchParserException("Tokenizer exception with message: " + message,
|
||||
SearchParserException.MessageKeys.TOKENIZER_EXCEPTION, message);
|
||||
}
|
||||
final SearchOptionImpl searchOption = new SearchOptionImpl();
|
||||
searchOption.setSearchExpression(searchExpression);
|
||||
|
|
|
@ -24,7 +24,11 @@ public class SearchParserException extends UriParserSyntaxException {
|
|||
|
||||
private static final long serialVersionUID = 5781553037561337795L;
|
||||
|
||||
public static enum MessageKeys implements MessageKey {
|
||||
public enum MessageKeys implements MessageKey {
|
||||
/** parameter: message */
|
||||
TOKENIZER_EXCEPTION,
|
||||
/** parameter: tokenCharacter */
|
||||
INVALID_TOKEN_CHARACTER_FOUND,
|
||||
/** parameter: operatorkind */
|
||||
INVALID_BINARY_OPERATOR_POSITION,
|
||||
/** parameter: operatorkind */
|
||||
|
|
|
@ -37,6 +37,15 @@ UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system
|
|||
UriParserSyntaxException.SYNTAX=The URI is malformed.
|
||||
UriParserSyntaxException.DUPLICATED_ALIAS=Duplicated alias. An alias '%1$s' was already specified!.
|
||||
|
||||
SearchParserException.TOKENIZER_EXCEPTION=Exception during tokenizer creation with message '%1$s'.
|
||||
SearchParserException.INVALID_TOKEN_CHARACTER_FOUND=Invalid token character with value '%1$s' found.
|
||||
SearchParserException.INVALID_BINARY_OPERATOR_POSITION=Invalid binary operator position for kind '%1$s' found.
|
||||
SearchParserException.INVALID_NOT_OPERAND=Invalid not operand for kind '%1$s' found.
|
||||
SearchParserException.EXPECTED_DIFFERENT_TOKEN=Expected token '%1$s' but found '%2$s'.
|
||||
SearchParserException.NO_EXPRESSION_FOUND=No expression found.
|
||||
SearchParserException.INVALID_OPERATOR_AFTER_AND=Invalid operator after AND found of kind '%1$s'.
|
||||
|
||||
|
||||
UriParserSemanticException.FUNCTION_NOT_FOUND=The function import '%1$s' has no function with parameters '%2$s'.
|
||||
UriParserSemanticException.RESOURCE_PART_ONLY_FOR_TYPED_PARTS='%1$s' is only allowed for typed parts.
|
||||
UriParserSemanticException.RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE=The resource part '%1$s' must be preceded by a structural type.
|
||||
|
|
|
@ -23,17 +23,19 @@ import static org.apache.olingo.server.api.uri.queryoption.search.SearchBinaryOp
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.apache.olingo.server.api.ODataLibraryException;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SearchOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.search.SearchExpression;
|
||||
import org.apache.olingo.server.api.uri.queryoption.search.SearchUnary;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SearchParserAndTokenizerTest {
|
||||
|
||||
@Test
|
||||
public void basicParsing() throws Exception {
|
||||
SearchExpressionValidator.init("\"99\"")
|
||||
.validate(with("99"));
|
||||
SearchExpressionValidator.init("a")
|
||||
.validate(with("a"));
|
||||
SearchExpressionValidator.init("a AND b")
|
||||
|
@ -70,16 +72,10 @@ public class SearchParserAndTokenizerTest {
|
|||
.validate("{{'a' OR 'b'} AND {NOT 'c'}}");
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void sebuilder() {
|
||||
System.out.println(with("c", or("a", and("b"))).toString());
|
||||
System.out.println(with("a", and("b", and("c"))).toString());
|
||||
System.out.println(with("a").toString());
|
||||
System.out.println(with(not("a")).toString());
|
||||
System.out.println(with("a", and("b")).toString());
|
||||
System.out.println(with("a", or("b")).toString());
|
||||
System.out.println(with("a", and(not("b"))).toString());
|
||||
public void invalidSearchQuery() throws Exception {
|
||||
SearchExpressionValidator.init("99").validate(SearchParserException.class,
|
||||
SearchParserException.MessageKeys.TOKENIZER_EXCEPTION);
|
||||
}
|
||||
|
||||
private static SearchExpression with(String term) {
|
||||
|
@ -162,11 +158,13 @@ public class SearchParserAndTokenizerTest {
|
|||
return this;
|
||||
}
|
||||
|
||||
private void validate(Class<? extends Exception> exception) throws SearchTokenizerException {
|
||||
private void validate(Class<? extends ODataLibraryException> exception, ODataLibraryException.MessageKey key)
|
||||
throws SearchTokenizerException {
|
||||
try {
|
||||
new SearchTokenizer().tokenize(searchQuery);
|
||||
} catch (Exception e) {
|
||||
validate(searchQuery);
|
||||
} catch (ODataLibraryException e) {
|
||||
Assert.assertEquals(exception, e.getClass());
|
||||
Assert.assertEquals(key, e.getMessageKey());
|
||||
return;
|
||||
}
|
||||
Assert.fail("Expected exception " + exception.getClass().getSimpleName() + " was not thrown.");
|
||||
|
|
Loading…
Reference in New Issue