[OLINGO-467] Added EdmFacets support
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/ffe51503 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/ffe51503 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/ffe51503 Branch: refs/heads/Olingo-129_PocJpaDataStore Commit: ffe515037ecda34671cd6802469cded516bbcc3c Parents: 95a11bc Author: Michael Bolz <[email protected]> Authored: Fri Oct 31 15:19:16 2014 +0100 Committer: Michael Bolz <[email protected]> Committed: Fri Oct 31 15:19:16 2014 +0100 ---------------------------------------------------------------------- .../core/edm/AnnotationEdmProvider.java | 23 +- .../core/edm/AnnotationEdmProviderTest.java | 28 ++ .../processor/core/model/Building.java | 3 +- .../annotation/processor/core/model/City.java | 3 +- .../processor/core/model/Employee.java | 5 +- .../processor/core/model/RefBase.java | 3 +- .../annotation/processor/core/model/Room.java | 4 +- .../processor/ref/model/Building.java | 3 +- .../processor/ref/model/Employee.java | 4 +- .../annotation/processor/ref/model/RefBase.java | 3 +- .../annotation/processor/ref/MetadataTest.java | 345 +++++++++++++++++++ .../core/model/JPAEdmFunctionImportTest.java | 4 +- .../odata2/api/annotation/edm/EdmFacets.java | 4 +- 13 files changed, 417 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java index 9c46da2..c152a00 100644 --- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java +++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProvider.java @@ -35,13 +35,16 @@ import java.util.UUID; import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper; import org.apache.olingo.odata2.annotation.processor.core.util.ClassHelper; import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType; +import org.apache.olingo.odata2.api.annotation.edm.EdmConcurrencyControl; import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet; import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType; +import org.apache.olingo.odata2.api.annotation.edm.EdmFacets; import org.apache.olingo.odata2.api.annotation.edm.EdmKey; import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent; import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty; import org.apache.olingo.odata2.api.annotation.edm.EdmProperty; import org.apache.olingo.odata2.api.annotation.edm.EdmType; +import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode; import org.apache.olingo.odata2.api.edm.EdmMultiplicity; import org.apache.olingo.odata2.api.edm.FullQualifiedName; import org.apache.olingo.odata2.api.edm.provider.AnnotationAttribute; @@ -57,6 +60,7 @@ import org.apache.olingo.odata2.api.edm.provider.EntityContainer; import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo; import org.apache.olingo.odata2.api.edm.provider.EntitySet; import org.apache.olingo.odata2.api.edm.provider.EntityType; +import org.apache.olingo.odata2.api.edm.provider.Facets; import org.apache.olingo.odata2.api.edm.provider.FunctionImport; import org.apache.olingo.odata2.api.edm.provider.Key; import org.apache.olingo.odata2.api.edm.provider.NavigationProperty; @@ -460,10 +464,27 @@ public class AnnotationEdmProvider extends EdmProvider { type = getEdmType(field.getType()); } sp.setType(ANNOTATION_HELPER.mapTypeKind(type)); - + sp.setFacets(createFacets(ep.facets(), field.getAnnotation(EdmConcurrencyControl.class))); return sp; } + private Facets createFacets(final EdmFacets facets, final EdmConcurrencyControl concurrencyControl) { + Facets resultFacets = new Facets().setNullable(facets.nullable()); + if(facets.maxLength() > -1) { + resultFacets.setMaxLength(facets.maxLength()); + } + if(facets.precision() > -1) { + resultFacets.setPrecision(facets.precision()); + } + if(facets.scale() > -1) { + resultFacets.setScale(facets.scale()); + } + if (concurrencyControl != null) { + resultFacets.setConcurrencyMode(EdmConcurrencyMode.Fixed); + } + return resultFacets; + } + private Property createComplexProperty(final Field field, final String defaultNamespace) { ComplexProperty cp = new ComplexProperty(); // settings from property http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java index 30c87bb..a067a19 100644 --- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java +++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java @@ -308,6 +308,8 @@ public class AnnotationEdmProviderTest { assertEquals("EmployeeId", employeeKeys.get(0).getName()); assertEquals(6, employee.getProperties().size()); assertEquals(3, employee.getNavigationProperties().size()); + Property name = getProperty(employee, "EmployeeName"); + assertEquals(Integer.valueOf(20), name.getFacets().getMaxLength()); for (NavigationProperty navigationProperty : employee.getNavigationProperties()) { if (navigationProperty.getName().equals("ne_Manager")) { @@ -322,6 +324,27 @@ public class AnnotationEdmProviderTest { } } + + @Test + public void facetsTest() throws Exception { + EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee")); + assertEquals("Employee", employee.getName()); + Property name = getProperty(employee, "EmployeeName"); + assertEquals(Integer.valueOf(20), name.getFacets().getMaxLength()); + assertTrue(name.getFacets().isNullable()); + Property id = getProperty(employee, "EmployeeId"); + assertFalse(id.getFacets().isNullable()); + + ComplexType city = aep.getComplexType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_City")); + Property postalCode = getProperty(city.getProperties(), "PostalCode"); + assertEquals(Integer.valueOf(5), postalCode.getFacets().getMaxLength()); + + EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room")); + Property version = getProperty(room, "Version"); + assertEquals(Integer.valueOf(0), version.getFacets().getScale()); + assertEquals(Integer.valueOf(0), version.getFacets().getPrecision()); + } + @Test public void entityTypeTeam() throws Exception { // validate team @@ -443,12 +466,17 @@ public class AnnotationEdmProviderTest { return getProperty(properties, propertyName) != null; } + private Property getProperty(EntityType entity, String propertyName) { + return getProperty(entity.getProperties(), propertyName); + } + private Property getProperty(final List<Property> properties, final String name) { for (Property property : properties) { if (name.equals(property.getName())) { return property; } } + fail("Requested property with name '" + name + "' not available."); return null; } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java index 350ef16..a78e915 100644 --- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java +++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet; import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType; +import org.apache.olingo.odata2.api.annotation.edm.EdmFacets; import org.apache.olingo.odata2.api.annotation.edm.EdmKey; import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty; import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity; @@ -37,7 +38,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmType; @EdmEntitySet(name = "Buildings") public class Building { @EdmKey - @EdmProperty(type = EdmType.INT32) + @EdmProperty(type = EdmType.INT32, facets = @EdmFacets(nullable = false)) private String id; @EdmProperty private String name; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java index 2e630ba..814b66c 100644 --- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java +++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java @@ -19,6 +19,7 @@ package org.apache.olingo.odata2.annotation.processor.core.model; import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType; +import org.apache.olingo.odata2.api.annotation.edm.EdmFacets; import org.apache.olingo.odata2.api.annotation.edm.EdmProperty; /** @@ -27,7 +28,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmProperty; @EdmComplexType(name = "c_City", namespace = ModelSharedConstants.NAMESPACE_1) public class City { - @EdmProperty + @EdmProperty(facets = @EdmFacets(maxLength = 5)) private String postalCode; @EdmProperty private String cityName; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java index 136a2e1..ce709d7 100644 --- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java +++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java @@ -23,6 +23,7 @@ import java.util.Calendar; import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet; import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType; +import org.apache.olingo.odata2.api.annotation.edm.EdmFacets; import org.apache.olingo.odata2.api.annotation.edm.EdmKey; import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent; import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType; @@ -37,9 +38,9 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmType; @EdmEntitySet(name = "Employees") public class Employee { @EdmKey - @EdmProperty(name = "EmployeeId", type = EdmType.STRING) + @EdmProperty(name = "EmployeeId", type = EdmType.STRING, facets = @EdmFacets(nullable = false)) private String employeeId; - @EdmProperty(name = "EmployeeName") + @EdmProperty(name = "EmployeeName", facets = @EdmFacets(maxLength = 20)) private String employeeName; @EdmProperty private int age; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java index e998efc..0877d9a 100644 --- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java +++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java @@ -17,6 +17,7 @@ package org.apache.olingo.odata2.annotation.processor.core.model; import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType; +import org.apache.olingo.odata2.api.annotation.edm.EdmFacets; import org.apache.olingo.odata2.api.annotation.edm.EdmKey; import org.apache.olingo.odata2.api.annotation.edm.EdmProperty; import org.apache.olingo.odata2.api.annotation.edm.EdmType; @@ -28,7 +29,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmType; public abstract class RefBase { @EdmProperty(name = "Name") protected String name; - @EdmProperty(name = "Id", type = EdmType.STRING) + @EdmProperty(name = "Id", type = EdmType.STRING, facets = @EdmFacets(nullable = false)) @EdmKey protected int id; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java index c808cbd..40f9202 100644 --- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java +++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java @@ -18,8 +18,10 @@ package org.apache.olingo.odata2.annotation.processor.core.model; import java.util.ArrayList; import java.util.List; +import org.apache.olingo.odata2.api.annotation.edm.EdmConcurrencyControl; import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet; import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType; +import org.apache.olingo.odata2.api.annotation.edm.EdmFacets; import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty; import org.apache.olingo.odata2.api.annotation.edm.EdmProperty; @@ -32,7 +34,7 @@ public class Room extends RefBase { @EdmProperty private Integer seats; - @EdmProperty + @EdmProperty(facets = @EdmFacets(scale = 0, precision = 0)) private Integer version; @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms") private Building building; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Building.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Building.java b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Building.java index 125c936..4499649 100644 --- a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Building.java +++ b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Building.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet; import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType; +import org.apache.olingo.odata2.api.annotation.edm.EdmFacets; import org.apache.olingo.odata2.api.annotation.edm.EdmKey; import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty; import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity; @@ -37,7 +38,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmType; @EdmEntitySet(name = "Buildings") public class Building { @EdmKey - @EdmProperty(type = EdmType.INT32) + @EdmProperty(type = EdmType.INT32, facets = @EdmFacets(nullable = false)) private int id; @EdmProperty private String name; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Employee.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Employee.java b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Employee.java index b8bf457..462a977 100644 --- a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Employee.java +++ b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/Employee.java @@ -38,9 +38,9 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmType; @EdmEntitySet(name = "Employees") public class Employee { @EdmKey - @EdmProperty(name = "EmployeeId", type = EdmType.STRING) + @EdmProperty(name = "EmployeeId", type = EdmType.STRING, facets = @EdmFacets(nullable = false)) private String employeeId; - @EdmProperty(name = "EmployeeName") + @EdmProperty(name = "EmployeeName", facets = @EdmFacets(maxLength = 20)) private String employeeName; @EdmProperty private Integer age; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/RefBase.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/RefBase.java b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/RefBase.java index d0d3edc..cc2169b 100644 --- a/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/RefBase.java +++ b/odata2-annotation-processor/annotation-processor-ref/src/main/java/org/apache/olingo/odata2/annotation/processor/ref/model/RefBase.java @@ -19,6 +19,7 @@ package org.apache.olingo.odata2.annotation.processor.ref.model; import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType; +import org.apache.olingo.odata2.api.annotation.edm.EdmFacets; import org.apache.olingo.odata2.api.annotation.edm.EdmKey; import org.apache.olingo.odata2.api.annotation.edm.EdmProperty; import org.apache.olingo.odata2.api.annotation.edm.EdmType; @@ -30,7 +31,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmType; public abstract class RefBase { @EdmProperty(name = "Name") protected String name; - @EdmProperty(name = "Id", type = EdmType.STRING) + @EdmProperty(name = "Id", type = EdmType.STRING, facets = @EdmFacets(nullable = false)) @EdmKey protected String id; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java ---------------------------------------------------------------------- diff --git a/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java b/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java new file mode 100644 index 0000000..5114594 --- /dev/null +++ b/odata2-annotation-processor/annotation-processor-ref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/MetadataTest.java @@ -0,0 +1,345 @@ +/******************************************************************************* + * 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.odata2.annotation.processor.ref; + +import org.apache.http.HttpResponse; +import org.apache.olingo.odata2.api.commons.HttpContentType; +import org.apache.olingo.odata2.testutil.server.ServletType; +import org.junit.Before; +import org.junit.Test; + +import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists; +import static org.junit.Assert.assertFalse; + +/** + * Tests employing the reference scenario reading the metadata document in XML format + * + */ +public class MetadataTest extends AbstractRefXmlTest { + + public MetadataTest(final ServletType servletType) { + super(servletType); + } + + private static String payload; + + @Before + public void prepare() throws Exception { + payload = getBody(callUri("$metadata")); + } + + @Test + public void metadataDocument() throws Exception { + final HttpResponse response = callUri("$metadata"); + checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8); + assertFalse(getBody(response).isEmpty()); + + notFound("$invalid"); + badRequest("$metadata?$format=atom"); + } + + @Test + public void testGeneral() throws Exception { + assertXpathExists("/edmx:Edmx[@Version='1.0']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices[@m:DataServiceVersion='1.0']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema[@Namespace='RefScenario']", payload); + } + + @Test + public void testEntityTypes() throws Exception { + // Employee + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and @m:HasStream='true']", payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and @m:HasStream='true']/edm:Key", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and " + + "@m:HasStream='true']/edm:Key/edm:PropertyRef[@Name='EmployeeId']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and" + + " @m:HasStream='true']/edm:Property[@Name='EmployeeId' and @Type='Edm.String' and @Nullable='false']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and" + + " @m:HasStream='true']/edm:Property[@Name='EmployeeName' and @Type='Edm.String']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and" + + " @m:HasStream='true']/edm:Property[@Name='Location' and @Type='RefScenario.c_Location']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and " + + "@m:HasStream='true']/edm:Property[@Name='Age' and @Type='Edm.Int32']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and " + + "@m:HasStream='true']/edm:Property[@Name='EntryDate' and @Type='Edm.DateTime' and " + + "@Nullable='true']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and " + + "@m:HasStream='true']/edm:Property[@Name='ImageUrl' and @Type='Edm.String']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and" + + " @m:HasStream='true']/edm:NavigationProperty[@Name='ne_Manager' and " + + "@Relationship='RefScenario.ManagerEmployees' and @FromRole='r_Employee' and @ToRole='r_Manager']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and" + + " @m:HasStream='true']/edm:NavigationProperty[@Name='ne_Team' and " + + "@Relationship='RefScenario.TeamEmployees' and @FromRole='r_Employee' and @ToRole='r_Team']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Employee' and " + + "@m:HasStream='true']/edm:NavigationProperty[@Name='ne_Room' and " + + "@Relationship='RefScenario.r_Employee-r_Room' and @FromRole='r_Employee' and @ToRole='r_Room']", + payload); + + // Team + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Team' and @BaseType='RefScenario.Base']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Team' and " + + "@BaseType='RefScenario.Base']/edm:Property[@Name='IsScrumTeam' and " + + "@Type='Edm.Boolean' and @Nullable='true']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Team' and " + + "@BaseType='RefScenario.Base']/edm:NavigationProperty[@Name='nt_Employees' and " + + "@Relationship='RefScenario.TeamEmployees' and @FromRole='r_Team' and @ToRole='r_Employee']", + payload); + + // Room + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Room' and @BaseType='RefScenario.Base']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Room' and " + + "@BaseType='RefScenario.Base']/edm:Property[@Name='Seats' and @Type='Edm.Int32']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Room' and " + + "@BaseType='RefScenario.Base']/edm:Property[@Name='Version' and @Type='Edm.Int32']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Room' and" + + " @BaseType='RefScenario.Base']/edm:NavigationProperty[@Name='nr_Employees' and " + + "@Relationship='RefScenario.r_Employee-r_Room' and @FromRole='r_Room' and @ToRole='r_Employee']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Room' and " + + "@BaseType='RefScenario.Base']/edm:NavigationProperty[@Name='nr_Building' and " + + "@Relationship='RefScenario.BuildingRooms' and @FromRole='r_Room' and @ToRole='r_Building']", + payload); + + // Manager + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Manager' and " + + "@BaseType='RefScenario.Employee']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Manager' and " + + "@BaseType='RefScenario.Employee']/edm:NavigationProperty[@Name='nm_Employees' and " + + "@Relationship='RefScenario.ManagerEmployees' and @FromRole='r_Manager' and @ToRole='r_Employee']", + payload); + + // Building + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Building']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Building']/edm:Key", payload); + assertXpathExists( "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Building']/edm:Key/edm" + + ":PropertyRef[@Name='Id']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Building']" + + "/edm:Property[@Name='Id' and @Type='Edm.Int32' and @Nullable='false']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Building']" + + "/edm:Property[@Name='Name' and @Type='Edm.String']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Building']/" + + "edm:Property[@Name='Image' and @Type='Edm.Binary']", payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Building']" + + "/edm:NavigationProperty[@Name='nb_Rooms' and @Relationship='RefScenario.BuildingRooms' " + + "and @FromRole='r_Building' and @ToRole='r_Room']", payload); + + // Base + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Base' and @Abstract='true']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Base' and @Abstract='true']/edm:Key", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Base' and @Abstract='true']" + + "/edm:Key/edm:PropertyRef[@Name='Id']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Base' and @Abstract='true']" + + "/edm:Property[@Name='Id' and @Type='Edm.String' and @Nullable='false']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType[@Name='Base' and @Abstract='true']" + + "/edm:Property[@Name='Name' and @Type='Edm.String']",payload); + } + + @Test + public void testComplexTypes() throws Exception { + // Location + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:ComplexType[@Name='c_Location']", payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:ComplexType[@Name='c_Location']/edm:Property[@Name='City' and " + + "@Type='RefScenario.c_City']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:ComplexType[@Name='c_Location']/edm:Property[@Name='Country' " + + "and @Type='Edm.String']", + payload); + + // Location + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:ComplexType[@Name='c_City']", payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:ComplexType[@Name='c_City']/edm:Property[@Name='PostalCode' " + + "and @Type='Edm.String']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:ComplexType[@Name='c_City']/edm:Property[@Name='CityName' " + + "and @Type='Edm.String']", + payload); + } + + @Test + public void testAssociation() throws Exception { + // ManagerEmployees + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='ManagerEmployees']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='ManagerEmployees']" + + "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employee']", payload); + assertXpathExists( "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='ManagerEmployees']" + + "/edm:End[@Type='RefScenario.Manager' and @Multiplicity='1' and @Role='r_Manager']", payload); + + // TeamEmployees + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='TeamEmployees']", payload); + assertXpathExists( "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='TeamEmployees']" + + "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employee']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='TeamEmployees']" + + "/edm:End[@Type='RefScenario.Team' and @Multiplicity='1' and @Role='r_Team']", payload); + + // RoomEmployees + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employee-r_Room']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employee-r_Room']" + + "/edm:End[@Type='RefScenario.Employee' and @Multiplicity='*' and @Role='r_Employee']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='r_Employee-r_Room']" + + "/edm:End[@Type='RefScenario.Room' and @Multiplicity='1' and @Role='r_Room']", payload); + + // BuildingRooms + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='BuildingRooms']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='BuildingRooms']" + + "/edm:End[@Type='RefScenario.Building' and @Multiplicity='1' and @Role='r_Building']", payload); + assertXpathExists("/edmx:Edmx/edmx:DataServices/edm:Schema/edm:Association[@Name='BuildingRooms']" + + "/edm:End[@Type='RefScenario.Room' and @Multiplicity='*' and @Role='r_Room']", payload); + } + + @Test + public void testEntityContainer() throws Exception { + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']", payload); + + // EntitySets + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + + "@m:IsDefaultEntityContainer='true']/edm:EntitySet[@Name='Employees' and " + + "@EntityType='RefScenario.Employee']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:EntitySet[@Name='Teams' and @EntityType='RefScenario.Team']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:EntitySet[@Name='Rooms' and @EntityType='RefScenario.Room']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:EntitySet[@Name='Managers' and @EntityType='RefScenario.Manager']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + + "@m:IsDefaultEntityContainer='true']/edm:EntitySet[@Name='Buildings' and " + + "@EntityType='RefScenario.Building']", + payload); + + // AssociationSets + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='ManagerEmployees' and " + + "@Association='RefScenario.ManagerEmployees']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='ManagerEmployees' and " + + "@Association='RefScenario.ManagerEmployees']/edm:End[@EntitySet='Managers' and @Role='r_Manager']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='ManagerEmployees' and " + + "@Association='RefScenario.ManagerEmployees']/edm:End[@EntitySet='Employees' and @Role='r_Employee']", + payload); + + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='TeamEmployees' and " + + "@Association='RefScenario.TeamEmployees']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='TeamEmployees' and " + + "@Association='RefScenario.TeamEmployees']/edm:End[@EntitySet='Teams' and @Role='r_Team']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='TeamEmployees' and " + + "@Association='RefScenario.TeamEmployees']/edm:End[@EntitySet='Employees' and @Role='r_Employee']", + payload); + + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employee-r_Room' and " + + "@Association='RefScenario.r_Employee-r_Room']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employee-r_Room' and " + + "@Association='RefScenario.r_Employee-r_Room']/edm:End[@EntitySet='Rooms' and @Role='r_Room']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='r_Employee-r_Room' and " + + "@Association='RefScenario.r_Employee-r_Room']/edm:End[@EntitySet='Employees' and @Role='r_Employee']", + payload); + + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='BuildingRooms' and " + + "@Association='RefScenario.BuildingRooms']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='BuildingRooms' and " + + "@Association='RefScenario.BuildingRooms']/edm:End[@EntitySet='Buildings' and @Role='r_Building']", + payload); + assertXpathExists( + "/edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityContainer[@Name='DefaultContainer' and " + + "@m:IsDefaultEntityContainer='true']/edm:AssociationSet[@Name='BuildingRooms' and " + + "@Association='RefScenario.BuildingRooms']/edm:End[@EntitySet='Rooms' and @Role='r_Room']", + payload); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java index b30a504..f22eca6 100644 --- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java +++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java @@ -376,7 +376,7 @@ public class JPAEdmFunctionImportTest extends JPAEdmTestModelView { facets = funcImpParamList.get(1).getFacets(); assertNotNull(facets); - assertEquals(false, facets.isNullable()); + assertEquals(true, facets.isNullable()); assertEquals(10, facets.getPrecision().intValue()); assertEquals(2, facets.getScale().intValue()); @@ -399,7 +399,7 @@ public class JPAEdmFunctionImportTest extends JPAEdmTestModelView { EdmFacets facets = funcImpParamList.get(0).getFacets(); assertNotNull(facets); assertNull(facets.getMaxLength()); - assertEquals(false, facets.isNullable()); + assertEquals(true, facets.isNullable()); assertNull(facets.getPrecision()); assertNull(facets.getScale()); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ffe51503/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java index d220812..4ad0514 100644 --- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java +++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java @@ -56,9 +56,9 @@ public @interface EdmFacets { /** * The information if the type in use is nullable. - * The default value for nullable is <code>false</code>. + * The default value for nullable is <code>true</code>. * * @return <code>true</code> if the type in use is nullable, <code>false</code> otherwise. */ - boolean nullable() default false; + boolean nullable() default true; }
