Repository: olingo-odata4 Updated Branches: refs/heads/OLINGO-423_EdmxReferenceHandling fd033d7de -> b006070be
[OLINGO-423] Added BasicITCase for metadata Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/b006070b Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/b006070b Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/b006070b Branch: refs/heads/OLINGO-423_EdmxReferenceHandling Commit: b006070bea5a6cd2813dc7bd0480864a7bbc82ee Parents: fd033d7 Author: mibo <[email protected]> Authored: Tue Oct 14 08:28:34 2014 +0200 Committer: mibo <[email protected]> Committed: Tue Oct 14 08:30:55 2014 +0200 ---------------------------------------------------------------------- .../olingo/fit/AbstractBaseTestITCase.java | 10 ++ .../olingo/fit/tecsvc/client/BasicITCase.java | 25 +++- fit/src/test/resources/metadata-ref.xml | 123 +++++++++++++++++++ 3 files changed, 155 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b006070b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java index 3b219b0..a300518 100644 --- a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java @@ -58,6 +58,7 @@ public abstract class AbstractBaseTestITCase { TomcatTestServer.init(9080) .addServlet(TechnicalServlet.class, "/odata-server-tecsvc/odata.svc/*") .addServlet(StaticContent.class, "/odata-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml") + .addServlet(MetadataContent.class, "/odata-metadata/$metadata") .addWebApp() .start(); } @@ -135,4 +136,13 @@ public abstract class AbstractBaseTestITCase { Thread.currentThread().getContextClassLoader().getResourceAsStream("org-odata-core-v1.xml"))); } } + + public static class MetadataContent extends HttpServlet { + private static final long serialVersionUID = -6663569573355398997L; + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.getOutputStream().write(IOUtils.toByteArray( + Thread.currentThread().getContextClassLoader().getResourceAsStream("metadata-ref.xml"))); + } + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b006070b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java index 7a645ef..47737b7 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; @@ -38,7 +39,9 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRe import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; +import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; +import org.apache.olingo.client.api.edm.xml.XMLMetadata; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.domain.ODataError; @@ -79,7 +82,6 @@ public class BasicITCase extends AbstractBaseTestITCase { } @Test - @Ignore("Ignored till refactoring is finished") public void readMetadata() { EdmMetadataRequest request = getClient().getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI); assertNotNull(request); @@ -92,8 +94,25 @@ public class BasicITCase extends AbstractBaseTestITCase { assertNotNull(edm); assertEquals("olingo.odata.test1", edm.getSchema("olingo.odata.test1").getNamespace()); assertEquals("Namespace1_Alias", edm.getSchema("olingo.odata.test1").getAlias()); - assertNotNull(edm.getTerm(new FullQualifiedName("Core.Description"))); - assertEquals(2, edm.getSchemas().size()); + assertEquals(1, edm.getSchemas().size()); + } + + @Test + public void readViaXmlMetadata() { + XMLMetadataRequest request = getClient().getRetrieveRequestFactory() + .getXMLMetadataRequest(SERVICE_URI.replace("odata-server-tecsvc/odata.svc", "odata-metadata")); + assertNotNull(request); + + ODataRetrieveResponse<XMLMetadata> response = request.execute(); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); + + XMLMetadata xmlMetadata = response.getBody(); + + assertNotNull(xmlMetadata); + assertTrue(xmlMetadata instanceof org.apache.olingo.client.api.edm.xml.v4.XMLMetadata); + assertEquals("ODataDemo", xmlMetadata.getSchema("ODataDemo").getNamespace()); + assertEquals(1, ((org.apache.olingo.client.api.edm.xml.v4.XMLMetadata) xmlMetadata).getReferences().size()); + assertEquals(2, xmlMetadata.getSchemas().size()); } @Test http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b006070b/fit/src/test/resources/metadata-ref.xml ---------------------------------------------------------------------- diff --git a/fit/src/test/resources/metadata-ref.xml b/fit/src/test/resources/metadata-ref.xml new file mode 100644 index 0000000..b2f2eb0 --- /dev/null +++ b/fit/src/test/resources/metadata-ref.xml @@ -0,0 +1,123 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> +<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0"> + <edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/cs01/vocabularies/Org.OData.Core.V1.xml"> + <edmx:Include Namespace="Org.OData.Core.V1" Alias="Core"/> + </edmx:Reference> + <edmx:DataServices> + <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="ODataDemo"> + <TypeDefinition Name="Length" UnderlyingType="Edm.Int32"> + <Annotation Term="Org.OData.Measures.V1.Unit" String="Centimeters"/> + </TypeDefinition> + <TypeDefinition Name="Weight" UnderlyingType="Edm.Int32"> + <Annotation Term="Org.OData.Measures.V1.Unit" String="Kilograms"/> + </TypeDefinition> + <ComplexType Name="Size"> + <Property Name="Height" Type="Self.Length" /> + <Property Name="Weight" Type="Self.Weight" /> + </ComplexType> + <EntityType Name="Product" HasStream="true"> + <Key> + <PropertyRef Name="ID"/> + </Key> + <Property Name="ID" Type="Edm.Int32" Nullable="false"/> + <Property Name="Description" Type="Edm.String"> + <Annotation Term="Core.IsLanguageDependent"/> + </Property> + <Property Name="ReleaseDate" Type="Edm.Date"/> + <Property Name="DiscontinuedDate" Type="Edm.Date"/> + <Property Name="Rating" Type="Edm.Int32"/> + <Property Name="Price" Type="Edm.Decimal"> + <Annotation Term="UoM.ISOCurrency" Path="Currency"/> + </Property> + <Property Name="Currency" Type="Edm.String" MaxLength="3"/> + <NavigationProperty Name="Category" Type="ODataDemo.Category" Nullable="false" Partner="Products"/> + <NavigationProperty Name="Supplier" Type="ODataDemo.Supplier" Partner="Products"/> + </EntityType> + <EntityType Name="Category"> + <Key> + <PropertyRef Name="ID"/> + </Key> + <Property Name="ID" Type="Edm.Int32" Nullable="false"/> + <Property Name="Name" Type="Edm.String"> + <Annotation Term="Core.IsLanguageDependent"/> + </Property> + <NavigationProperty Name="Products" Partner="Category" Type="Collection(ODataDemo.Product)"> + <OnDelete Action="Cascade"/> + </NavigationProperty> + </EntityType> + <EntityType Name="Supplier"> + <Key> + <PropertyRef Name="ID"/> + </Key> + <Property Name="ID" Type="Edm.String" Nullable="false"/> + <Property Name="Name" Type="Edm.String"/> + <Property Name="Address" Type="ODataDemo.Address" Nullable="false"/> + <Property Name="Concurrency" Type="Edm.Int32" Nullable="false"/> + <NavigationProperty Name="Products" Partner="Supplier"/> Type="Collection(ODataDemo.Product)"/> + </EntityType> + <EntityType Name="Country"> + <Key> + <PropertyRef Name="Code"/> + </Key> + <Property Name="Code" Type="Edm.String" MaxLength="2" Nullable="false"/> + <Property Name="Name" Type="Edm.String"/> + </EntityType> + <ComplexType Name="Address"> + <Property Name="Street" Type="Edm.String"/> + <Property Name="City" Type="Edm.String"/> + <Property Name="State" Type="Edm.String"/> + <Property Name="ZipCode" Type="Edm.String"/> + <Property Name="CountryName" Type="Edm.String"/> + <NavigationProperty Name="Country" Type="ODataDemo.Country"> + <ReferentialConstraint Property="CountryName" ReferencedProperty="Name"/> + </NavigationProperty> + </ComplexType> + <Function Name="ProductsByRating"> + <Parameter Name="Rating" Type="Edm.Int32"/> + <ReturnType Type="Collection(ODataDemo.Product)"/> + </Function> + <EntityContainer Name="DemoService"> + <EntitySet Name="Products" EntityType="ODataDemo.Product"> + <NavigationPropertyBinding Path="Category" Target="Categories"/> + </EntitySet> + <EntitySet Name="Categories" EntityType="ODataDemo.Category"> + <NavigationPropertyBinding Path="Products" Target="Products"/> + </EntitySet> + <EntitySet Name="Suppliers" EntityType="ODataDemo.Supplier"> + <NavigationPropertyBinding Path="Products" Target="Products"/> + <NavigationPropertyBinding Path="Address/Country" Target="Countries"/> + <Annotation Term="Core.OptimisticConcurrencyControl"> + <Collection> + <PropertyPath>Concurrency</PropertyPath> + </Collection> + </Annotation> + </EntitySet> + <Singleton Name="Contoso" Type="Self.Supplier"> + <NavigationPropertyBinding Path="Products" Target="Products"/> + </Singleton> + <EntitySet Name="Countries" EntityType="ODataDemo.Country"/> + <FunctionImport Name="ProductsByRating" EntitySet="Products" Function="ODataDemo.ProductsByRating"/> + </EntityContainer> + </Schema> + </edmx:DataServices> +</edmx:Edmx>
