ExpressionVisitorImpl implements ExpressionVisitor<Object> { @Override public Filter visitBinaryExpressionOperation( BinaryExpression.Operation operation, Object left, Object right) { Optional<Filter> filterOptional = _getFilterOptional( operation, left, right, _locale); return filterOptional.orElseThrow( () -> new UnsupportedOperationException( "Unsupported method visitBinaryExpressionOperation with " + "operation " + operation)); } ExpressionVisitorImpl(
		Format format, Locale locale, EntityModel entityModel); @Override Filter visitBinaryExpressionOperation(
		BinaryExpression.Operation operation, Object left, Object right); @Override Object visitCollectionPropertyExpression(
			CollectionPropertyExpression collectionPropertyExpression); @Override Object visitComplexPropertyExpression(
		ComplexPropertyExpression complexPropertyExpression); @Override Object visitLambdaFunctionExpression(
			LambdaFunctionExpression.Type type, String variable,
			Expression expression); @Override EntityField visitLambdaVariableExpression(
			LambdaVariableExpression lambdaVariableExpression); @Override Object visitListExpressionOperation(
			ListExpression.Operation operation, Object left, List<Object> right); @Override Object visitLiteralExpression(LiteralExpression literalExpression); @Override Object visitMemberExpression(MemberExpression memberExpression); @Override Object visitMethodExpression(
		List<Object> expressions, MethodExpression.Type type); @Override Object visitPrimitivePropertyExpression(
		PrimitivePropertyExpression primitivePropertyExpression); @Override Filter visitUnaryExpressionOperation(
		UnaryExpression.Operation operation, Object operand);  }
@Test public void testVisitBinaryExpressionOperationWithAndOperation() { TermFilter leftTermFilter = new TermFilter("title", "title1"); TermFilter rightTermFilter = new TermFilter("title", "title2"); BooleanFilter booleanFilter = (BooleanFilter) _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.AND, leftTermFilter, rightTermFilter); Assert.assertTrue(booleanFilter.hasClauses()); List<BooleanClause<Filter>> booleanClauses = booleanFilter.getMustBooleanClauses(); Assert.assertEquals( booleanClauses.toString(), 2, booleanClauses.size()); BooleanClause<Filter> queryBooleanClause1 = booleanClauses.get(0); Assert.assertEquals(leftTermFilter, queryBooleanClause1.getClause()); Assert.assertEquals( BooleanClauseOccur.MUST, queryBooleanClause1.getBooleanClauseOccur()); BooleanClause<Filter> queryBooleanClause2 = booleanClauses.get(1); Assert.assertEquals(rightTermFilter, queryBooleanClause2.getClause()); Assert.assertEquals( BooleanClauseOccur.MUST, queryBooleanClause2.getBooleanClauseOccur()); }
@SuppressWarnings("unchecked") @Test public void testVisitBinaryExpressionOperationWithEqualOperation() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); EntityField entityField = entityFieldsMap.get("title"); String value = "title1"; TermFilter termFilter = (TermFilter)_expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.EQ, entityField, value); Assert.assertEquals(entityField.getName(), termFilter.getField()); Assert.assertEquals(value, termFilter.getValue()); }
@Test public void testVisitBinaryExpressionOperationWithEqualOperationAndNullValue() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); EntityField entityField = entityFieldsMap.get("title"); BooleanFilter booleanFilter = (BooleanFilter) _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.EQ, entityField, null); Assert.assertTrue(booleanFilter.hasClauses()); List<BooleanClause<Filter>> booleanClauses = booleanFilter.getMustNotBooleanClauses(); Assert.assertEquals( booleanClauses.toString(), 1, booleanClauses.size()); BooleanClause<Filter> queryBooleanClause = booleanClauses.get(0); ExistsFilter existsFilter = (ExistsFilter)queryBooleanClause.getClause(); Assert.assertEquals(entityField.getName(), existsFilter.getField()); }
@SuppressWarnings("unchecked") @Test public void testVisitBinaryExpressionOperationWithGreaterEqualOperation() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); EntityField entityField = entityFieldsMap.get("title"); String value = "title1"; RangeTermFilter rangeTermFilter = (RangeTermFilter) _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.GE, entityField, value); Assert.assertEquals(entityField.getName(), rangeTermFilter.getField()); Assert.assertEquals(value, rangeTermFilter.getLowerBound()); Assert.assertTrue(rangeTermFilter.isIncludesLower()); Assert.assertNull(rangeTermFilter.getUpperBound()); Assert.assertTrue(rangeTermFilter.isIncludesUpper()); }
@SuppressWarnings("unchecked") @Test public void testVisitBinaryExpressionOperationWithGreaterOperation() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); EntityField entityField = entityFieldsMap.get("title"); String value = "title1"; RangeTermFilter rangeTermFilter = (RangeTermFilter) _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.GT, entityField, value); Assert.assertEquals(entityField.getName(), rangeTermFilter.getField()); Assert.assertEquals(value, rangeTermFilter.getLowerBound()); Assert.assertFalse(rangeTermFilter.isIncludesLower()); Assert.assertNull(rangeTermFilter.getUpperBound()); Assert.assertTrue(rangeTermFilter.isIncludesUpper()); }
@Test public void testVisitBinaryExpressionOperationWithGreaterOperationAndNullValue() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); AbstractThrowableAssert exception = Assertions.assertThatThrownBy( () -> _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.GT, entityFieldsMap.get("title"), null) ).isInstanceOf( UnsupportedOperationException.class ); exception.hasMessage( "Unsupported method _getGTFilter with null values"); }
@Test public void testVisitBinaryExpressionOperationWithGreaterOrEqualOperationAndNullValue() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); AbstractThrowableAssert exception = Assertions.assertThatThrownBy( () -> _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.GE, entityFieldsMap.get("title"), null) ).isInstanceOf( UnsupportedOperationException.class ); exception.hasMessage( "Unsupported method _getGEFilter with null values"); }
@SuppressWarnings("unchecked") @Test public void testVisitBinaryExpressionOperationWithLowerEqualOperation() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); EntityField entityField = entityFieldsMap.get("title"); String value = "title1"; RangeTermFilter rangeTermFilter = (RangeTermFilter) _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.LE, entityField, value); Assert.assertEquals(entityField.getName(), rangeTermFilter.getField()); Assert.assertNull(rangeTermFilter.getLowerBound()); Assert.assertFalse(rangeTermFilter.isIncludesLower()); Assert.assertEquals(value, rangeTermFilter.getUpperBound()); Assert.assertTrue(rangeTermFilter.isIncludesUpper()); }
@SuppressWarnings("unchecked") @Test public void testVisitBinaryExpressionOperationWithLowerOperation() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); EntityField entityField = entityFieldsMap.get("title"); String value = "title1"; RangeTermFilter rangeTermFilter = (RangeTermFilter) _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.LT, entityField, value); Assert.assertEquals(entityField.getName(), rangeTermFilter.getField()); Assert.assertEquals(value, rangeTermFilter.getUpperBound()); Assert.assertNull(rangeTermFilter.getLowerBound()); }
@Test public void testVisitBinaryExpressionOperationWithLowerOperationAndNullValue() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); AbstractThrowableAssert exception = Assertions.assertThatThrownBy( () -> _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.LT, entityFieldsMap.get("title"), null) ).isInstanceOf( UnsupportedOperationException.class ); exception.hasMessage( "Unsupported method _getLTFilter with null values"); }
@Test public void testVisitBinaryExpressionOperationWithLowerOrEqualOperationAndNullValue() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); AbstractThrowableAssert exception = Assertions.assertThatThrownBy( () -> _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.LE, entityFieldsMap.get("title"), null) ).isInstanceOf( UnsupportedOperationException.class ); exception.hasMessage( "Unsupported method _getLEFilter with null values"); }
@Test public void testVisitBinaryExpressionOperationWithNotEqualOperation() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); EntityField entityField = entityFieldsMap.get("title"); String value = "title1"; BooleanFilter booleanFilter = (BooleanFilter) _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.NE, entityField, value); Assert.assertTrue(booleanFilter.hasClauses()); List<BooleanClause<Filter>> booleanClauses = booleanFilter.getMustNotBooleanClauses(); Assert.assertEquals( booleanClauses.toString(), 1, booleanClauses.size()); BooleanClause<Filter> queryBooleanClause = booleanClauses.get(0); Assert.assertEquals( BooleanClauseOccur.MUST_NOT, queryBooleanClause.getBooleanClauseOccur()); TermFilter termFilter = (TermFilter)queryBooleanClause.getClause(); Assert.assertEquals(entityField.getName(), termFilter.getField()); Assert.assertEquals(value, termFilter.getValue()); }
@Test public void testVisitBinaryExpressionOperationWithNotEqualOperationAndNullValue() { Map<String, EntityField> entityFieldsMap = _entityModel.getEntityFieldsMap(); EntityField entityField = entityFieldsMap.get("title"); ExistsFilter existsFilter = (ExistsFilter)_expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.NE, entityField, null); Assert.assertEquals(entityField.getName(), existsFilter.getField()); }
@Test public void testVisitBinaryExpressionOperationWithOrOperation() { TermFilter leftTermFilter = new TermFilter("title", "title1"); TermFilter rightTermFilter = new TermFilter("title", "title2"); BooleanFilter booleanFilter = (BooleanFilter) _expressionVisitorImpl.visitBinaryExpressionOperation( BinaryExpression.Operation.OR, leftTermFilter, rightTermFilter); Assert.assertTrue(booleanFilter.hasClauses()); List<BooleanClause<Filter>> booleanClauses = booleanFilter.getShouldBooleanClauses(); Assert.assertEquals( booleanClauses.toString(), 2, booleanClauses.size()); BooleanClause<Filter> queryBooleanClause1 = booleanClauses.get(0); Assert.assertEquals(leftTermFilter, queryBooleanClause1.getClause()); Assert.assertEquals( BooleanClauseOccur.SHOULD, queryBooleanClause1.getBooleanClauseOccur()); BooleanClause<Filter> queryBooleanClause2 = booleanClauses.get(1); Assert.assertEquals(rightTermFilter, queryBooleanClause2.getClause()); Assert.assertEquals( BooleanClauseOccur.SHOULD, queryBooleanClause2.getBooleanClauseOccur()); }