org.apache.http.impl.client.DecompressingHttpClient#org.apache.olingo.client.api.ODataClient源码实例Demo

下面列出了org.apache.http.impl.client.DecompressingHttpClient#org.apache.olingo.client.api.ODataClient 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: syndesis   文件: ODataUpdateTests.java
private static String queryProperty(String serviceURI, String resourcePath, String keyPredicate, String property) {
    ClientEntity olEntity = null;
    ODataRetrieveResponse<ClientEntity> response = null;
    try {
        URI httpURI = URI.create(serviceURI + FORWARD_SLASH +
                                        resourcePath + OPEN_BRACKET +
                                        QUOTE_MARK + keyPredicate + QUOTE_MARK +
                                        CLOSE_BRACKET);
        ODataClient client = ODataClientFactory.getClient();
        response = client.getRetrieveRequestFactory().getEntityRequest(httpURI).execute();
        assertEquals(HttpStatus.SC_OK, response.getStatusCode());

        olEntity = response.getBody();
        assertNotNull(olEntity);
        return olEntity.getProperty(property).getPrimitiveValue().toString();
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
 
源代码2 项目: olingo-odata4   文件: AbstractRequest.java
protected void checkResponse(
        final ODataClient odataClient, final HttpResponse response, final String accept) {

  if (response.getStatusLine().getStatusCode() >= 400) {
    Header contentTypeHeader = response.getEntity() != null ? response.getEntity().getContentType() : null;
    try {
      final ODataRuntimeException exception = ODataErrorResponseChecker.checkResponse(
              odataClient,
              response.getStatusLine(),
              response.getEntity() == null ? null : response.getEntity().getContent(),
                  (contentTypeHeader != null && 
                  contentTypeHeader.getValue().contains(TEXT_CONTENT_TYPE)) ? TEXT_CONTENT_TYPE : accept);
      if (exception != null) {
        if (exception instanceof ODataClientErrorException) {
          ((ODataClientErrorException)exception).setHeaderInfo(response.getAllHeaders());
        }
        throw exception;
      }
    } catch (IOException e) {
      throw new ODataRuntimeException(
              "Received '" + response.getStatusLine() + "' but could not extract error body", e);
    }
  }
}
 
源代码3 项目: syndesis   文件: ODataTestServer.java
public ClientEntity getData(String keyPredicate) {
    String resourcePath = resourcePath() + OPEN_BRACKET + keyPredicate + CLOSE_BRACKET;

    String serviceUri = serviceSSLUri();
    if (serviceUri == null) {
        serviceUri = servicePlainUri();
    }

    ODataClient client = ODataClientFactory.getClient();
    URI customersUri = client.newURIBuilder(serviceUri)
                                                  .appendEntitySetSegment(resourcePath).build();

    ODataRetrieveResponse<ClientEntity> response
        = client.getRetrieveRequestFactory().getEntityRequest(customersUri).execute();

    return response.getBody();
}
 
源代码4 项目: olingo-odata4   文件: ODataClientTest.java
@Test
public void searchTest() {
  ODataClient client = ODataClientFactory.getClient();
  assertNotNull(client);
  SearchFactory searchFactory = client.getSearchFactory();
  assertNotNull(searchFactory);
  LiteralSearch literal = (LiteralSearch) searchFactory.literal("test");
  assertNotNull(literal);
  assertEquals("test", literal.build());
  AndSearch and = (AndSearch) searchFactory.and(literal, literal);
  assertNotNull(and);
  assertEquals("(test AND test)", and.build());
  OrSearch or = (OrSearch) searchFactory.or(literal, literal);
  assertNotNull(or);
  assertEquals("(test OR test)", or.build());
  NotSearch not = (NotSearch) searchFactory.not(literal);
  assertNotNull(not);
  assertEquals("NOT (test)", not.build());
}
 
源代码5 项目: olingo-odata4   文件: ErrorTest.java
@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());
      
}
 
源代码6 项目: olingo-odata4   文件: OAuth2TestITCase.java
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());
}
 
@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());
}
 
源代码8 项目: olingo-odata4   文件: ConformanceITCase.java
/**
 * 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)"));
}
 
源代码9 项目: syndesis   文件: ODataMetaDataExtension.java
private static Edm requestEdm(Map<String, Object> parameters, String serviceUrl) {
    ODataClient client = ODataClientFactory.getClient();
    HttpClientFactory factory = ODataUtil.newHttpFactory(parameters);
    client.getConfiguration().setHttpClientFactory(factory);

    EdmMetadataRequest request = client.getRetrieveRequestFactory().getMetadataRequest(serviceUrl);
    ODataRetrieveResponse<Edm> response = request.execute();

    if (response.getStatusCode() != 200) {
        throw new IllegalStateException("Metatdata response failure. Return code: " + response.getStatusCode());
    }

    return response.getBody();
}
 
源代码10 项目: olingo-odata4   文件: URIBuilderTest.java
@Test
public void test11OLINGO753() throws ODataDeserializerException {
  final ODataClient client = ODataClientFactory.getClient();
  final URI uri = client.newURIBuilder(SERVICE_ROOT).appendEntitySetSegment("EntitySet").
      appendOperationCallSegment("functionName").
      appendNavigationSegment("NavSeg").count().addParameterAlias("first", "'1'").build();
  final Map<String, ClientValue> parameters = new HashMap<String, ClientValue>();
  final ClientPrimitiveValue value = client.getObjectFactory().
      newPrimitiveValueBuilder().setValue(new ParameterAlias("first")).build();
  parameters.put("parameterName", value);
  URI newUri = URIUtils.buildFunctionInvokeURI(uri, parameters);
  assertNotNull(newUri);
  assertEquals("http://host/service/EntitySet/functionName(parameterName%3D%40first)/"
      + "NavSeg/%24count?%40first='1'", newUri.toASCIIString());
}
 
源代码11 项目: olingo-odata4   文件: ODataMediaRequestImpl.java
/**
 * Private constructor.
 *
 * @param odataClient client instance getting this request
 * @param query query to be executed.
 */
ODataMediaRequestImpl(final ODataClient odataClient, final URI query) {
  super(odataClient, query);

  setAccept(ContentType.APPLICATION_OCTET_STREAM.toString());
  setContentType(ContentType.APPLICATION_OCTET_STREAM.toString());
}
 
源代码12 项目: olingo-odata4   文件: URIBuilderTest.java
@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());
}
 
private ODataClient setupMock(Exception e) {
    Set<TransportDescriptor> transports = new HashSet<TransportDescriptor>();
    transports.add(TransportDescriptor.create("L21K90002N", "xxx~123", false));
    transports.add(TransportDescriptor.create("L21K90002L", "xxx~123", false));
    transports.add(TransportDescriptor.create("L21K90002J", "xxx~123", true));
    return setupMock(e, transports);
}
 
源代码14 项目: olingo-odata4   文件: AbstractODataResponse.java
public AbstractODataResponse(
    final ODataClient odataClient, final HttpClient httpclient, final HttpResponse res) {

  this.odataClient = odataClient;
  this.httpClient = httpclient;
  this.res = res;
  if (res != null) {
    initFromHttpResponse(res);
  }
}
 
源代码15 项目: olingo-odata4   文件: SingletonTestITCase.java
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());
}
 
源代码16 项目: olingo-odata4   文件: URIBuilderTest.java
@Test
public void test5OLINGO753() throws ODataDeserializerException {
  final ODataClient client = ODataClientFactory.getClient();
  final URI uri = client.newURIBuilder(SERVICE_ROOT).appendEntitySetSegment("EntitySet").
      appendOperationCallSegment("functionName").count().filter("PropertyString eq '1'").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')"
      + "/%24count?%24filter=PropertyString%20eq%20'1'", newUri.toASCIIString());
}
 
源代码17 项目: olingo-odata4   文件: EntityRetrieveTestITCase.java
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());
  }
}
 
源代码18 项目: olingo-odata4   文件: PropertyTestITCase.java
private void _enum(final ODataClient client, final ContentType contentType) {
  final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
      appendEntitySetSegment("Products").appendKeySegment(5).appendPropertySegment("CoverColors");
  final ODataPropertyRequest<ClientProperty> req = client.getRetrieveRequestFactory().
      getPropertyRequest(uriBuilder.build());
  req.setFormat(contentType);

  final ClientProperty prop = req.execute().getBody();
  assertNotNull(prop);
  // cast to workaround JDK 6 bug, fixed in JDK 7
  assertEquals("Collection(Microsoft.Test.OData.Services.ODataWCFService.Color)",
      ((ClientValuable) prop).getValue().getTypeName());
}
 
源代码19 项目: olingo-odata4   文件: PropertyTestITCase.java
private void geospatial(final ODataClient client, final ContentType contentType) {
  final URIBuilder uriBuilder = client.newURIBuilder(testStaticServiceRootURL).
      appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Home");
  final ODataPropertyRequest<ClientProperty> req = client.getRetrieveRequestFactory().
      getPropertyRequest(uriBuilder.build());
  req.setFormat(contentType);

  final ClientProperty prop = req.execute().getBody();
  assertNotNull(prop);
  // cast to workaround JDK 6 bug, fixed in JDK 7
  assertEquals("Edm.GeographyPoint", ((ClientValuable) prop).getValue().getTypeName());
}
 
源代码20 项目: olingo-odata4   文件: AbstractRequest.java
protected void checkRequest(final ODataClient odataClient, final HttpUriRequest request) {
  // If using and Edm enabled client, checks that the cached service root matches the request URI
  if (odataClient instanceof EdmEnabledODataClient
          && !request.getURI().toASCIIString().startsWith(
                  ((EdmEnabledODataClient) odataClient).getServiceRoot())) {

    throw new IllegalArgumentException(
            String.format("The current request URI %s does not match the configured service root %s",
                    request.getURI().toASCIIString(),
                    ((EdmEnabledODataClient) odataClient).getServiceRoot()));
  }
}
 
源代码21 项目: olingo-odata4   文件: URIBuilderTest.java
@Test
public void testDuplicateCustomQueryOption() throws ODataDeserializerException {
  final ODataClient client = ODataClientFactory.getClient();
  final URI uri = client.newURIBuilder(SERVICE_ROOT).appendEntitySetSegment("EntitySet").
      addCustomQueryOption("x", "z").
      addCustomQueryOption("x", "y").build();
  assertEquals("http://host/service/EntitySet?x=y", uri.toASCIIString());
}
 
源代码22 项目: olingo-odata4   文件: EntityReferencesITCase.java
@Test
public void createMissingNavigationProperty() throws Exception {
  final ODataClient client = getClient();
  final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendRefSegment().build();
  final URI ref = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
  
  try {
    client.getCUDRequestFactory().getReferenceAddingRequest(new URI(SERVICE_URI), uri, ref).execute();
  } catch (ODataClientErrorException e) {
    assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
  }
}
 
@Test
public void count() throws Exception{
  final ODataClient client = getEdmEnabledClient();
  Map<QueryOption, Object> options = new EnumMap<QueryOption, Object>(QueryOption.class);
  options.put(QueryOption.SELECT, "PropertyInt16");
  options.put(QueryOption.COUNT, true);

  final URI uri =
      client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).expandWithOptions(
          NAV_PROPERTY_ET_TWO_KEY_NAV_MANY, options).addQueryOption(QueryOption.SELECT,
              "PropertyInt16,PropertyString").build();
     
  final ODataRetrieveResponse<ClientEntitySet> response =
      client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute();

  final List<ClientEntity> entities = response.getBody().getEntities();
  assertEquals(4, entities.size());

  for (final ClientEntity entity : entities) {
    final Object propInt16 = entity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue();
    final Object propString = entity.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue();
    final ClientEntitySet entitySet =
        entity.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();

    if ((propInt16.equals(1) ||propInt16.equals((short)1)) && propString.equals("1")) {
      assertEquals(Integer.valueOf(2), entitySet.getCount());
    } else if ((propInt16.equals(1) ||propInt16.equals((short)1)) && propString.equals("2")) {
      assertEquals(Integer.valueOf(1), entitySet.getCount());
    } else if ((propInt16.equals(2) ||propInt16.equals((short)2)) && propString.equals("1")) {
      assertEquals(Integer.valueOf(1), entitySet.getCount());
    } else if ((propInt16.equals(3) ||propInt16.equals((short)3)) && propString.equals("1")) {
      assertEquals(Integer.valueOf(0), entitySet.getCount());
    } else {
      fail();
    }
  }
}
 
@Test
public void countOnly() throws Exception {
  final ODataClient client = getEdmEnabledClient();
  Map<QueryOption, Object> options = new EnumMap<QueryOption, Object>(QueryOption.class);

  final URI uri =
      client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).expandWithOptions(
          NAV_PROPERTY_ET_TWO_KEY_NAV_MANY, false, true, options).addQueryOption(QueryOption.SELECT,
              "PropertyInt16,PropertyString").build();
  final ODataRetrieveResponse<ClientEntitySet> response =
      client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute();

  final List<ClientEntity> entities = response.getBody().getEntities();
  assertEquals(4, entities.size());

  for (final ClientEntity entity : entities) {
    final Object propInt16 = entity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue();
    final Object propString = entity.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue();
    final ClientEntitySet entitySet =
        entity.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();

    if ((propInt16.equals(1) ||propInt16.equals((short)1)) && propString.equals("1")) {
      assertEquals(Integer.valueOf(2), entitySet.getCount());
    } else if ((propInt16.equals(1) ||propInt16.equals((short)1)) && propString.equals("2")) {
      assertEquals(Integer.valueOf(1), entitySet.getCount());
    } else if ((propInt16.equals(2) ||propInt16.equals((short)2)) && propString.equals("1")) {
      assertEquals(Integer.valueOf(1), entitySet.getCount());
    } else if ((propInt16.equals(3) ||propInt16.equals((short)3)) && propString.equals("1")) {
      assertEquals(Integer.valueOf(0), entitySet.getCount());
    } else {
      fail();
    }
  }
}
 
源代码25 项目: olingo-odata4   文件: JsonSerializerTest.java
@Test
public void testClientEntityJSONWithNull() throws ODataSerializerException {
  String expectedJson = "{\"@odata.type\":\"#test.testClientEntity\","
      + "\"[email protected]\":\"Int32\","
      + "\"testInt32\":12,"
      + "\"[email protected]\":\"Int32\""
      + ",\"testInt32Null\":null,"
      + "\"[email protected]\":\"String\","
      + "\"testString\":\"testString\","
      + "\"[email protected]\":\"String\","
      + "\"testStringNull\":null}";

  ODataClient odataClient = ODataClientFactory.getClient();
  ClientObjectFactory objFactory = odataClient.getObjectFactory();
  ClientEntity clientEntity = objFactory.newEntity(new FullQualifiedName("test", "testClientEntity"));

  clientEntity.getProperties().add(
      objFactory.newPrimitiveProperty(
          "testInt32",
          objFactory.newPrimitiveValueBuilder().buildInt32(12)));
  clientEntity.getProperties().add(
      objFactory.newPrimitiveProperty(
          "testInt32Null",
          objFactory.newPrimitiveValueBuilder().buildInt32(null)));
  clientEntity.getProperties().add(
      objFactory.newPrimitiveProperty(
          "testString",
          objFactory.newPrimitiveValueBuilder().buildString("testString")));
  clientEntity.getProperties().add(
      objFactory.newPrimitiveProperty(
          "testStringNull",
          objFactory.newPrimitiveValueBuilder().buildString(null)));

  JsonSerializer jsonSerializer = new JsonSerializer(false, ContentType.JSON_FULL_METADATA);

  StringWriter writer = new StringWriter();
  jsonSerializer.write(writer, odataClient.getBinder().getEntity(clientEntity));
  assertThat(writer.toString(), is(expectedJson));
}
 
源代码26 项目: olingo-odata4   文件: ConformanceITCase.java
/**
 * 2. MUST specify OData-Version (section 8.1.5) and Content-Type (section 8.1.1) in any request with a payload.
 */
@Test
public void checkClientWithPayloadHeader() {
  assumeTrue("json conformance test with content type", isJson());

  ClientEntity newEntity = getFactory().newEntity(ET_ALL_PRIM);
  newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
      getFactory().newPrimitiveValueBuilder().buildInt64((long) 42)));
  final ODataClient client = getClient();
  newEntity.addLink(getFactory().newEntityNavigationLink(NAV_PROPERTY_ET_TWO_PRIM_ONE,
      client.newURIBuilder(SERVICE_URI)
          .appendEntitySetSegment(ES_TWO_PRIM)
          .appendKeySegment(32766)
          .build()));

  final ODataEntityCreateRequest<ClientEntity> createRequest = client.getCUDRequestFactory().getEntityCreateRequest(
      client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build(),
      newEntity);
  assertNotNull(createRequest);
  createRequest.setFormat(contentType);
  // check for OData-Version
  assertEquals(ODATA_MAX_VERSION_NUMBER, createRequest.getHeader(HttpHeader.ODATA_VERSION));

  // check for Content-Type
  assertEquals(
      ContentType.APPLICATION_JSON.toContentTypeString(),
      createRequest.getHeader(HttpHeader.CONTENT_TYPE));
  assertEquals(
      ContentType.APPLICATION_JSON.toContentTypeString(),
      createRequest.getContentType());

  final ODataEntityCreateResponse<ClientEntity> createResponse = createRequest.execute();

  assertEquals(HttpStatusCode.CREATED.getStatusCode(), createResponse.getStatusCode());
}
 
源代码27 项目: olingo-odata4   文件: URIBuilderTest.java
@Test
public void test6OLINGO753() throws ODataDeserializerException {
  final ODataClient client = ODataClientFactory.getClient();
  final URI uri = client.newURIBuilder(SERVICE_ROOT).
      appendOperationCallSegment("functionName").count().filter("PropertyString eq '1'").build();
  final Map<String, ClientValue> parameters = new HashMap<String, ClientValue>();
  URI newUri = URIUtils.buildFunctionInvokeURI(uri, parameters);
  assertNotNull(newUri);
  assertEquals("http://host/service/functionName()"
      + "/%24count?%24filter=PropertyString%20eq%20'1'", newUri.toASCIIString());
}
 
源代码28 项目: olingo-odata4   文件: ConformanceITCase.java
/**
 * 7. MUST generate PATCH requests for updates, if the client supports updates (section 11.4.3).
 **/
@Test
public void patchEntityRequestForUpdates() {
  final ODataClient client = getClient();
  final ClientEntity patch = client.getObjectFactory().newEntity(ET_TWO_PRIM);     
  final URI uri = client.newURIBuilder(SERVICE_URI)
          .appendEntitySetSegment(ES_TWO_PRIM)
          .appendKeySegment(32766)
          .build();
  patch.setEditLink(uri);
  final String newString = "Seconds: (" + System.currentTimeMillis() + ")";
  patch.getProperties().add(client.getObjectFactory().newPrimitiveProperty("PropertyString",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString(newString)));

  final ODataEntityUpdateRequest<ClientEntity> req =            
      client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patch);
  assertNotNull(req);
  assertEquals(ODATA_MAX_VERSION_NUMBER, req.getHeader(HttpHeader.ODATA_MAX_VERSION));
  
  final ODataEntityUpdateResponse<ClientEntity> res = req.execute();
  assertNotNull(res);
  assertEquals(200, res.getStatusCode());   
          
  final ClientEntity entity = res.getBody();
  assertNotNull(entity);
  assertEquals(newString, entity.getProperty("PropertyString").getPrimitiveValue().toString());
}
 
源代码29 项目: olingo-odata4   文件: XMLMetadataRequestImpl.java
private XMLMetadataResponseImpl(final ODataClient odataClient, final HttpClient httpClient,
    final HttpResponse res, final XMLMetadata metadata) {

  super(odataClient, httpClient, null);
  initFromHttpResponse(res);
  this.metadata = metadata;
}
 
源代码30 项目: olingo-odata4   文件: URIBuilderTest.java
@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());
}