mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-06 16:49:09 +00:00
[OLINGO-260] V4 bound operation invoke
This commit is contained in:
parent
390d3a3a7a
commit
77e9e86d59
@ -34,6 +34,7 @@ import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataOperation;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmOperation;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.ext.proxy.api.OperationExecutor;
|
||||
@ -180,17 +181,34 @@ class OperationInvocationHandler<C extends CommonEdmEnabledODataClient<?>> exten
|
||||
private Map.Entry<URI, EdmOperation> getBoundOperation(final Operation operation, final List<String> parameterNames) {
|
||||
final CommonODataEntity entity = ((EntityTypeInvocationHandler<?>) target).getEntity();
|
||||
|
||||
final ODataOperation boundOp = entity.getOperation(operation.name());
|
||||
ODataOperation boundOp = entity.getOperation(operation.name());
|
||||
if (boundOp == null) {
|
||||
boundOp = entity.getOperation(new FullQualifiedName(targetFQN.getNamespace(), operation.name()).toString());
|
||||
}
|
||||
if (boundOp == null) {
|
||||
throw new IllegalArgumentException(String.format("Could not find any matching operation '%s' bound to %s",
|
||||
operation.name(), entity.getTypeName()));
|
||||
}
|
||||
|
||||
EdmOperation edmOperation;
|
||||
if (operation.type() == OperationType.FUNCTION) {
|
||||
edmOperation = client.getCachedEdm().getBoundFunction(
|
||||
new FullQualifiedName(targetFQN.getNamespace(), boundOp.getTitle()),
|
||||
entity.getTypeName(), false, parameterNames);
|
||||
} else {
|
||||
edmOperation = client.getCachedEdm().getBoundAction(
|
||||
new FullQualifiedName(targetFQN.getNamespace(), boundOp.getTitle()),
|
||||
entity.getTypeName(), false);
|
||||
final FullQualifiedName operationFQN = boundOp.getTitle().indexOf('.') == -1
|
||||
? new FullQualifiedName(targetFQN.getNamespace(), boundOp.getTitle())
|
||||
: new FullQualifiedName(boundOp.getTitle());
|
||||
|
||||
EdmEntityType entityType = client.getCachedEdm().getEntityType(entity.getTypeName());
|
||||
EdmOperation edmOperation = null;
|
||||
while (edmOperation == null && entityType != null) {
|
||||
edmOperation = operation.type() == OperationType.FUNCTION
|
||||
? client.getCachedEdm().getBoundFunction(
|
||||
operationFQN, entityType.getFullQualifiedName(), false, parameterNames)
|
||||
: client.getCachedEdm().getBoundAction(
|
||||
operationFQN, entityType.getFullQualifiedName(), false);
|
||||
if (entityType.getBaseType() != null) {
|
||||
entityType = entityType.getBaseType();
|
||||
}
|
||||
}
|
||||
if (edmOperation == null) {
|
||||
throw new IllegalArgumentException(String.format("Could not find any matching operation '%s' bound to %s",
|
||||
operation.name(), entity.getTypeName()));
|
||||
}
|
||||
|
||||
return new AbstractMap.SimpleEntry<URI, EdmOperation>(boundOp.getTarget(), edmOperation);
|
||||
@ -200,10 +218,7 @@ class OperationInvocationHandler<C extends CommonEdmEnabledODataClient<?>> exten
|
||||
private Map.Entry<URI, EdmOperation> getCollectionBoundOperation(
|
||||
final Operation operation, final List<String> parameterNames) {
|
||||
|
||||
final Edm edm = client.getCachedEdm();
|
||||
|
||||
final EdmOperation edmOperation;
|
||||
|
||||
EdmOperation edmOperation;
|
||||
if (operation.type() == OperationType.FUNCTION) {
|
||||
edmOperation = client.getCachedEdm().getBoundFunction(
|
||||
new FullQualifiedName(targetFQN.getNamespace(), operation.name()), targetFQN, true, parameterNames);
|
||||
|
@ -19,6 +19,7 @@
|
||||
package org.apache.olingo.ext.proxy.utils;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -239,15 +240,17 @@ public final class CoreUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Object primitiveValueToObject(final ODataPrimitiveValue value) {
|
||||
private static Object primitiveValueToObject(final ODataPrimitiveValue value, final Class<?> reference) {
|
||||
Object obj;
|
||||
|
||||
try {
|
||||
obj = value.toValue() instanceof Timestamp
|
||||
? value.toCastValue(Calendar.class)
|
||||
: value.toValue();
|
||||
: reference == null
|
||||
? value.toValue()
|
||||
: value.toCastValue(reference);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
LOG.warn("Could not read temporal value as Calendar, reverting to Timestamp", e);
|
||||
LOG.warn("While casting primitive value {} to {}", value, reference, e);
|
||||
obj = value.toValue();
|
||||
}
|
||||
|
||||
@ -262,6 +265,19 @@ public final class CoreUtils {
|
||||
bean.getClass().getMethod(setterName, getter.getReturnType()).invoke(bean, value);
|
||||
}
|
||||
|
||||
private static Class<?> getPropertyClass(final Class<?> entityClass, final String propertyName) {
|
||||
Class<?> propertyClass = null;
|
||||
try {
|
||||
final Field field = entityClass.getField(propertyName);
|
||||
if (field != null) {
|
||||
propertyClass = field.getType();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not determine the Java type of {}", propertyName, e);
|
||||
}
|
||||
return propertyClass;
|
||||
}
|
||||
|
||||
public static Object getKey(
|
||||
final CommonEdmEnabledODataClient<?> client, final Class<?> entityTypeRef, final CommonODataEntity entity) {
|
||||
|
||||
@ -272,7 +288,8 @@ public final class CoreUtils {
|
||||
if (keyRef == null) {
|
||||
final CommonODataProperty property = entity.getProperty(firstValidEntityKey(entityTypeRef));
|
||||
if (property != null && property.hasPrimitiveValue()) {
|
||||
res = primitiveValueToObject(property.getPrimitiveValue());
|
||||
res = primitiveValueToObject(
|
||||
property.getPrimitiveValue(), getPropertyClass(entityTypeRef, property.getName()));
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
@ -332,7 +349,8 @@ public final class CoreUtils {
|
||||
if (property.hasNullValue()) {
|
||||
setPropertyValue(bean, getter, null);
|
||||
} else if (property.hasPrimitiveValue()) {
|
||||
setPropertyValue(bean, getter, primitiveValueToObject(property.getPrimitiveValue()));
|
||||
setPropertyValue(bean, getter, primitiveValueToObject(
|
||||
property.getPrimitiveValue(), getPropertyClass(reference, property.getName())));
|
||||
} else if (property.hasComplexValue()) {
|
||||
final Object complex = Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
@ -356,7 +374,8 @@ public final class CoreUtils {
|
||||
while (collPropItor.hasNext()) {
|
||||
final ODataValue value = collPropItor.next();
|
||||
if (value.isPrimitive()) {
|
||||
collection.add(primitiveValueToObject(value.asPrimitive()));
|
||||
collection.add(primitiveValueToObject(
|
||||
value.asPrimitive(), getPropertyClass(reference, property.getName())));
|
||||
} else if (value.isComplex()) {
|
||||
final Object collItem = Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
@ -436,7 +455,7 @@ public final class CoreUtils {
|
||||
while (collPropItor.hasNext()) {
|
||||
final ODataValue value = collPropItor.next();
|
||||
if (value.isPrimitive()) {
|
||||
collection.add(CoreUtils.primitiveValueToObject(value.asPrimitive()));
|
||||
collection.add(CoreUtils.primitiveValueToObject(value.asPrimitive(), internalRef));
|
||||
} else if (value.isComplex()) {
|
||||
final Object collItem = Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
@ -452,7 +471,7 @@ public final class CoreUtils {
|
||||
} else if (property instanceof ODataProperty && ((ODataProperty) property).hasEnumValue()) {
|
||||
res = buildEnumInstance(((ODataProperty) property).getEnumValue());
|
||||
} else {
|
||||
res = primitiveValueToObject(property.getPrimitiveValue());
|
||||
res = primitiveValueToObject(property.getPrimitiveValue(), internalRef);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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 java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccessLevel;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccountInfo;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Address;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Customer;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.
|
||||
PaymentInstrument;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Person;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Product;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.
|
||||
ProductDetailCollection;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.
|
||||
ProductDetailKey;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void getEmployeesCount() {
|
||||
assertNotNull(container.getCompany().get(0).operations().getEmployeesCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProductDetails() {
|
||||
final ProductDetailCollection result = container.getProducts().get(5).operations().getProductDetails(1);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRelatedProduct() {
|
||||
final ProductDetailKey key = new ProductDetailKey();
|
||||
key.setProductID(6);
|
||||
key.setProductDetailID(1);
|
||||
|
||||
final Product product = container.getProductDetails().get(key).operations().getRelatedProduct();
|
||||
assertEquals(6, product.getProductID(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultPI() {
|
||||
final PaymentInstrument pi = container.getAccounts().get(101).operations().getDefaultPI();
|
||||
assertEquals(101901, pi.getPaymentInstrumentID(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAccountInfo() {
|
||||
final AccountInfo accountInfo = container.getAccounts().get(101).operations().getAccountInfo();
|
||||
assertNotNull(accountInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getActualAmount() {
|
||||
final Double amount = container.getAccounts().get(101).getMyGiftCard().operations().getActualAmount(1.1);
|
||||
assertEquals(41.79, amount, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void increaseRevenue() {
|
||||
final Long result = container.getCompany().get(0).operations().increaseRevenue(12L);
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addAccessRight() {
|
||||
final AccessLevel accessLevel = container.getProducts().get(5).operations().addAccessRight(AccessLevel.Execute);
|
||||
assertNotNull(accessLevel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetAddress() {
|
||||
final Customer customer = container.getCustomers().get(2);
|
||||
|
||||
final Address address = customer.factory().newHomeAddress();
|
||||
address.setStreet("Via Le Mani Dal Naso, 123");
|
||||
address.setPostalCode("Tollo");
|
||||
address.setCity("66010");
|
||||
|
||||
final Person person = container.getCustomers().get(2).operations().
|
||||
resetAddress(Collections.singletonList(address), 0);
|
||||
assertEquals(2, person.getPersonID(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDefaultPI() {
|
||||
final PaymentInstrument pi = container.getAccounts().get(101).operations().refreshDefaultPI(Calendar.getInstance());
|
||||
assertEquals(101901, pi.getPaymentInstrumentID(), 0);
|
||||
}
|
||||
}
|
@ -21,11 +21,9 @@ 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.junit.Test;
|
||||
|
||||
/**
|
||||
* This is the unit test class to check entity create operations.
|
||||
*/
|
||||
public class SingletonTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
@ -37,4 +35,14 @@ public class SingletonTestITCase extends AbstractTestITCase {
|
||||
assertEquals(1, container.getCompany().count(), 0);
|
||||
entityContext.detachAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update() {
|
||||
final Company company = container.getCompany().get(0);
|
||||
company.setRevenue(132520L);
|
||||
|
||||
container.flush();
|
||||
|
||||
assertEquals(132520L, container.getCompany().get(0).getRevenue(), 0);
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,7 @@ import org.junit.Test;
|
||||
public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
|
||||
private Edm getEdm() {
|
||||
final Edm edm = getClient().getRetrieveRequestFactory().
|
||||
getMetadataRequest(testStaticServiceRootURL).execute().getBody();
|
||||
final Edm edm = client.getRetrieveRequestFactory().getMetadataRequest(testStaticServiceRootURL).execute().getBody();
|
||||
assertNotNull(edm);
|
||||
|
||||
return edm;
|
||||
@ -64,9 +63,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertNotNull(container);
|
||||
|
||||
// GetEmployeesCount
|
||||
URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
|
||||
URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
|
||||
final ODataEntityRequest<Singleton> singletonReq =
|
||||
getClient().getRetrieveRequestFactory().getSingletonRequest(builder.build());
|
||||
client.getRetrieveRequestFactory().getSingletonRequest(builder.build());
|
||||
singletonReq.setFormat(format);
|
||||
final Singleton company = singletonReq.execute().getBody();
|
||||
assertNotNull(company);
|
||||
@ -79,16 +78,16 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertNotNull(func);
|
||||
|
||||
final ODataInvokeRequest<ODataProperty> getEmployeesCountReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
|
||||
getEmployeesCountReq.setFormat(format);
|
||||
final ODataProperty getEmployeesCountRes = getEmployeesCountReq.execute().getBody();
|
||||
assertNotNull(getEmployeesCountRes);
|
||||
assertTrue(getEmployeesCountRes.hasPrimitiveValue());
|
||||
|
||||
// GetProductDetails
|
||||
builder = getClient().getURIBuilder(testStaticServiceRootURL).
|
||||
builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Products").appendKeySegment(5);
|
||||
ODataEntityRequest<ODataEntity> entityReq = getClient().getRetrieveRequestFactory().
|
||||
ODataEntityRequest<ODataEntity> entityReq = client.getRetrieveRequestFactory().
|
||||
getEntityRequest(builder.build());
|
||||
entityReq.setFormat(format);
|
||||
ODataEntity entity = entityReq.execute().getBody();
|
||||
@ -100,9 +99,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
|
||||
assertNotNull(func);
|
||||
|
||||
final ODataPrimitiveValue count = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1);
|
||||
final ODataPrimitiveValue count = client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(1);
|
||||
final ODataInvokeRequest<ODataEntitySet> getProductDetailsReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func,
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func,
|
||||
Collections.<String, ODataValue>singletonMap("count", count));
|
||||
getProductDetailsReq.setFormat(format);
|
||||
final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody();
|
||||
@ -113,9 +112,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
final Map<String, Object> keyMap = new LinkedHashMap<String, Object>();
|
||||
keyMap.put("ProductID", 6);
|
||||
keyMap.put("ProductDetailID", 1);
|
||||
builder = getClient().getURIBuilder(testStaticServiceRootURL).
|
||||
builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("ProductDetails").appendKeySegment(keyMap);
|
||||
entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq.setFormat(format);
|
||||
entity = entityReq.execute().getBody();
|
||||
assertNotNull(entity);
|
||||
@ -127,7 +126,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertNotNull(func);
|
||||
|
||||
final ODataInvokeRequest<ODataEntity> getRelatedProductReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
|
||||
getRelatedProductReq.setFormat(format);
|
||||
final ODataEntity getRelatedProductRes = getRelatedProductReq.execute().getBody();
|
||||
assertNotNull(getRelatedProductRes);
|
||||
@ -136,9 +135,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertEquals(6, getRelatedProductRes.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
|
||||
// GetDefaultPI
|
||||
builder = getClient().getURIBuilder(testStaticServiceRootURL).
|
||||
builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Accounts").appendKeySegment(101);
|
||||
entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq.setFormat(format);
|
||||
entity = entityReq.execute().getBody();
|
||||
assertNotNull(entity);
|
||||
@ -150,7 +149,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertNotNull(func);
|
||||
|
||||
final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
|
||||
getDefaultPIReq.setFormat(format);
|
||||
final ODataEntity getDefaultPIRes = getDefaultPIReq.execute().getBody();
|
||||
assertNotNull(getDefaultPIRes);
|
||||
@ -167,7 +166,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertNotNull(func);
|
||||
|
||||
final ODataInvokeRequest<ODataProperty> getAccountInfoReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
|
||||
getAccountInfoReq.setFormat(format);
|
||||
final ODataProperty getAccountInfoRes = getAccountInfoReq.execute().getBody();
|
||||
assertNotNull(getAccountInfoRes);
|
||||
@ -176,7 +175,7 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
getAccountInfoRes.getComplexValue().getTypeName());
|
||||
|
||||
// GetActualAmount
|
||||
entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(
|
||||
entityReq = client.getRetrieveRequestFactory().getEntityRequest(
|
||||
entity.getNavigationLink("MyGiftCard").getLink());
|
||||
entityReq.setFormat(format);
|
||||
entity = entityReq.execute().getBody();
|
||||
@ -189,9 +188,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
|
||||
assertNotNull(func);
|
||||
|
||||
final ODataPrimitiveValue bonusRate = getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.1);
|
||||
final ODataPrimitiveValue bonusRate = client.getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.1);
|
||||
final ODataInvokeRequest<ODataProperty> getActualAmountReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func,
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func,
|
||||
Collections.<String, ODataValue>singletonMap("bonusRate", bonusRate));
|
||||
getActualAmountReq.setFormat(format);
|
||||
final ODataProperty getActualAmountRes = getActualAmountReq.execute().getBody();
|
||||
@ -215,9 +214,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertNotNull(container);
|
||||
|
||||
// IncreaseRevenue
|
||||
URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
|
||||
URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
|
||||
ODataEntityRequest<ODataEntity> entityReq =
|
||||
getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
client.getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq.setFormat(format);
|
||||
ODataEntity entity = entityReq.execute().getBody();
|
||||
assertNotNull(entity);
|
||||
@ -228,10 +227,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
EdmAction act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
|
||||
assertNotNull(act);
|
||||
|
||||
final ODataPrimitiveValue increaseValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.Int64).setValue(12).build();
|
||||
final ODataPrimitiveValue increaseValue =
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().buildInt64(12L);
|
||||
final ODataInvokeRequest<ODataProperty> increaseRevenueReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
|
||||
Collections.<String, ODataValue>singletonMap("IncreaseValue", increaseValue));
|
||||
increaseRevenueReq.setFormat(format);
|
||||
final ODataProperty increaseRevenueRes = increaseRevenueReq.execute().getBody();
|
||||
@ -239,9 +238,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertTrue(increaseRevenueRes.hasPrimitiveValue());
|
||||
|
||||
// AddAccessRight
|
||||
builder = getClient().getURIBuilder(testStaticServiceRootURL).
|
||||
builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Products").appendKeySegment(5);
|
||||
entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq.setFormat(format);
|
||||
entity = entityReq.execute().getBody();
|
||||
assertNotNull(entity);
|
||||
@ -252,10 +251,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
|
||||
assertNotNull(act);
|
||||
|
||||
final ODataEnumValue accessRight = getClient().getObjectFactory().
|
||||
final ODataEnumValue accessRight = client.getObjectFactory().
|
||||
newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "Execute");
|
||||
final ODataInvokeRequest<ODataProperty> getProductDetailsReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
|
||||
Collections.<String, ODataValue>singletonMap("accessRight", accessRight));
|
||||
getProductDetailsReq.setFormat(format);
|
||||
final ODataProperty getProductDetailsRes = getProductDetailsReq.execute().getBody();
|
||||
@ -263,9 +262,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertTrue(getProductDetailsRes.hasEnumValue());
|
||||
|
||||
// ResetAddress
|
||||
builder = getClient().getURIBuilder(testStaticServiceRootURL).
|
||||
builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Customers").appendKeySegment(2);
|
||||
entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq.setFormat(format);
|
||||
entity = entityReq.execute().getBody();
|
||||
assertNotNull(entity);
|
||||
@ -278,9 +277,9 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
assertNotNull(act);
|
||||
|
||||
final ODataCollectionValue<org.apache.olingo.commons.api.domain.v4.ODataValue> addresses =
|
||||
getClient().getObjectFactory().
|
||||
client.getObjectFactory().
|
||||
newCollectionValue("Collection(Microsoft.Test.OData.Services.ODataWCFService.Address)");
|
||||
final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
|
||||
final ODataComplexValue<ODataProperty> address = client.getObjectFactory().
|
||||
newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
|
||||
address.add(client.getObjectFactory().newPrimitiveProperty("Street",
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().buildString("Piazza La Bomba E Scappa")));
|
||||
@ -289,21 +288,21 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
|
||||
client.getObjectFactory().newPrimitiveValueBuilder().buildString("66010")));
|
||||
addresses.add(address);
|
||||
final ODataPrimitiveValue index = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(0);
|
||||
final ODataPrimitiveValue index = client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(0);
|
||||
final Map<String, ODataValue> params = new LinkedHashMap<String, ODataValue>(2);
|
||||
params.put("addresses", addresses);
|
||||
params.put("index", index);
|
||||
final ODataInvokeRequest<ODataEntity> resetAddressReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act, params);
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act, params);
|
||||
resetAddressReq.setFormat(format);
|
||||
final ODataEntity resetAddressRes = resetAddressReq.execute().getBody();
|
||||
assertNotNull(resetAddressRes);
|
||||
assertEquals(2, resetAddressRes.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
|
||||
|
||||
// RefreshDefaultPI
|
||||
builder = getClient().getURIBuilder(testStaticServiceRootURL).
|
||||
builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Accounts").appendKeySegment(101);
|
||||
entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq = client.getRetrieveRequestFactory().getEntityRequest(builder.build());
|
||||
entityReq.setFormat(format);
|
||||
entity = entityReq.execute().getBody();
|
||||
assertNotNull(entity);
|
||||
@ -314,10 +313,10 @@ public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
|
||||
act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
|
||||
assertNotNull(act);
|
||||
|
||||
final ODataPrimitiveValue newDate = getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
final ODataPrimitiveValue newDate = client.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2014-04-09T00:00:00Z").build();
|
||||
final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
|
||||
getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
|
||||
client.getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
|
||||
Collections.<String, ODataValue>singletonMap("newDate", newDate));
|
||||
getDefaultPIReq.setFormat(format);
|
||||
final ODataEntity getDefaultPIRes = getDefaultPIReq.execute().getBody();
|
||||
|
@ -34,7 +34,6 @@ import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataValuable;
|
||||
import org.apache.olingo.commons.api.domain.v4.Singleton;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.junit.Test;
|
||||
@ -106,8 +105,7 @@ public class SingletonTestITCase extends AbstractTestITCase {
|
||||
final Singleton changes = getClient().getObjectFactory().newSingleton(
|
||||
new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Company"));
|
||||
changes.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Revenue",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.Int64).setText("132520").build()));
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt64(132520L)));
|
||||
|
||||
final URI uri = client.getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company").build();
|
||||
final ODataEntityUpdateRequest<Singleton> req = getClient().getCUDRequestFactory().
|
||||
|
Loading…
x
Reference in New Issue
Block a user