• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ODataClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.olingo.client.api.ODataClient的典型用法代码示例。如果您正苦于以下问题:Java ODataClient类的具体用法?Java ODataClient怎么用?Java ODataClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ODataClient类属于org.apache.olingo.client.api包,在下文中一共展示了ODataClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getEdmTest

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void getEdmTest() throws Exception {
  final ODataClient client = getODataClient();
  final String serviceUrl = getServiceUrl();
  final ODataServiceDocumentRequest reqeust =
      client.getRetrieveRequestFactory().getServiceDocumentRequest(serviceUrl);

  reqeust.setFormat(ContentType.APPLICATION_XML);

  final Edm redHelixEdm = readEdm(client, serviceUrl);

  Assert.assertEquals(1, redHelixEdm.getSchemas().size());

  for (EdmSchema schema : redHelixEdm.getSchemas()) {
    Assert.assertEquals(RED_HELIX_NAME_SPACE, schema.getNamespace());
  }
}
 
开发者ID:RedHelixOrg,项目名称:RedHelix-1,代码行数:18,代码来源:EdmTest.java


示例2: read

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void read(final ODataClient client, final ContentType contentType) {
  final URIBuilder uriBuilder =
      client.newURIBuilder(testOAuth2ServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8);

  final ODataEntityRequest<ClientEntity> req =
      client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
  req.setFormat(contentType);

  final ODataRetrieveResponse<ClientEntity> res = req.execute();
  assertEquals(200, res.getStatusCode());

  final String etag = res.getETag();
  assertTrue(StringUtils.isNotBlank(etag));

  final ClientEntity order = res.getBody();
  assertEquals(etag, order.getETag());
  assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Order", order.getTypeName().toString());
  assertEquals("Edm.Int32", order.getProperty("OrderID").getPrimitiveValue().getTypeName());
  assertEquals("Edm.DateTimeOffset", order.getProperty("OrderDate").getPrimitiveValue().getTypeName());
  assertEquals("Edm.Duration", order.getProperty("ShelfLife").getPrimitiveValue().getTypeName());
  assertEquals("Collection(Edm.Duration)", order.getProperty("OrderShelfLifes").getCollectionValue().getTypeName());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:23,代码来源:OAuth2TestITCase.java


示例3: read

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void read(final ODataClient client, final ContentType contentType) throws IOException {
  final URIBuilder builder = client.newURIBuilder(testDemoServiceRootURL).
      appendEntitySetSegment("Advertisements").
      appendKeySegment(UUID.fromString("f89dee73-af9f-4cd4-b330-db93c25ff3c7"));
  final ODataEntityRequest<ClientEntity> entityReq =
      client.getRetrieveRequestFactory().getEntityRequest(builder.build());
  entityReq.setFormat(contentType);

  final ClientEntity entity = entityReq.execute().getBody();
  assertNotNull(entity);
  assertTrue(entity.isMediaEntity());
  // cast to workaround JDK 6 bug, fixed in JDK 7
  assertEquals(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName().toString(),
      ((ClientValuable) entity.getProperty("AirDate")).getValue().getTypeName());

  final ODataMediaRequest streamReq = client.getRetrieveRequestFactory().
      getMediaRequest(entity.getMediaContentSource());
  final ODataRetrieveResponse<InputStream> streamRes = streamReq.execute();
  assertEquals(200, streamRes.getStatusCode());

  final byte[] actual = new byte[Integer.parseInt(streamRes.getHeader("Content-Length").iterator().next())];
  IOUtils.read(streamRes.getBody(), actual, 0, actual.length);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:24,代码来源:MediaEntityTestITCase.java


示例4: singleEntityWithExpand

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void singleEntityWithExpand() {
  /* A single entity request will be dispatched to a different processor method than entity set request */
  final ODataClient client = getEdmEnabledClient();
  Map<String, Object> keys = new HashMap<String, Object>();
  keys.put("PropertyInt16", 1);
  keys.put("PropertyString", "1");

  final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(keys)
      .expandWithOptions(NAV_PROPERTY_ET_KEY_NAV_MANY,
          Collections.singletonMap(QueryOption.FILTER, (Object) "PropertyInt16 lt 2"))
      .build();
  final ODataRetrieveResponse<ClientEntity> response =
          client.getRetrieveRequestFactory().getEntityRequest(uri).execute();
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());

  final ClientEntitySet entitySet =
      response.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
  assertEquals(1, entitySet.getEntities().size());
  assertShortOrInt(1, entitySet.getEntities().get(0).getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:22,代码来源:ExpandWithSystemQueryOptionsITCase.java


示例5: checkResponse

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
protected void checkResponse(
        final ODataClient odataClient, final HttpResponse response, final String accept) {

  if (response.getStatusLine().getStatusCode() >= 400) {
    try {
      final ODataRuntimeException exception = ODataErrorResponseChecker.checkResponse(
              odataClient,
              response.getStatusLine(),
              response.getEntity() == null ? null : response.getEntity().getContent(),
              accept);
      if (exception != null) {
        throw exception;
      }
    } catch (IOException e) {
      throw new ODataRuntimeException(
              "Received '" + response.getStatusLine() + "' but could not extract error body", e);
    }
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:20,代码来源:AbstractRequest.java


示例6: expandWithSearchQuery

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void expandWithSearchQuery() {
  final ODataClient client = getEdmEnabledClient();
  Map<QueryOption, Object> expandOptions = new EnumMap<QueryOption, Object>(QueryOption.class);
  expandOptions.put(QueryOption.SEARCH, "abc");
  expandOptions.put(QueryOption.FILTER, "PropertyInt16 eq 1");
  
  final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
      .expandWithOptions(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY, expandOptions)
      .build();

  final ODataEntitySetRequest<ClientEntitySet> request = client.getRetrieveRequestFactory().getEntitySetRequest(uri);
  
  try {
    request.execute();
  } catch(ODataServerErrorException e) {
    assertEquals("HTTP/1.1 501 Not Implemented", e.getMessage());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:20,代码来源:ExpandWithSystemQueryOptionsITCase.java


示例7: entityNavigationReference

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
/**
 * 9. MAY request entity references in place of entities previously returned in the response (section 11.2.7).
 */
@Test
public void entityNavigationReference() {
  final ODataClient client = getClient();
  final URIBuilder uriBuilder = client.newURIBuilder(SERVICE_URI)
          .appendEntitySetSegment(ES_TWO_PRIM)
          .appendKeySegment(32767)
          .appendNavigationSegment("NavPropertyETAllPrimOne")
          .appendRefSegment();

  ODataEntityRequest<ClientEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());

  ODataRetrieveResponse<ClientEntity> res = req.execute();
  assertNotNull(res);

  final ClientEntity entity = res.getBody();
  assertNotNull(entity);
  assertTrue(entity.getId().toASCIIString().endsWith("ESAllPrim(32767)"));
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:22,代码来源:ConformanceITCase.java


示例8: supportMetadataMinimal

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
/**
 * 12. MAY support odata.metadata=minimal in a JSON response (see [OData-JSON]).
 */
@Test
public void supportMetadataMinimal() {
  assumeTrue("format should be json", isJson());
  ODataClient client = getClient();
  final URIBuilder uriBuilder = client.newURIBuilder(SERVICE_URI)
          .appendEntitySetSegment(ES_TWO_PRIM)
          .appendKeySegment(32767)
          .expand("NavPropertyETAllPrimOne");

  final ODataEntityRequest<ClientEntity> req =
      client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
  req.setFormat(ContentType.JSON);

  assertEquals("application/json;odata.metadata=minimal", req.getHeader("Accept"));
  assertEquals("application/json;odata.metadata=minimal", req.getAccept());

  final ODataRetrieveResponse<ClientEntity> res = req.execute();
  assertTrue(res.getContentType().startsWith("application/json; odata.metadata=minimal"));

  assertNotNull(res.getBody());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:25,代码来源:ConformanceITCase.java


示例9: getResponseTemplate

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
/**
 * Gets an empty response that can be initialized by a stream.
 * <br/>
 * This method has to be used to build response items about a batch request.
 *
 * @param <V> ODataResponse type.
 * @return empty OData response instance.
 */
@SuppressWarnings("unchecked")
public <V extends ODataResponse> V getResponseTemplate() {
  for (Class<?> clazz : this.getClass().getDeclaredClasses()) {
    if (ODataResponse.class.isAssignableFrom(clazz)) {
      try {
        final Constructor<?> constructor = clazz.getDeclaredConstructor(
            this.getClass(), ODataClient.class, HttpClient.class, HttpResponse.class);
        constructor.setAccessible(true);
        return (V) constructor.newInstance(this, odataClient, httpClient, null);
      } catch (Exception e) {
        LOG.error("Error retrieving response class template instance", e);
      }
    }
  }

  throw new IllegalStateException("No response class template has been found");
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:26,代码来源:AbstractODataRequest.java


示例10: test1OLINGO1102

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void test1OLINGO1102() throws Exception {
  ODataClient odataClient = ODataClientFactory.getClient();
  InputStream entity = getClass().getResourceAsStream("500error." + getSuffix(ContentType.JSON));
  StatusLine statusLine = mock(StatusLine.class);
  when(statusLine.getStatusCode()).thenReturn(500);
  when(statusLine.toString()).thenReturn("Internal Server Error");
  
  ODataClientErrorException exp = (ODataClientErrorException) ODataErrorResponseChecker.
      checkResponse(odataClient, statusLine, entity, "Json");
  assertTrue(exp.getMessage().contains("(500) Internal Server Error"));
  ODataError error = exp.getODataError();
  assertTrue(error.getMessage().startsWith("Internal Server Error"));
  assertEquals(500, Integer.parseInt(error.getCode()));
  assertEquals(2, error.getInnerError().size());
  assertEquals("\"Method does not support entities of specific type\"", error.getInnerError().get("message"));
  assertEquals("\"FaultException\"", error.getInnerError().get("type"));
  assertNull(error.getDetails());
      
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:21,代码来源:ErrorTest.java


示例11: getBasicAuthClient

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
protected ODataClient getBasicAuthClient(String username, String password) {
  ODataClient odata = getClient();
  odata.getConfiguration()
          .setHttpClientFactory(new BasicAuthHttpClientFactory(username, password));
  odata.getConfiguration().setDefaultPubFormat(getContentType());
  return odata;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:8,代码来源:AbstractTecSvcITCase.java


示例12: setupMock

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ODataClient setupMock(Exception e) {

    ODataInvokeRequest<ClientEntity> functionInvokeRequest = createMock(ODataInvokeRequest.class);
    expect(functionInvokeRequest.setAccept(capture(contentType))).andReturn(functionInvokeRequest);

    if(e != null) {
        expect(functionInvokeRequest.execute())
            .andThrow(e);
    } else {
        ODataInvokeResponse<ClientEntity> responseMock = createMock(ODataInvokeResponse.class);
        expect(responseMock.getStatusCode()).andReturn(200);
        responseMock.close(); expectLastCall();
        replay(responseMock);
        expect(functionInvokeRequest.execute()).andReturn(responseMock);
    }

    InvokeRequestFactory invokeRequestFactoryMock = createMock(InvokeRequestFactory.class);
    expect(invokeRequestFactoryMock.getFunctionInvokeRequest(capture(address), eq(ClientEntity.class))).andReturn(functionInvokeRequest);

    ODataClient clientMock = createMockBuilder(ODataClientImpl.class)
            .addMockedMethod("getInvokeRequestFactory")
            .addMockedMethod("getConfiguration").createMock();
    expect(clientMock.getInvokeRequestFactory()).andReturn(invokeRequestFactoryMock);
    expect(clientMock.getConfiguration()).andReturn(getConfiguration());

    replay(functionInvokeRequest, invokeRequestFactoryMock, clientMock);

    return clientMock;
}
 
开发者ID:SAP,项目名称:devops-cm-client,代码行数:31,代码来源:CMODataClientReleaseTransportTest.java


示例13: setupMock

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ODataClient setupMock(Exception e) {

    ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> responseMock = createMock(ODataRetrieveResponse.class);

    if(e != null) {
        expect(responseMock.getBody()).andThrow(e);
    } else {

        ClientEntitySetIterator<ClientEntitySet, ClientEntity> iteratorMock = createMock(ClientEntitySetIterator.class);
        expect(iteratorMock.hasNext()).andReturn(true);
        expect(iteratorMock.next()).andReturn(setupTransportMock("L21K90002N", false));
        expect(iteratorMock.hasNext()).andReturn(true);
        expect(iteratorMock.next()).andReturn(setupTransportMock("L21K90002L", false));
        expect(iteratorMock.hasNext()).andReturn(true);
        expect(iteratorMock.next()).andReturn(setupTransportMock("L21K90002J", true));
        expect(iteratorMock.hasNext()).andReturn(false);

        expect(responseMock.getBody()).andReturn(iteratorMock);
        replay(iteratorMock);
    }

    responseMock.close();
    expectLastCall();

    ODataEntitySetIteratorRequest<ClientEntitySet, ClientEntity> oDataEntityRequestMock = createMock(ODataEntitySetIteratorRequest.class);
    expect(oDataEntityRequestMock.setAccept(capture(contentType))).andReturn(oDataEntityRequestMock);
    expect(oDataEntityRequestMock.execute()).andReturn(responseMock);

    RetrieveRequestFactory retrieveRequestFactoryMock = createMock(RetrieveRequestFactory.class);
    expect(retrieveRequestFactoryMock.getEntitySetIteratorRequest(capture(address))).andReturn(oDataEntityRequestMock);

    ODataClient clientMock = createMockBuilder(ODataClientImpl.class)
            .addMockedMethod("getRetrieveRequestFactory")
            .addMockedMethod("getConfiguration").createMock();
    expect(clientMock.getRetrieveRequestFactory()).andReturn(retrieveRequestFactoryMock);
    expect(clientMock.getConfiguration()).andReturn(getConfiguration());
    replay(responseMock, oDataEntityRequestMock, retrieveRequestFactoryMock, clientMock);
    return clientMock;
}
 
开发者ID:SAP,项目名称:devops-cm-client,代码行数:41,代码来源:CMODataClientGetTransportsTest.java


示例14: read

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void read(final ODataClient client, final ContentType contentType) throws EdmPrimitiveTypeException {
  final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
  final ODataEntityRequest<ClientSingleton> singleton =
      client.getRetrieveRequestFactory().getSingletonRequest(builder.build());
  singleton.setFormat(contentType);
  final ClientSingleton company = singleton.execute().getBody();
  assertNotNull(company);

  assertEquals(0, company.getProperty("CompanyID").getPrimitiveValue().toCastValue(Integer.class), 0);
  // cast to workaround JDK 6 bug, fixed in JDK 7
  assertEquals("Microsoft.Test.OData.Services.ODataWCFService.CompanyCategory",
      ((ClientValuable) company.getProperty("CompanyCategory")).getValue().getTypeName());
  assertTrue(company.getProperty("CompanyCategory").hasEnumValue());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:15,代码来源:SingletonTestITCase.java


示例15: readWithAnnotations

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void readWithAnnotations(final ODataClient client, final ContentType contentType)
    throws EdmPrimitiveTypeException {

  final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Boss");
  final ODataEntityRequest<ClientSingleton> singleton =
      client.getRetrieveRequestFactory().getSingletonRequest(builder.build());
  singleton.setFormat(contentType);
  singleton.setPrefer(client.newPreferences().includeAnnotations("*"));
  final ClientSingleton boss = singleton.execute().getBody();
  assertNotNull(boss);

  assertFalse(boss.getAnnotations().isEmpty());
  final ClientAnnotation isBoss = boss.getAnnotations().get(0);
  assertTrue(isBoss.getPrimitiveValue().toCastValue(Boolean.class));
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:16,代码来源:SingletonTestITCase.java


示例16: entitySetNavigationLink

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
private void entitySetNavigationLink(final ODataClient client, final ContentType contentType) {
  final URI uri = client.newURIBuilder(testStaticServiceRootURL).
      appendEntitySetSegment("Accounts").appendKeySegment(101).build();
  final ODataEntityRequest<ClientEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uri);
  req.setFormat(contentType);

  final ClientEntity entity = req.execute().getBody();
  assertNotNull(entity);

  // With JSON, entity set navigation links are only recognizable via Edm
  if (contentType.equals(ContentType.APPLICATION_ATOM_XML) || client instanceof EdmEnabledODataClient) {
    assertEquals(ClientLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("MyPaymentInstruments").getType());
    assertEquals(ClientLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("ActiveSubscriptions").getType());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:16,代码来源:EntityRetrieveTestITCase.java


示例17: test8OLINGO753

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void test8OLINGO753() throws ODataDeserializerException {
  final ODataClient client = ODataClientFactory.getClient();
  final URI uri = client.newURIBuilder(SERVICE_ROOT).appendEntitySetSegment("EntitySet").
      appendOperationCallSegment("functionName").filter("PropertyString eq '1'").
      appendNavigationSegment("NavSeg").appendActionCallSegment("ActionName").count().build();
  final Map<String, ClientValue> parameters = new HashMap<String, ClientValue>();
  final ClientPrimitiveValue value = client.getObjectFactory().
      newPrimitiveValueBuilder().buildString("parameterValue");
  parameters.put("parameterName", value);
  URI newUri = URIUtils.buildFunctionInvokeURI(uri, parameters);
  assertNotNull(newUri);
  assertEquals("http://host/service/EntitySet/functionName(parameterName%3D'parameterValue')/NavSeg/ActionName"
      + "/%24count?%24filter=PropertyString%20eq%20'1'", newUri.toASCIIString());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:16,代码来源:URIBuilderTest.java


示例18: test2OLINGO753

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void test2OLINGO753() throws ODataDeserializerException {
  final ODataClient client = ODataClientFactory.getClient();
  final URI uri = client.newURIBuilder(SERVICE_ROOT).appendOperationCallSegment("functionName").
      filter("paramName eq 1").format("json").count().build();
  final Map<String, ClientValue> parameters = new HashMap<String, ClientValue>();
  final ClientPrimitiveValue value = client.getObjectFactory().
      newPrimitiveValueBuilder().buildString("parameterValue");
  parameters.put("parameterName", value);
  URI newUri = URIUtils.buildFunctionInvokeURI(uri, parameters);
  assertNotNull(newUri);
  assertEquals("http://host/service/functionName(parameterName%3D'parameterValue')"
      + "/%24count?%24filter=paramName%20eq%201&%24format=json", newUri.toASCIIString());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:15,代码来源:URIBuilderTest.java


示例19: deleteReferenceOnSingleNavigationProperty

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void deleteReferenceOnSingleNavigationProperty() {
  final ODataClient client = getClient();
  final URI uri = client.newURIBuilder(SERVICE_URI)
                        .appendEntitySetSegment(ES_KEY_NAV)
                        .appendKeySegment(1)
                        .appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_ONE)
                        .appendRefSegment()
                        .build();
  
  final ODataDeleteResponse deleteResponse = client.getCUDRequestFactory().getDeleteRequest(uri).execute();
  final String cookie = deleteResponse.getHeader(HttpHeader.SET_COOKIE).iterator().next();
  
  final URI uriGet = client.newURIBuilder(SERVICE_URI)
                           .appendEntitySetSegment(ES_KEY_NAV)
                           .appendKeySegment(1)
                           .expand(NAV_PROPERTY_ET_KEY_NAV_ONE)
                           .build();
  final ODataEntityRequest<ClientEntity> requestGet = client.getRetrieveRequestFactory().getEntityRequest(uriGet);
  requestGet.addCustomHeader(HttpHeader.COOKIE, cookie);
  final ODataRetrieveResponse<ClientEntity> responseGet = requestGet.execute();
  
  
  if (isJson()) {
    assertEquals(0, responseGet.getBody().getNavigationLinks().size());
  } else {
    // in xml the links will be always present; but the content will not be if no $expand unlike 
    // json;metadata=minimal; json=full is same as application/xml
    assertEquals(6, responseGet.getBody().getNavigationLinks().size());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:32,代码来源:EntityReferencesITCase.java


示例20: navigateTwoTimesThanDeleteReferenceInCollection

import org.apache.olingo.client.api.ODataClient; //导入依赖的package包/类
@Test
public void navigateTwoTimesThanDeleteReferenceInCollection() {
  final ODataClient client = getClient();
  final URI uri = client.newURIBuilder(SERVICE_URI)
                        .appendEntitySetSegment(ES_KEY_NAV)
                        .appendKeySegment(1)
                        .appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_MANY)
                        .appendKeySegment(2)
                        .appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_ONE)
                        .appendRefSegment()
                        .build();
  
  final ODataDeleteResponse deleteResponse = client.getCUDRequestFactory().getDeleteRequest(uri).execute();
  final String cookie = deleteResponse.getHeader(HttpHeader.SET_COOKIE).iterator().next();
  
  
  final URI uriGet = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
                                                      .appendKeySegment(1)
                                                      .appendNavigationSegment(NAV_PROPERTY_ET_KEY_NAV_MANY)
                                                      .appendKeySegment(2)
                                                      .expand(NAV_PROPERTY_ET_KEY_NAV_ONE)
                                                      .build();
  
  final ODataEntityRequest<ClientEntity> requestGet = client.getRetrieveRequestFactory().getEntityRequest(uriGet);
  requestGet.addCustomHeader(HttpHeader.COOKIE, cookie);
  final ODataRetrieveResponse<ClientEntity> responseGet = requestGet.execute();
  if (isJson()) {
    assertNull(responseGet.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE));
  } else {
    // in xml the links will be always present; but the content will not be if no $expand unlike 
    // json;metadata=minimal; json=full is same as application/xml
    Assert.assertFalse(responseGet.getBody()
        .getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE) instanceof ClientInlineEntity);
  }
  
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:37,代码来源:EntityReferencesITCase.java



注:本文中的org.apache.olingo.client.api.ODataClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Sequence类代码示例发布时间:2022-05-22
下一篇:
Java ExpandableLayout类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap