[OLINGO-260] provided singleton integration test on proxy
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/a528af77 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/a528af77 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/a528af77 Branch: refs/heads/olingo-266-ref Commit: a528af77ff5c360b689cfbfa66750496ff3ba00e Parents: 15dcb15 Author: fmartelli <[email protected]> Authored: Tue May 13 14:40:56 2014 +0200 Committer: Stephan Klevenz <[email protected]> Committed: Mon May 19 12:33:25 2014 +0200 ---------------------------------------------------------------------- .../commons/EntitySetInvocationHandler.java | 27 +++++++++++-- .../fit/proxy/v4/SingletonTestITCase.java | 40 ++++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a528af77/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java ---------------------------------------------------------------------- diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java index 10c68f2..209c8ea 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java @@ -55,6 +55,7 @@ import org.apache.olingo.ext.proxy.context.AttachedEntityStatus; import org.apache.olingo.ext.proxy.context.EntityContext; import org.apache.olingo.ext.proxy.context.EntityUUID; import org.apache.olingo.ext.proxy.utils.ClassUtils; +import org.apache.olingo.ext.proxy.utils.CoreUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -276,11 +277,29 @@ class EntitySetInvocationHandler<C extends CommonEdmEnabledODataClient<?>, T ext LOG.debug("Execute query '{}'", uriBuilder.toString()); - final ODataRetrieveResponse<CommonODataEntity> res = - client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute(); + final CommonODataEntity entity; + final String etag; - handler = EntityTypeInvocationHandler.getInstance(res.getBody(), this, typeRef); - handler.setETag(res.getETag()); + if (isSingleton) { + final ODataRetrieveResponse<org.apache.olingo.commons.api.domain.v4.Singleton> res = + ((ODataClient) client).getRetrieveRequestFactory().getSingletonRequest(uri).execute(); + + entity = res.getBody(); + etag = res.getETag(); + } else { + final ODataRetrieveResponse<CommonODataEntity> res = + client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute(); + + etag = res.getETag(); + entity = res.getBody(); + + if (entity == null || !key.equals(CoreUtils.getKey(client, typeRef, entity))) { + throw new IllegalArgumentException("Invalid singleton " + typeRef.getSimpleName() + "(" + key + ")"); + } + } + + handler = EntityTypeInvocationHandler.getInstance(entity, this, typeRef); + handler.setETag(etag); } catch (Exception e) { LOG.info("Entity '" + uuid + "' not found", e); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a528af77/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java new file mode 100644 index 0000000..6886756 --- /dev/null +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java @@ -0,0 +1,40 @@ +/* + * 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. + */ +package org.apache.olingo.fit.proxy.v4; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +/** + * This is the unit test class to check entity create operations. + */ +public class SingletonTestITCase extends AbstractTestITCase { + + @Test + public void read() { + assertNotNull(container.getCompany().get(0)); + entityContext.detachAll(); + assertNotNull(container.getCompany().iterator().next()); + entityContext.detachAll(); + assertEquals(1, container.getCompany().count(), 0); + entityContext.detachAll(); + } +}
