@Test(expected = EdmException.class) public void testInvalidAssociationEnd2() throws XMLStreamException, EntityProviderException, EdmException, UnsupportedEncodingException { 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 + "\">" + "<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=\"RefScenario2." + ASSOCIATION + "\">" + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream reader = createStreamReader(xmlWithInvalidAssociationSetEnd); parser.readMetadata(reader, true); }
public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
XmlMetadataDeserializer { public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } } }
XmlMetadataDeserializer { public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  }
XmlMetadataDeserializer { public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  EdmDataServices readMetadata(final InputStream content, final boolean validate); }
XmlMetadataDeserializer { public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  EdmDataServices readMetadata(final InputStream content, final boolean validate);  }