Java Code Examples for org.apache.olingo.odata2.api.edm.EdmEntityContainer#getEntitySets()
The following examples show how to use
org.apache.olingo.odata2.api.edm.EdmEntityContainer#getEntitySets() .
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: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void testMetadataWithNavigatons() throws XMLStreamException, EntityProviderException, EdmException, IOException { XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); String xml = readFile("metadataWithNavigations.xml"); InputStream reader = createStreamReader(xml); EdmDataServices result = parser.readMetadata(reader, true); assertEquals(2, result.getEdm().getSchemas().size()); ClientEdm edm = result.getEdm(); assertNotNull(edm); for (EdmSchema schema : result.getEdm().getSchemas()) { for (EdmEntityContainer container : schema.getEntityContainers()) { assertNotNull(container.getEntitySets()); int i=0; for(EdmEntitySet entitySet:container.getEntitySets()){ assertEquals(edm.getSchemas().get(1).getEntityTypes().get(i).getName(), entitySet.getEntityType().getName()); assertEquals(edm.getSchemas().get(1).getEntityTypes().get(i++).getKeyProperties().get(0), entitySet.getEntityType().getKeyProperties().get(0)); } } } }
Example 2
Source File: XmlMetadataAssociationTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void testRelatedEntitySet() throws XMLStreamException, EntityProviderException, EdmException, UnsupportedEncodingException { XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream content = createStreamReader(xmlWithAssociation); EdmDataServices result = parser.readMetadata(content, true); for (EdmSchema schema : result.getEdm().getSchemas()) { for (EdmEntityContainer container : schema.getEntityContainers()) { assertEquals(NAMESPACE2, schema.getNamespace()); assertEquals("Container1", container.getName()); assertEquals(Boolean.TRUE, container.isDefaultEntityContainer()); for (EdmEntitySet entitySet : container.getEntitySets()) { assertNotNull(entitySet.getEntityContainer()); for (EdmEntityType entityType : result.getEdm().getSchemas().get(0).getEntityTypes()) { for (String navigationPropertyName : entityType.getNavigationPropertyNames()) { EdmNavigationProperty navigationProperty = (EdmNavigationProperty) entityType .getProperty(navigationPropertyName); if(entitySet.getName().equals("Managers") && navigationProperty.getName().equals("nm_Employees")){ assertNotNull(entitySet.getRelatedEntitySet(navigationProperty)); } } } } } } }
Example 3
Source File: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void testEntitySet() throws XMLStreamException, EntityProviderException, EdmException, UnsupportedEncodingException { final String xmWithEntityContainer = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\" m:HasStream=\"true\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<Property Name=\"" + propertyNames[1] + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>" + "</EntityType>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">" + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream reader = createStreamReader(xmWithEntityContainer); EdmDataServices result = parser.readMetadata(reader, true); assertEquals("Container1", result.getEdm().getEntityContainer("Container1").getName()); for (EdmSchema schema : result.getEdm().getSchemas()) { for (EdmEntityContainer container : schema.getEntityContainers()) { assertEquals("Container1", container.getName()); assertEquals(Boolean.TRUE, container.isDefaultEntityContainer()); for (EdmEntitySet entitySet : container.getEntitySets()) { assertEquals("Employees", entitySet.getName()); assertEquals("Employee", entitySet.getEntityType().getName()); assertEquals(NAMESPACE, entitySet.getEntityType().getNamespace()); } } } }
Example 4
Source File: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void testEntityTypeInOtherSchema() throws XMLStreamException, EntityProviderException, EdmException, UnsupportedEncodingException { final String xmWithEntityContainer = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\" m:HasStream=\"true\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "</EntityType>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">" + "<EntitySet Name=\"Photos\" EntityType=\"" + NAMESPACE2 + ".Photo\"/>" + "</EntityContainer>" + "</Schema>" + "<Schema Namespace=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Photo\">" + "<Key><PropertyRef Name=\"Id\"/></Key>" + "<Property Name=\"Id\" Type=\"Edm.Int32\" Nullable=\"false\"/>" + "</EntityType>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream reader = createStreamReader(xmWithEntityContainer); EdmDataServices result = parser.readMetadata(reader, true); assertEquals("2.0", result.getDataServiceVersion()); for (EdmSchema schema : result.getEdm().getSchemas()) { for (EdmEntityContainer container : schema.getEntityContainers()) { assertEquals("Container1", container.getName()); for (EdmEntitySet entitySet : container.getEntitySets()) { assertEquals(NAMESPACE2, entitySet.getEntityType().getNamespace()); assertEquals("Photo", entitySet.getEntityType().getName()); } } } }
Example 5
Source File: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Test public void testMetadataRelatedEntitySet() throws XMLStreamException, EntityProviderException, EdmException, IOException { XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); String xml = readFile("metadataForRelatedEntity.xml"); InputStream reader = createStreamReader(xml); EdmDataServices result = parser.readMetadata(reader, true); assertEquals(1, result.getEdm().getSchemas().size()); ClientEdm edm = result.getEdm(); assertNotNull(edm); for (EdmSchema schema : result.getEdm().getSchemas()) { for (EdmEntityContainer container : schema.getEntityContainers()) { if (container.getName().equals("CUAN_BUSINESS_DOCUMENT_IMP_SRV_Entities")) { assertEquals("CUAN_BUSINESS_DOCUMENT_IMP_SRV_Entities", container.getName()); for (EdmEntitySet entitySet : container.getEntitySets()) { for(EdmEntityType entityType:schema.getEntityTypes()){ List<String> navigationPropertyNames = entityType.getNavigationPropertyNames(); for (String navigationPropertyName : navigationPropertyNames) { EdmNavigationProperty navigationProperty = (EdmNavigationProperty) entityType .getProperty(navigationPropertyName); if(((navigationProperty.getName().equals("BusinessDocuments") && ("ImportHeaders").equals(entitySet.getName())) || (((navigationProperty.getName().equals("ProductItems") || navigationProperty.getName().equals("Offers") || navigationProperty.getName().equals("Company") || navigationProperty.getName().equals("AdditionalObjectReferences") || navigationProperty.getName().equals("Person")) && ("BusinessDocuments").equals(entitySet.getName())))) && !navigationProperty.getName().equals(entitySet.getName()) ){ assertNotNull(entitySet.getRelatedEntitySet(navigationProperty)); }else{ assertNull(entitySet.getRelatedEntitySet(navigationProperty)); } } } } } } } }
Example 6
Source File: XmlMetadataAssociationTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Test public void testRelatedEntitySetWithCyclicAssociation() throws Exception { final String employees = "r_Employees"; final String manager = "r_Manager"; final String xmlWithInvalidAssociationSetEnd = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\" " + "xmlns:sap=\"http://www.sap.com/Protocols/SAPData\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\"" + employees + "\" ToRole=\"" + manager + "\" />" + "</EntityType>" + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">" + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\"" + manager + "\" ToRole=\"" + employees + "\" />" + "</EntityType>" + "<Association Name=\"" + ASSOCIATION + "\">" + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"" + employees + "\"/>" + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"" + manager + "\"/>" + "</Association>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">" + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>" + "<EntitySet Name=\"Managers\" EntityType=\"RefScenario.Manager\"/>" + "<AssociationSet Name=\"" + ASSOCIATION + "\" Association=\"RefScenario." + ASSOCIATION + "\" " + "sap:creatable=\"true\" sap:updatable=\"true\" " + "sap:deletable=\"false\">" + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "<End EntitySet=\"Employees\" Role=\"" + employees + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream reader = createStreamReader(xmlWithInvalidAssociationSetEnd); EdmDataServices result = parser.readMetadata(reader, true); List<String> annotationList = new ArrayList<String>(); annotationList.add("creatable"); annotationList.add("updatable"); annotationList.add("deletable"); for (EdmSchema schema : result.getEdm().getSchemas()) { for (EdmEntityContainer container : schema.getEntityContainers()) { for (EdmEntitySet entitySet : container.getEntitySets()) { for(EdmEntityType entityType:schema.getEntityTypes()){ List<String> navigationPropertyNames = entityType.getNavigationPropertyNames(); for (String navigationPropertyName : navigationPropertyNames) { EdmNavigationProperty navigationProperty = (EdmNavigationProperty) entityType .getProperty(navigationPropertyName); if((entitySet.getName().equals("Managers") && navigationProperty.getName().equals("nm_Employees")) || entitySet.getName().equals("Employees") && navigationProperty.getName().equals("ne_Manager") ){ assertNotNull(entitySet.getRelatedEntitySet(navigationProperty)); }else{ assertNull(entitySet.getRelatedEntitySet(navigationProperty)); } } } } } } }