diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java index bfc31e6c7..5ad7e99ba 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImpl.java @@ -72,7 +72,8 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType { if (baseTypeName != null) { baseType = buildBaseType(baseTypeName); } - if (baseType == null) { + if (baseType == null + || (baseType.isAbstract() && ((AbstractEdmEntityType) baseType).getKeyPropertyRefs().size() == 0)) { entityBaseType = null; final List key = entityType.getKey(); diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java index ddc9c2834..7ba846e1a 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java @@ -116,7 +116,112 @@ public class EdmEntityTypeImplTest { typeWithComplexKey = EdmEntityTypeImpl.getInstance(edm, typeWithComplexKeyName, typeWithComplexKeyProvider); } + + @Test + public void testAbstractBaseTypeWithoutKey() throws Exception { + EdmProvider provider = mock(EdmProvider.class); + EdmProviderImpl edm = new EdmProviderImpl(provider); + FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName"); + EntityType baseType = new EntityType(); + baseType.setName(baseName.getName()); + List properties = new ArrayList(); + properties.add(new Property().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + properties.add(new Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + baseType.setProperties(properties); + List navigationProperties = new ArrayList(); + navigationProperties.add(new NavigationProperty().setName("nav1")); + baseType.setNavigationProperties(navigationProperties); + when(provider.getEntityType(baseName)).thenReturn(baseType); + baseType.setAbstract(true); + EdmEntityType edmAbstarctBaseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType); + + FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName"); + EntityType type = new EntityType(); + type.setName(typeName.getName()); + type.setBaseType(baseName); + List typeProperties = new ArrayList(); + typeProperties.add(new Property().setName("address").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + typeProperties.add(new Property().setName("email").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + type.setProperties(typeProperties); + List key = new ArrayList(); + key.add(new PropertyRef().setPropertyName("email")); + type.setKey(key); + List typeNavigationProperties = new ArrayList(); + typeNavigationProperties.add(new NavigationProperty().setName("nav2")); + type.setNavigationProperties(typeNavigationProperties); + when(provider.getEntityType(typeName)).thenReturn(type); + + EdmEntityType edmType = EdmEntityTypeImpl.getInstance(edm, typeName, type); + + assertEquals(2, edmAbstarctBaseType.getPropertyNames().size()); + + assertEquals(1, edmType.getKeyPropertyRefs().size()); + assertEquals("email", edmType.getKeyPredicateNames().get(0)); + + assertEquals(4, edmType.getPropertyNames().size()); + assertEquals("Id", edmType.getPropertyNames().get(0)); + assertEquals("Name", edmType.getPropertyNames().get(1)); + assertEquals("address", edmType.getPropertyNames().get(2)); + assertEquals("email", edmType.getPropertyNames().get(3)); + + assertEquals(2, edmType.getNavigationPropertyNames().size()); + assertEquals("nav1", edmType.getNavigationPropertyNames().get(0)); + assertEquals("nav2", edmType.getNavigationPropertyNames().get(1)); + } + + @Test + public void testAbstractBaseTypeWithtKey() throws Exception { + EdmProvider provider = mock(EdmProvider.class); + EdmProviderImpl edm = new EdmProviderImpl(provider); + + FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName"); + EntityType baseType = new EntityType(); + baseType.setName(baseName.getName()); + List properties = new ArrayList(); + properties.add(new Property().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + properties.add(new Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + baseType.setProperties(properties); + List key = new ArrayList(); + key.add(new PropertyRef().setPropertyName("Id")); + baseType.setKey(key); + List navigationProperties = new ArrayList(); + navigationProperties.add(new NavigationProperty().setName("nav1")); + baseType.setNavigationProperties(navigationProperties); + when(provider.getEntityType(baseName)).thenReturn(baseType); + baseType.setAbstract(true); + EdmEntityType edmAbstarctBaseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType); + + FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName"); + EntityType type = new EntityType(); + type.setName(typeName.getName()); + type.setBaseType(baseName); + List typeProperties = new ArrayList(); + typeProperties.add(new Property().setName("address").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + typeProperties.add(new Property().setName("email").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); + type.setProperties(typeProperties); + List typeNavigationProperties = new ArrayList(); + typeNavigationProperties.add(new NavigationProperty().setName("nav2")); + type.setNavigationProperties(typeNavigationProperties); + when(provider.getEntityType(typeName)).thenReturn(type); + EdmEntityType edmType = EdmEntityTypeImpl.getInstance(edm, typeName, type); + + assertEquals(2, edmAbstarctBaseType.getPropertyNames().size()); + + assertEquals(1, edmType.getKeyPropertyRefs().size()); + assertEquals("Id", edmType.getKeyPredicateNames().get(0)); + + assertEquals(4, edmType.getPropertyNames().size()); + assertEquals("Id", edmType.getPropertyNames().get(0)); + assertEquals("Name", edmType.getPropertyNames().get(1)); + assertEquals("address", edmType.getPropertyNames().get(2)); + assertEquals("email", edmType.getPropertyNames().get(3)); + + assertEquals(2, edmType.getNavigationPropertyNames().size()); + assertEquals("nav1", edmType.getNavigationPropertyNames().get(0)); + assertEquals("nav2", edmType.getNavigationPropertyNames().get(1)); + } + @Test public void hasStream() { assertFalse(typeWithBaseType.hasStream());