[OLINGO786] FIx edm annotation classes
This also includes tests for all edm classes.
This commit is contained in:
parent
67ccbf9ddb
commit
41210245d7
|
@ -35,8 +35,8 @@ public abstract class AbstractClientCsdlEdmDeserializer<T> extends JsonDeseriali
|
|||
|
||||
protected CsdlConstantExpression parseAnnotationConstExprConstruct(final JsonParser jp)
|
||||
throws IOException {
|
||||
final CsdlConstantExpression constExpr = new CsdlConstantExpression();
|
||||
constExpr.setType(CsdlConstantExpression.ConstantExpressionType.fromString(jp.getCurrentName()));
|
||||
final CsdlConstantExpression constExpr =
|
||||
new CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.fromString(jp.getCurrentName()));
|
||||
constExpr.setValue(jp.nextTextValue());
|
||||
return constExpr;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.api.edm;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
|
||||
/**
|
||||
* This class models an OData Annotation which can be applied to a target.
|
||||
|
@ -35,5 +35,5 @@ public interface EdmAnnotation extends EdmAnnotatable {
|
|||
*/
|
||||
String getQualifier();
|
||||
|
||||
EdmAnnotationExpression getExpression();
|
||||
EdmExpression getExpression();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a logical and annotation
|
||||
*/
|
||||
public interface EdmAnd extends EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
public interface EdmAnd extends EdmLogicalOrComparisonExpression {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents an annotation path
|
||||
*/
|
||||
public interface EdmAnnotationPath extends EdmDynamicAnnotationExpression {
|
||||
public interface EdmAnnotationPath extends EdmDynamicExpression {
|
||||
|
||||
/**
|
||||
* Value of the path
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.olingo.commons.api.edm.EdmAnnotatable;
|
|||
/**
|
||||
* Represents an Edm:Apply expression
|
||||
*/
|
||||
public interface EdmApply extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
||||
public interface EdmApply extends EdmDynamicExpression, EdmAnnotatable {
|
||||
|
||||
/**
|
||||
* A QualifiedName specifying the name of the client-side function to apply.
|
||||
|
@ -45,5 +45,5 @@ public interface EdmApply extends EdmDynamicAnnotationExpression, EdmAnnotatable
|
|||
* Returns the expressions applied to the parameters of the function
|
||||
* @return List of expression
|
||||
*/
|
||||
List<EdmAnnotationExpression> getParameters();
|
||||
List<EdmExpression> getParameters();
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
|
|||
* Represents an edm:Cast expression.
|
||||
* Casts the value obtained from its single child expression to the specified type
|
||||
*/
|
||||
public interface EdmCast extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
||||
public interface EdmCast extends EdmDynamicExpression, EdmAnnotatable {
|
||||
/**
|
||||
* Returns the facet attribute MaxLength
|
||||
* @return Returns the facet attribute MaxLength
|
||||
|
@ -61,5 +61,5 @@ public interface EdmCast extends EdmDynamicAnnotationExpression, EdmAnnotatable
|
|||
* Cast value of the expression
|
||||
* @return Cast value
|
||||
*/
|
||||
EdmDynamicAnnotationExpression getValue();
|
||||
EdmExpression getValue();
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ import java.util.List;
|
|||
* The value calculated by the collection expression is the collection of the values calculated
|
||||
* by each of the child expressions.
|
||||
*/
|
||||
public interface EdmCollection extends EdmDynamicAnnotationExpression {
|
||||
public interface EdmCollection extends EdmDynamicExpression {
|
||||
|
||||
/**
|
||||
* Returns a list of child expression
|
||||
* @return List of child expression
|
||||
*/
|
||||
List<EdmAnnotationExpression> getItems();
|
||||
List<EdmExpression> getItems();
|
||||
}
|
||||
|
|
|
@ -23,12 +23,13 @@ import org.apache.olingo.commons.api.data.Valuable;
|
|||
/**
|
||||
* Represents a constant expression
|
||||
*/
|
||||
public interface EdmConstantAnnotationExpression extends EdmAnnotationExpression {
|
||||
public interface EdmConstantExpression extends EdmExpression {
|
||||
|
||||
/**
|
||||
* Value of the constant expression
|
||||
* @return value of the constant expression
|
||||
*/
|
||||
//TODO: Delete data package dependency
|
||||
Valuable getValue();
|
||||
|
||||
/**
|
|
@ -21,7 +21,7 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a dynamic expression
|
||||
*/
|
||||
public interface EdmDynamicAnnotationExpression extends EdmAnnotationExpression {
|
||||
public interface EdmDynamicExpression extends EdmExpression {
|
||||
|
||||
/**
|
||||
* Returns true if the expression is a logical edm:Not expression
|
|
@ -21,6 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a edm:Eq expression
|
||||
*/
|
||||
public interface EdmEq extends EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
public interface EdmEq extends EdmLogicalOrComparisonExpression {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -22,7 +22,13 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
* Super type of all annotation expressions
|
||||
* A expression is either constant or dynamic
|
||||
*/
|
||||
public interface EdmAnnotationExpression {
|
||||
public interface EdmExpression {
|
||||
|
||||
/**
|
||||
* Will return the name of the expression e.g. Apply or Cast.
|
||||
* @return the name of the expression
|
||||
*/
|
||||
String getExpressionName();
|
||||
|
||||
/**
|
||||
* Return true if the expression is constant
|
||||
|
@ -31,10 +37,10 @@ public interface EdmAnnotationExpression {
|
|||
boolean isConstant();
|
||||
|
||||
/**
|
||||
* Casts the expression to {@link EdmConstantAnnotationExpression}
|
||||
* Casts the expression to {@link EdmConstantExpression}
|
||||
* @return Constant Expression
|
||||
*/
|
||||
EdmConstantAnnotationExpression asConstant();
|
||||
EdmConstantExpression asConstant();
|
||||
|
||||
/**
|
||||
* Return true if the expression is dynamic
|
||||
|
@ -43,8 +49,8 @@ public interface EdmAnnotationExpression {
|
|||
boolean isDynamic();
|
||||
|
||||
/**
|
||||
* Cast the expression to {@link EdmDynamicAnnotationExpression}
|
||||
* Cast the expression to {@link EdmDynamicExpression}
|
||||
* @return Dynamic Expression
|
||||
*/
|
||||
EdmDynamicAnnotationExpression asDynamic();
|
||||
EdmDynamicExpression asDynamic();
|
||||
}
|
|
@ -21,6 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a edm:Ge expression
|
||||
*/
|
||||
public interface EdmGe extends EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
public interface EdmGe extends EdmLogicalOrComparisonExpression {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a edm:Gt expression
|
||||
*/
|
||||
public interface EdmGt extends EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
public interface EdmGt extends EdmLogicalOrComparisonExpression {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.apache.olingo.commons.api.edm.EdmAnnotatable;
|
|||
/**
|
||||
* Represents a edm:If expression
|
||||
*/
|
||||
public interface EdmIf extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
||||
public interface EdmIf extends EdmDynamicExpression, EdmAnnotatable {
|
||||
|
||||
/**
|
||||
* Returns the first expression of the edm:If expression.
|
||||
|
@ -31,7 +31,7 @@ public interface EdmIf extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
|||
*
|
||||
* @return First expression of the if expression
|
||||
*/
|
||||
EdmAnnotationExpression getGuard();
|
||||
EdmExpression getGuard();
|
||||
|
||||
/**
|
||||
* Return the second expression of the edm:If expression.
|
||||
|
@ -40,7 +40,7 @@ public interface EdmIf extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
|||
*
|
||||
* @return Second Expression of the edm:If expression
|
||||
*/
|
||||
EdmAnnotationExpression getThen();
|
||||
EdmExpression getThen();
|
||||
|
||||
/**
|
||||
* Return the third expression of the edm:If expression.
|
||||
|
@ -49,5 +49,5 @@ public interface EdmIf extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
|||
*
|
||||
* @return Third Expression of the edm:If expression
|
||||
*/
|
||||
EdmAnnotationExpression getElse();
|
||||
EdmExpression getElse();
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
|
|||
* The edm:IsOf expression evaluates a child expression and returns a Boolean value indicating whether
|
||||
* the child expression returns the specified type
|
||||
*/
|
||||
public interface EdmIsOf extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
||||
public interface EdmIsOf extends EdmDynamicExpression, EdmAnnotatable {
|
||||
|
||||
/**
|
||||
* Facet MaxLength
|
||||
|
@ -62,5 +62,5 @@ public interface EdmIsOf extends EdmDynamicAnnotationExpression, EdmAnnotatable
|
|||
* Returns true if the child expression returns the specified typed
|
||||
* @return Returns true if the child expression returns the specified typed
|
||||
*/
|
||||
EdmDynamicAnnotationExpression getValue();
|
||||
EdmExpression getValue();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.apache.olingo.commons.api.edm.EdmAnnotatable;
|
|||
* The edm:LabeledElement expression assigns a name to a child expression. The value of the child expression can
|
||||
* then be reused elsewhere with an edm:LabeledElementReference (See {@link EdmLabeledElementReference}) expression.
|
||||
*/
|
||||
public interface EdmLabeledElement extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
||||
public interface EdmLabeledElement extends EdmDynamicExpression, EdmAnnotatable {
|
||||
|
||||
/**
|
||||
* Returns the assigned name
|
||||
|
@ -37,5 +37,5 @@ public interface EdmLabeledElement extends EdmDynamicAnnotationExpression, EdmAn
|
|||
*
|
||||
* @return child expression
|
||||
*/
|
||||
EdmDynamicAnnotationExpression getValue();
|
||||
EdmExpression getValue();
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
* The edm:LabeledElementReference expression returns the value of an
|
||||
* edm:LabeledElement (see {@link EdmLabeledElement}) expression.
|
||||
*/
|
||||
public interface EdmLabeledElementReference extends EdmDynamicAnnotationExpression {
|
||||
public interface EdmLabeledElementReference extends EdmDynamicExpression {
|
||||
|
||||
/**
|
||||
* Returns the value of the edm:LabeledElement expression
|
||||
|
|
|
@ -21,6 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a edm:Le expression
|
||||
*/
|
||||
public interface EdmLe extends EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
public interface EdmLe extends EdmLogicalOrComparisonExpression {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -21,17 +21,17 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a generic expression with two child exprssions
|
||||
*/
|
||||
public interface EdmTwoParamsOpDynamicAnnotationExpression extends EdmDynamicAnnotationExpression {
|
||||
public interface EdmLogicalOrComparisonExpression extends EdmDynamicExpression {
|
||||
|
||||
/**
|
||||
* Returns the first expression (left child)
|
||||
* @return Child expression
|
||||
*/
|
||||
EdmAnnotationExpression getLeftExpression();
|
||||
EdmExpression getLeftExpression();
|
||||
|
||||
/**
|
||||
* Returns the second expression (right child)
|
||||
* @return Child expression
|
||||
*/
|
||||
EdmAnnotationExpression getRightExpression();
|
||||
EdmExpression getRightExpression();
|
||||
}
|
|
@ -21,6 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a edm:Lt expression
|
||||
*/
|
||||
public interface EdmLt extends EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
public interface EdmLt extends EdmLogicalOrComparisonExpression {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
* The edm:NavigationPropertyPath expression provides a value for terms or term properties that specify the
|
||||
* built-in abstract type Edm.NavigationPropertyPath
|
||||
*/
|
||||
public interface EdmNavigationPropertyPath extends EdmDynamicAnnotationExpression {
|
||||
public interface EdmNavigationPropertyPath extends EdmDynamicExpression {
|
||||
/**
|
||||
* Returns the navigation property path itself.
|
||||
*
|
||||
|
|
|
@ -21,6 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a edm:Ne expression
|
||||
*/
|
||||
public interface EdmNe extends EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
public interface EdmNe extends EdmLogicalOrComparisonExpression {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -21,11 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a logical edm:Le expression
|
||||
*/
|
||||
public interface EdmNot extends EdmDynamicAnnotationExpression {
|
||||
|
||||
/**
|
||||
* Returns an expression which should be inverted
|
||||
* @return the expression which must be inverted
|
||||
*/
|
||||
EdmAnnotationExpression getExpression();
|
||||
public interface EdmNot extends EdmLogicalOrComparisonExpression {
|
||||
//No additional methods needed.
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ import org.apache.olingo.commons.api.edm.EdmAnnotatable;
|
|||
/**
|
||||
* The edm:Null expression returns an untyped null value.
|
||||
*/
|
||||
public interface EdmNull extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
||||
public interface EdmNull extends EdmDynamicExpression, EdmAnnotatable {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
/**
|
||||
* Represents a logical edm:And expression
|
||||
*/
|
||||
public interface EdmOr extends EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
public interface EdmOr extends EdmLogicalOrComparisonExpression {
|
||||
// No additional methods needed for now.
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
* It can be used in annotations that target entity containers, entity sets, entity types, complex types,
|
||||
* navigation properties of structured types, and properties of structured types.
|
||||
*/
|
||||
public interface EdmPath extends EdmDynamicAnnotationExpression {
|
||||
public interface EdmPath extends EdmDynamicExpression {
|
||||
|
||||
/**
|
||||
* Returns the target value of the expression
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
* The edm:PropertyPath expression provides a value for terms or term properties that specify the built-in
|
||||
* abstract type Edm.PropertyPath.
|
||||
*/
|
||||
public interface EdmPropertyPath extends EdmDynamicAnnotationExpression {
|
||||
public interface EdmPropertyPath extends EdmDynamicExpression {
|
||||
|
||||
/**
|
||||
* Returns the property path itself.
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.apache.olingo.commons.api.edm.EdmAnnotatable;
|
|||
* The edm:PropertyValue element supplies a value to a property on the type instantiated by an
|
||||
* edm:Record expression (See {@link EdmRecord}). The value is obtained by evaluating an expression.
|
||||
*/
|
||||
public interface EdmPropertyValue extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
||||
public interface EdmPropertyValue extends EdmDynamicExpression, EdmAnnotatable {
|
||||
/**
|
||||
* Property name
|
||||
* @return Property name
|
||||
|
@ -35,6 +35,6 @@ public interface EdmPropertyValue extends EdmDynamicAnnotationExpression, EdmAnn
|
|||
* Evaluated value of the expression (property value)
|
||||
* @return evaluated value of the expression
|
||||
*/
|
||||
EdmAnnotationExpression getValue();
|
||||
EdmExpression getValue();
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
|||
* The edm:Record expression enables a new entity type or complex type instance to be constructed.
|
||||
* A record expression contains zero or more edm:PropertyValue (See {@link EdmPropertyValue} )elements.
|
||||
*/
|
||||
public interface EdmRecord extends EdmDynamicAnnotationExpression, EdmAnnotatable {
|
||||
public interface EdmRecord extends EdmDynamicExpression, EdmAnnotatable {
|
||||
|
||||
/**
|
||||
* List of edm:PropertyValues (See {@link EdmPropertyValue}
|
||||
|
|
|
@ -22,11 +22,11 @@ package org.apache.olingo.commons.api.edm.annotation;
|
|||
* The edm:UrlRef expression enables a value to be obtained by sending a GET request to the value of
|
||||
* the UrlRef expression.
|
||||
*/
|
||||
public interface EdmUrlRef extends EdmDynamicAnnotationExpression {
|
||||
public interface EdmUrlRef extends EdmDynamicExpression {
|
||||
|
||||
/**
|
||||
* Returns a expression of type Edm.String
|
||||
* @return expression of type Edm.String
|
||||
*/
|
||||
EdmAnnotationExpression getValue();
|
||||
EdmExpression getValue();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class CsdlCast extends CsdlDynamicExpression implements CsdlAnnotatable{
|
|||
private Integer precision;
|
||||
private Integer scale;
|
||||
private SRID srid;
|
||||
private CsdlDynamicExpression value;
|
||||
private CsdlExpression value;
|
||||
private List<CsdlAnnotation> annotations = new ArrayList<CsdlAnnotation>();
|
||||
|
||||
@Override
|
||||
|
@ -114,11 +114,11 @@ public class CsdlCast extends CsdlDynamicExpression implements CsdlAnnotatable{
|
|||
* Cast value of the expression
|
||||
* @return Cast value
|
||||
*/
|
||||
public CsdlDynamicExpression getValue() {
|
||||
public CsdlExpression getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(final CsdlDynamicExpression value) {
|
||||
public void setValue(final CsdlExpression value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class CsdlConstantExpression extends CsdlExpression {
|
|||
|
||||
private static final long serialVersionUID = 5618680702707972904L;
|
||||
|
||||
private ConstantExpressionType type;
|
||||
private final ConstantExpressionType type;
|
||||
private String value;
|
||||
|
||||
/**
|
||||
|
@ -96,7 +96,9 @@ public class CsdlConstantExpression extends CsdlExpression {
|
|||
}
|
||||
}
|
||||
|
||||
public CsdlConstantExpression() {}
|
||||
public CsdlConstantExpression(ConstantExpressionType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public CsdlConstantExpression(ConstantExpressionType type, String value) {
|
||||
this.type = type;
|
||||
|
@ -111,16 +113,6 @@ public class CsdlConstantExpression extends CsdlExpression {
|
|||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the constant expression
|
||||
* @param type type of the constant expression
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public CsdlConstantExpression setType(final ConstantExpressionType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of the constant expression
|
||||
* @return value of the constant expression as String
|
||||
|
|
|
@ -18,53 +18,20 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotatable;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmTerm;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotatable;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyValue;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmAndImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmAnnotationPathImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmApplyImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmCastImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmCollectionImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmConstantAnnotationExpressionImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmEqImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmGeImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmGtImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmIfImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmIsOfImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmLabeledElementImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmLabeledElementReferenceImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmLeImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmLtImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmNavigationPropertyPathImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmNeImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmNotImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmNullImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmOrImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmPathImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmPropertyPathImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmPropertyValueImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmRecordImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.EdmUrlRefImpl;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
|
||||
public class EdmAnnotationImpl extends AbstractEdmAnnotatable implements EdmAnnotation {
|
||||
|
||||
private final CsdlAnnotation annotation;
|
||||
private EdmTerm term;
|
||||
private EdmAnnotationExpression expression;
|
||||
private EdmExpression expression;
|
||||
|
||||
public EdmAnnotationImpl(final Edm edm, final CsdlAnnotation annotation) {
|
||||
super(edm, annotation);
|
||||
|
@ -74,6 +41,9 @@ public class EdmAnnotationImpl extends AbstractEdmAnnotatable implements EdmAnno
|
|||
@Override
|
||||
public EdmTerm getTerm() {
|
||||
if (term == null) {
|
||||
if (annotation.getTerm() == null) {
|
||||
throw new EdmException("Term must not be null for an annotation.");
|
||||
}
|
||||
term = edm.getTerm(new FullQualifiedName(annotation.getTerm()));
|
||||
}
|
||||
return term;
|
||||
|
@ -84,142 +54,14 @@ public class EdmAnnotationImpl extends AbstractEdmAnnotatable implements EdmAnno
|
|||
return annotation.getQualifier();
|
||||
}
|
||||
|
||||
private EdmAnnotationExpression getExpression(final CsdlExpression exp) {
|
||||
EdmAnnotationExpression _expression = null;
|
||||
|
||||
if (exp.isConstant()) {
|
||||
_expression = new EdmConstantAnnotationExpressionImpl(exp.asConstant());
|
||||
} else if (annotation.getExpression().isDynamic()) {
|
||||
_expression = getDynamicExpression(exp.asDynamic());
|
||||
}
|
||||
|
||||
return _expression;
|
||||
}
|
||||
|
||||
private EdmDynamicAnnotationExpression getDynamicExpression(final CsdlDynamicExpression exp) {
|
||||
EdmDynamicAnnotationExpression _expression = null;
|
||||
|
||||
if (exp.isLogicalOrComparison()) {
|
||||
switch (exp.asLogicalOrComparison().getType()) {
|
||||
case Not:
|
||||
_expression = new EdmNotImpl(getExpression(exp.asLogicalOrComparison().getLeft()));
|
||||
break;
|
||||
case And:
|
||||
_expression = new EdmAndImpl(
|
||||
getExpression(exp.asLogicalOrComparison().getLeft()),
|
||||
getExpression(exp.asLogicalOrComparison().getRight()));
|
||||
break;
|
||||
|
||||
case Or:
|
||||
_expression = new EdmOrImpl(
|
||||
getExpression(exp.asLogicalOrComparison().getLeft()),
|
||||
getExpression(exp.asLogicalOrComparison().getRight()));
|
||||
break;
|
||||
|
||||
case Eq:
|
||||
_expression = new EdmEqImpl(
|
||||
getExpression(exp.asLogicalOrComparison().getLeft()),
|
||||
getExpression(exp.asLogicalOrComparison().getRight()));
|
||||
break;
|
||||
|
||||
case Ne:
|
||||
_expression = new EdmNeImpl(
|
||||
getExpression(exp.asLogicalOrComparison().getLeft()),
|
||||
getExpression(exp.asLogicalOrComparison().getRight()));
|
||||
break;
|
||||
|
||||
case Ge:
|
||||
_expression = new EdmGeImpl(
|
||||
getExpression(exp.asLogicalOrComparison().getLeft()),
|
||||
getExpression(exp.asLogicalOrComparison().getRight()));
|
||||
break;
|
||||
|
||||
case Gt:
|
||||
_expression = new EdmGtImpl(
|
||||
getExpression(exp.asLogicalOrComparison().getLeft()),
|
||||
getExpression(exp.asLogicalOrComparison().getRight()));
|
||||
break;
|
||||
|
||||
case Le:
|
||||
_expression = new EdmLeImpl(
|
||||
getExpression(exp.asLogicalOrComparison().getLeft()),
|
||||
getExpression(exp.asLogicalOrComparison().getRight()));
|
||||
break;
|
||||
|
||||
case Lt:
|
||||
_expression = new EdmLtImpl(
|
||||
getExpression(exp.asLogicalOrComparison().getLeft()),
|
||||
getExpression(exp.asLogicalOrComparison().getRight()));
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
} else if (exp.isAnnotationPath()) {
|
||||
_expression = new EdmAnnotationPathImpl(exp.asAnnotationPath().getValue());
|
||||
} else if (exp.isApply()) {
|
||||
final List<EdmAnnotationExpression> parameters =
|
||||
new ArrayList<EdmAnnotationExpression>(exp.asApply().getParameters().size());
|
||||
for (CsdlExpression param : exp.asApply().getParameters()) {
|
||||
parameters.add(getExpression(param));
|
||||
}
|
||||
_expression = new EdmApplyImpl(exp.asApply().getFunction(), parameters);
|
||||
} else if (exp.isCast()) {
|
||||
_expression = new EdmCastImpl(edm, exp.asCast(), getDynamicExpression(exp.asCast().getValue()));
|
||||
} else if (exp.isCollection()) {
|
||||
final List<EdmAnnotationExpression> items =
|
||||
new ArrayList<EdmAnnotationExpression>(exp.asCollection().getItems().size());
|
||||
for (CsdlExpression param : exp.asCollection().getItems()) {
|
||||
items.add(getExpression(param));
|
||||
}
|
||||
_expression = new EdmCollectionImpl(items);
|
||||
} else if (exp.isIf()) {
|
||||
_expression = new EdmIfImpl(
|
||||
getExpression(exp.asIf().getGuard()),
|
||||
getExpression(exp.asIf().getThen()),
|
||||
getExpression(exp.asIf().getElse()));
|
||||
} else if (exp.isIsOf()) {
|
||||
_expression = new EdmIsOfImpl(edm, exp.asIsOf(), getDynamicExpression(exp.asIsOf().getValue().asDynamic()));
|
||||
} else if (exp.isLabeledElement()) {
|
||||
_expression = new EdmLabeledElementImpl(
|
||||
exp.asLabeledElement().getName(), getDynamicExpression(exp.asLabeledElement().getValue().asDynamic()));
|
||||
} else if (exp.isLabeledElementReference()) {
|
||||
_expression = new EdmLabeledElementReferenceImpl(exp.asLabeledElementReference().getValue());
|
||||
} else if (exp.isNull()) {
|
||||
_expression = new EdmNullImpl();
|
||||
} else if (exp.isNavigationPropertyPath()) {
|
||||
_expression = new EdmNavigationPropertyPathImpl(exp.asNavigationPropertyPath().getValue());
|
||||
} else if (exp.isPath()) {
|
||||
_expression = new EdmPathImpl(exp.asPath().getValue());
|
||||
} else if (exp.isPropertyPath()) {
|
||||
_expression = new EdmPropertyPathImpl(exp.asPropertyPath().getValue());
|
||||
} else if (exp.isPropertyValue()) {
|
||||
_expression = new EdmPropertyValueImpl(
|
||||
exp.asPropertyValue().getProperty(), getExpression(exp.asPropertyValue().getValue()));
|
||||
} else if (exp.isRecord()) {
|
||||
final List<EdmPropertyValue> propertyValues =
|
||||
new ArrayList<EdmPropertyValue>(exp.asRecord().getPropertyValues().size());
|
||||
for (CsdlPropertyValue propertyValue : exp.asRecord().getPropertyValues()) {
|
||||
propertyValues.add(new EdmPropertyValueImpl(
|
||||
propertyValue.getProperty(), getExpression(propertyValue.getValue())));
|
||||
}
|
||||
_expression = new EdmRecordImpl(edm, exp.asRecord().getType(), propertyValues);
|
||||
} else if (exp.isUrlRef()) {
|
||||
_expression = new EdmUrlRefImpl(getExpression(exp.asUrlRef().getValue()));
|
||||
}
|
||||
|
||||
if (_expression instanceof EdmAnnotatable && exp instanceof CsdlAnnotatable) {
|
||||
for (CsdlAnnotation _annotation : ((CsdlAnnotatable) exp).getAnnotations()) {
|
||||
((EdmAnnotatable) _expression).getAnnotations().add(new EdmAnnotationImpl(edm, _annotation));
|
||||
}
|
||||
}
|
||||
|
||||
return _expression;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getExpression() {
|
||||
public EdmExpression getExpression() {
|
||||
if (expression == null) {
|
||||
expression = getExpression(annotation.getExpression());
|
||||
if (annotation.getExpression() != null) {
|
||||
expression = AbstractEdmExpression.getExpression(edm, annotation.getExpression());
|
||||
}
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,36 +18,39 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotatable;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.EdmTerm;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotatable;
|
||||
import org.apache.olingo.commons.core.edm.AbstractEdmAnnotatable;
|
||||
|
||||
public abstract class AbstractEdmAnnotatableDynamicAnnotationExpression
|
||||
extends AbstractEdmDynamicAnnotationExpression implements EdmAnnotatable {
|
||||
public abstract class AbstractEdmAnnotatableDynamicExpression extends AbstractEdmDynamicExpression implements
|
||||
EdmAnnotatable {
|
||||
|
||||
private final List<EdmAnnotation> annotations = new ArrayList<EdmAnnotation>();
|
||||
private final AnnotationHelper helper;
|
||||
|
||||
public AbstractEdmAnnotatableDynamicExpression(Edm edm, String name, CsdlAnnotatable annotatable) {
|
||||
super(edm, name);
|
||||
helper = new AnnotationHelper(edm, annotatable);
|
||||
}
|
||||
|
||||
//TODO: Can we derive this method from AbstractEdmAnnotatable?
|
||||
@Override
|
||||
public EdmAnnotation getAnnotation(final EdmTerm term, String qualifier) {
|
||||
EdmAnnotation result = null;
|
||||
for (EdmAnnotation annotation : getAnnotations()) {
|
||||
if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) {
|
||||
if (qualifier == annotation.getQualifier()
|
||||
|| (qualifier != null && qualifier.equals(annotation.getQualifier()))) {
|
||||
result = annotation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return helper.getAnnotation(term, qualifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmAnnotation> getAnnotations() {
|
||||
return annotations;
|
||||
return helper.getAnnotations();
|
||||
}
|
||||
|
||||
private class AnnotationHelper extends AbstractEdmAnnotatable {
|
||||
|
||||
public AnnotationHelper(Edm edm, CsdlAnnotatable annotatable) {
|
||||
super(edm, annotatable);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
|
||||
public abstract class AbstractEdmAnnotationExpression implements EdmAnnotationExpression {
|
||||
|
||||
@Override
|
||||
public boolean isConstant() {
|
||||
return this instanceof EdmConstantAnnotationExpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmConstantAnnotationExpression asConstant() {
|
||||
return isConstant() ? (EdmConstantAnnotationExpression) this : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDynamic() {
|
||||
return this instanceof EdmDynamicAnnotationExpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmDynamicAnnotationExpression asDynamic() {
|
||||
return isDynamic() ? (EdmDynamicAnnotationExpression) this : null;
|
||||
}
|
||||
}
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,12 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnd;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationPath;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmApply;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmCast;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmCollection;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmEq;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmGe;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmGt;
|
||||
|
@ -44,8 +45,11 @@ import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue;
|
|||
import org.apache.olingo.commons.api.edm.annotation.EdmRecord;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmUrlRef;
|
||||
|
||||
public abstract class AbstractEdmDynamicAnnotationExpression
|
||||
extends AbstractEdmAnnotationExpression implements EdmDynamicAnnotationExpression {
|
||||
public abstract class AbstractEdmDynamicExpression extends AbstractEdmExpression implements EdmDynamicExpression {
|
||||
|
||||
public AbstractEdmDynamicExpression(Edm edm, String name) {
|
||||
super(edm, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNot() {
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
/**
|
||||
* Groups dynamic expressions that may be provided using element notation or attribute notation.
|
||||
*/
|
||||
public abstract class AbstractEdmElementOrAttributeNotation extends AbstractEdmDynamicAnnotationExpression {
|
||||
|
||||
private final String value;
|
||||
|
||||
public AbstractEdmElementOrAttributeNotation(final String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public abstract class AbstractEdmExpression implements EdmExpression {
|
||||
|
||||
private final String name;
|
||||
protected final Edm edm;
|
||||
|
||||
public AbstractEdmExpression(Edm edm, String name) {
|
||||
this.edm = edm;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpressionName() {
|
||||
return name;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean isConstant() {
|
||||
return this instanceof EdmConstantExpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmConstantExpression asConstant() {
|
||||
return isConstant() ? (EdmConstantExpression) this : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDynamic() {
|
||||
return this instanceof EdmDynamicExpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmDynamicExpression asDynamic() {
|
||||
return isDynamic() ? (EdmDynamicExpression) this : null;
|
||||
}
|
||||
|
||||
public static EdmExpression getExpression(Edm edm, final CsdlExpression exp) {
|
||||
EdmExpression _expression = null;
|
||||
|
||||
if (exp.isConstant()) {
|
||||
_expression = new EdmConstantExpressionImpl(edm, exp.asConstant());
|
||||
} else if (exp.isDynamic()) {
|
||||
_expression = getDynamicExpression(edm, exp.asDynamic());
|
||||
}
|
||||
|
||||
return _expression;
|
||||
}
|
||||
|
||||
private static EdmDynamicExpression getDynamicExpression(Edm edm, final CsdlDynamicExpression exp) {
|
||||
|
||||
EdmDynamicExpression _expression = null;
|
||||
|
||||
if (exp.isLogicalOrComparison()) {
|
||||
CsdlLogicalOrComparisonExpression expLocal = exp.asLogicalOrComparison();
|
||||
switch (exp.asLogicalOrComparison().getType()) {
|
||||
case Not:
|
||||
_expression = new EdmNotImpl(edm, expLocal);
|
||||
break;
|
||||
case And:
|
||||
_expression = new EdmAndImpl(edm, expLocal);
|
||||
break;
|
||||
|
||||
case Or:
|
||||
_expression = new EdmOrImpl(edm, expLocal);
|
||||
break;
|
||||
|
||||
case Eq:
|
||||
_expression = new EdmEqImpl(edm, expLocal);
|
||||
break;
|
||||
|
||||
case Ne:
|
||||
_expression = new EdmNeImpl(edm, expLocal);
|
||||
break;
|
||||
|
||||
case Ge:
|
||||
_expression = new EdmGeImpl(edm, expLocal);
|
||||
break;
|
||||
|
||||
case Gt:
|
||||
_expression = new EdmGtImpl(edm, expLocal);
|
||||
break;
|
||||
|
||||
case Le:
|
||||
_expression = new EdmLeImpl(edm, expLocal);
|
||||
break;
|
||||
|
||||
case Lt:
|
||||
_expression = new EdmLtImpl(edm, expLocal);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
} else if (exp.isAnnotationPath()) {
|
||||
_expression = new EdmAnnotationPathImpl(edm, exp.asAnnotationPath());
|
||||
} else if (exp.isApply()) {
|
||||
_expression = new EdmApplyImpl(edm, exp.asApply());
|
||||
} else if (exp.isCast()) {
|
||||
_expression = new EdmCastImpl(edm, exp.asCast());
|
||||
} else if (exp.isCollection()) {
|
||||
_expression = new EdmCollectionImpl(edm, exp.asCollection());
|
||||
} else if (exp.isIf()) {
|
||||
_expression = new EdmIfImpl(edm, exp.asIf());
|
||||
} else if (exp.isIsOf()) {
|
||||
_expression = new EdmIsOfImpl(edm, exp.asIsOf());
|
||||
} else if (exp.isLabeledElement()) {
|
||||
_expression = new EdmLabeledElementImpl(edm, exp.asLabeledElement());
|
||||
} else if (exp.isLabeledElementReference()) {
|
||||
_expression = new EdmLabeledElementReferenceImpl(edm, exp.asLabeledElementReference());
|
||||
} else if (exp.isNull()) {
|
||||
_expression = new EdmNullImpl(edm, exp.asNull());
|
||||
} else if (exp.isNavigationPropertyPath()) {
|
||||
_expression = new EdmNavigationPropertyPathImpl(edm, exp.asNavigationPropertyPath());
|
||||
} else if (exp.isPath()) {
|
||||
_expression = new EdmPathImpl(edm, exp.asPath());
|
||||
} else if (exp.isPropertyPath()) {
|
||||
_expression = new EdmPropertyPathImpl(edm, exp.asPropertyPath());
|
||||
} else if (exp.isPropertyValue()) {
|
||||
_expression = new EdmPropertyValueImpl(edm, exp.asPropertyValue());
|
||||
} else if (exp.isRecord()) {
|
||||
_expression = new EdmRecordImpl(edm, exp.asRecord());
|
||||
} else if (exp.isUrlRef()) {
|
||||
_expression = new EdmUrlRefImpl(edm, exp.asUrlRef());
|
||||
}
|
||||
|
||||
return _expression;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmLogicalOrComparisonExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
//CHECKSTYLE:OFF
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression.LogicalOrComparisonExpressionType;
|
||||
|
||||
//CHECKSTYLE:ON
|
||||
|
||||
public abstract class AbstractEdmLogicalOrComparisonExpression
|
||||
extends AbstractEdmAnnotatableDynamicExpression implements EdmLogicalOrComparisonExpression {
|
||||
|
||||
private EdmExpression left;
|
||||
private EdmExpression right;
|
||||
private CsdlLogicalOrComparisonExpression csdlExp;
|
||||
|
||||
public AbstractEdmLogicalOrComparisonExpression(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp.getType().toString(), csdlExp);
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmExpression getLeftExpression() {
|
||||
if (left == null) {
|
||||
if (csdlExp.getLeft() == null) {
|
||||
throw new EdmException("Comparison Or Logical expression MUST have a left and right expression.");
|
||||
}
|
||||
left = AbstractEdmExpression.getExpression(edm, csdlExp.getLeft());
|
||||
if (csdlExp.getType() == LogicalOrComparisonExpressionType.Not) {
|
||||
right = left;
|
||||
}
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmExpression getRightExpression() {
|
||||
if (right == null) {
|
||||
if (csdlExp.getRight() == null) {
|
||||
throw new EdmException("Comparison Or Logical expression MUST have a left and right expression.");
|
||||
}
|
||||
right = AbstractEdmExpression.getExpression(edm, csdlExp.getRight());
|
||||
if (csdlExp.getType() == LogicalOrComparisonExpressionType.Not) {
|
||||
left = right;
|
||||
}
|
||||
}
|
||||
return right;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmTwoParamsOpDynamicAnnotationExpression;
|
||||
|
||||
public abstract class AbstractEdmTwoParamsOpDynamicAnnotationExpression
|
||||
extends AbstractEdmDynamicAnnotationExpression implements EdmTwoParamsOpDynamicAnnotationExpression {
|
||||
|
||||
private final EdmAnnotationExpression left;
|
||||
|
||||
private final EdmAnnotationExpression right;
|
||||
|
||||
public AbstractEdmTwoParamsOpDynamicAnnotationExpression(
|
||||
final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getLeftExpression() {
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getRightExpression() {
|
||||
return right;
|
||||
}
|
||||
}
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,14 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnd;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmAndImpl extends AbstractEdmTwoParamsOpDynamicAnnotationExpression implements EdmAnd {
|
||||
public class EdmAndImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmAnd {
|
||||
|
||||
public EdmAndImpl(final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
super(left, right);
|
||||
public EdmAndImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,12 +18,21 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationPath;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlAnnotationPath;
|
||||
|
||||
public class EdmAnnotationPathImpl extends AbstractEdmElementOrAttributeNotation implements EdmAnnotationPath {
|
||||
public class EdmAnnotationPathImpl extends AbstractEdmDynamicExpression implements EdmAnnotationPath {
|
||||
|
||||
public EdmAnnotationPathImpl(final String value) {
|
||||
super(value);
|
||||
private final CsdlAnnotationPath csdlExp;
|
||||
|
||||
public EdmAnnotationPathImpl(Edm edm, CsdlAnnotationPath csdlExp) {
|
||||
super(edm, "AnnotationPath");
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return csdlExp.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,30 +18,51 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmApply;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlApply;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression;
|
||||
|
||||
public class EdmApplyImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmApply {
|
||||
public class EdmApplyImpl extends AbstractEdmAnnotatableDynamicExpression implements EdmApply {
|
||||
|
||||
private final String function;
|
||||
private CsdlApply csdlExp;
|
||||
|
||||
private final List<EdmAnnotationExpression> parameters;
|
||||
private String function;
|
||||
private List<EdmExpression> parameters;
|
||||
|
||||
public EdmApplyImpl(final String function, final List<EdmAnnotationExpression> parameters) {
|
||||
this.function = function;
|
||||
this.parameters = parameters;
|
||||
public EdmApplyImpl(Edm edm, CsdlApply csdlExp) {
|
||||
super(edm, "Apply", csdlExp);
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunction() {
|
||||
if (function == null) {
|
||||
if (csdlExp.getFunction() == null) {
|
||||
throw new EdmException("An Apply expression must specify a function.");
|
||||
}
|
||||
function = csdlExp.getFunction();
|
||||
}
|
||||
return function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmAnnotationExpression> getParameters() {
|
||||
public List<EdmExpression> getParameters() {
|
||||
if (parameters == null) {
|
||||
List<EdmExpression> localParameters = new ArrayList<EdmExpression>();
|
||||
if (csdlExp.getParameters() != null) {
|
||||
for (CsdlExpression param : csdlExp.getParameters()) {
|
||||
localParameters.add(getExpression(edm, param));
|
||||
}
|
||||
}
|
||||
parameters = Collections.unmodifiableList(localParameters);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,27 +19,23 @@
|
|||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmCast;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.geo.SRID;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlCast;
|
||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
|
||||
public class EdmCastImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmCast {
|
||||
|
||||
private final Edm edm;
|
||||
public class EdmCastImpl extends AbstractEdmAnnotatableDynamicExpression implements EdmCast {
|
||||
|
||||
private final CsdlCast cast;
|
||||
|
||||
private final EdmDynamicAnnotationExpression value;
|
||||
|
||||
private EdmExpression value;
|
||||
private EdmType type;
|
||||
|
||||
public EdmCastImpl(final Edm edm, final CsdlCast cast, final EdmDynamicAnnotationExpression value) {
|
||||
this.edm = edm;
|
||||
this.cast = cast;
|
||||
this.value = value;
|
||||
public EdmCastImpl(final Edm edm, final CsdlCast csdlExp) {
|
||||
super(edm, "Cast", csdlExp);
|
||||
this.cast = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +61,9 @@ public class EdmCastImpl extends AbstractEdmAnnotatableDynamicAnnotationExpressi
|
|||
@Override
|
||||
public EdmType getType() {
|
||||
if (type == null) {
|
||||
if (cast.getType() == null) {
|
||||
throw new EdmException("Must specify a type for a Cast expression.");
|
||||
}
|
||||
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(cast.getType()).build();
|
||||
type = typeInfo.getType();
|
||||
}
|
||||
|
@ -72,7 +71,13 @@ public class EdmCastImpl extends AbstractEdmAnnotatableDynamicAnnotationExpressi
|
|||
}
|
||||
|
||||
@Override
|
||||
public EdmDynamicAnnotationExpression getValue() {
|
||||
public EdmExpression getValue() {
|
||||
if (value == null) {
|
||||
if (cast.getValue() == null) {
|
||||
throw new EdmException("Cast expressions require an expression value.");
|
||||
}
|
||||
value = getExpression(edm, cast.getValue());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,22 +18,37 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmCollection;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlCollection;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression;
|
||||
|
||||
public class EdmCollectionImpl extends AbstractEdmDynamicAnnotationExpression implements EdmCollection {
|
||||
public class EdmCollectionImpl extends AbstractEdmDynamicExpression implements EdmCollection {
|
||||
|
||||
private final List<EdmAnnotationExpression> items;
|
||||
private List<EdmExpression> items;
|
||||
private CsdlCollection csdlCollection;
|
||||
|
||||
public EdmCollectionImpl(final List<EdmAnnotationExpression> items) {
|
||||
this.items = items;
|
||||
public EdmCollectionImpl(Edm edm, CsdlCollection csdlExp) {
|
||||
super(edm, "Collection");
|
||||
this.csdlCollection = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmAnnotationExpression> getItems() {
|
||||
public List<EdmExpression> getItems() {
|
||||
if (items == null) {
|
||||
List<EdmExpression> localItems = new ArrayList<EdmExpression>();
|
||||
if (csdlCollection.getItems() != null) {
|
||||
for (CsdlExpression item : csdlCollection.getItems()) {
|
||||
localItems.add(getExpression(edm, item));
|
||||
}
|
||||
}
|
||||
items = Collections.unmodifiableList(localItems);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,27 +26,66 @@ import org.apache.olingo.commons.api.Constants;
|
|||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.Valuable;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
|
||||
public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotationExpression {
|
||||
public class EdmConstantExpressionImpl extends AbstractEdmExpression implements EdmConstantExpression {
|
||||
|
||||
private final Valuable value;
|
||||
private final EdmPrimitiveType type;
|
||||
private Valuable value;
|
||||
private EdmPrimitiveType type;
|
||||
private final CsdlConstantExpression constExprConstruct;
|
||||
|
||||
public EdmConstantAnnotationExpressionImpl(final CsdlConstantExpression constExprConstruct) {
|
||||
public EdmConstantExpressionImpl(Edm edm, final CsdlConstantExpression constExprConstruct) {
|
||||
super(edm, constExprConstruct.getType().toString());
|
||||
this.constExprConstruct = constExprConstruct;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Valuable getValue() {
|
||||
if(value == null){
|
||||
build();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString() {
|
||||
return constExprConstruct.getValue();
|
||||
|
||||
// if (value == null) {
|
||||
// build();
|
||||
// }
|
||||
// if (value == null) {
|
||||
// return "";
|
||||
// } else if (value.isEnum()) {
|
||||
// return value.getValue().toString();
|
||||
// } else if (value.isGeospatial()) {
|
||||
// return value.toString();
|
||||
// } else {
|
||||
// // TODO: check after copied from ClientPrimitiveValueImpl
|
||||
// try {
|
||||
// return type.valueToString(value.getValue(), null, null,
|
||||
// Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
// } catch (EdmPrimitiveTypeException e) {
|
||||
// throw new IllegalArgumentException(e);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private void build() {
|
||||
if (constExprConstruct.getType() == CsdlConstantExpression.ConstantExpressionType.EnumMember) {
|
||||
// TODO: Delete ProeprtyValue here
|
||||
final List<Property> enumValues = new ArrayList<Property>();
|
||||
String enumTypeName = null;
|
||||
for (String split : StringUtils.split(constExprConstruct.getValue(), ' ')) {
|
||||
final String[] enumSplit = StringUtils.split(split, '/');
|
||||
enumTypeName = enumSplit[0];
|
||||
enumValues.add(new Property(enumSplit[0], enumSplit[1]));
|
||||
enumValues.add(new Property(enumSplit[0], null, ValueType.ENUM, enumSplit[1]));
|
||||
}
|
||||
if (enumValues.size() == 1) {
|
||||
value = enumValues.get(0);
|
||||
|
@ -106,48 +145,4 @@ public class EdmConstantAnnotationExpressionImpl implements EdmConstantAnnotatio
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConstant() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmConstantAnnotationExpression asConstant() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDynamic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmDynamicAnnotationExpression asDynamic() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Valuable getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString() {
|
||||
if (value == null) {
|
||||
return "";
|
||||
} else if (value.isEnum()) {
|
||||
return value.toString();
|
||||
} else if (value.isGeospatial()) {
|
||||
return value.toString();
|
||||
} else {
|
||||
// TODO: check after copied from ClientPrimitiveValueImpl
|
||||
try {
|
||||
return type.valueToString(value.getValue(), null, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmEq;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmEqImpl extends AbstractEdmTwoParamsOpDynamicAnnotationExpression implements EdmEq {
|
||||
public class EdmEqImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmEq {
|
||||
|
||||
public EdmEqImpl(final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
super(left, right);
|
||||
public EdmEqImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmGe;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmGeImpl extends AbstractEdmTwoParamsOpDynamicAnnotationExpression implements EdmGe {
|
||||
public class EdmGeImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmGe {
|
||||
|
||||
public EdmGeImpl(final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
super(left, right);
|
||||
public EdmGeImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmGt;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmGtImpl extends AbstractEdmTwoParamsOpDynamicAnnotationExpression implements EdmGt {
|
||||
public class EdmGtImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmGt {
|
||||
|
||||
public EdmGtImpl(final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
super(left, right);
|
||||
public EdmGtImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,37 +18,52 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmIf;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlIf;
|
||||
|
||||
public class EdmIfImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmIf {
|
||||
public class EdmIfImpl extends AbstractEdmAnnotatableDynamicExpression implements EdmIf {
|
||||
|
||||
private final EdmAnnotationExpression guard;
|
||||
private EdmExpression guard;
|
||||
private EdmExpression _then;
|
||||
private EdmExpression _else;
|
||||
private CsdlIf csdlExp;
|
||||
|
||||
private final EdmAnnotationExpression _then;
|
||||
|
||||
private final EdmAnnotationExpression _else;
|
||||
|
||||
public EdmIfImpl(final EdmAnnotationExpression guard,
|
||||
final EdmAnnotationExpression _then, final EdmAnnotationExpression _else) {
|
||||
|
||||
this.guard = guard;
|
||||
this._then = _then;
|
||||
this._else = _else;
|
||||
public EdmIfImpl(Edm edm, CsdlIf csdlExp) {
|
||||
super(edm, "If", csdlExp);
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getGuard() {
|
||||
public EdmExpression getGuard() {
|
||||
if (guard == null) {
|
||||
if (csdlExp.getGuard() == null) {
|
||||
throw new EdmException("Guard clause of an if expression must not be null");
|
||||
}
|
||||
guard = getExpression(edm, csdlExp.getGuard());
|
||||
}
|
||||
return guard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getThen() {
|
||||
public EdmExpression getThen() {
|
||||
if (_then == null) {
|
||||
if (csdlExp.getThen() == null) {
|
||||
throw new EdmException("Then clause of an if expression must not be null");
|
||||
}
|
||||
_then = getExpression(edm, csdlExp.getThen());
|
||||
}
|
||||
return _then;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getElse() {
|
||||
public EdmExpression getElse() {
|
||||
// The else clause might be null in certain conditions so we can`t evaluate this here.
|
||||
if (_else == null && csdlExp.getElse() != null) {
|
||||
_else = getExpression(edm, csdlExp.getElse());
|
||||
}
|
||||
return _else;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,27 +19,25 @@
|
|||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmIsOf;
|
||||
import org.apache.olingo.commons.api.edm.geo.SRID;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlIsOf;
|
||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
|
||||
public class EdmIsOfImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmIsOf {
|
||||
public class EdmIsOfImpl extends AbstractEdmAnnotatableDynamicExpression implements EdmIsOf {
|
||||
|
||||
private final Edm edm;
|
||||
|
||||
private final CsdlIsOf isOf;
|
||||
|
||||
private final EdmDynamicAnnotationExpression value;
|
||||
|
||||
private EdmExpression value;
|
||||
private EdmType type;
|
||||
|
||||
public EdmIsOfImpl(final Edm edm, final CsdlIsOf isOf, final EdmDynamicAnnotationExpression value) {
|
||||
public EdmIsOfImpl(final Edm edm, final CsdlIsOf isOf) {
|
||||
super(edm, "IsOf", isOf);
|
||||
this.edm = edm;
|
||||
this.isOf = isOf;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +63,9 @@ public class EdmIsOfImpl extends AbstractEdmAnnotatableDynamicAnnotationExpressi
|
|||
@Override
|
||||
public EdmType getType() {
|
||||
if (type == null) {
|
||||
if(isOf.getType() == null){
|
||||
throw new EdmException("Must specify a type for an IsOf expression.");
|
||||
}
|
||||
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(isOf.getType()).build();
|
||||
type = typeInfo.getType();
|
||||
}
|
||||
|
@ -72,7 +73,13 @@ public class EdmIsOfImpl extends AbstractEdmAnnotatableDynamicAnnotationExpressi
|
|||
}
|
||||
|
||||
@Override
|
||||
public EdmDynamicAnnotationExpression getValue() {
|
||||
public EdmExpression getValue() {
|
||||
if(value == null){
|
||||
if(isOf.getValue() == null){
|
||||
throw new EdmException("IsOf expressions require an expression value.");
|
||||
}
|
||||
value = getExpression(edm, isOf.getValue());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,28 +18,39 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmLabeledElement;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLabeledElement;
|
||||
|
||||
public class EdmLabeledElementImpl
|
||||
extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmLabeledElement {
|
||||
extends AbstractEdmAnnotatableDynamicExpression implements EdmLabeledElement {
|
||||
|
||||
private final String name;
|
||||
private EdmExpression value;
|
||||
private CsdlLabeledElement csdlLableledElement;
|
||||
|
||||
private final EdmDynamicAnnotationExpression value;
|
||||
|
||||
public EdmLabeledElementImpl(final String name, final EdmDynamicAnnotationExpression value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
public EdmLabeledElementImpl(Edm edm, CsdlLabeledElement csdlExp) {
|
||||
super(edm, "LabeledElement", csdlExp);
|
||||
this.csdlLableledElement = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
if (csdlLableledElement.getName() == null) {
|
||||
throw new EdmException("The LabeledElement expression must have a name attribute.");
|
||||
}
|
||||
return csdlLableledElement.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmDynamicAnnotationExpression getValue() {
|
||||
public EdmExpression getValue() {
|
||||
if (value == null) {
|
||||
if (csdlLableledElement.getValue() == null) {
|
||||
throw new EdmException("The LabeledElement expression must have a child expression");
|
||||
}
|
||||
value = getExpression(edm, csdlLableledElement.getValue());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,13 +18,21 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmLabeledElementReference;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLabeledElementReference;
|
||||
|
||||
public class EdmLabeledElementReferenceImpl
|
||||
extends AbstractEdmElementOrAttributeNotation implements EdmLabeledElementReference {
|
||||
public class EdmLabeledElementReferenceImpl extends AbstractEdmDynamicExpression implements EdmLabeledElementReference {
|
||||
|
||||
public EdmLabeledElementReferenceImpl(final String value) {
|
||||
super(value);
|
||||
private final CsdlLabeledElementReference csdlExp;
|
||||
|
||||
public EdmLabeledElementReferenceImpl(Edm edm, CsdlLabeledElementReference csdlExp) {
|
||||
super(edm, "LabeledElementReference");
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return csdlExp.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmLe;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmLeImpl extends AbstractEdmTwoParamsOpDynamicAnnotationExpression implements EdmLe {
|
||||
public class EdmLeImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmLe {
|
||||
|
||||
public EdmLeImpl(final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
super(left, right);
|
||||
public EdmLeImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmLt;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmLtImpl extends AbstractEdmTwoParamsOpDynamicAnnotationExpression implements EdmLt {
|
||||
public class EdmLtImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmLt {
|
||||
|
||||
public EdmLtImpl(final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
super(left, right);
|
||||
public EdmLtImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,13 +18,21 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmNavigationPropertyPath;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlNavigationPropertyPath;
|
||||
|
||||
public class EdmNavigationPropertyPathImpl
|
||||
extends AbstractEdmElementOrAttributeNotation implements EdmNavigationPropertyPath {
|
||||
public class EdmNavigationPropertyPathImpl extends AbstractEdmDynamicExpression implements EdmNavigationPropertyPath {
|
||||
|
||||
public EdmNavigationPropertyPathImpl(final String value) {
|
||||
super(value);
|
||||
private final CsdlNavigationPropertyPath csdlExp;
|
||||
|
||||
public EdmNavigationPropertyPathImpl(Edm edm, CsdlNavigationPropertyPath csdlExp) {
|
||||
super(edm, "NavigationPropertyPath");
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return csdlExp.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmNe;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmNeImpl extends AbstractEdmTwoParamsOpDynamicAnnotationExpression implements EdmNe {
|
||||
public class EdmNeImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmNe {
|
||||
|
||||
public EdmNeImpl(final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
super(left, right);
|
||||
public EdmNeImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,21 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmNot;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmNotImpl extends AbstractEdmDynamicAnnotationExpression implements EdmNot {
|
||||
public class EdmNotImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmNot {
|
||||
|
||||
private final EdmAnnotationExpression expression;
|
||||
|
||||
public EdmNotImpl(final EdmAnnotationExpression expression) {
|
||||
this.expression = expression;
|
||||
public EdmNotImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmNull;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlNull;
|
||||
|
||||
public class EdmNullImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmNull {
|
||||
// No additional methods needed for now.
|
||||
public class EdmNullImpl extends AbstractEdmAnnotatableDynamicExpression implements EdmNull {
|
||||
|
||||
public EdmNullImpl(Edm edm, CsdlNull csdlExp) {
|
||||
super(edm, "Null", csdlExp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmOr;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
|
||||
public class EdmOrImpl extends AbstractEdmTwoParamsOpDynamicAnnotationExpression implements EdmOr {
|
||||
public class EdmOrImpl extends AbstractEdmLogicalOrComparisonExpression implements EdmOr {
|
||||
|
||||
public EdmOrImpl(final EdmAnnotationExpression left, final EdmAnnotationExpression right) {
|
||||
super(left, right);
|
||||
public EdmOrImpl(Edm edm, CsdlLogicalOrComparisonExpression csdlExp) {
|
||||
super(edm, csdlExp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,12 +18,21 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmPath;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPath;
|
||||
|
||||
public class EdmPathImpl extends AbstractEdmElementOrAttributeNotation implements EdmPath {
|
||||
public class EdmPathImpl extends AbstractEdmDynamicExpression implements EdmPath {
|
||||
|
||||
public EdmPathImpl(final String value) {
|
||||
super(value);
|
||||
private final CsdlPath csdlExp;
|
||||
|
||||
public EdmPathImpl(Edm edm, CsdlPath csdlExp) {
|
||||
super(edm, "Path");
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return csdlExp.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,21 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmPropertyPath;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyPath;
|
||||
|
||||
public class EdmPropertyPathImpl extends AbstractEdmElementOrAttributeNotation implements EdmPropertyPath {
|
||||
public class EdmPropertyPathImpl extends AbstractEdmDynamicExpression implements EdmPropertyPath {
|
||||
|
||||
public EdmPropertyPathImpl(final String value) {
|
||||
super(value);
|
||||
private final CsdlPropertyPath csdlExp;
|
||||
|
||||
public EdmPropertyPathImpl(Edm edm, CsdlPropertyPath csdlExp) {
|
||||
super(edm, "PropertyPath");
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return csdlExp.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,28 +18,39 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyValue;
|
||||
|
||||
public class EdmPropertyValueImpl
|
||||
extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmPropertyValue {
|
||||
extends AbstractEdmAnnotatableDynamicExpression implements EdmPropertyValue {
|
||||
|
||||
private final String property;
|
||||
private EdmExpression value;
|
||||
private CsdlPropertyValue csdlExp;
|
||||
|
||||
private final EdmAnnotationExpression value;
|
||||
|
||||
public EdmPropertyValueImpl(final String property, final EdmAnnotationExpression value) {
|
||||
this.property = property;
|
||||
this.value = value;
|
||||
public EdmPropertyValueImpl(Edm edm, CsdlPropertyValue csdlExp) {
|
||||
super(edm, "PropertyValue", csdlExp);
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty() {
|
||||
return property;
|
||||
if (csdlExp.getProperty() == null) {
|
||||
throw new EdmException("PropertyValue expressions require a referenced property value.");
|
||||
}
|
||||
return csdlExp.getProperty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getValue() {
|
||||
public EdmExpression getValue() {
|
||||
if (value == null) {
|
||||
if (csdlExp.getValue() == null) {
|
||||
throw new EdmException("PropertyValue expressions require an expression value.");
|
||||
}
|
||||
value = getExpression(edm, csdlExp.getValue());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,36 +18,57 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmRecord;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyValue;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlRecord;
|
||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
|
||||
public class EdmRecordImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmRecord {
|
||||
|
||||
private final List<EdmPropertyValue> propertyValues;
|
||||
public class EdmRecordImpl extends AbstractEdmAnnotatableDynamicExpression implements EdmRecord {
|
||||
|
||||
private List<EdmPropertyValue> propertyValues;
|
||||
private EdmStructuredType type;
|
||||
private CsdlRecord record;
|
||||
|
||||
public EdmRecordImpl(final Edm edm, final String type, final List<EdmPropertyValue> propertyValues) {
|
||||
this.propertyValues = propertyValues;
|
||||
|
||||
if (type != null) {
|
||||
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(type).build();
|
||||
this.type = typeInfo.getEntityType() == null ? typeInfo.getComplexType() : typeInfo.getEntityType();
|
||||
}
|
||||
public EdmRecordImpl(final Edm edm, CsdlRecord csdlExp) {
|
||||
super(edm, "Record", csdlExp);
|
||||
this.record = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmPropertyValue> getPropertyValues() {
|
||||
if (propertyValues == null) {
|
||||
List<EdmPropertyValue> localValues = new ArrayList<EdmPropertyValue>();
|
||||
if (record.getPropertyValues() != null) {
|
||||
for (CsdlPropertyValue value : record.getPropertyValues()) {
|
||||
localValues.add(new EdmPropertyValueImpl(edm, value));
|
||||
}
|
||||
}
|
||||
propertyValues = Collections.unmodifiableList(localValues);
|
||||
}
|
||||
return propertyValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmStructuredType getType() {
|
||||
if (type == null) {
|
||||
if (record.getType() == null) {
|
||||
throw new EdmException("Must specify a type for a Record expression.");
|
||||
}
|
||||
final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(record.getType()).build();
|
||||
if (typeInfo.isEntityType() || typeInfo.isComplexType()) {
|
||||
type = typeInfo.isEntityType() ? typeInfo.getEntityType() : typeInfo.getComplexType();
|
||||
} else {
|
||||
throw new EdmException("Record expressions must specify a complex or entity type.");
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* 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
|
||||
|
@ -18,20 +18,30 @@
|
|||
*/
|
||||
package org.apache.olingo.commons.core.edm.annotation;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmUrlRef;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlUrlRef;
|
||||
|
||||
public class EdmUrlRefImpl extends AbstractEdmDynamicAnnotationExpression implements EdmUrlRef {
|
||||
public class EdmUrlRefImpl extends AbstractEdmDynamicExpression implements EdmUrlRef {
|
||||
|
||||
private final EdmAnnotationExpression value;
|
||||
private final CsdlUrlRef csdlExp;
|
||||
private EdmExpression value;
|
||||
|
||||
public EdmUrlRefImpl(final EdmAnnotationExpression value) {
|
||||
this.value = value;
|
||||
public EdmUrlRefImpl(Edm edm, CsdlUrlRef csdlExp) {
|
||||
super(edm, "UrlRef");
|
||||
this.csdlExp = csdlExp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAnnotationExpression getValue() {
|
||||
public EdmExpression getValue() {
|
||||
if (value == null) {
|
||||
if (csdlExp.getValue() == null) {
|
||||
throw new EdmException("URLRef expressions require an expression value.");
|
||||
}
|
||||
value = getExpression(edm, csdlExp.getValue());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
|
||||
public class AbstractAnnotationTest {
|
||||
|
||||
protected EdmDynamicExpression assertDynamic(EdmExpression exp) {
|
||||
assertNotNull(exp);
|
||||
assertTrue(exp.isDynamic());
|
||||
assertFalse(exp.isConstant());
|
||||
assertNull(exp.asConstant());
|
||||
return exp.asDynamic();
|
||||
}
|
||||
|
||||
protected EdmConstantExpression assertConstant(EdmExpression exp) {
|
||||
assertNotNull(exp);
|
||||
assertTrue(exp.isConstant());
|
||||
assertFalse(exp.isDynamic());
|
||||
assertNull(exp.asDynamic());
|
||||
return exp.asConstant();
|
||||
}
|
||||
|
||||
protected void assertSingleKindDynamicExpression(EdmDynamicExpression dynExpr){
|
||||
List<Boolean> allIsMethodValues = new ArrayList<Boolean>();
|
||||
//Logical Operators
|
||||
allIsMethodValues.add(dynExpr.isAnd());
|
||||
allIsMethodValues.add(dynExpr.isOr());
|
||||
allIsMethodValues.add(dynExpr.isNot());
|
||||
//Comparison Operators
|
||||
allIsMethodValues.add(dynExpr.isEq());
|
||||
allIsMethodValues.add(dynExpr.isNe());
|
||||
allIsMethodValues.add(dynExpr.isGt());
|
||||
allIsMethodValues.add(dynExpr.isGe());
|
||||
allIsMethodValues.add(dynExpr.isLt());
|
||||
allIsMethodValues.add(dynExpr.isLe());
|
||||
//Other Dynamic Kinds
|
||||
allIsMethodValues.add(dynExpr.isAnnotationPath());
|
||||
allIsMethodValues.add(dynExpr.isApply());
|
||||
allIsMethodValues.add(dynExpr.isCast());
|
||||
allIsMethodValues.add(dynExpr.isCollection());
|
||||
allIsMethodValues.add(dynExpr.isIf());
|
||||
allIsMethodValues.add(dynExpr.isIsOf());
|
||||
allIsMethodValues.add(dynExpr.isLabeledElement());
|
||||
allIsMethodValues.add(dynExpr.isLabeledElementReference());
|
||||
allIsMethodValues.add(dynExpr.isNull());
|
||||
allIsMethodValues.add(dynExpr.isNavigationPropertyPath());
|
||||
allIsMethodValues.add(dynExpr.isPath());
|
||||
allIsMethodValues.add(dynExpr.isPropertyPath());
|
||||
allIsMethodValues.add(dynExpr.isPropertyValue());
|
||||
allIsMethodValues.add(dynExpr.isRecord());
|
||||
allIsMethodValues.add(dynExpr.isUrlRef());
|
||||
|
||||
|
||||
//Remove all false values so that only one "true" value remains
|
||||
allIsMethodValues.removeAll(Collections.singletonList(new Boolean(false)));
|
||||
assertFalse(allIsMethodValues.contains(null));
|
||||
assertTrue(allIsMethodValues.contains(new Boolean(true)));
|
||||
assertEquals(1, allIsMethodValues.size());
|
||||
|
||||
|
||||
|
||||
List<Object> allAsMethodValues = new ArrayList<Object>();
|
||||
//Logical Operators
|
||||
allAsMethodValues.add(dynExpr.asAnd());
|
||||
allAsMethodValues.add(dynExpr.asOr());
|
||||
allAsMethodValues.add(dynExpr.asNot());
|
||||
//Comparison Operators
|
||||
allAsMethodValues.add(dynExpr.asEq());
|
||||
allAsMethodValues.add(dynExpr.asNe());
|
||||
allAsMethodValues.add(dynExpr.asGt());
|
||||
allAsMethodValues.add(dynExpr.asGe());
|
||||
allAsMethodValues.add(dynExpr.asLt());
|
||||
allAsMethodValues.add(dynExpr.asLe());
|
||||
//Other Dynamic Kinds
|
||||
allAsMethodValues.add(dynExpr.asAnnotationPath());
|
||||
allAsMethodValues.add(dynExpr.asApply());
|
||||
allAsMethodValues.add(dynExpr.asCast());
|
||||
allAsMethodValues.add(dynExpr.asCollection());
|
||||
allAsMethodValues.add(dynExpr.asIf());
|
||||
allAsMethodValues.add(dynExpr.asIsOf());
|
||||
allAsMethodValues.add(dynExpr.asLabeledElement());
|
||||
allAsMethodValues.add(dynExpr.asLabeledElementReference());
|
||||
allAsMethodValues.add(dynExpr.asNull());
|
||||
allAsMethodValues.add(dynExpr.asNavigationPropertyPath());
|
||||
allAsMethodValues.add(dynExpr.asPath());
|
||||
allAsMethodValues.add(dynExpr.asPropertyPath());
|
||||
allAsMethodValues.add(dynExpr.asPropertyValue());
|
||||
allAsMethodValues.add(dynExpr.asRecord());
|
||||
allAsMethodValues.add(dynExpr.asUrlRef());
|
||||
|
||||
//Remove all false values so that only one "true" value remains
|
||||
allAsMethodValues.removeAll(Collections.singletonList(null));
|
||||
assertFalse(allAsMethodValues.contains(null));
|
||||
assertEquals(1, allAsMethodValues.size());
|
||||
assertTrue(allAsMethodValues.get(0) instanceof EdmDynamicExpression);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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 as 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlAnnotationPath;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmAnnotationPathTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialAnnotationPath() {
|
||||
EdmExpression path = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlAnnotationPath());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(path);
|
||||
assertTrue(dynExp.isAnnotationPath());
|
||||
assertNotNull(dynExp.asAnnotationPath());
|
||||
|
||||
assertEquals("AnnotationPath", dynExp.getExpressionName());
|
||||
assertNull(dynExp.asAnnotationPath().getValue());
|
||||
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationPathWithValue() {
|
||||
EdmExpression exp =
|
||||
AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlAnnotationPath().setValue("value"));
|
||||
assertEquals("value", exp.asDynamic().asAnnotationPath().getValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmApply;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlApply;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
//CHECKSTYLE:OFF
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression.LogicalOrComparisonExpressionType;
|
||||
//CHECKSTYLE:ON
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmApplyImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialApply() {
|
||||
EdmExpression apply = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlApply());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(apply);
|
||||
assertTrue(dynExp.isApply());
|
||||
assertNotNull(dynExp.asApply());
|
||||
|
||||
assertEquals("Apply", dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmApply asApply = dynExp.asApply();
|
||||
|
||||
try {
|
||||
asApply.getFunction();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("An Apply expression must specify a function.", e.getMessage());
|
||||
}
|
||||
assertNotNull(asApply.getParameters());
|
||||
assertTrue(asApply.getParameters().isEmpty());
|
||||
|
||||
assertNotNull(asApply.getAnnotations());
|
||||
assertTrue(asApply.getAnnotations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionAndNoParameters() {
|
||||
EdmExpression apply = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlApply().setFunction("Function"));
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(apply);
|
||||
EdmApply asApply = dynExp.asApply();
|
||||
|
||||
assertEquals("Function", asApply.getFunction());
|
||||
assertNotNull(asApply.getParameters());
|
||||
assertTrue(asApply.getParameters().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionWithParameters() {
|
||||
CsdlApply csdlApply = new CsdlApply();
|
||||
csdlApply.setFunction("Function");
|
||||
|
||||
List<CsdlExpression> parameters = new ArrayList<CsdlExpression>();
|
||||
parameters.add(new CsdlConstantExpression(ConstantExpressionType.String));
|
||||
parameters.add(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.And));
|
||||
csdlApply.setParameters(parameters);
|
||||
|
||||
List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
|
||||
csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
|
||||
csdlApply.setAnnotations(csdlAnnotations);
|
||||
|
||||
EdmExpression apply = AbstractEdmExpression.getExpression(mock(Edm.class), csdlApply);
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(apply);
|
||||
EdmApply asApply = dynExp.asApply();
|
||||
|
||||
assertEquals("Function", asApply.getFunction());
|
||||
assertNotNull(asApply.getParameters());
|
||||
assertEquals(2, asApply.getParameters().size());
|
||||
assertTrue(asApply.getParameters().get(0).isConstant());
|
||||
assertTrue(asApply.getParameters().get(1).isDynamic());
|
||||
|
||||
assertNotNull(asApply.getAnnotations());
|
||||
assertEquals(1, asApply.getAnnotations().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmCast;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlCast;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmCastImplTest extends AbstractAnnotationTest{
|
||||
|
||||
@Test
|
||||
public void initialCast() {
|
||||
EdmExpression cast = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlCast());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(cast);
|
||||
assertTrue(dynExp.isCast());
|
||||
assertNotNull(dynExp.asCast());
|
||||
|
||||
assertEquals("Cast", dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
try {
|
||||
dynExp.asCast().getValue();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Cast expressions require an expression value.", e.getMessage());
|
||||
}
|
||||
|
||||
EdmCast asCast = dynExp.asCast();
|
||||
assertNull(asCast.getMaxLength());
|
||||
assertNull(asCast.getPrecision());
|
||||
assertNull(asCast.getScale());
|
||||
assertNull(asCast.getSrid());
|
||||
try {
|
||||
asCast.getType();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Must specify a type for a Cast expression.", e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(asCast.getAnnotations());
|
||||
assertTrue(asCast.getAnnotations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void castWithExpression() {
|
||||
CsdlCast csdlExp = new CsdlCast();
|
||||
csdlExp.setMaxLength(new Integer(1));
|
||||
csdlExp.setPrecision(new Integer(2));
|
||||
csdlExp.setScale(new Integer(3));
|
||||
csdlExp.setType("Edm.String");
|
||||
csdlExp.setValue(new CsdlConstantExpression(ConstantExpressionType.String));
|
||||
List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
|
||||
csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
|
||||
csdlExp.setAnnotations(csdlAnnotations);
|
||||
EdmExpression isOf = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
EdmCast asIsOf = isOf.asDynamic().asCast();
|
||||
|
||||
assertEquals(new Integer(1), asIsOf.getMaxLength());
|
||||
assertEquals(new Integer(2), asIsOf.getPrecision());
|
||||
assertEquals(new Integer(3), asIsOf.getScale());
|
||||
|
||||
assertNotNull(asIsOf.getType());
|
||||
assertTrue(asIsOf.getType() instanceof EdmPrimitiveType);
|
||||
|
||||
assertNotNull(asIsOf.getValue());
|
||||
assertTrue(asIsOf.getValue().isConstant());
|
||||
|
||||
assertNotNull(asIsOf.getAnnotations());
|
||||
assertEquals(1, asIsOf.getAnnotations().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmCollection;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlCollection;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
//CHECKSTYLE:OFF
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression.LogicalOrComparisonExpressionType;
|
||||
//CHECKSTYLE:ON
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmCollectionImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialCollection() {
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlCollection());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(exp);
|
||||
assertTrue(dynExp.isCollection());
|
||||
assertNotNull(dynExp.asCollection());
|
||||
|
||||
assertEquals("Collection", dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmCollection asCollection = dynExp.asCollection();
|
||||
|
||||
assertNotNull(asCollection.getItems());
|
||||
assertTrue(asCollection.getItems().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectionWithThreeItems() {
|
||||
CsdlCollection csdlCollection = new CsdlCollection();
|
||||
List<CsdlExpression> items = new ArrayList<CsdlExpression>();
|
||||
items.add(new CsdlConstantExpression(ConstantExpressionType.String));
|
||||
items.add(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.And));
|
||||
items.add(new CsdlConstantExpression(ConstantExpressionType.Bool));
|
||||
csdlCollection.setItems(items);
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlCollection);
|
||||
EdmCollection asCollection = exp.asDynamic().asCollection();
|
||||
|
||||
assertNotNull(asCollection.getItems());
|
||||
assertEquals(3, asCollection.getItems().size());
|
||||
|
||||
assertTrue(asCollection.getItems().get(0).isConstant());
|
||||
assertTrue(asCollection.getItems().get(1).isDynamic());
|
||||
assertTrue(asCollection.getItems().get(2).isConstant());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmConstantExpressionImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void binaryExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.Binary, "qrvM3e7_");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("Binary", exp.asConstant().getExpressionName());
|
||||
assertEquals("qrvM3e7_", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boolExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.Bool, "true");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("Bool", exp.asConstant().getExpressionName());
|
||||
assertEquals("true", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.Date, "2012-02-29");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("Date", exp.asConstant().getExpressionName());
|
||||
assertEquals("2012-02-29", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateTimeOffsetExpression() {
|
||||
CsdlConstantExpression csdlExp =
|
||||
new CsdlConstantExpression(ConstantExpressionType.DateTimeOffset, "2012-02-29T01:02:03Z");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("DateTimeOffset", exp.asConstant().getExpressionName());
|
||||
assertEquals("2012-02-29T01:02:03Z", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decimalExpression() {
|
||||
CsdlConstantExpression csdlExp =
|
||||
new CsdlConstantExpression(ConstantExpressionType.Decimal, "-123456789012345678901234567890");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("Decimal", exp.asConstant().getExpressionName());
|
||||
assertEquals("-123456789012345678901234567890", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void durationExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.Duration, "PT10S");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("Duration", exp.asConstant().getExpressionName());
|
||||
assertEquals("PT10S", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enumMemberExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.EnumMember, "Enum/enumMember");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("EnumMember", exp.asConstant().getExpressionName());
|
||||
assertEquals("Enum/enumMember", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void floatExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.Float, "1.42");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("Float", exp.asConstant().getExpressionName());
|
||||
assertEquals("1.42", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void guidExpression() {
|
||||
CsdlConstantExpression csdlExp =
|
||||
new CsdlConstantExpression(ConstantExpressionType.Guid, "aabbccdd-aabb-ccdd-eeff-aabbccddeeff");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("Guid", exp.asConstant().getExpressionName());
|
||||
assertEquals("aabbccdd-aabb-ccdd-eeff-aabbccddeeff", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.Int, "42");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("Int", exp.asConstant().getExpressionName());
|
||||
assertEquals("42", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.String, "ABCD");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("String", exp.asConstant().getExpressionName());
|
||||
assertEquals("ABCD", exp.asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeOfDayExpression() {
|
||||
CsdlConstantExpression csdlExp = new CsdlConstantExpression(ConstantExpressionType.TimeOfDay, "00:00:00.999");
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
assertConstant(exp);
|
||||
|
||||
assertEquals("TimeOfDay", exp.asConstant().getExpressionName());
|
||||
assertEquals("00:00:00.999", exp.asConstant().getValueAsString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmIf;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlIf;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
//CHECKSTYLE:OFF
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression.LogicalOrComparisonExpressionType;
|
||||
//CHECKSTYLE:ON
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmIfImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialIf() {
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlIf());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(exp);
|
||||
assertTrue(dynExp.isIf());
|
||||
assertNotNull(dynExp.asIf());
|
||||
|
||||
assertEquals("If", dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmIf asIf = dynExp.asIf();
|
||||
|
||||
try {
|
||||
asIf.getGuard();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Guard clause of an if expression must not be null", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
asIf.getThen();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Then clause of an if expression must not be null", e.getMessage());
|
||||
}
|
||||
|
||||
assertNull(asIf.getElse());
|
||||
|
||||
assertNotNull(asIf.getAnnotations());
|
||||
assertTrue(asIf.getAnnotations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withAllExpressions() {
|
||||
CsdlIf csdlIf = new CsdlIf();
|
||||
csdlIf.setGuard(new CsdlConstantExpression(ConstantExpressionType.Bool));
|
||||
csdlIf.setThen(new CsdlConstantExpression(ConstantExpressionType.String));
|
||||
csdlIf.setElse(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.And));
|
||||
List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
|
||||
csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
|
||||
csdlIf.setAnnotations(csdlAnnotations);
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlIf);
|
||||
EdmIf asIf = exp.asDynamic().asIf();
|
||||
|
||||
assertNotNull(asIf.getGuard());
|
||||
assertTrue(asIf.getGuard().isConstant());
|
||||
assertNotNull(asIf.getThen());
|
||||
assertTrue(asIf.getThen().isConstant());
|
||||
assertNotNull(asIf.getElse());
|
||||
assertTrue(asIf.getElse().isDynamic());
|
||||
|
||||
assertNotNull(asIf.getAnnotations());
|
||||
assertEquals(1, asIf.getAnnotations().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmIsOf;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlIsOf;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmIsOfImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialIsOf() {
|
||||
EdmExpression isOf = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlIsOf());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(isOf);
|
||||
assertTrue(dynExp.isIsOf());
|
||||
assertNotNull(dynExp.asIsOf());
|
||||
|
||||
assertEquals("IsOf", dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
try {
|
||||
dynExp.asIsOf().getValue();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("IsOf expressions require an expression value.", e.getMessage());
|
||||
}
|
||||
|
||||
EdmIsOf asIsOf = dynExp.asIsOf();
|
||||
assertNull(asIsOf.getMaxLength());
|
||||
assertNull(asIsOf.getPrecision());
|
||||
assertNull(asIsOf.getScale());
|
||||
assertNull(asIsOf.getSrid());
|
||||
try {
|
||||
asIsOf.getType();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Must specify a type for an IsOf expression.", e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(asIsOf.getAnnotations());
|
||||
assertTrue(asIsOf.getAnnotations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isOfWithExpression() {
|
||||
CsdlIsOf csdlExp = new CsdlIsOf();
|
||||
csdlExp.setMaxLength(new Integer(1));
|
||||
csdlExp.setPrecision(new Integer(2));
|
||||
csdlExp.setScale(new Integer(3));
|
||||
csdlExp.setType("Edm.String");
|
||||
csdlExp.setValue(new CsdlConstantExpression(ConstantExpressionType.String));
|
||||
List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
|
||||
csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
|
||||
csdlExp.setAnnotations(csdlAnnotations);
|
||||
EdmExpression isOf = AbstractEdmExpression.getExpression(mock(Edm.class), csdlExp);
|
||||
|
||||
EdmIsOf asIsOf = isOf.asDynamic().asIsOf();
|
||||
|
||||
assertEquals(new Integer(1), asIsOf.getMaxLength());
|
||||
assertEquals(new Integer(2), asIsOf.getPrecision());
|
||||
assertEquals(new Integer(3), asIsOf.getScale());
|
||||
|
||||
assertNotNull(asIsOf.getType());
|
||||
assertTrue(asIsOf.getType() instanceof EdmPrimitiveType);
|
||||
|
||||
assertNotNull(asIsOf.getValue());
|
||||
assertTrue(asIsOf.getValue().isConstant());
|
||||
|
||||
assertNotNull(asIsOf.getAnnotations());
|
||||
assertEquals(1, asIsOf.getAnnotations().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmLabeledElement;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLabeledElement;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmLabeledElementImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialLabeledElement() {
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlLabeledElement());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(exp);
|
||||
assertTrue(dynExp.isLabeledElement());
|
||||
assertNotNull(dynExp.asLabeledElement());
|
||||
|
||||
assertEquals("LabeledElement", dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmLabeledElement asLabeled = dynExp.asLabeledElement();
|
||||
|
||||
try {
|
||||
asLabeled.getName();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("The LabeledElement expression must have a name attribute.", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
asLabeled.getValue();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("The LabeledElement expression must have a child expression", e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(asLabeled.getAnnotations());
|
||||
assertTrue(asLabeled.getAnnotations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void labeledElementWithNameAndValue() {
|
||||
CsdlLabeledElement csdlLabeledElement = new CsdlLabeledElement();
|
||||
csdlLabeledElement.setName("name");
|
||||
csdlLabeledElement.setValue(new CsdlConstantExpression(ConstantExpressionType.String));
|
||||
List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
|
||||
csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
|
||||
csdlLabeledElement.setAnnotations(csdlAnnotations);
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlLabeledElement);
|
||||
EdmLabeledElement asLabeled = exp.asDynamic().asLabeledElement();
|
||||
|
||||
assertEquals("name", asLabeled.getName());
|
||||
assertNotNull(asLabeled.getValue());
|
||||
assertTrue(asLabeled.getValue().isConstant());
|
||||
|
||||
assertNotNull(asLabeled.getAnnotations());
|
||||
assertEquals(1, asLabeled.getAnnotations().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLabeledElementReference;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmLabledElementReferenceImplTest extends AbstractAnnotationTest {
|
||||
@Test
|
||||
public void initialPropertyPath() {
|
||||
EdmExpression path = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlLabeledElementReference());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(path);
|
||||
assertTrue(dynExp.isLabeledElementReference());
|
||||
assertNotNull(dynExp.asLabeledElementReference());
|
||||
|
||||
assertEquals("LabeledElementReference", dynExp.getExpressionName());
|
||||
assertNull(dynExp.asLabeledElementReference().getValue());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationPathWithValue() {
|
||||
EdmExpression exp =
|
||||
AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlLabeledElementReference().setValue("value"));
|
||||
assertEquals("value", exp.asDynamic().asLabeledElementReference().getValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmLogicalOrComparisonExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression;
|
||||
//CHECKSTYLE:OFF
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression.LogicalOrComparisonExpressionType;
|
||||
//CHECKSTYLE:ON
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmLogicalOrComparisonImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialLogicalOrOperationsClasses() {
|
||||
for (LogicalOrComparisonExpressionType type : LogicalOrComparisonExpressionType.values()) {
|
||||
EdmExpression path = AbstractEdmExpression.getExpression(
|
||||
mock(Edm.class),
|
||||
new CsdlLogicalOrComparisonExpression(type));
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(path);
|
||||
assertEquals(type.toString(), dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmLogicalOrComparisonExpression logicOrComparisonExp = (EdmLogicalOrComparisonExpression) dynExp;
|
||||
try {
|
||||
logicOrComparisonExp.getLeftExpression();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Comparison Or Logical expression MUST have a left and right expression.", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
logicOrComparisonExp.getRightExpression();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Comparison Or Logical expression MUST have a left and right expression.", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logicalOrOperationsClassesWithExpressions() {
|
||||
for (LogicalOrComparisonExpressionType type : LogicalOrComparisonExpressionType.values()) {
|
||||
EdmExpression path = AbstractEdmExpression.getExpression(
|
||||
mock(Edm.class),
|
||||
new CsdlLogicalOrComparisonExpression(type)
|
||||
.setLeft(new CsdlConstantExpression(ConstantExpressionType.String))
|
||||
.setRight(new CsdlLogicalOrComparisonExpression(type)));
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(path);
|
||||
assertEquals(type.toString(), dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmLogicalOrComparisonExpression logicOrComparisonExp = (EdmLogicalOrComparisonExpression) dynExp;
|
||||
assertNotNull(logicOrComparisonExp.getLeftExpression());
|
||||
assertNotNull(logicOrComparisonExp.getRightExpression());
|
||||
if (type == LogicalOrComparisonExpressionType.Not) {
|
||||
assertTrue(logicOrComparisonExp.getLeftExpression() == logicOrComparisonExp.getRightExpression());
|
||||
} else {
|
||||
assertTrue(logicOrComparisonExp.getLeftExpression() instanceof EdmConstantExpression);
|
||||
assertTrue(logicOrComparisonExp.getRightExpression() instanceof EdmDynamicExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlNavigationPropertyPath;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmNavigationPropertyPathImpTest extends AbstractAnnotationTest {
|
||||
@Test
|
||||
public void initialPropertyPath() {
|
||||
EdmExpression path = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlNavigationPropertyPath());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(path);
|
||||
assertTrue(dynExp.isNavigationPropertyPath());
|
||||
assertNotNull(dynExp.asNavigationPropertyPath());
|
||||
|
||||
assertEquals("NavigationPropertyPath", dynExp.getExpressionName());
|
||||
assertNull(dynExp.asNavigationPropertyPath().getValue());
|
||||
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationPathWithValue() {
|
||||
EdmExpression exp =
|
||||
AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlNavigationPropertyPath().setValue("value"));
|
||||
assertEquals("value", exp.asDynamic().asNavigationPropertyPath().getValue());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPath;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmPathImplTest extends AbstractAnnotationTest{
|
||||
@Test
|
||||
public void initialPropertyPath() {
|
||||
EdmExpression path = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlPath());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(path);
|
||||
assertTrue(dynExp.isPath());
|
||||
assertNotNull(dynExp.asPath());
|
||||
|
||||
assertEquals("Path", dynExp.getExpressionName());
|
||||
assertNull(dynExp.asPath().getValue());
|
||||
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationPathWithValue() {
|
||||
EdmExpression exp =
|
||||
AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlPath().setValue("value"));
|
||||
assertEquals("value", exp.asDynamic().asPath().getValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyPath;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmPropertyPathImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialPropertyPath() {
|
||||
EdmExpression path = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlPropertyPath());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(path);
|
||||
assertTrue(dynExp.isPropertyPath());
|
||||
assertNotNull(dynExp.asPropertyPath());
|
||||
|
||||
assertEquals("PropertyPath", dynExp.getExpressionName());
|
||||
assertNull(dynExp.asPropertyPath().getValue());
|
||||
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationPathWithValue() {
|
||||
EdmExpression exp =
|
||||
AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlPropertyPath().setValue("value"));
|
||||
assertEquals("value", exp.asDynamic().asPropertyPath().getValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyValue;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmPropertyValueImplTest extends AbstractAnnotationTest {
|
||||
@Test
|
||||
public void initialPropertyValue() {
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlPropertyValue());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(exp);
|
||||
assertTrue(dynExp.isPropertyValue());
|
||||
assertNotNull(dynExp.asPropertyValue());
|
||||
|
||||
assertEquals("PropertyValue", dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmPropertyValue asPropValue = dynExp.asPropertyValue();
|
||||
try {
|
||||
asPropValue.getProperty();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("PropertyValue expressions require a referenced property value.", e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
asPropValue.getValue();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("PropertyValue expressions require an expression value.", e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(asPropValue.getAnnotations());
|
||||
assertTrue(asPropValue.getAnnotations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyValue() {
|
||||
CsdlPropertyValue csdlPropertyValue = new CsdlPropertyValue();
|
||||
csdlPropertyValue.setProperty("property");
|
||||
csdlPropertyValue.setValue(new CsdlConstantExpression(ConstantExpressionType.String));
|
||||
List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
|
||||
csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
|
||||
csdlPropertyValue.setAnnotations(csdlAnnotations);
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlPropertyValue);
|
||||
EdmPropertyValue asPropValue = exp.asDynamic().asPropertyValue();
|
||||
|
||||
assertNotNull(asPropValue.getProperty());
|
||||
assertEquals("property", asPropValue.getProperty());
|
||||
assertNotNull(asPropValue.getValue());
|
||||
assertTrue(asPropValue.getValue().isConstant());
|
||||
|
||||
assertNotNull(asPropValue.getAnnotations());
|
||||
assertEquals(1, asPropValue.getAnnotations().size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmRecord;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPropertyValue;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlRecord;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmRecordImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialRecord() {
|
||||
EdmExpression record = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlRecord());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(record);
|
||||
assertTrue(dynExp.isRecord());
|
||||
assertNotNull(dynExp.asRecord());
|
||||
|
||||
assertEquals("Record", dynExp.getExpressionName());
|
||||
assertNotNull(dynExp.asRecord().getPropertyValues());
|
||||
assertTrue(dynExp.asRecord().getPropertyValues().isEmpty());
|
||||
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmRecord asRecord = dynExp.asRecord();
|
||||
try {
|
||||
asRecord.getType();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Must specify a type for a Record expression.", e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(asRecord.getAnnotations());
|
||||
assertTrue(asRecord.getAnnotations().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordWithEntityTypeAndPropValues() {
|
||||
CsdlRecord csdlRecord = new CsdlRecord();
|
||||
csdlRecord.setType("ns.et");
|
||||
Edm mock = mock(Edm.class);
|
||||
when(mock.getEntityType(new FullQualifiedName("ns.et"))).thenReturn(mock(EdmEntityType.class));
|
||||
List<CsdlPropertyValue> propertyValues = new ArrayList<CsdlPropertyValue>();
|
||||
propertyValues.add(new CsdlPropertyValue());
|
||||
csdlRecord.setPropertyValues(propertyValues);
|
||||
List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
|
||||
csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
|
||||
csdlRecord.setAnnotations(csdlAnnotations);
|
||||
EdmExpression record = AbstractEdmExpression.getExpression(mock, csdlRecord);
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(record);
|
||||
EdmRecord asRecord = dynExp.asRecord();
|
||||
|
||||
assertNotNull(asRecord.getPropertyValues());
|
||||
assertEquals(1, asRecord.getPropertyValues().size());
|
||||
|
||||
assertNotNull(asRecord.getType());
|
||||
assertTrue(asRecord.getType() instanceof EdmEntityType);
|
||||
|
||||
assertNotNull(asRecord.getAnnotations());
|
||||
assertEquals(1, asRecord.getAnnotations().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordWithComplexType() {
|
||||
CsdlRecord csdlRecord = new CsdlRecord();
|
||||
csdlRecord.setType("ns.ct");
|
||||
Edm mock = mock(Edm.class);
|
||||
when(mock.getComplexType(new FullQualifiedName("ns.ct"))).thenReturn(mock(EdmComplexType.class));
|
||||
EdmExpression record = AbstractEdmExpression.getExpression(mock, csdlRecord);
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(record);
|
||||
EdmRecord asRecord = dynExp.asRecord();
|
||||
|
||||
assertNotNull(asRecord.getType());
|
||||
assertTrue(asRecord.getType() instanceof EdmComplexType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordWithInvalidTypes() {
|
||||
Edm edm = mock(Edm.class);
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(edm, new CsdlRecord().setType("ns.invalid"));
|
||||
EdmRecord record = exp.asDynamic().asRecord();
|
||||
try {
|
||||
record.getType();
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Record expressions must specify a complex or entity type.", e.getMessage());
|
||||
}
|
||||
|
||||
// Primitive
|
||||
exp = AbstractEdmExpression.getExpression(edm, new CsdlRecord().setType("Edm.String"));
|
||||
record = exp.asDynamic().asRecord();
|
||||
try {
|
||||
record.getType();
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Record expressions must specify a complex or entity type.", e.getMessage());
|
||||
}
|
||||
|
||||
// Enum
|
||||
when(edm.getEnumType(new FullQualifiedName("ns.enum"))).thenReturn(mock(EdmEnumType.class));
|
||||
exp = AbstractEdmExpression.getExpression(edm, new CsdlRecord().setType("ns.enum"));
|
||||
record = exp.asDynamic().asRecord();
|
||||
try {
|
||||
record.getType();
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Record expressions must specify a complex or entity type.", e.getMessage());
|
||||
}
|
||||
|
||||
// Typedef
|
||||
when(edm.getTypeDefinition(new FullQualifiedName("ns.typedef"))).thenReturn(mock(EdmTypeDefinition.class));
|
||||
exp = AbstractEdmExpression.getExpression(edm, new CsdlRecord().setType("ns.typedef"));
|
||||
record = exp.asDynamic().asRecord();
|
||||
try {
|
||||
record.getType();
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Record expressions must specify a complex or entity type.", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.commons.core.edm.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmUrlRef;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlNull;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlUrlRef;
|
||||
import org.apache.olingo.commons.core.edm.annotation.AbstractEdmExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmUrlRefImplTest extends AbstractAnnotationTest {
|
||||
|
||||
@Test
|
||||
public void initialUrlRef() {
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), new CsdlUrlRef());
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(exp);
|
||||
assertTrue(dynExp.isUrlRef());
|
||||
assertNotNull(dynExp.asUrlRef());
|
||||
|
||||
assertEquals("UrlRef", dynExp.getExpressionName());
|
||||
assertSingleKindDynamicExpression(dynExp);
|
||||
|
||||
EdmUrlRef asUrlRef = dynExp.asUrlRef();
|
||||
try {
|
||||
asUrlRef.getValue();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("URLRef expressions require an expression value.", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlRefWithValue() {
|
||||
CsdlUrlRef csdlUrlRef = new CsdlUrlRef();
|
||||
csdlUrlRef.setValue(new CsdlConstantExpression(ConstantExpressionType.String));
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlUrlRef);
|
||||
EdmUrlRef asUrlRef = exp.asDynamic().asUrlRef();
|
||||
assertNotNull(asUrlRef.getValue());
|
||||
assertTrue(asUrlRef.getValue().isConstant());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlRefWithInvalidValue() {
|
||||
CsdlUrlRef csdlUrlRef = new CsdlUrlRef();
|
||||
csdlUrlRef.setValue(new CsdlConstantExpression(ConstantExpressionType.Bool));
|
||||
EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlUrlRef);
|
||||
EdmUrlRef asUrlRef = exp.asDynamic().asUrlRef();
|
||||
assertNotNull(asUrlRef.getValue());
|
||||
assertTrue(asUrlRef.getValue().isConstant());
|
||||
|
||||
csdlUrlRef = new CsdlUrlRef();
|
||||
csdlUrlRef.setValue(new CsdlNull());
|
||||
exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlUrlRef);
|
||||
asUrlRef = exp.asDynamic().asUrlRef();
|
||||
assertNotNull(asUrlRef.getValue());
|
||||
assertTrue(asUrlRef.getValue().isDynamic());
|
||||
assertTrue(asUrlRef.getValue().asDynamic().isNull());
|
||||
assertNotNull(asUrlRef.getValue().asDynamic().asNull());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.apache.olingo.server.core.edm.provider;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmTerm;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
|
||||
import org.apache.olingo.commons.core.edm.EdmAnnotationImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmAnnotationImplTest {
|
||||
|
||||
@Test
|
||||
public void initialAnnotation() {
|
||||
EdmAnnotation anno = new EdmAnnotationImpl(mock(Edm.class), new CsdlAnnotation());
|
||||
|
||||
assertNull(anno.getQualifier());
|
||||
assertNotNull(anno.getAnnotations());
|
||||
assertTrue(anno.getAnnotations().isEmpty());
|
||||
assertNull(anno.getExpression());
|
||||
try {
|
||||
anno.getTerm();
|
||||
fail("EdmException expected");
|
||||
} catch (EdmException e) {
|
||||
assertEquals("Term must not be null for an annotation.", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleAnnotationNoExpression() {
|
||||
Edm mock = mock(Edm.class);
|
||||
EdmTerm termMock = mock(EdmTerm.class);
|
||||
when(mock.getTerm(new FullQualifiedName("ns", "termName"))).thenReturn(termMock);
|
||||
EdmAnnotation anno =
|
||||
new EdmAnnotationImpl(mock, new CsdlAnnotation().setQualifier("Qualifier").setTerm("ns.termName"));
|
||||
|
||||
assertEquals("Qualifier", anno.getQualifier());
|
||||
assertNotNull(anno.getAnnotations());
|
||||
assertTrue(anno.getAnnotations().isEmpty());
|
||||
assertNotNull(anno.getTerm());
|
||||
assertEquals(termMock, anno.getTerm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleAnnotationWitConstantExpression() {
|
||||
EdmAnnotation anno =
|
||||
new EdmAnnotationImpl(mock(Edm.class), new CsdlAnnotation()
|
||||
.setExpression(new CsdlConstantExpression(ConstantExpressionType.String).setValue("value")));
|
||||
|
||||
assertEquals("value", anno.getExpression().asConstant().getValueAsString());
|
||||
}
|
||||
|
||||
}
|
|
@ -53,8 +53,8 @@ import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
|||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantAnnotationExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmConstantExpression;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmExpression;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
|
@ -504,13 +504,13 @@ public class MetadataDocumentXmlSerializer {
|
|||
String term = getAliasedFullQualifiedName(annotation.getTerm().getFullQualifiedName(), false);
|
||||
writer.writeAttribute(XML_TERM_ATT, term);
|
||||
String qualifier = annotation.getQualifier();
|
||||
if(qualifier != null) {
|
||||
if (qualifier != null) {
|
||||
writer.writeAttribute(XML_QUALIFIER_ATT, qualifier);
|
||||
}
|
||||
EdmAnnotationExpression expression = annotation.getExpression();
|
||||
if(expression != null) {
|
||||
if(expression.isConstant()) {
|
||||
EdmConstantAnnotationExpression constExpression = expression.asConstant();
|
||||
EdmExpression expression = annotation.getExpression();
|
||||
if (expression != null) {
|
||||
if (expression.isConstant()) {
|
||||
EdmConstantExpression constExpression = expression.asConstant();
|
||||
Valuable value = constExpression.getValue();
|
||||
writer.writeAttribute(value.getType(), constExpression.getValueAsString());
|
||||
} else {
|
||||
|
@ -521,7 +521,6 @@ public class MetadataDocumentXmlSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void appendNavigationProperties(final XMLStreamWriter writer, final EdmStructuredType type)
|
||||
throws XMLStreamException {
|
||||
List<String> navigationPropertyNames = new ArrayList<String>(type.getNavigationPropertyNames());
|
||||
|
|
Loading…
Reference in New Issue