[OLINGO-260] (Proxy) context tests
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/ad770860 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/ad770860 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/ad770860 Branch: refs/heads/master Commit: ad770860869de24e4311699d78a50f08aa222cc0 Parents: 42c29de Author: Francesco Chicchiriccò <--global> Authored: Tue May 13 15:56:11 2014 +0200 Committer: Stephan Klevenz <[email protected]> Committed: Mon May 19 14:32:16 2014 +0200 ---------------------------------------------------------------------- .../proxy/commons/ComplexInvocationHandler.java | 94 ++++++++--- .../proxy/commons/EntityInvocationHandler.java | 168 ++++++++++--------- .../java/org/apache/olingo/fit/V3Services.java | 18 +- .../olingo/fit/utils/AbstractUtilities.java | 1 + .../olingo/fit/proxy/v3/ContextTestITCase.java | 92 +++++----- 5 files changed, 210 insertions(+), 163 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ad770860/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java index b85452d..28bf280 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java @@ -20,6 +20,7 @@ package org.apache.olingo.ext.proxy.commons; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.util.ArrayList; @@ -31,6 +32,7 @@ import org.apache.olingo.client.api.CommonEdmEnabledODataClient; import org.apache.olingo.commons.api.domain.CommonODataProperty; import org.apache.olingo.commons.api.domain.ODataComplexValue; import org.apache.olingo.commons.api.domain.ODataLinked; +import org.apache.olingo.commons.api.domain.ODataValue; import org.apache.olingo.commons.api.edm.EdmElement; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.core.edm.EdmTypeInfo; @@ -41,16 +43,17 @@ import org.apache.olingo.ext.proxy.context.AttachedEntityStatus; import org.apache.olingo.ext.proxy.utils.ClassUtils; import org.apache.olingo.ext.proxy.utils.CoreUtils; -public class ComplexInvocationHandler extends AbstractStructuredInvocationHandler { +public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?>> + extends AbstractTypeInvocationHandler<C> { private static final long serialVersionUID = 2629912294765040037L; - public static ComplexInvocationHandler getInstance( + public static ComplexTypeInvocationHandler<?> getInstance( final CommonEdmEnabledODataClient<?> client, final String propertyName, final Class<?> reference, - final EntityInvocationHandler handler) { - + final EntityTypeInvocationHandler<?> handler) { + final Class<?> complexTypeRef; if (Collection.class.isAssignableFrom(reference)) { complexTypeRef = ClassUtils.extractTypeArg(reference); @@ -69,28 +72,38 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle final ODataComplexValue<? extends CommonODataProperty> complex = client.getObjectFactory().newComplexValue(typeName.toString()); - return (ComplexInvocationHandler) ComplexInvocationHandler.getInstance( + return (ComplexTypeInvocationHandler<?>) ComplexTypeInvocationHandler.getInstance( client, complex, complexTypeRef, handler); } - public static ComplexInvocationHandler getInstance( + @SuppressWarnings({"unchecked", "rawtypes"}) + static ComplexTypeInvocationHandler<?> getInstance( final CommonEdmEnabledODataClient<?> client, final ODataComplexValue<?> complex, final Class<?> typeRef, - final EntityInvocationHandler handler) { + final EntityTypeInvocationHandler<?> handler) { - return new ComplexInvocationHandler(client, complex, typeRef, handler); + return new ComplexTypeInvocationHandler(client, complex, typeRef, handler); } - public ComplexInvocationHandler( - final CommonEdmEnabledODataClient<?> client, + public ComplexTypeInvocationHandler( + final C client, final ODataComplexValue<?> complex, final Class<?> typeRef, - final EntityInvocationHandler handler) { + final EntityTypeInvocationHandler<C> handler) { super(client, typeRef, complex, handler); } + public void setComplex(final ODataComplexValue<?> complex) { + this.internal = complex; + } + + @Override + public FullQualifiedName getName() { + return new FullQualifiedName(((ODataComplexValue<?>) this.internal).getTypeName()); + } + @SuppressWarnings("unchecked") public ODataComplexValue<CommonODataProperty> getComplex() { return (ODataComplexValue<CommonODataProperty>) this.internal; @@ -99,7 +112,48 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle @Override protected Object getPropertyValue(final String name, final Type type) { try { - return CoreUtils.getValueFromProperty(client, getComplex().get(name), type, getEntityHandler()); + final Object res; + + final CommonODataProperty property = getComplex().get(name); + if (property == null) { + res = null; + } else if (property.hasComplexValue()) { + res = Proxy.newProxyInstance( + Thread.currentThread().getContextClassLoader(), + new Class<?>[] {(Class<?>) type}, + ComplexTypeInvocationHandler.getInstance( + client, property.getValue().asComplex(), (Class<?>) type, targetHandler)); + + } else if (property.hasCollectionValue()) { + final ParameterizedType collType = (ParameterizedType) type; + final Class<?> collItemClass = (Class<?>) collType.getActualTypeArguments()[0]; + + final ArrayList<Object> collection = new ArrayList<Object>(); + + final Iterator<ODataValue> collPropItor = property.getValue().asCollection().iterator(); + while (collPropItor.hasNext()) { + final ODataValue value = collPropItor.next(); + if (value.isPrimitive()) { + collection.add(CoreUtils.primitiveValueToObject(value.asPrimitive())); + } else if (value.isComplex()) { + final Object collItem = Proxy.newProxyInstance( + Thread.currentThread().getContextClassLoader(), + new Class<?>[] {collItemClass}, + ComplexTypeInvocationHandler.getInstance( + client, value.asComplex(), collItemClass, targetHandler)); + + collection.add(collItem); + } + } + + res = collection; + } else { + res = type == null + ? CoreUtils.getValueFromProperty(client, property) + : CoreUtils.getValueFromProperty(client, property, type); + } + + return res; } catch (Exception e) { throw new IllegalArgumentException("Error getting value for property '" + name + "'", e); } @@ -117,7 +171,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle } } - for (final Iterator<? extends CommonODataProperty> itor = getComplex().iterator(); itor.hasNext();) { + for (Iterator<? extends CommonODataProperty> itor = getComplex().iterator(); itor.hasNext();) { final CommonODataProperty property = itor.next(); if (!propertyNames.contains(property.getName())) { res.add(property.getName()); @@ -150,13 +204,15 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle toBeAdded = value; } - final EdmTypeInfo type = new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression( + final EdmTypeInfo type = new EdmTypeInfo.Builder(). + setEdm(client.getCachedEdm()).setTypeExpression( edmProperty.isCollection() ? "Collection(" + property.type() + ")" : property.type()).build(); - client.getBinder().add(getComplex(), CoreUtils.getODataProperty(client, property.name(), type, toBeAdded)); + client.getBinder().add( + getComplex(), CoreUtils.getODataProperty(client, property.name(), type, toBeAdded)); - if (getEntityHandler() != null && !entityContext.isAttached(getEntityHandler())) { - entityContext.attach(getEntityHandler(), AttachedEntityStatus.CHANGED); + if (targetHandler != null && !entityContext.isAttached(targetHandler)) { + entityContext.attach(targetHandler, AttachedEntityStatus.CHANGED); } } @@ -166,7 +222,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle throw new UnsupportedOperationException("Internal object is not navigable"); } - return retrieveNavigationProperty(property, getter, containerHandler.getFactory().getServiceRoot()); + return retriveNavigationProperty(property, getter); } @Override @@ -181,6 +237,6 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle @Override public boolean isChanged() { - return getEntityHandler() == null ? false : getEntityHandler().isChanged(); + return targetHandler == null ? false : targetHandler.isChanged(); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ad770860/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java index 6b1f08b..0e093b4 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java @@ -20,26 +20,29 @@ package org.apache.olingo.ext.proxy.commons; import java.io.InputStream; import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.net.URI; +import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Set; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.olingo.client.api.CommonEdmEnabledODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.domain.CommonODataEntity; import org.apache.olingo.commons.api.domain.CommonODataProperty; import org.apache.olingo.commons.api.domain.ODataLinked; +import org.apache.olingo.commons.api.domain.ODataValue; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; +import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ODataMediaFormat; import org.apache.olingo.ext.proxy.api.annotations.EntityType; import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; @@ -48,12 +51,11 @@ import org.apache.olingo.ext.proxy.context.AttachedEntityStatus; import org.apache.olingo.ext.proxy.context.EntityUUID; import org.apache.olingo.ext.proxy.utils.CoreUtils; -public class EntityInvocationHandler extends AbstractStructuredInvocationHandler { +public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?>> + extends AbstractTypeInvocationHandler<C> { private static final long serialVersionUID = 2629912294765040037L; - private final URI entityURI; - protected Map<String, Object> propertyChanges = new HashMap<String, Object>(); protected Map<NavigationProperty, Object> linkChanges = new HashMap<NavigationProperty, Object>(); @@ -68,46 +70,42 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler private EntityUUID uuid; - static EntityInvocationHandler getInstance( - final URI entityURI, + static EntityTypeInvocationHandler<?> getInstance( final CommonODataEntity entity, - final EntitySetInvocationHandler<?, ?, ?> entitySet, + final EntitySetInvocationHandler<?, ?, ?, ?> entitySet, final Class<?> typeRef) { return getInstance( - entityURI, entity, - entitySet.getEntitySetURI(), + entitySet.getEntitySetName(), typeRef, entitySet.containerHandler); } - static EntityInvocationHandler getInstance( - final URI entityURI, + @SuppressWarnings({"unchecked", "rawtypes"}) + static EntityTypeInvocationHandler<?> getInstance( final CommonODataEntity entity, - final URI entitySetURI, + final String entitySetName, final Class<?> typeRef, - final EntityContainerInvocationHandler containerHandler) { + final EntityContainerInvocationHandler<?> containerHandler) { - return new EntityInvocationHandler(entityURI, entity, entitySetURI, typeRef, containerHandler); + return new EntityTypeInvocationHandler(entity, entitySetName, typeRef, containerHandler); } - private EntityInvocationHandler( - final URI entityURI, + private EntityTypeInvocationHandler( final CommonODataEntity entity, - final URI entitySetURI, + final String entitySetName, final Class<?> typeRef, - final EntityContainerInvocationHandler containerHandler) { + final EntityContainerInvocationHandler<C> containerHandler) { super(containerHandler.getClient(), typeRef, (ODataLinked) entity, containerHandler); - this.entityURI = entityURI; this.internal = entity; getEntity().setMediaEntity(typeRef.getAnnotation(EntityType.class).hasStream()); this.uuid = new EntityUUID( containerHandler.getEntityContainerName(), - entitySetURI, + entitySetName, typeRef, CoreUtils.getKey(client, typeRef, entity)); } @@ -118,13 +116,13 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler this.uuid = new EntityUUID( getUUID().getContainerName(), - getUUID().getEntitySetURI(), + getUUID().getEntitySetName(), getUUID().getType(), CoreUtils.getKey(client, typeRef, entity)); - this.streamedPropertyChanges.clear(); this.propertyChanges.clear(); this.linkChanges.clear(); + this.streamedPropertyChanges.clear(); this.propertiesTag = 0; this.linksTag = 0; } @@ -133,22 +131,23 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler return uuid; } + @Override + public FullQualifiedName getName() { + return getEntity().getTypeName(); + } + public String getEntityContainerName() { return uuid.getContainerName(); } - public URI getEntitySetURI() { - return uuid.getEntitySetURI(); + public String getEntitySetName() { + return uuid.getEntitySetName(); } public final CommonODataEntity getEntity() { return (CommonODataEntity) internal; } - public URI getEntityURI() { - return entityURI; - } - /** * Gets the current ETag defined into the wrapped entity. * @@ -190,24 +189,57 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler @Override protected Object getPropertyValue(final String name, final Type type) { try { - if (!(type instanceof ParameterizedType) && (Class<?>) type == InputStream.class) { - return getStreamedProperty(name); - } else { - final CommonODataProperty property = getEntity().getProperty(name); - - Object res; - if (propertyChanges.containsKey(name)) { - res = propertyChanges.get(name); - } else { - res = CoreUtils.getValueFromProperty(client, property, type, this); - - if (res != null) { - chacheProperty(name, res); + final CommonODataProperty property = getEntity().getProperty(name); + + Object res; + if (propertyChanges.containsKey(name)) { + res = propertyChanges.get(name); + } else if (property == null) { + res = null; + } else if (property.hasComplexValue()) { + res = Proxy.newProxyInstance( + Thread.currentThread().getContextClassLoader(), + new Class<?>[] {(Class<?>) type}, + ComplexTypeInvocationHandler.getInstance( + client, property.getValue().asComplex(), (Class<?>) type, this)); + + addPropertyChanges(name, res); + } else if (property.hasCollectionValue()) { + final ParameterizedType collType = (ParameterizedType) type; + final Class<?> collItemClass = (Class<?>) collType.getActualTypeArguments()[0]; + + final ArrayList<Object> collection = new ArrayList<Object>(); + + final Iterator<ODataValue> collPropItor = property.getValue().asCollection().iterator(); + while (collPropItor.hasNext()) { + final ODataValue value = collPropItor.next(); + if (value.isPrimitive()) { + collection.add(CoreUtils.primitiveValueToObject(value.asPrimitive())); + } else if (value.isComplex()) { + final Object collItem = Proxy.newProxyInstance( + Thread.currentThread().getContextClassLoader(), + new Class<?>[] {collItemClass}, + ComplexTypeInvocationHandler.getInstance( + client, value.asComplex(), collItemClass, this)); + + collection.add(collItem); } } - return res; + res = collection; + + addPropertyChanges(name, res); + } else { + res = type == null + ? CoreUtils.getValueFromProperty(client, property) + : CoreUtils.getValueFromProperty(client, property, type); + + if (res != null) { + addPropertyChanges(name, res); + } } + + return res; } catch (Exception e) { throw new IllegalArgumentException("Error getting value for property '" + name + "'", e); } @@ -238,33 +270,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler } @Override - @SuppressWarnings("unchecked") protected void setPropertyValue(final Property property, final Object value) { - if (property.type().equalsIgnoreCase("Edm." + EdmPrimitiveTypeKind.Stream.toString())) { + if (property.type().equalsIgnoreCase(EdmPrimitiveTypeKind.Stream.toString())) { setStreamedProperty(property, (InputStream) value); } else { addPropertyChanges(property.name(), value); - - if (value != null) { - final Collection<?> coll; - if (Collection.class.isAssignableFrom(value.getClass())) { - coll = Collection.class.cast(value); - } else { - coll = Collections.singleton(value); - } - - for (Object item : coll) { - if (item instanceof Proxy) { - final InvocationHandler handler = Proxy.getInvocationHandler(item); - if ((handler instanceof ComplexInvocationHandler) - && ((ComplexInvocationHandler) handler).getEntityHandler() == null) { - ((ComplexInvocationHandler) handler).setEntityHandler(this); - } - } - } - } } - attach(AttachedEntityStatus.CHANGED); } @@ -293,6 +304,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler } public InputStream getStream() { + final URI contentSource = getEntity().getMediaContentSource(); if (this.stream == null @@ -311,15 +323,15 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler return this.stream; } - public Object getStreamedProperty(final String name) { + public Object getStreamedProperty(final Property property) { - InputStream res = streamedPropertyChanges.get(name); + InputStream res = streamedPropertyChanges.get(property.name()); try { if (res == null) { final URI link = URIUtils.getURI( containerHandler.getFactory().getServiceRoot(), - CoreUtils.getMediaEditLink(name, getEntity()).toASCIIString()); + CoreUtils.getEditMediaLink(property.name(), getEntity()).toASCIIString()); final ODataMediaRequest req = client.getRetrieveRequestFactory().getMediaRequest(link); res = req.execute().getBody(); @@ -334,8 +346,8 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler } private void setStreamedProperty(final Property property, final InputStream input) { - final Object obj = streamedPropertyChanges.get(property.name()); - if (obj instanceof InputStream) { + final Object obj = propertyChanges.get(property.name()); + if (obj != null && obj instanceof InputStream) { IOUtils.closeQuietly((InputStream) obj); } @@ -349,11 +361,11 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler if (linkChanges.containsKey(property)) { navPropValue = linkChanges.get(property); } else { - navPropValue = retrieveNavigationProperty(property, getter, containerHandler.getFactory().getServiceRoot()); + navPropValue = retriveNavigationProperty(property, getter); } if (navPropValue != null) { - cacheLink(property, navPropValue); + addLinkChanges(property, navPropValue); } return navPropValue; @@ -361,10 +373,6 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler @Override protected void addPropertyChanges(final String name, final Object value) { - propertyChanges.put(name, value); - } - - protected void chacheProperty(final String name, final Object value) { final int checkpoint = propertyChanges.hashCode(); propertyChanges.put(name, value); updatePropertiesTag(checkpoint); @@ -372,10 +380,6 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler @Override protected void addLinkChanges(final NavigationProperty navProp, final Object value) { - linkChanges.put(navProp, value); - } - - protected void cacheLink(final NavigationProperty navProp, final Object value) { final int checkpoint = linkChanges.hashCode(); linkChanges.put(navProp, value); updateLinksTag(checkpoint); @@ -393,7 +397,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler @Override public boolean equals(final Object obj) { - return obj instanceof EntityInvocationHandler - && ((EntityInvocationHandler) obj).getUUID().equals(uuid); + return obj instanceof EntityTypeInvocationHandler + && ((EntityTypeInvocationHandler) obj).getUUID().equals(uuid); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ad770860/fit/src/main/java/org/apache/olingo/fit/V3Services.java ---------------------------------------------------------------------- diff --git a/fit/src/main/java/org/apache/olingo/fit/V3Services.java b/fit/src/main/java/org/apache/olingo/fit/V3Services.java index 0a0eb09..45642c3 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V3Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V3Services.java @@ -156,7 +156,7 @@ public class V3Services extends AbstractServices { addChangesetItemIntro(chbos, lastContebtID, cboundary); res = bodyPartRequest(new MimeBodyPart(part.getInputStream()), references); - if (res==null || res.getStatus() >= 400) { + if (res.getStatus() >= 400) { throw new Exception("Failure processing changeset"); } @@ -211,22 +211,6 @@ public class V3Services extends AbstractServices { } @GET - @Path("/Car/{type:.*}") - public Response filterCar( - @Context UriInfo uriInfo, - @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept, - @QueryParam("$top") @DefaultValue(StringUtils.EMPTY) String top, - @QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) String skip, - @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format, - @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) String count, - @QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) String filter, - @QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) String orderby, - @QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) String skiptoken) { - - return super.getEntitySet(uriInfo, accept, "Car", top, skip, format, count, filter, orderby, skiptoken); - } - - @GET @Path("/Login({entityId})") public Response getLogin( @Context UriInfo uriInfo, http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ad770860/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java ---------------------------------------------------------------------- diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java index 00259321..77c24d6 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java @@ -41,6 +41,7 @@ import javax.ws.rs.NotFoundException; import javax.ws.rs.core.Response; import javax.xml.stream.XMLStreamException; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileObject; import org.apache.olingo.commons.api.data.Entity; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ad770860/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java index df6ef13..c7e2948 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java @@ -34,7 +34,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; -import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler; +import org.apache.olingo.ext.proxy.commons.EntityTypeInvocationHandler; import org.apache.olingo.ext.proxy.context.AttachedEntityStatus; import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types. ContactDetails; @@ -62,10 +62,10 @@ public class ContextTestITCase extends AbstractTestITCase { final Customer customer1 = container.getCustomer().newCustomer(); final Customer customer2 = container.getCustomer().newCustomer(); - final EntityInvocationHandler source1 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer1); - final EntityInvocationHandler source2 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer2); + final EntityTypeInvocationHandler source1 = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer1); + final EntityTypeInvocationHandler source2 = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer2); assertTrue(entityContext.isAttached(source1)); assertTrue(entityContext.isAttached(source2)); @@ -85,12 +85,12 @@ public class ContextTestITCase extends AbstractTestITCase { final Customer customer2 = container.getCustomer().get(-9); final Customer customer3 = container.getCustomer().get(-10); - final EntityInvocationHandler source1 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer1); - final EntityInvocationHandler source2 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer2); - final EntityInvocationHandler source3 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer3); + final EntityTypeInvocationHandler source1 = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer1); + final EntityTypeInvocationHandler source2 = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer2); + final EntityTypeInvocationHandler source3 = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer3); assertFalse(entityContext.isAttached(source1)); assertFalse(entityContext.isAttached(source2)); @@ -133,10 +133,10 @@ public class ContextTestITCase extends AbstractTestITCase { assertNotNull(customer.getInfo()); - final EntityInvocationHandler source = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer); - final EntityInvocationHandler target = - (EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo); + final EntityTypeInvocationHandler source = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer); + final EntityTypeInvocationHandler target = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo); assertTrue(entityContext.isAttached(source)); assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(source)); @@ -160,10 +160,10 @@ public class ContextTestITCase extends AbstractTestITCase { assertNotNull(customer.getInfo()); - final EntityInvocationHandler source = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer); - final EntityInvocationHandler target = - (EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo); + final EntityTypeInvocationHandler source = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer); + final EntityTypeInvocationHandler target = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo); assertTrue(entityContext.isAttached(source)); assertEquals(AttachedEntityStatus.CHANGED, entityContext.getStatus(source)); @@ -187,10 +187,10 @@ public class ContextTestITCase extends AbstractTestITCase { assertNotNull(customer.getInfo()); - final EntityInvocationHandler source = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer); - final EntityInvocationHandler target = - (EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo); + final EntityTypeInvocationHandler source = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer); + final EntityTypeInvocationHandler target = + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo); assertTrue(entityContext.isAttached(source)); assertEquals(AttachedEntityStatus.CHANGED, entityContext.getStatus(source)); @@ -218,14 +218,16 @@ public class ContextTestITCase extends AbstractTestITCase { assertNotNull(customer.getOrders()); assertEquals(3, customer.getOrders().size()); - final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer); + final EntityTypeInvocationHandler<?> source = + (EntityTypeInvocationHandler<?>) Proxy.getInvocationHandler(customer); assertTrue(entityContext.isAttached(source)); assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(source)); assertEquals(3, ((Collection) (source.getLinkChanges().entrySet().iterator().next().getValue())).size()); for (Order order : toBeLinked) { - final EntityInvocationHandler target = (EntityInvocationHandler) Proxy.getInvocationHandler(order); + final EntityTypeInvocationHandler<?> target = + (EntityTypeInvocationHandler<?>) Proxy.getInvocationHandler(order); assertTrue(entityContext.isAttached(target)); assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(target)); @@ -237,7 +239,7 @@ public class ContextTestITCase extends AbstractTestITCase { assertFalse(entityContext.isAttached(source)); for (Order order : toBeLinked) { - assertFalse(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(order))); + assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(order))); } } @@ -263,7 +265,7 @@ public class ContextTestITCase extends AbstractTestITCase { assertEquals(2, customer.getBackupContactInfo().iterator().next().getAlternativeNames().size()); assertTrue(customer.getBackupContactInfo().iterator().next().getAlternativeNames().contains("alternative4")); - final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer); + final EntityTypeInvocationHandler source = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer); assertTrue(entityContext.isAttached(source)); assertEquals(AttachedEntityStatus.NEW, entityContext.getStatus(source)); @@ -320,7 +322,7 @@ public class ContextTestITCase extends AbstractTestITCase { public void checkContextInCaseOfErrors() { final Login login = container.getLogin().newLogin(); - final EntityInvocationHandler handler = (EntityInvocationHandler) Proxy.getInvocationHandler(login); + final EntityTypeInvocationHandler handler = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(login); assertTrue(entityContext.isAttached(handler)); @@ -387,18 +389,18 @@ public class ContextTestITCase extends AbstractTestITCase { customer.setPrimaryContactInfo(cd); customer.setBackupContactInfo(Collections.<ContactDetails>singletonList(bcd)); - assertTrue(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo))); - assertTrue(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer))); + assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo))); + assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer))); for (Order linked : toBeLinked) { - assertTrue(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked))); + assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(linked))); } container.flush(); - assertFalse(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo))); - assertFalse(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer))); + assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customerInfo))); + assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer))); for (Order linked : toBeLinked) { - assertFalse(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked))); + assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(linked))); } assertEquals("some new info ...", container.getCustomerInfo().get(16).getInformation()); @@ -406,22 +408,22 @@ public class ContextTestITCase extends AbstractTestITCase { container.getOrder().delete(toBeLinked); container.getCustomer().delete(customer.getCustomerId()); - assertTrue(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer))); + assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer))); for (Order linked : toBeLinked) { - assertTrue(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked))); + assertTrue(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(linked))); } container.flush(); - assertFalse(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer))); + assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(customer))); for (Order linked : toBeLinked) { - assertFalse(entityContext.isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked))); + assertFalse(entityContext.isAttached((EntityTypeInvocationHandler) Proxy.getInvocationHandler(linked))); } } private void checkUnlink( final String sourceName, - final EntityInvocationHandler source) { + final EntityTypeInvocationHandler<?> source) { boolean found = false; for (Map.Entry<NavigationProperty, Object> property : source.getLinkChanges().entrySet()) { @@ -434,8 +436,8 @@ public class ContextTestITCase extends AbstractTestITCase { private void checkLink( final String sourceName, - final EntityInvocationHandler source, - final EntityInvocationHandler target, + final EntityTypeInvocationHandler<?> source, + final EntityTypeInvocationHandler<?> target, final boolean isCollection) { boolean found = false; @@ -444,13 +446,13 @@ public class ContextTestITCase extends AbstractTestITCase { if (isCollection) { found = false; for (Object proxy : (Collection) property.getValue()) { - if (target.equals((EntityInvocationHandler) Proxy.getInvocationHandler(proxy))) { + if (target.equals((EntityTypeInvocationHandler) Proxy.getInvocationHandler(proxy))) { found = true; } } } else { found = target.equals( - (EntityInvocationHandler) Proxy.getInvocationHandler(property.getValue())); + (EntityTypeInvocationHandler) Proxy.getInvocationHandler(property.getValue())); } } } @@ -459,9 +461,9 @@ public class ContextTestITCase extends AbstractTestITCase { private void checkUnidirectional( final String sourceName, - final EntityInvocationHandler source, + final EntityTypeInvocationHandler<?> source, final String targetName, - final EntityInvocationHandler target, + final EntityTypeInvocationHandler<?> target, final boolean isCollection) { checkLink(sourceName, source, target, isCollection);
