[OLINGO-260] provided singleton integration test on proxy

This commit is contained in:
fmartelli 2014-05-13 14:40:56 +02:00
parent 1a14f3f193
commit 36219a267a
2 changed files with 63 additions and 4 deletions

View File

@ -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);
}

View File

@ -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();
}
}