本文整理汇总了Java中org.apache.olingo.client.api.domain.ClientObjectFactory.newEntity方法的典型用法代码示例。如果您正苦于以下问题:Java ClientObjectFactory.newEntity方法的具体用法?Java ClientObjectFactory.newEntity怎么用?Java ClientObjectFactory.newEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.olingo.client.api.domain.ClientObjectFactory
的用法示例。
在下文中一共展示了ClientObjectFactory.newEntity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: consistency
import org.apache.olingo.client.api.domain.ClientObjectFactory; //导入方法依赖的package包/类
@Test
public void consistency() throws Exception {
final EdmEnabledODataClient client = getEdmEnabledClient();
final ClientObjectFactory factory = getFactory();
final String cookie = getCookie();
// Do not set PropertyString(Nullable=false)
final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
entity.getProperties().add(
factory.newCollectionProperty(COL_PROPERTY_STRING,
factory.newCollectionValue(EDM_STRING).add(
factory.newPrimitiveValueBuilder().buildString("Test"))));
final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
try {
ODataEntityCreateRequest<ClientEntity> request = client.getCUDRequestFactory()
.getEntityCreateRequest(targetURI, entity);
request.addCustomHeader(HttpHeader.COOKIE, cookie);
request.execute();
fail("Expecting bad request");
} catch (ODataClientErrorException e) {
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
}
// Entity must not be created
validateSet(targetURI, cookie, (short) 1, (short) 2, (short) 3);
}
示例2: deepInsertWithBindingSameNavigationProperty
import org.apache.olingo.client.api.domain.ClientObjectFactory; //导入方法依赖的package包/类
@Test
public void deepInsertWithBindingSameNavigationProperty() {
final ClientObjectFactory factory = getFactory();
final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
entity.getProperties().add(factory.newPrimitiveProperty(PROPERTY_STRING, factory
.newPrimitiveValueBuilder()
.buildString("1")));
entity.getProperties().add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue
(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
((short) 1)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("1")))));
final ClientEntity innerEntity = factory.newEntity(ET_KEY_NAV);
innerEntity.getProperties().add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
.buildString("2")));
innerEntity.getProperties().add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 1)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("2")))));
innerEntity.addLink(factory.newEntityNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE,
getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_TWO_KEY_NAV)
.appendKeySegment(new LinkedHashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put(PROPERTY_INT16, 3);
put(PROPERTY_STRING, "1");
}
}).build()));
final ClientInlineEntity inlineLink = factory.newDeepInsertEntity(NAV_PROPERTY_ET_KEY_NAV_ONE, innerEntity);
entity.addLink(inlineLink);
entity.addLink(factory.newEntityNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE,
getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_TWO_KEY_NAV)
.appendKeySegment(new LinkedHashMap<String, Object>() {
private static final long serialVersionUID = 3109256773218160485L;
{
put(PROPERTY_INT16, 3);
put(PROPERTY_STRING, "1");
}
}).build()));
final URI bindingURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(3)
.build();
entity.addLink(factory.newEntityNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE, bindingURI));
final URI targetURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
final ODataEntityCreateResponse<ClientEntity> response =
getEdmEnabledClient().getCUDRequestFactory().getEntityCreateRequest(targetURI, entity).execute();
assertEquals(HttpStatusCode.CREATED.getStatusCode(), response.getStatusCode());
if (isJson()) {
assertEquals(1, response.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE)
.asInlineEntity()
.getEntity()
.getProperty(PROPERTY_COMP_TWO_PRIM)
.getComplexValue()
.get(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
}
}
示例3: badRequestInChangeSet
import org.apache.olingo.client.api.domain.ClientObjectFactory; //导入方法依赖的package包/类
@Test
public void badRequestInChangeSet() {
/*
* A bad request (status code >= 400) without "continue on error prefer header" in a changeset
* should return a single response with Content-Type: application/http
*
* See:
* OData Version 4.0 Part 1: Protocol Plus Errata 01
* 11.7.4 Responding to a Batch Request
*
* When a request within a change set fails, the change set response is not represented using
* the multipart/mixed media type. Instead, a single response, using the application/http media type
* and a Content-Transfer-Encoding header with a value of binary, is returned that applies to all requests
* in the change set and MUST be formatted according to the Error Handling defined
* for the particular response format.
*/
// Try to create entity, with invalid type
ClientObjectFactory factory = getFactory();
final ClientEntity entity = factory.newEntity(ES_NOT_AVAILABLE);
entity.getProperties().add(
factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("1")));
BatchManager payloadManager = getClient().getBatchRequestFactory().getBatchRequest(SERVICE_URI).payloadManager();
final ODataChangeset changeset = payloadManager.addChangeset();
final URI targetURI = getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_NOT_AVAILABLE_NAME)
.build();
final ODataEntityCreateRequest<ClientEntity> createRequest = getClient().getCUDRequestFactory()
.getEntityCreateRequest(targetURI, entity);
changeset.addRequest(createRequest);
final ODataBatchResponse response = payloadManager.getResponse();
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
// Check response items
final Iterator<ODataBatchResponseItem> responseBodyIter = response.getBody();
assertTrue(responseBodyIter.hasNext());
final ODataBatchResponseItem changeSetResponse = responseBodyIter.next();
assertTrue(changeSetResponse.isChangeset());
assertTrue(changeSetResponse.hasNext());
final ODataResponse updateResponse = changeSetResponse.next();
assertTrue(changeSetResponse.isBreaking());
assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), updateResponse.getStatusCode());
assertContentType(updateResponse.getContentType());
}
示例4: deepInsertOnNavigationPropertyInComplexProperty
import org.apache.olingo.client.api.domain.ClientObjectFactory; //导入方法依赖的package包/类
@Test
@Ignore
public void deepInsertOnNavigationPropertyInComplexProperty() {
final EdmEnabledODataClient client = getEdmEnabledClient();
final ClientObjectFactory factory = getFactory();
final ClientEntity inlineEntity = factory.newEntity(ET_TWO_KEY_NAV);
inlineEntity.getProperties()
.add(factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
inlineEntity.getProperties()
.add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
inlineEntity.getProperties()
.add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 1)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("1")))));
final ClientEntity entity = factory.newEntity(ET_TWO_KEY_NAV);
entity.getProperties()
.add(factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
entity.getProperties()
.add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
entity.getProperties()
.add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 2)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("2")))));
final ClientLink link = factory.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, inlineEntity);
final ClientComplexValue complexValueCreate = factory.newComplexValue(CT_NAV_FIVE_PROP);
complexValueCreate.getNavigationLinks().add(link);
entity.getProperties()
.add(factory.newCollectionProperty(COL_PROPERTY_COMP_NAV,
factory.newCollectionValue(CT_NAV_FIVE_PROP).add(complexValueCreate)));
final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).build();
final ODataEntityCreateResponse<ClientEntity> response = client.getCUDRequestFactory()
.getEntityCreateRequest(targetURI, entity)
.execute();
assertEquals(HttpStatusCode.CREATED.getStatusCode(), response.getStatusCode());
final Iterator<ClientValue> iter = response.getBody()
.getProperty(COL_PROPERTY_COMP_NAV)
.getCollectionValue()
.iterator();
assertTrue(iter.hasNext());
final ClientComplexValue complexValue = iter.next().asComplex();
final ClientLink linkedEntity = complexValue.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE);
assertNotNull(linkedEntity);
assertEquals(1, linkedEntity.asInlineEntity()
.getEntity()
.getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
}