Java Code Examples for org.apache.olingo.commons.api.edm.provider.CsdlEntityType#setNavigationProperties()
The following examples show how to use
org.apache.olingo.commons.api.edm.provider.CsdlEntityType#setNavigationProperties() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EdmNavigationPropertyImplTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void navigationPropertyWithPartner() throws Exception { CsdlEdmProvider provider = mock(CsdlEdmProvider.class); EdmProviderImpl edm = new EdmProviderImpl(provider); final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); CsdlEntityType entityTypeProvider = new CsdlEntityType(); entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList()); List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>(); navigationProperties.add(new CsdlNavigationProperty().setName("partnerName").setType(entityTypeName)); entityTypeProvider.setNavigationProperties(navigationProperties); when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty(); propertyProvider.setType(entityTypeName); propertyProvider.setNullable(false); propertyProvider.setPartner("partnerName"); EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider); EdmNavigationProperty partner = property.getPartner(); assertNotNull(partner); // Caching assertTrue(partner == property.getPartner()); }
Example 2
Source File: EdmNavigationPropertyImplTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test(expected = EdmException.class) public void navigationPropertyWithNonexistentPartner() throws Exception { CsdlEdmProvider provider = mock(CsdlEdmProvider.class); EdmProviderImpl edm = new EdmProviderImpl(provider); final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); CsdlEntityType entityTypeProvider = new CsdlEntityType(); entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList()); List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>(); navigationProperties.add(new CsdlNavigationProperty().setName("partnerName").setType(entityTypeName)); entityTypeProvider.setNavigationProperties(navigationProperties); when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty(); propertyProvider.setType(entityTypeName); propertyProvider.setNullable(false); propertyProvider.setPartner("wrong"); EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider); property.getPartner(); }
Example 3
Source File: MetadataParser.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void readEntityType(XMLEventReader reader, StartElement element, CsdlSchema schema) throws XMLStreamException { CsdlEntityType entityType = new CsdlEntityType(); entityType.setProperties(new ArrayList<CsdlProperty>()); entityType.setNavigationProperties(new ArrayList<CsdlNavigationProperty>()); entityType.setKey(new ArrayList<CsdlPropertyRef>()); entityType.setName(attr(element, "Name")); if (attr(element, "BaseType") != null) { entityType.setBaseType(new FullQualifiedName(attr(element, "BaseType"))); } entityType.setAbstract(Boolean.parseBoolean(attr(element, "Abstract"))); entityType.setOpenType(Boolean.parseBoolean(attr(element, "OpenType"))); entityType.setHasStream(Boolean.parseBoolean(attr(element, "HasStream"))); readEntityProperties(reader, entityType); schema.getEntityTypes().add(entityType); }
Example 4
Source File: EdmEntityTypeImplTest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Before public void setupTypes() throws Exception { CsdlEdmProvider provider = mock(CsdlEdmProvider.class); EdmProviderImpl edm = new EdmProviderImpl(provider); FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName"); CsdlEntityType baseType = new CsdlEntityType(); baseType.setName(baseName.getName()); List<CsdlProperty> properties = new ArrayList<CsdlProperty>(); properties.add(new CsdlProperty().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); properties.add(new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); baseType.setProperties(properties); List<CsdlPropertyRef> key = new ArrayList<CsdlPropertyRef>(); key.add(new CsdlPropertyRef().setName("Id")); baseType.setKey(key); List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>(); navigationProperties.add(new CsdlNavigationProperty().setName("nav1")); baseType.setNavigationProperties(navigationProperties); when(provider.getEntityType(baseName)).thenReturn(baseType); this.baseType = new EdmEntityTypeImpl(edm, baseName, baseType); FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName"); CsdlEntityType type = new CsdlEntityType(); type.setName(typeName.getName()); type.setBaseType(baseName); List<CsdlProperty> typeProperties = new ArrayList<CsdlProperty>(); typeProperties.add(new CsdlProperty().setName("address").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName())); typeProperties.add(new CsdlProperty().setName("email").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName())); type.setProperties(typeProperties); List<CsdlNavigationProperty> typeNavigationProperties = new ArrayList<CsdlNavigationProperty>(); typeNavigationProperties.add(new CsdlNavigationProperty().setName("nav2")); type.setNavigationProperties(typeNavigationProperties); when(provider.getEntityType(typeName)).thenReturn(type); typeWithBaseType = new EdmEntityTypeImpl(edm, typeName, type); FullQualifiedName typeWithComplexKeyName = new FullQualifiedName("namespace", "typeName"); CsdlEntityType typeWithComplexKeyProvider = new CsdlEntityType(); typeWithComplexKeyProvider.setName(typeWithComplexKeyName.getName()); List<CsdlProperty> typeWithComplexKeyProperties = new ArrayList<CsdlProperty>(); typeWithComplexKeyProperties.add(new CsdlProperty().setName("Id").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName())); List<CsdlProperty> complexTypeProperties = new ArrayList<CsdlProperty>(); complexTypeProperties.add(new CsdlProperty().setName("ComplexPropName").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName())); FullQualifiedName complexTypeName = new FullQualifiedName("namespace", "complexTypeName"); when(provider.getComplexType(complexTypeName)).thenReturn( new CsdlComplexType().setName("complexTypeName").setProperties(complexTypeProperties)); typeWithComplexKeyProperties.add(new CsdlProperty().setName("Comp").setType(complexTypeName)); typeWithComplexKeyProvider.setProperties(typeWithComplexKeyProperties); List<CsdlPropertyRef> keyForTypeWithComplexKey = new ArrayList<CsdlPropertyRef>(); keyForTypeWithComplexKey.add(new CsdlPropertyRef().setName("Id")); keyForTypeWithComplexKey.add(new CsdlPropertyRef().setName("Comp/ComplexPropName").setAlias("alias")); typeWithComplexKeyProvider.setKey(keyForTypeWithComplexKey); when(provider.getEntityType(typeWithComplexKeyName)).thenReturn(typeWithComplexKeyProvider); typeWithComplexKey = new EdmEntityTypeImpl(edm, typeWithComplexKeyName, typeWithComplexKeyProvider); }
Example 5
Source File: EdmEntityTypeImplTest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Test public void testAbstractBaseTypeWithoutKey() throws Exception { CsdlEdmProvider provider = mock(CsdlEdmProvider.class); EdmProviderImpl edm = new EdmProviderImpl(provider); FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName"); CsdlEntityType baseType = new CsdlEntityType(); baseType.setName(baseName.getName()); List<CsdlProperty> properties = new ArrayList<CsdlProperty>(); properties.add(new CsdlProperty().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); properties.add(new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); baseType.setProperties(properties); List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>(); navigationProperties.add(new CsdlNavigationProperty().setName("nav1")); baseType.setNavigationProperties(navigationProperties); when(provider.getEntityType(baseName)).thenReturn(baseType); baseType.setAbstract(true); EdmEntityType edmAbstarctBaseType = new EdmEntityTypeImpl(edm, baseName, baseType); assertEquals(2, edmAbstarctBaseType.getPropertyNames().size()); assertEquals("Id", edmAbstarctBaseType.getPropertyNames().get(0)); assertEquals("Name", edmAbstarctBaseType.getPropertyNames().get(1)); FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName"); CsdlEntityType type = new CsdlEntityType(); type.setName(typeName.getName()); type.setBaseType(baseName); List<CsdlProperty> typeProperties = new ArrayList<CsdlProperty>(); typeProperties.add(new CsdlProperty().setName("address").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName())); typeProperties.add(new CsdlProperty().setName("email").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName())); type.setProperties(typeProperties); List<CsdlPropertyRef> key = new ArrayList<CsdlPropertyRef>(); key.add(new CsdlPropertyRef().setName("email")); type.setKey(key); List<CsdlNavigationProperty> typeNavigationProperties = new ArrayList<CsdlNavigationProperty>(); typeNavigationProperties.add(new CsdlNavigationProperty().setName("nav2")); type.setNavigationProperties(typeNavigationProperties); when(provider.getEntityType(typeName)).thenReturn(type); EdmEntityType edmType = new EdmEntityTypeImpl(edm, typeName, type); assertNotNull(edmType.getBaseType()); 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)); }
Example 6
Source File: EdmEntityTypeImplTest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Test public void testAbstractBaseTypeWithtKey() throws Exception { CsdlEdmProvider provider = mock(CsdlEdmProvider.class); EdmProviderImpl edm = new EdmProviderImpl(provider); FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName"); CsdlEntityType baseType = new CsdlEntityType(); baseType.setName(baseName.getName()); List<CsdlProperty> properties = new ArrayList<CsdlProperty>(); properties.add(new CsdlProperty().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); properties.add(new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); baseType.setProperties(properties); List<CsdlPropertyRef> key = new ArrayList<CsdlPropertyRef>(); key.add(new CsdlPropertyRef().setName("Id")); baseType.setKey(key); List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>(); navigationProperties.add(new CsdlNavigationProperty().setName("nav1")); baseType.setNavigationProperties(navigationProperties); when(provider.getEntityType(baseName)).thenReturn(baseType); baseType.setAbstract(true); EdmEntityType edmAbstarctBaseType = new EdmEntityTypeImpl(edm, baseName, baseType); FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName"); CsdlEntityType type = new CsdlEntityType(); type.setName(typeName.getName()); type.setBaseType(baseName); List<CsdlProperty> typeProperties = new ArrayList<CsdlProperty>(); typeProperties.add(new CsdlProperty().setName("address").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName())); typeProperties.add(new CsdlProperty().setName("email").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName())); type.setProperties(typeProperties); List<CsdlNavigationProperty> typeNavigationProperties = new ArrayList<CsdlNavigationProperty>(); typeNavigationProperties.add(new CsdlNavigationProperty().setName("nav2")); type.setNavigationProperties(typeNavigationProperties); when(provider.getEntityType(typeName)).thenReturn(type); EdmEntityType edmType = new EdmEntityTypeImpl(edm, typeName, type); assertNotNull(edmType.getBaseType()); 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)); }