You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/10/22 10:40:16 UTC
[33/48] olingo-odata4 git commit: [OLINGO786] FIx edm annotation
classes
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java
index 9464e34..d4af2ee 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java
@@ -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;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmUrlRefImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmUrlRefImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmUrlRefImpl.java
index 3c2db50..1210dbc 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmUrlRefImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmUrlRefImpl.java
@@ -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;
}
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/AbstractAnnotationTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/AbstractAnnotationTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/AbstractAnnotationTest.java
new file mode 100644
index 0000000..2f6bbab
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/AbstractAnnotationTest.java
@@ -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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmAnnotationPathTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmAnnotationPathTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmAnnotationPathTest.java
new file mode 100644
index 0000000..122abd7
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmAnnotationPathTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmApplyImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmApplyImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmApplyImplTest.java
new file mode 100644
index 0000000..459536a
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmApplyImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmCastImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmCastImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmCastImplTest.java
new file mode 100644
index 0000000..1427e18
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmCastImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmCollectionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmCollectionImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmCollectionImplTest.java
new file mode 100644
index 0000000..0d7e72d
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmCollectionImplTest.java
@@ -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());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmConstantExpressionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmConstantExpressionImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmConstantExpressionImplTest.java
new file mode 100644
index 0000000..e45c760
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmConstantExpressionImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmIfImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmIfImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmIfImplTest.java
new file mode 100644
index 0000000..fa41522
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmIfImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmIsOfImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmIsOfImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmIsOfImplTest.java
new file mode 100644
index 0000000..cba3abf
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmIsOfImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLabeledElementImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLabeledElementImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLabeledElementImplTest.java
new file mode 100644
index 0000000..3a5a6a0
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLabeledElementImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLabledElementReferenceImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLabledElementReferenceImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLabledElementReferenceImplTest.java
new file mode 100644
index 0000000..0fa2e64
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLabledElementReferenceImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLogicalOrComparisonImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLogicalOrComparisonImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLogicalOrComparisonImplTest.java
new file mode 100644
index 0000000..e5a4cf9
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmLogicalOrComparisonImplTest.java
@@ -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);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmNavigationPropertyPathImpTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmNavigationPropertyPathImpTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmNavigationPropertyPathImpTest.java
new file mode 100644
index 0000000..d4fe6f1
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmNavigationPropertyPathImpTest.java
@@ -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());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPathImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPathImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPathImplTest.java
new file mode 100644
index 0000000..5f32f07
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPathImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPropertyPathImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPropertyPathImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPropertyPathImplTest.java
new file mode 100644
index 0000000..eb0228e
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPropertyPathImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPropertyValueImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPropertyValueImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPropertyValueImplTest.java
new file mode 100644
index 0000000..28d1740
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmPropertyValueImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmRecordImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmRecordImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmRecordImplTest.java
new file mode 100644
index 0000000..2f3bc1b
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmRecordImplTest.java
@@ -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());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmUrlRefImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmUrlRefImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmUrlRefImplTest.java
new file mode 100644
index 0000000..1f6d703
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/annotations/EdmUrlRefImplTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41210245/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmAnnotationImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmAnnotationImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmAnnotationImplTest.java
new file mode 100644
index 0000000..869af0f
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmAnnotationImplTest.java
@@ -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());
+ }
+
+}