[OLINGO-260] provided singleton integration test on proxy
This commit is contained in:
parent
9902955c8b
commit
d4400f608e
|
@ -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 CommonODataEntity entity;
|
||||
final String etag;
|
||||
|
||||
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();
|
||||
|
||||
handler = EntityTypeInvocationHandler.getInstance(res.getBody(), this, typeRef);
|
||||
handler.setETag(res.getETag());
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -19,27 +19,22 @@
|
|||
package org.apache.olingo.fit.proxy.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Company;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.CompanyCategory;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* This is the unit test class to check entity create operations.
|
||||
*/
|
||||
public class SingletonTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void read() {
|
||||
final Company company = container.getCompany().get();
|
||||
assertEquals(0, company.getCompanyID(), 0);
|
||||
assertEquals(CompanyCategory.IT, company.getCompanyCategory());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update() {
|
||||
final Company company = container.getCompany().get();
|
||||
company.setRevenue(132520L);
|
||||
|
||||
container.flush();
|
||||
|
||||
assertEquals(132520L, container.getCompany().get().getRevenue(), 0);
|
||||
assertNotNull(container.getCompany().get(0));
|
||||
entityContext.detachAll();
|
||||
assertNotNull(container.getCompany().iterator().next());
|
||||
entityContext.detachAll();
|
||||
assertEquals(1, container.getCompany().count(), 0);
|
||||
entityContext.detachAll();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue