Repository: olingo-odata4 Updated Branches: refs/heads/master f87321f98 -> 713ed0efa
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/713ed0ef/fit/src/main/resources/V40/Products/6/entity.xml ---------------------------------------------------------------------- diff --git a/fit/src/main/resources/V40/Products/6/entity.xml b/fit/src/main/resources/V40/Products/6/entity.xml new file mode 100644 index 0000000..e7bdabb --- /dev/null +++ b/fit/src/main/resources/V40/Products/6/entity.xml @@ -0,0 +1,48 @@ +<?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. + +--> +<entry xml:base="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://docs.oasis-open.org/odata/ns/data" xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:context="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/$metadata#Products/$entity"> + <id>http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Products(6)</id> + <category term="#Microsoft.Test.OData.Services.ODataWCFService.Product" scheme="http://docs.oasis-open.org/odata/ns/scheme" /> + <link rel="edit" href="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Products(6)" /> + <link rel="http://docs.oasis-open.org/odata/ns/related/Details" type="application/atom+xml;type=feed" title="Details" href="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/Products(6)/Details" /> + <title /> + <updated>2014-04-23T11:58:19Z</updated> + <author> + <name /> + </author> + <content type="application/xml"> + <m:properties> + <d:ProductID m:type="Int32">6</d:ProductID> + <d:Name>Mushrooms</d:Name> + <d:QuantityPerUnit>Pound</d:QuantityPerUnit> + <d:UnitPrice m:type="Single">3.24</d:UnitPrice> + <d:QuantityInStock m:type="Int32">100</d:QuantityInStock> + <d:Discontinued m:type="Boolean">false</d:Discontinued> + <d:UserAccess m:type="#Microsoft.Test.OData.Services.ODataWCFService.AccessLevel">ReadWrite</d:UserAccess> + <d:SkinColor m:type="#Microsoft.Test.OData.Services.ODataWCFService.Color">Blue</d:SkinColor> + <d:CoverColors m:type="#Collection(Microsoft.Test.OData.Services.ODataWCFService.Color)"> + <m:element>Red</m:element> + <m:element>Blue</m:element> + </d:CoverColors> + </m:properties> + </content> +</entry> http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/713ed0ef/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java index 6e27741..21669b1 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java @@ -185,6 +185,7 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult> * Just to create response templates to be initialized from batch. */ private ODataInvokeResponseImpl() { + super(); } /** @@ -203,20 +204,16 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult> @Override public T getBody() { if (invokeResult == null) { - if (ODataNoContent.class.isAssignableFrom(reference)) { - invokeResult = reference.cast(new ODataNoContent()); - } - try { - if (CommonODataEntitySet.class.isAssignableFrom(reference)) { + if (ODataNoContent.class.isAssignableFrom(reference)) { + invokeResult = reference.cast(new ODataNoContent()); + } else if (CommonODataEntitySet.class.isAssignableFrom(reference)) { invokeResult = reference.cast(odataClient.getReader().readEntitySet(res.getEntity().getContent(), ODataPubFormat.fromString(getContentType()))); - } - if (CommonODataEntity.class.isAssignableFrom(reference)) { + } else if (CommonODataEntity.class.isAssignableFrom(reference)) { invokeResult = reference.cast(odataClient.getReader().readEntity(res.getEntity().getContent(), ODataPubFormat.fromString(getContentType()))); - } - if (CommonODataProperty.class.isAssignableFrom(reference)) { + } else if (CommonODataProperty.class.isAssignableFrom(reference)) { invokeResult = reference.cast(odataClient.getReader().readProperty(res.getEntity().getContent(), ODataFormat.fromString(getContentType()))); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/713ed0ef/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java index 6bb9307..f00d14a 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java @@ -22,14 +22,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; import java.util.Collections; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; import org.apache.olingo.client.api.uri.v4.URIBuilder; @@ -50,34 +45,13 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ODataPubFormat; -import org.junit.Assume; -import org.junit.BeforeClass; import org.junit.Test; public class BoundOperationInvokeTestITCase extends AbstractTestITCase { - private static final String serviceRoot = "http://odatae2etest.azurewebsites.net/javatest/DefaultService"; - - // TODO: remove once fit provides function / action imports - @BeforeClass - public static void checkServerIsOnline() throws IOException { - final Socket socket = new Socket(); - boolean reachable = false; - try { - socket.connect(new InetSocketAddress("odatae2etest.azurewebsites.net", 80), 2000); - reachable = true; - } catch (Exception e) { - LOG.warn("External test service not reachable, ignoring this whole class: {}", - OperationImportInvokeTestITCase.class.getName()); - } finally { - IOUtils.closeQuietly(socket); - } - Assume.assumeTrue(reachable); - } - private Edm getEdm() { final Edm edm = getClient().getRetrieveRequestFactory(). - getMetadataRequest(serviceRoot).execute().getBody(); + getMetadataRequest(testStaticServiceRootURL).execute().getBody(); assertNotNull(edm); return edm; @@ -89,11 +63,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { assertNotNull(container); // GetEmployeesCount - URIBuilder builder = getClient().getURIBuilder(serviceRoot).appendSingletonSegment("Company"); + URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company"); ODataEntityRequest<ODataEntity> entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); ODataEntity entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -112,10 +85,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { assertTrue(getEmployeesCountRes.hasPrimitiveValue()); // GetProductDetails - builder = getClient().getURIBuilder(serviceRoot).appendEntitySetSegment("Products").appendKeySegment(5); + builder = getClient().getURIBuilder(testStaticServiceRootURL). + appendEntitySetSegment("Products").appendKeySegment(5); entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -135,14 +108,13 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { assertEquals(1, getProductDetailsRes.getCount()); // GetRelatedProduct - final Map<String, Object> keyMap = new HashMap<String, Object>(); + final Map<String, Object> keyMap = new LinkedHashMap<String, Object>(); keyMap.put("ProductID", 6); keyMap.put("ProductDetailID", 1); - builder = getClient().getURIBuilder(serviceRoot).appendEntitySetSegment("ProductDetails"). - appendKeySegment(keyMap); + builder = getClient().getURIBuilder(testStaticServiceRootURL). + appendEntitySetSegment("ProductDetails").appendKeySegment(keyMap); entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -155,22 +127,17 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { final ODataInvokeRequest<ODataEntity> getRelatedProductReq = getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func); getRelatedProductReq.setFormat(format); - //TODO test service returns error instead of Products(6) - try { - final ODataEntity getRelatedProductRes = getRelatedProductReq.execute().getBody(); - assertNotNull(getRelatedProductRes); - assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Product", - getRelatedProductRes.getTypeName().toString()); - assertEquals(6, getRelatedProductRes.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0); - } catch (Exception e) { - // ignore - } + final ODataEntity getRelatedProductRes = getRelatedProductReq.execute().getBody(); + assertNotNull(getRelatedProductRes); + assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Product", + getRelatedProductRes.getTypeName().toString()); + assertEquals(6, getRelatedProductRes.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0); // GetDefaultPI - builder = getClient().getURIBuilder(serviceRoot).appendEntitySetSegment("Accounts").appendKeySegment(101); + builder = getClient().getURIBuilder(testStaticServiceRootURL). + appendEntitySetSegment("Accounts").appendKeySegment(101); entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -209,8 +176,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { // GetActualAmount entityReq = getClient().getRetrieveRequestFactory().getEntityRequest( entity.getNavigationLink("MyGiftCard").getLink()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); entity = entityReq.execute().getBody(); assertNotNull(entity); assertEquals(301, entity.getProperty("GiftCardID").getPrimitiveValue().toCastValue(Integer.class), 0); @@ -247,11 +213,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { assertNotNull(container); // IncreaseRevenue - URIBuilder builder = getClient().getURIBuilder(serviceRoot).appendSingletonSegment("Company"); + URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company"); ODataEntityRequest<ODataEntity> entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); ODataEntity entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -272,10 +237,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { assertTrue(increaseRevenueRes.hasPrimitiveValue()); // AddAccessRight - builder = getClient().getURIBuilder(serviceRoot).appendEntitySetSegment("Products").appendKeySegment(5); + builder = getClient().getURIBuilder(testStaticServiceRootURL). + appendEntitySetSegment("Products").appendKeySegment(5); entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -296,10 +261,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { assertTrue(getProductDetailsRes.hasEnumValue()); // ResetAddress - builder = getClient().getURIBuilder(serviceRoot).appendEntitySetSegment("Customers").appendKeySegment(2); + builder = getClient().getURIBuilder(testStaticServiceRootURL). + appendEntitySetSegment("Customers").appendKeySegment(2); entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -334,10 +299,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { assertEquals(2, resetAddressRes.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0); // RefreshDefaultPI - builder = getClient().getURIBuilder(serviceRoot).appendEntitySetSegment("Accounts").appendKeySegment(101); + builder = getClient().getURIBuilder(testStaticServiceRootURL). + appendEntitySetSegment("Accounts").appendKeySegment(101); entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build()); - // TODO: remove when fit is used since external test server does not advertise actions in Atom - entityReq.setFormat(ODataPubFormat.JSON_FULL_METADATA); + entityReq.setFormat(format); entity = entityReq.execute().getBody(); assertNotNull(entity); @@ -363,12 +328,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase { @Test public void atomActions() throws EdmPrimitiveTypeException { - //TODO test service doesn't support yet Atom POST params - try { - actions(ODataPubFormat.ATOM); - } catch (Exception e) { - // ignore - } + actions(ODataPubFormat.ATOM); } @Test http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/713ed0ef/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java index bfc5718..96ec485 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java @@ -40,7 +40,6 @@ import org.apache.olingo.commons.api.edm.EdmActionImport; import org.apache.olingo.commons.api.edm.EdmEntityContainer; import org.apache.olingo.commons.api.edm.EdmFunctionImport; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.format.ODataPubFormat; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/713ed0ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java index b3777fd..6b87469 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AtomSerializer.java @@ -34,6 +34,7 @@ import org.apache.olingo.commons.api.data.Feed; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.Value; +import org.apache.olingo.commons.api.domain.ODataOperation; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.format.ContentType; @@ -214,7 +215,6 @@ public class AtomSerializer extends AbstractAtomDealer { writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE, entry.getBaseURI().toASCIIString()); } - // server mode only if (serverMode && StringUtils.isNotBlank(entry.getETag())) { writer.writeAttribute( version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), @@ -239,7 +239,6 @@ public class AtomSerializer extends AbstractAtomDealer { common(writer, (AbstractODataObject) entry); } - // server mode only if (serverMode) { if (entry.getEditLink() != null) { links(writer, Collections.singletonList(entry.getEditLink())); @@ -254,6 +253,17 @@ public class AtomSerializer extends AbstractAtomDealer { links(writer, entry.getNavigationLinks()); links(writer, entry.getMediaEditLinks()); + if (serverMode) { + for (ODataOperation operation : entry.getOperations()) { + writer.writeStartElement( + version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_ACTION); + writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor()); + writer.writeAttribute(Constants.ATTR_TITLE, operation.getTitle()); + writer.writeAttribute(Constants.ATTR_TARGET, operation.getTarget().toASCIIString()); + writer.writeEndElement(); + } + } + writer.writeStartElement(Constants.ATOM_ELEM_CONTENT); if (entry.isMediaEntry()) { if (StringUtils.isNotBlank(entry.getMediaContentType())) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/713ed0ef/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java ---------------------------------------------------------------------- diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java index db4ab7c..b7dcf8d 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONEntrySerializer.java @@ -29,6 +29,7 @@ import org.apache.olingo.commons.api.data.Container; import org.apache.olingo.commons.api.data.Entry; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; +import org.apache.olingo.commons.api.domain.ODataOperation; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.core.edm.EdmTypeInfo; @@ -107,6 +108,15 @@ public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> { } } + if (serverMode) { + for (ODataOperation operation : entry.getOperations()) { + jgen.writeObjectFieldStart("#" + StringUtils.substringAfterLast(operation.getMetadataAnchor(), "#")); + jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle()); + jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString()); + jgen.writeEndObject(); + } + } + jgen.writeEndObject(); } }
