org.apache.olingo.odata2.api.edm.Edm Java Examples
The following examples show how to use
org.apache.olingo.odata2.api.edm.Edm.
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: JsonFeedEntitySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected=EntityProviderException.class) public void unbalancedPropertyEntryWithoutKeyWithEmptyInlineFeedIncludingMetadata() throws Exception { Edm edm = MockFacade.getMockEdm(); EdmTyped imageUrlProperty = edm.getEntityType("RefScenario", "Employee").getProperty("ImageUrl"); EdmFacets facets = mock(EdmFacets.class); when(facets.getMaxLength()).thenReturn(1); when(((EdmProperty) imageUrlProperty).getFacets()).thenReturn(facets); Entity roomData = new Entity(); roomData.addProperty("Name", "Neu Schwanstein"); roomData.addProperty("Seats", new Integer(20)); roomData.setWriteProperties(EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)) .includeMetadata(true).build()); EntityCollection innerData = new EntityCollection(); roomData.addNavigation("nr_Employees", innerData); EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Rooms"); new JsonSerializerDeserializer().writeEntry(entitySet, roomData); }
Example #2
Source File: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected = EntityProviderException.class) public void testComplexTypeWithInvalidBaseType2() throws XMLStreamException, EntityProviderException, EdmException, UnsupportedEncodingException { final String xml = "<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[2] + "\" Type=\"RefScenario.c_Location\" Nullable=\"false\"/>" + "</EntityType>" + "<ComplexType Name=\"c_BaseType_for_Location\" Abstract=\"true\">" + "<Property Name=\"Country\" Type=\"Edm.String\"/>" + "</ComplexType>" + "<ComplexType Name=\"c_Location\" BaseType=\"c_BaseType_for_Location\">" + "</ComplexType>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream reader = createStreamReader(xml); parser.readMetadata(reader, true); }
Example #3
Source File: ServiceTicketODataConsumer.java From C4CODATAAPIDEVGUIDE with Apache License 2.0 | 6 votes |
private Edm readEdm() throws EntityProviderException, IllegalStateException, IOException { // This is used for both setting the Edm and CSRF Token :) if (m_edm != null) { return m_edm; } String serviceUrl = new StringBuilder(getODataServiceUrl()) .append(SEPARATOR).append(METADATA).toString(); logger.info("Metadata url => " + serviceUrl); final HttpGet get = new HttpGet(serviceUrl); get.setHeader(AUTHORIZATION_HEADER, getAuthorizationHeader()); get.setHeader(CSRF_TOKEN_HEADER, CSRF_TOKEN_FETCH); HttpResponse response = getHttpClient().execute(get); m_csrfToken = response.getFirstHeader(CSRF_TOKEN_HEADER).getValue(); logger.info("CSRF token => " + m_csrfToken); m_edm = EntityProvider.readMetadata(response.getEntity().getContent(), false); return m_edm; }
Example #4
Source File: AtomServiceDocumentConsumer.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private CommonAttributesImpl parseCommonAttribute(final XMLStreamReader reader) { CommonAttributesImpl attribute = new CommonAttributesImpl(); List<ExtensionAttribute> extAttributes = new ArrayList<ExtensionAttribute>(); attribute.setBase(reader.getAttributeValue(null, FormatXml.XML_BASE)); attribute.setLang(reader.getAttributeValue(null, FormatXml.XML_LANG)); for (int i = 0; i < reader.getAttributeCount(); i++) { if (!(FormatXml.XML_BASE.equals(reader.getAttributeLocalName(i)) && Edm.PREFIX_XML.equals(reader.getAttributePrefix(i)) || (FormatXml.XML_LANG.equals(reader.getAttributeLocalName(i)) && Edm.PREFIX_XML.equals(reader .getAttributePrefix(i))) || ("local".equals(reader.getAttributeNamespace(i)) || DEFAULT_PREFIX.equals(reader.getAttributePrefix(i))))) { extAttributes.add(new ExtensionAttributeImpl() .setName(reader.getAttributeLocalName(i)) .setNamespace(reader.getAttributeNamespace(i)) .setPrefix(reader.getAttributePrefix(i)) .setText(reader.getAttributeValue(i))); } } return attribute.setAttributes(extAttributes); }
Example #5
Source File: XmlPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void readComplexPropertyWithoutTypeAttribute() throws Exception { String xml = "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Country>Germany</Country>" + "<City m:type=\"RefScenario.c_City\">" + "<PostalCode>69124</PostalCode>" + "<CityName>Heidelberg</CityName>" + "</City>" + "</Location>"; XMLStreamReader reader = createReaderForTest(xml, true); final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location"); Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, null); Map<String, Object> locationMap = (Map<String, Object>) resultMap.get("Location"); assertEquals("Germany", locationMap.get("Country")); Map<String, Object> cityMap = (Map<String, Object>) locationMap.get("City"); assertEquals("69124", cityMap.get("PostalCode")); assertEquals("Heidelberg", cityMap.get("CityName")); }
Example #6
Source File: JsonEntryEntitySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeWithoutFacetsValidation() throws Exception { Edm edm = MockFacade.getMockEdm(); EdmTyped roomNameProperty = edm.getEntityType("RefScenario", "Room").getProperty("Name"); EdmFacets facets = mock(EdmFacets.class); when(facets.getMaxLength()).thenReturn(3); when(((EdmProperty) roomNameProperty).getFacets()).thenReturn(facets); EdmEntitySet entitySet = edm.getDefaultEntityContainer().getEntitySet("Rooms"); String name = "1234567890"; Entity roomData = new Entity(); roomData.addProperty("Id", "4711"); roomData.addProperty("Name", name); EntitySerializerProperties properties = EntitySerializerProperties .fromProperties(DEFAULT_PROPERTIES).validatingFacets(false).build(); roomData.setWriteProperties(properties); final ODataResponse response = new JsonSerializerDeserializer().writeEntry(entitySet, roomData); final String json = verifyResponse(response); assertNotNull(response); assertEquals("{\"Id\":\"4711\",\"Name\":\"1234567890\"}", json); }
Example #7
Source File: XmlMetadataConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected = EntityProviderException.class) public void testMissingEdmxCloseTag() throws XMLStreamException, EntityProviderException { final String xml = "<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\"/>" + "<Property Name=\"" + propertyNames[2] + "\" Type=\"RefScenario.c_Location\" Nullable=\"false\"/>" + "</EntityType>" + "<ComplexType Name=\"c_Location\">" + "<Property Name=\"Country\" Type=\"Edm.String\"/>" + "</ComplexType>" + "</Schema>" + "</edmx:DataServices>"; XmlMetadataConsumer parser = new XmlMetadataConsumer(); XMLStreamReader reader = createStreamReader(xml); parser.readMetadata(reader, true); }
Example #8
Source File: XmlLinksEntityProducer.java From olingo-odata2 with Apache License 2.0 | 6 votes |
public void append(final XMLStreamWriter writer, final EntityInfoAggregator entityInfo, final List<Map<String, Object>> data) throws EntityProviderException { try { writer.writeStartElement(FormatXml.D_LINKS); writer.writeDefaultNamespace(Edm.NAMESPACE_D_2007_08); if (properties.getInlineCount() != null) { writer.writeStartElement(Edm.PREFIX_M, FormatXml.M_COUNT, Edm.NAMESPACE_M_2007_08); writer.writeNamespace(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08); writer.writeCharacters(properties.getInlineCount().toString()); writer.writeEndElement(); } XmlLinkEntityProducer provider = new XmlLinkEntityProducer(properties); for (final Map<String, Object> entityData : data) { provider.append(writer, entityInfo, entityData, false); } writer.writeEndElement(); writer.flush(); } catch (final XMLStreamException e) { throw new EntityProviderProducerException(EntityProviderException.COMMON, e); } }
Example #9
Source File: XmlFeedDeserializer.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * * @param reader * @param eia * @param readProperties * @return {@link ODataDeltaFeed} object * @throws EntityProviderException */ public ODataDeltaFeed readFeed(final XMLStreamReader reader, final EntityInfoAggregator eia, final DeserializerProperties readProperties) throws EntityProviderException { try { // read xml tag reader.require(XMLStreamConstants.START_DOCUMENT, null, null); reader.nextTag(); // read feed tag reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_FEED); Map<String, String> foundPrefix2NamespaceUri = extractNamespacesFromTag(reader); foundPrefix2NamespaceUri.putAll(readProperties.getValidatedPrefixNamespaceUris()); checkAllMandatoryNamespacesAvailable(foundPrefix2NamespaceUri); DeserializerProperties entryReadProperties = DeserializerProperties.initFrom(readProperties) .addValidatedPrefixes(foundPrefix2NamespaceUri).build(); // read feed data (metadata and entries) return readFeedData(reader, eia, entryReadProperties); } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
Example #10
Source File: XmlPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected = EntityProviderException.class) public void readComplexPropertyWithInvalidTypeAttribute() throws Exception { String xml = "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" m:type=\"Invalid\">" + "<Country>Germany</Country>" + "<City m:type=\"RefScenario.c_City\">" + "<PostalCode>69124</PostalCode>" + "<CityName>Heidelberg</CityName>" + "</City>" + "</Location>"; XMLStreamReader reader = createReaderForTest(xml, true); final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location"); new XmlPropertyConsumer().readProperty(reader, property, null); }
Example #11
Source File: AtomFeedProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private ExpandSelectTreeNode getSelectExpandTree(final String pathSegment, final String selectString, final String expandString) throws Exception { Edm edm = RuntimeDelegate.createEdm(new EdmTestProvider()); UriParserImpl uriParser = new UriParserImpl(edm); List<PathSegment> pathSegments = new ArrayList<PathSegment>(); pathSegments.add(new ODataPathSegmentImpl(pathSegment, null)); Map<String, String> queryParameters = new HashMap<String, String>(); if (selectString != null) { queryParameters.put("$select", selectString); } if (expandString != null) { queryParameters.put("$expand", expandString); } UriInfo uriInfo = uriParser.parse(pathSegments, queryParameters); ExpandSelectTreeCreator expandSelectTreeCreator = new ExpandSelectTreeCreator(uriInfo.getSelect(), uriInfo.getExpand()); ExpandSelectTreeNode expandSelectTree = expandSelectTreeCreator.create(); assertNotNull(expandSelectTree); return expandSelectTree; }
Example #12
Source File: EntryXmlChangeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void updateIncomplete() throws Exception { final String requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n" + " xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n" + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n" + " <m:properties><d:EmployeeName>Mister X</d:EmployeeName></m:properties>" + "\n" + "</entry>"; putUri("Employees('1')", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.NO_CONTENT); final String body = getBody(callUri("Employees('1')")); assertXpathEvaluatesTo("Mister X", "/atom:entry/m:properties/d:EmployeeName", body); assertXpathEvaluatesTo("0", "/atom:entry/m:properties/d:Age", body); assertXpathEvaluatesTo("true", "/atom:entry/m:properties/d:EntryDate/@m:null", body); final String requestBody2 = requestBody.replace("<d:EmployeeName>Mister X</d:EmployeeName>", "<d:Location><d:Country>Allemagne</d:Country></d:Location>"); putUri("Employees('1')", requestBody2, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.NO_CONTENT); final String body2 = getBody(callUri("Employees('1')")); assertXpathEvaluatesTo("Allemagne", "/atom:entry/m:properties/d:Location/d:Country", body2); assertXpathEvaluatesTo("true", "/atom:entry/m:properties/d:Location/d:City/d:CityName/@m:null", body2); assertXpathEvaluatesTo("true", "/atom:entry/m:properties/d:EmployeeName/@m:null", body2); }
Example #13
Source File: XmlPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected = EntityProviderException.class) public void readComplexPropertyWithInvalidDeepChild() throws Exception { String xml = "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" m:type=\"RefScenario.c_Location\">" + "<Country>Germany</Country>" + "<City m:type=\"RefScenario.c_City\">" + "<Invalid>69124</Invalid>" + "<CityName>Heidelberg</CityName>" + "</City>" + "</Location>"; XMLStreamReader reader = createReaderForTest(xml, true); final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location"); new XmlPropertyConsumer().readProperty(reader, property, null); }
Example #14
Source File: PropertyXmlChangeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void complexProperty() throws Exception { final String url1 = "Employees('2')/Location"; String requestBody = getBody(callUri(url1)).replace(CITY_2_NAME, "XXX"); putUri(url1, requestBody, HttpContentType.APPLICATION_XML, HttpStatusCodes.NO_CONTENT); assertXpathEvaluatesTo("XXX", "/d:Location/d:City/d:CityName", getBody(callUri(url1))); final String url2 = "Employees('2')/Location/City"; requestBody = getBody(callUri(url2)).replace("XXX", "YYY"); putUri(url2, requestBody, HttpContentType.APPLICATION_XML, HttpStatusCodes.NO_CONTENT); assertXpathEvaluatesTo("YYY", "/d:City/d:CityName", getBody(callUri(url2))); requestBody = "<City xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\"><PostalCode>00000</PostalCode></City>"; callUri(ODataHttpMethod.PATCH, url2, null, null, requestBody, HttpContentType.APPLICATION_XML, HttpStatusCodes.NO_CONTENT); assertXpathEvaluatesTo("YYY", "/d:City/d:CityName", getBody(callUri(url2))); }
Example #15
Source File: XmlCollectionEntityProducer.java From olingo-odata2 with Apache License 2.0 | 6 votes |
public static void append(final XMLStreamWriter writer, final EntityPropertyInfo propertyInfo, final List<?> data) throws EntityProviderException { try { writer.writeStartElement(propertyInfo.getName()); writer.writeDefaultNamespace(Edm.NAMESPACE_D_2007_08); if (propertyInfo.isComplex()) { writer.writeNamespace(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08); } XmlPropertyEntityProducer provider = new XmlPropertyEntityProducer(false, true); for (final Object propertyData : data) { provider.append(writer, FormatXml.D_ELEMENT, propertyInfo, propertyData); } writer.writeEndElement(); writer.flush(); } catch (XMLStreamException e) { throw new EntityProviderProducerException(EntityProviderException.COMMON, e); } }
Example #16
Source File: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected = EntityProviderException.class) public void ODATAJAVA_77_ExceptionScenario() throws Exception { final String metadata = "" + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + " <EntityType Name= \"ConfigParameter\" BaseType= \"RefScenario2.Parameter\" />" + " <EntityType Name= \"DataConfigParameter\" BaseType= \"RefScenario2.ConfigParameter\" />" + " <EntityType Name= \"StringDataConfigParameter\" BaseType= \"RefScenario2.DataConfigParameter\" />" + " <EntityType Name= \"Parameter\">" + " <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />" + " </EntityType>" + " </Schema>" + " </edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream reader = createStreamReader(metadata); parser.readMetadata(reader, true); }
Example #17
Source File: XmlMetadataConsumerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test(expected=EntityProviderException.class) public void ODATAJAVA_77_ExceptionScenario() throws Exception { final String metadata = "" + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + " <EntityType Name= \"ConfigParameter\" BaseType= \"RefScenario2.Parameter\" />" + " <EntityType Name= \"DataConfigParameter\" BaseType= \"RefScenario2.ConfigParameter\" />" + " <EntityType Name= \"StringDataConfigParameter\" BaseType= \"RefScenario2.DataConfigParameter\" />" + " <EntityType Name= \"Parameter\">" + " <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />" + " </EntityType>" + " </Schema>" + " </edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataConsumer parser = new XmlMetadataConsumer(); XMLStreamReader reader = createStreamReader(metadata); parser.readMetadata(reader, true); }
Example #18
Source File: ODataClientImpl.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public UriInfo parseUri(Edm edm, String uri) throws UriSyntaxException, UriNotMatchingException, EdmException { final String[] path = uri.split(QUESTIONMARK, -1); if (path.length > 2) { throw new UriSyntaxException(UriSyntaxException.URISYNTAX); } final List<PathSegment> pathSegments = getPathSegments(path[0]); Map<String, List<String>> queryParameters; if (path.length == 2) { queryParameters = getQueryParameters(unescape(path[1])); } else { queryParameters = new HashMap<String, List<String>>(); } return new UriParserImpl(edm).parseAll(pathSegments, queryParameters); }
Example #19
Source File: AtomEntryEntityProducer.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException { try { String mediaResourceMimeType = null; EdmMapping entityTypeMapping = eia.getEntityType().getMapping(); if (entityTypeMapping != null) { String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey(); if (mediaResourceMimeTypeKey != null) { mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey); } } if (mediaResourceMimeType == null) { mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString(); } writer.writeStartElement(FormatXml.ATOM_LINK); writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + "/$value"); writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA); writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType); writer.writeEndElement(); } catch (XMLStreamException e) { throw new EntityProviderProducerException(EntityProviderException.COMMON, e); } }
Example #20
Source File: EdmStructuralTypeImplProv.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Override public String toString() { try { return namespace + Edm.DELIMITER + getName(); } catch (final EdmException e) { return null; } }
Example #21
Source File: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void testMetadataDokumentWithWhitepaces() throws Exception { final String metadata = "" + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + " <EntityType Name= \"Photo\">" + " <Key> " + " <PropertyRef Name=\"Id\" />" + " </Key>" + " <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />" + " <MyAnnotation xmlns=\"http://company.com/odata\"> " + " <child> value1</child>" + " <child>value2</child>" + " </MyAnnotation>" + " </EntityType>" + " </Schema>" + " </edmx:DataServices>" + "</edmx:Edmx>"; InputStream reader = createStreamReader(metadata); EdmDataServices result = ODataClient.newInstance().readMetadata(reader, true); assertEquals(1, result.getEdm().getSchemas().size()); List<EdmEntityType> entityTypes = result.getEdm().getSchemas().get(0).getEntityTypes(); assertEquals(1, entityTypes.size()); EdmEntityType entityType = entityTypes.get(0); EdmAnnotations annotation= entityType.getAnnotations(); List<EdmAnnotationElement> annotationElements = annotation.getAnnotationElements(); assertEquals(1, annotationElements.size()); EdmAnnotationElement annotationElement = annotationElements.get(0); List<EdmAnnotationElement> childElements = annotationElement.getChildElements(); assertEquals(2, childElements.size()); assertEquals(" value1", childElements.get(0).getText()); assertEquals("value2", childElements.get(1).getText()); }
Example #22
Source File: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void ODATAJAVA_77_testMetadataDokumentWithMultiLevelEntityType() throws Exception { final String metadata = "" + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + " <EntityType Name= \"Parameter\">" + " <Key> " + " <PropertyRef Name=\"Id\" />" + " </Key>" + " <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />" + " </EntityType>" + " <EntityType Name= \"ConfigParameter\" BaseType= \"RefScenario2.Parameter\" />" + " <EntityType Name= \"DataConfigParameter\" BaseType= \"RefScenario2.ConfigParameter\" />" + " <EntityType Name= \"StringDataConfigParameter\" BaseType= \"RefScenario2.DataConfigParameter\" />" + " </Schema>" + " </edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream reader = createStreamReader(metadata); EdmDataServices result = parser.readMetadata(reader, true); assertEquals(1, result.getEdm().getSchemas().size()); List<EdmEntityType> entityTypes = result.getEdm().getSchemas().get(0).getEntityTypes(); assertEquals(4, entityTypes.size()); }
Example #23
Source File: AbstractSimpleType.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Override public String toString() { try { return getNamespace() + Edm.DELIMITER + getName(); } catch (final EdmException e) { return super.toString(); } }
Example #24
Source File: XmlMetadataConsumerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test(expected = EntityProviderException.class) public void testInvalidAssociationEnd() throws XMLStreamException, EntityProviderException { 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 + "1" + "\"/>" + "<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=\"Employees\" Role=\"" + employees + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataConsumer parser = new XmlMetadataConsumer(); XMLStreamReader reader = createStreamReader(xmlWithInvalidAssociationSetEnd); parser.readMetadata(reader, true); }
Example #25
Source File: XmlMetadataConsumerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void ODATAJAVA_77_testBaseTypeKey() throws Exception { final String metadata = "" + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + " <EntityType Name= \"Parameter\">" + " <Key> " + " <PropertyRef Name=\"Id\" />" + " </Key>" + " <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />" + " </EntityType>" + " <EntityType Name= \"ConfigParameter\" BaseType= \"RefScenario2.Parameter\" />" + " <EntityType Name= \"DataConfigParameter\" BaseType= \"RefScenario2.ConfigParameter\" >" + " <Key> " + " <PropertyRef Name=\"Name\" />" + " </Key>" + " <Property Name=\"Name\" Type=\"Edm.String\" Nullable=\"false\" />" + " </EntityType>" + " <EntityType Name= \"StringDataConfigParameter\" BaseType= \"RefScenario2.DataConfigParameter\" />" + " </Schema>" + " </edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataConsumer parser = new XmlMetadataConsumer(); XMLStreamReader reader = createStreamReader(metadata); DataServices result = parser.readMetadata(reader, true); assertEquals(1, result.getSchemas().size()); List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes(); assertEquals(4, entityTypes.size()); }
Example #26
Source File: XmlMetadataDeserializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@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); }
Example #27
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test(expected = EntityProviderException.class) public void serializeWithFacetsValidation() throws Exception { Edm edm = MockFacade.getMockEdm(); EdmTyped roomNameProperty = edm.getEntityType("RefScenario", "Room").getProperty("Name"); EdmFacets facets = mock(EdmFacets.class); when(facets.getMaxLength()).thenReturn(3); when(((EdmProperty) roomNameProperty).getFacets()).thenReturn(facets); roomData.put("Name", "1234567"); AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(edm.getDefaultEntityContainer().getEntitySet("Rooms"), roomData, DEFAULT_PROPERTIES); Assert.assertNotNull(response); }
Example #28
Source File: XmlPropertyConsumerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void readStringPropertyNull() throws Exception { final String xml = "<EntryDate xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\" m:null=\"true\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" />"; XMLStreamReader reader = createReaderForTest(xml, true); final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("EntryDate"); final Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, null); assertTrue(resultMap.containsKey("EntryDate")); assertNull(resultMap.get("EntryDate")); }
Example #29
Source File: XmlMetadataDeserializer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private EdmProperty readProperty(final XMLStreamReader reader, Edm edm) throws XMLStreamException, EntityProviderException, EdmException { reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY); EdmPropertyImpl property; List<EdmAnnotationElement> annotationElements = new ArrayList<EdmAnnotationElement>(); String type = reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE); if (type == null) { throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE .addContent(XmlMetadataConstants.EDM_TYPE).addContent(XmlMetadataConstants.EDM_PROPERTY)); } FullQualifiedName fqName = extractFQName(type); if (EdmSimpleType.EDM_NAMESPACE.equals(fqName.getNamespace())) { property = readSimpleProperty(reader, fqName); } else { property = readComplexProperty(reader, fqName, edm); } property.setFacets(readFacets(reader)); property.setCustomizableFeedMappings(readCustomizableFeedMappings(reader)); property.setMimeType(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, XmlMetadataConstants.M_MIMETYPE)); EdmAnnotations annotations = new EdmAnnotationsImpl(); ((EdmAnnotationsImpl) annotations).setAnnotationAttributes(readAnnotationAttribute(reader)); while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDM_PROPERTY.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); annotationElements.add(readAnnotationElement(reader)); } } if (!annotationElements.isEmpty()) { ((EdmAnnotationsImpl) annotations).setAnnotationElements(annotationElements); } property.setAnnotations(annotations); return property; }
Example #30
Source File: AtomServiceDocumentConsumer.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private ExtensionElementImpl parseExtensionSansTitleElement(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException { ExtensionElementImpl extElement = new ExtensionElementImpl(); if (!(Edm.NAMESPACE_APP_2007.equals(reader.getNamespaceURI()) || (FormatXml.ATOM_TITLE.equals(reader.getLocalName()) && Edm.NAMESPACE_ATOM_2005.equals(reader.getNamespaceURI())))) { extElement = parseElement(reader); } return extElement; }