You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/08/06 14:22:23 UTC
olingo-odata4 git commit: [OLINGO-659] Some minor FIT refactorings
Repository: olingo-odata4
Updated Branches:
refs/heads/master 7ab63759c -> 1b200437b
[OLINGO-659] Some minor FIT refactorings
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/1b200437
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/1b200437
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/1b200437
Branch: refs/heads/master
Commit: 1b200437b4c000a8dacfce36e631b6569c7fc00e
Parents: 7ab6375
Author: Christian Holzer <c....@sap.com>
Authored: Thu Aug 6 14:17:05 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Thu Aug 6 14:17:48 2015 +0200
----------------------------------------------------------------------
.../olingo/fit/tecsvc/client/BindingITCase.java | 116 ++++++-------------
.../fit/tecsvc/client/BindingXmlITCase.java | 11 +-
.../core/serialization/ODataBinderImpl.java | 12 ++
3 files changed, 49 insertions(+), 90 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1b200437/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
index ca95ed6..9d1a9ed 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
@@ -38,8 +38,6 @@ import org.apache.olingo.client.api.domain.ClientEntity;
import org.apache.olingo.client.api.domain.ClientInlineEntity;
import org.apache.olingo.client.api.domain.ClientLink;
import org.apache.olingo.client.api.domain.ClientObjectFactory;
-import org.apache.olingo.client.api.domain.ClientProperty;
-import org.apache.olingo.client.api.domain.ClientValue;
import org.apache.olingo.client.core.ODataClientFactory;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -51,7 +49,7 @@ import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Test;
public class BindingITCase extends AbstractBaseTestITCase {
- private static final String SERVICE_URI = TecSvcConst.BASE_URI;
+ protected static final String SERVICE_URI = TecSvcConst.BASE_URI;
private static final String SERVICE_NAMESPACE = "olingo.odata.test1";
private static final String ES_KEY_NAV = "ESKeyNav";
@@ -156,22 +154,26 @@ public class BindingITCase extends AbstractBaseTestITCase {
final ODataRetrieveResponse<ClientEntity> entityGetResponse = entityGetRequest.execute();
// NAV_PROPERTY_ET_KEY_NAV_ONE
- assertEquals(1, entityGetResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals(Short.valueOf((short) 1), entityGetResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE)
+ .asInlineEntity().getEntity().getProperty(PROPERTY_INT16).getPrimitiveValue().toCastValue(Short.class));
// NAV_PROPERTY_ET_KEY_NAV_MANY(0)
- Iterator<ClientValue> iterator =
- entityGetResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_MANY).getCollectionValue().iterator();
- assertEquals(2, iterator.next().asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ Iterator<ClientEntity> iterator = entityGetResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY)
+ .asInlineEntitySet().getEntitySet().getEntities().iterator();
+ assertEquals(Short.valueOf((short) 2), iterator.next().getProperty(PROPERTY_INT16).getPrimitiveValue()
+ .toCastValue(Short.class));
// NAV_PROPERTY_ET_KEY_NAV_MANY(1)
- assertEquals(3, iterator.next().asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals(Short.valueOf((short) 3), iterator.next().getProperty(PROPERTY_INT16).getPrimitiveValue()
+ .toCastValue(Short.class));
// NAV_PROPERTY_ET_TWO_KEY_NAV_MANY(0)
- assertEquals(1, entityGetResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).getCollectionValue()
- .iterator().next().asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
- assertEquals("1", entityGetResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).getCollectionValue()
- .iterator().next().asComplex().get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertEquals(Short.valueOf((short)1), entityGetResponse.getBody()
+ .getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet().getEntities()
+ .iterator().next().getProperty(PROPERTY_INT16).getPrimitiveValue().toCastValue(Short.class));
+ assertEquals("1", entityGetResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY)
+ .asInlineEntitySet().getEntitySet().getEntities().iterator().next()
+ .getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
// Check if partner navigation link has been set up
final URI etTwoKeyNavEntityURI =
@@ -182,12 +184,12 @@ public class BindingITCase extends AbstractBaseTestITCase {
etTwoKeyNavEntityRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> etTwoKeyNavEntityResponse = etTwoKeyNavEntityRequest.execute();
- assertEquals(entityInt16Key, etTwoKeyNavEntityResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE)
- .getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toCastValue(Short.class));
+ assertEquals(entityInt16Key, etTwoKeyNavEntityResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE)
+ .asInlineEntity().getEntity().getProperty(PROPERTY_INT16).getPrimitiveValue().toCastValue(Short.class));
}
@Test
- public void testUpdateBinding() {
+ public void testUpdateBinding() throws Exception {
// The entity MUST NOT contain related entities as inline content. It MAY contain binding information
// for navigation properties. For single-valued navigation properties this replaces the relationship.
// For collection-valued navigation properties this adds to the relationship.
@@ -224,15 +226,19 @@ public class BindingITCase extends AbstractBaseTestITCase {
entityRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> entityResponse = entityRequest.execute();
- assertEquals(3, entityResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
- assertEquals(3, entityResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_MANY).getCollectionValue().size());
-
- Iterator<ClientValue> iterator =
- entityResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_MANY).getCollectionValue().iterator();
- assertEquals(1, iterator.next().asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
- assertEquals(2, iterator.next().asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
- assertEquals(3, iterator.next().asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals(Short.valueOf((short) 3), entityResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE)
+ .asInlineEntity().getEntity().getProperty(PROPERTY_INT16).getPrimitiveValue().toCastValue(Short.class));
+ assertEquals(3, entityResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY).asInlineEntitySet()
+ .getEntitySet().getEntities().size());
+
+ Iterator<ClientEntity> iterator = entityResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY)
+ .asInlineEntitySet().getEntitySet().getEntities().iterator();
+ assertEquals(Short.valueOf((short) 1), iterator.next().getProperty(PROPERTY_INT16).getPrimitiveValue()
+ .toCastValue(Short.class));
+ assertEquals(Short.valueOf((short) 2), iterator.next().getProperty(PROPERTY_INT16).getPrimitiveValue()
+ .toCastValue(Short.class));
+ assertEquals(Short.valueOf((short) 3), iterator.next().getProperty(PROPERTY_INT16).getPrimitiveValue()
+ .toCastValue(Short.class));
}
@Test
@@ -275,55 +281,8 @@ public class BindingITCase extends AbstractBaseTestITCase {
}
@Test
- public void testUpdateSingleNavigationPropertyWithNull() {
- final ODataClient client = getClient();
- final URI entityURI =
- client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
- final ClientObjectFactory of = client.getObjectFactory();
-
- // Request to single (non collection) navigation property
- ClientEntity entity = of.newEntity(ET_KEY_NAV);
- final ClientProperty navPropery = of.newComplexProperty(NAV_PROPERTY_ET_KEY_NAV_ONE, null);
- entity.getProperties().add(navPropery);
-
- ODataEntityUpdateResponse<ClientEntity> updateResponse =
- client.getCUDRequestFactory().getEntityUpdateRequest(entityURI, UpdateType.PATCH, entity).execute();
- assertEquals(HttpStatusCode.OK.getStatusCode(), updateResponse.getStatusCode());
-
- final ODataEntityRequest<ClientEntity> getRequest =
- client.getRetrieveRequestFactory().getEntityRequest(
- client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).expand(
- NAV_PROPERTY_ET_KEY_NAV_ONE).build());
- getRequest.addCustomHeader(HttpHeader.COOKIE, updateResponse.getHeader(HttpHeader.SET_COOKIE).iterator().next());
- final ODataRetrieveResponse<ClientEntity> getResponse = getRequest.execute();
-
- ClientProperty property = getResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE);
- assertEquals(null, property.getPrimitiveValue());
- }
-
- @Test
- public void testUpdateCollectionNavigationPropertyWithNull() {
- final ODataClient client = getClient();
- final URI entityURI =
- client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
- final ClientObjectFactory of = client.getObjectFactory();
-
- // Request to single (non collection) navigation property
- ClientEntity entity = of.newEntity(ET_KEY_NAV);
- final ClientProperty navPropery = of.newComplexProperty(NAV_PROPERTY_ET_KEY_NAV_MANY, null);
- entity.getProperties().add(navPropery);
-
- try {
- client.getCUDRequestFactory().getEntityUpdateRequest(entityURI, UpdateType.PATCH, entity).execute();
- fail();
- } catch (ODataClientErrorException e) {
- assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
- }
- }
-
- @Test
public void testDeepInsertWithBindingSameNavigationProperty() {
- final EdmEnabledODataClient client = getClient(SERVICE_URI);
+ final EdmEnabledODataClient client = getClient();
client.getConfiguration().setDefaultPubFormat(ContentType.JSON);
final ClientObjectFactory of = client.getObjectFactory();
@@ -344,7 +303,7 @@ public class BindingITCase extends AbstractBaseTestITCase {
client.newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_TWO_KEY_NAV)
.appendKeySegment(new LinkedHashMap<String, Object>() {
- private static final long serialVersionUID = 3109256773218160485L;
+ private static final long serialVersionUID = 1L;
{
put(PROPERTY_INT16, 3);
@@ -389,14 +348,9 @@ public class BindingITCase extends AbstractBaseTestITCase {
.toValue());
}
- @Override
- protected ODataClient getClient() {
- ODataClient odata = ODataClientFactory.getClient();
+ protected EdmEnabledODataClient getClient() {
+ EdmEnabledODataClient odata = ODataClientFactory.getEdmEnabledClient(SERVICE_URI);
odata.getConfiguration().setDefaultPubFormat(ContentType.JSON);
return odata;
}
-
- protected EdmEnabledODataClient getClient(String serviceURI) {
- return ODataClientFactory.getEdmEnabledClient(serviceURI, ContentType.JSON);
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1b200437/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingXmlITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingXmlITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingXmlITCase.java
index 9e9079e..538f82c 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingXmlITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingXmlITCase.java
@@ -22,21 +22,14 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import org.apache.olingo.client.api.EdmEnabledODataClient;
-import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.core.ODataClientFactory;
import org.apache.olingo.commons.api.format.ContentType;
-import org.junit.Ignore;
-@Ignore
-/**
- * I believe BindingITCase was not written correctly, as they seem to use navigation property and
- * any other property interchangeably. Once we fix that then we can remove the ignore
- */
public class BindingXmlITCase extends BindingITCase {
@Override
- protected ODataClient getClient() {
- ODataClient odata = ODataClientFactory.getClient();
+ protected EdmEnabledODataClient getClient() {
+ EdmEnabledODataClient odata = ODataClientFactory.getEdmEnabledClient(SERVICE_URI);
odata.getConfiguration().setDefaultPubFormat(ContentType.APPLICATION_ATOM_XML);
return odata;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1b200437/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
index 1f42d9b..a870306 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
@@ -90,6 +90,7 @@ import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.geo.Geospatial;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
@@ -713,6 +714,9 @@ public class ODataBinderImpl implements ODataBinder {
} else {
if (propertyType == null || propertyType.equals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString())) {
typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build();
+ } else if(isPrimiteveType(typeName)) {
+ // Inheritance is not allowed for primitve types, so we use the type given by the EDM
+ typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build();
} else {
typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build();
}
@@ -720,6 +724,14 @@ public class ODataBinderImpl implements ODataBinder {
return typeInfo;
}
+ private boolean isPrimiteveType(final FullQualifiedName typeName) {
+ try {
+ return EdmPrimitiveTypeKind.valueOfFQN(typeName) != null;
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
+ }
+
protected ClientProperty getODataProperty(final EdmType type, final Property resource) {
final EdmTypeInfo typeInfo = buildTypeInfo(type == null ? null : type.getFullQualifiedName(), resource.getType());