Java Code Examples for org.apache.olingo.commons.api.edm.provider.CsdlEntityType#setKey()
The following examples show how to use
org.apache.olingo.commons.api.edm.provider.CsdlEntityType#setKey() .
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 navigationProperty() 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()); when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty(); propertyProvider.setType(entityTypeName); propertyProvider.setNullable(false); EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider); assertFalse(property.isCollection()); assertFalse(property.isNullable()); EdmType type = property.getType(); assertEquals(EdmTypeKind.ENTITY, type.getKind()); assertEquals("ns", type.getNamespace()); assertEquals("entity", type.getName()); assertNull(property.getReferencingPropertyName("referencedPropertyName")); assertNull(property.getPartner()); assertFalse(property.containsTarget()); // Test caching EdmType cachedType = property.getType(); assertTrue(type == cachedType); }
Example 2
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 3
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 4
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 5
Source File: DemoEdmProvider.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if(entityTypeName.equals(ET_PRODUCT_FQN)){ //create EntityType properties CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create CsdlPropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name , description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 6
Source File: DemoEdmProvider.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if(ET_PRODUCT_FQN.equals(entityTypeName)){ //create EntityType properties CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create PropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 7
Source File: DemoEdmProvider.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if(ET_PRODUCT_FQN.equals(entityTypeName)){ //create EntityType properties CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create PropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 8
Source File: DemoEdmProvider.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if(ET_PRODUCT_FQN.equals(entityTypeName)){ //create EntityType properties CsdlProperty id = new CsdlProperty().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName("Name") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName("Description") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create PropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 9
Source File: DemoEdmProvider.java From cxf with Apache License 2.0 | 5 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if (entityTypeName.equals(ET_PRODUCT_FQN)) { //create EntityType properties CsdlProperty id = new CsdlProperty() .setName("ID") .setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty() .setName("Name") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty() .setName("Description") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create CsdlPropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 10
Source File: DemoEdmProvider.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if(entityTypeName.equals(ET_PRODUCT_FQN)){ //create EntityType properties CsdlProperty id = new CsdlProperty().setName("ID") .setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName("Name") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName("Description") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create CsdlPropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 11
Source File: DemoEdmProvider.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if (ET_PRODUCT_FQN.equals(entityTypeName)) { // create EntityType properties CsdlProperty id = new CsdlProperty().setName("ID").setType( EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName("Name").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName("Description").setType( EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create PropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 12
Source File: DemoEdmProvider.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if(entityTypeName.equals(ET_PRODUCT_FQN)){ //create EntityType properties CsdlProperty id = new CsdlProperty().setName("ID") .setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName("Name") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName("Description") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create CsdlPropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 13
Source File: DemoEdmProvider.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if(ET_PRODUCT_FQN.equals(entityTypeName)){ //create EntityType properties CsdlProperty id = new CsdlProperty().setName("ID") .setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName("Name") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName("Description") .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); // create PropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName("ID"); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 14
Source File: ProductsEdmProvider.java From syndesis with Apache License 2.0 | 5 votes |
@Override public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) { // this method is called for one of the EntityTypes that are configured in the Schema if (entityTypeName.equals(ET_PRODUCT_FQN)) { //create EntityType properties CsdlProperty id = new CsdlProperty().setName(PRODUCT_ID).setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName()); CsdlProperty name = new CsdlProperty().setName(PRODUCT_NAME).setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty description = new CsdlProperty().setName(PRODUCT_DESCRIPTION).setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); CsdlProperty serialNums = new CsdlProperty() .setName(PRODUCT_SERIALS) .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()) .setCollection(true); CsdlProperty specification = new CsdlProperty() .setName(PRODUCT_SPEC) .setType(ET_SPEC_FQN); // create CsdlPropertyRef for Key element CsdlPropertyRef propertyRef = new CsdlPropertyRef(); propertyRef.setName(PRODUCT_ID); // configure EntityType CsdlEntityType entityType = new CsdlEntityType(); entityType.setName(ET_PRODUCT_NAME); entityType.setProperties(Arrays.asList(id, name, description, serialNums, specification)); entityType.setKey(Collections.singletonList(propertyRef)); return entityType; } return null; }
Example 15
Source File: EdmNavigationPropertyImplTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void navigationPropertyWithReferntialConstraint() 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()); when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty(); propertyProvider.setType(entityTypeName); propertyProvider.setNullable(false); propertyProvider.setContainsTarget(true); List<CsdlReferentialConstraint> referentialConstraints = new ArrayList<CsdlReferentialConstraint>(); referentialConstraints.add(new CsdlReferentialConstraint().setProperty("property").setReferencedProperty( "referencedProperty")); propertyProvider.setReferentialConstraints(referentialConstraints); EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider); assertEquals("property", property.getReferencingPropertyName("referencedProperty")); assertNull(property.getReferencingPropertyName("wrong")); assertTrue(property.containsTarget()); assertNotNull(property.getReferentialConstraints()); List<EdmReferentialConstraint> edmReferentialConstraints = property.getReferentialConstraints(); assertEquals(1, edmReferentialConstraints.size()); assertTrue(edmReferentialConstraints == property.getReferentialConstraints()); }
Example 16
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)); }
Example 17
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 18
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); }