org.apache.olingo.client.api.domain.ClientEntity Java Examples

The following examples show how to use org.apache.olingo.client.api.domain.ClientEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilterSystemQueryITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void floor() {
  ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq floor(3.8)");
  assertEquals(1, result.getBody().getEntities().size());

  ClientEntity clientEntity = result.getBody().getEntities().get(0);
  assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
  assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());

  result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 eq floor(3.1)");
  assertEquals(1, result.getBody().getEntities().size());

  clientEntity = result.getBody().getEntities().get(0);
  assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
  assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());
}
 
Example #2
Source File: ODataUpdateTests.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
}
 
Example #3
Source File: EntitySetTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void ref(final ContentType contentType) throws ODataDeserializerException {
  final InputStream input = getClass().getResourceAsStream("collectionOfEntityReferences." + getSuffix(contentType));
  final ClientEntitySet entitySet = client.getBinder().getODataEntitySet(
      client.getDeserializer(contentType).toEntitySet(input));
  assertNotNull(entitySet);

  for (ClientEntity entity : entitySet.getEntities()) {
    assertNotNull(entity.getId());
  }
  entitySet.setCount(entitySet.getEntities().size());

  final ClientEntitySet written =
      client.getBinder().getODataEntitySet(new ResWrap<EntityCollection>((URI) null, null,
          client.getBinder().getEntitySet(entitySet)));
  assertEquals(entitySet, written);
}
 
Example #4
Source File: BasicITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void test3Olingo1064() throws ODataDeserializerException {
  EdmMetadataRequest request = getClient().getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
  assertNotNull(request);
  setCookieHeader(request);    
  
  ODataRetrieveResponse<Edm> response = request.execute();
  saveCookieHeader(response);
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());

  Edm edm = response.getBody();
  
  EdmEnabledODataClient odataClient = ODataClientFactory.getEdmEnabledClient(SERVICE_URI, edm, null);
  final InputStream input = Thread.currentThread().getContextClassLoader().
      getResourceAsStream("ESCompAllPrimWithEmptyValueForComplexProperty.json");
  ClientEntity entity = odataClient.getReader().readEntity(input, ContentType.JSON);
  assertEquals("olingo.odata.test1.CTAllPrim", entity.getProperty(PROPERTY_COMP).getComplexValue().getTypeName());
  assertEquals(PROPERTY_COMP, entity.getProperty(PROPERTY_COMP).getName());
  assertTrue(entity.getProperty(PROPERTY_COMP).hasNullValue());
}
 
Example #5
Source File: ClientEntitySetIteratorTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEntitySetIterator3() throws IOException, URISyntaxException {
    String str = "{\"@odata.context\":\"$metadata#Cubes(Name)\","
        + "\"@odata.metadataEtag\": \"W/\\\"582997db-15b9-4a23-a8b0-c91bf45b4194\\\"\","
        + "\"value\":[{\"PropertyInt16\": 0,\"PropertyString\": \"\"}]}";
    
    InputStream stream = new ByteArrayInputStream(str.getBytes());
    ODataClient oDataClient = ODataClientFactory.getClient();
    ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator = 
        new ClientEntitySetIterator<ClientEntitySet, ClientEntity>(
        oDataClient, stream, ContentType.parse(ContentType.JSON.toString()));

    ArrayList<ClientEntity> entities = new ArrayList<ClientEntity>();
    while (entitySetIterator.hasNext()) {
        ClientEntity next = entitySetIterator.next();
        entities.add(next);
    }

    Assert.assertEquals(1, entities.size());

    Assert.assertEquals("", entities.get(0).getProperty("PropertyString").getPrimitiveValue().toString());
}
 
Example #6
Source File: AsyncSupportITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityAction() throws Exception {
  Calendar dateTime = Calendar.getInstance();
  dateTime.clear();
  dateTime.set(1012, 2, 0, 0, 0, 0);
  final Map<String, ClientValue> parameters = Collections.singletonMap(
      "ParameterDate",
      (ClientValue) getFactory().newPrimitiveValueBuilder()
          .setType(EdmPrimitiveTypeKind.Date).setValue(dateTime).build());
  ODataClient client = getClient();
  URI uri = client.newURIBuilder(TecSvcConst.BASE_URI)
      .appendActionCallSegment("AIRTESAllPrimParam").build();

  ODataInvokeRequest<ClientEntity> req = client.getInvokeRequestFactory()
      .getActionInvokeRequest(uri, ClientEntity.class, parameters);
  AsyncRequestWrapper<ODataRetrieveResponse<ClientEntity>>
  asyncReqWrp = client.getAsyncRequestFactory().getAsyncRequestWrapper(req);
  AsyncResponseWrapper<ODataRetrieveResponse<ClientEntity>>
  asyncRespWrp = asyncReqWrp.execute();
  waitTillDone(asyncRespWrp, 5);
  @SuppressWarnings("unchecked")
  ODataInvokeResponse<ClientEntity> response = (ODataInvokeResponse<ClientEntity>)asyncRespWrp.getODataResponse();
 
  assertEquals(HttpStatusCode.CREATED.getStatusCode(), response.getStatusCode());
  assertEquals(TecSvcConst.BASE_URI  +"/ESAllPrim(1)", response.getHeader(HttpHeader.LOCATION).iterator().next());
}
 
Example #7
Source File: EntityTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void withStream(final ContentType contentType) throws Exception {
  final InputStream input = getClass().getResourceAsStream("PersonDetails_1." + getSuffix(contentType));
  final ClientEntity entity = client.getBinder().getODataEntity(
      client.getDeserializer(contentType).toEntity(input));
  assertNotNull(entity);

  assertFalse(entity.isMediaEntity());

  final ClientLink editMedia = entity.getMediaEditLink("Photo");
  assertNotNull(editMedia);

  final ClientEntity written = client.getBinder().getODataEntity(
      new ResWrap<Entity>((URI) null, null, client.getBinder().getEntity(entity)));
  assertEquals(entity, written);
  input.close();
}
 
Example #8
Source File: CMODataSolmanClient.java    From devops-cm-client with Apache License 2.0 6 votes vote down vote up
static CMODataTransport toTransport(String changeID, ClientEntity transportEntity, boolean failOnMissingProperty) {

        String transportId = getValueAsString("TransportID", transportEntity);
        checkState(!isBlank(transportId), format("Transport id found to be null or empty when retrieving transports for change '%s'.", changeID), failOnMissingProperty);

        String developmentSystemId = getValueAsString("DevelopmentSystemID", transportEntity);
        checkState( developmentSystemId != null, format("DevelopmentSystemID was null when retrieving transports for change '%s'.", changeID), failOnMissingProperty);

        String bModifiable = getValueAsString("IsModifiable", transportEntity);
        checkState(!isBlank(bModifiable), format("Modifiable flag found to be null or empty when retrieving transports for change '%s'.", changeID), failOnMissingProperty);

        String description = getValueAsString("Description", transportEntity);
        String owner = getValueAsString("Owner", transportEntity);

        logger.debug(format("Transport '%s' retrieved for change document '%s'. isModifiable: '%s', Owner: '%s' ,Description: '%s'.",
            transportId, changeID, bModifiable, owner, description));

        return new CMODataTransport(
                transportId,
                developmentSystemId,
                parseBoolean(bModifiable),
                description,
                owner);
    }
 
Example #9
Source File: ODataWriterImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public InputStream writeEntities(final Collection<ClientEntity> entities, final ContentType contentType)
    throws ODataSerializerException {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  OutputStreamWriter writer;
  try {
    writer = new OutputStreamWriter(output, Constants.UTF8);
  } catch (final UnsupportedEncodingException e) {
    writer = null;
  }
  try {
    final ODataSerializer serializer = client.getSerializer(contentType);
    for (ClientEntity entity : entities) {
      serializer.write(writer, client.getBinder().getEntity(entity));
    }

    return new ByteArrayInputStream(output.toByteArray());
  } finally {
    IOUtils.closeQuietly(writer);
  }
}
 
Example #10
Source File: ProxyUtils.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public static Object getEntityProxy(
        final AbstractService<?> service,
        final ClientEntity entity,
        final URI entitySetURI,
        final Class<?> type,
        final String eTag,
        final boolean checkInTheContext) {

  EntityInvocationHandler handler = EntityInvocationHandler.getInstance(entity, entitySetURI, type, service);

  if (StringUtils.isNotBlank(eTag)) {
    // override ETag into the wrapped object.
    handler.setETag(eTag);
  }

  if (checkInTheContext && service.getContext().entityContext().isAttached(handler)) {
    handler = service.getContext().entityContext().getEntity(handler.getUUID());
    handler.setEntity(entity);
  }

  return Proxy.newProxyInstance(
          Thread.currentThread().getContextClassLoader(),
          new Class<?>[] {type},
          handler);
}
 
Example #11
Source File: FilterSystemQueryITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void substringStartGiven() {
  ODataRetrieveResponse<ClientEntitySet> result =
      sendRequest(ES_TWO_KEY_NAV, "substring(PropertyComp/PropertyComp/PropertyString,6) eq 'Value'");

  assertEquals(4, result.getBody().getEntities().size());

  ClientEntity clientEntity = result.getBody().getEntities().get(0);
  assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
  assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());

  clientEntity = result.getBody().getEntities().get(1);
  assertShortOrInt(1, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
  assertEquals("2", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());

  clientEntity = result.getBody().getEntities().get(2);
  assertShortOrInt(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
  assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());

  clientEntity = result.getBody().getEntities().get(3);
  assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
  assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());
}
 
Example #12
Source File: CMODataClientGetTransportsTest.java    From devops-cm-client with Apache License 2.0 6 votes vote down vote up
private static ClientEntity setupTransportMock(String transportId, String developmentSystemId, boolean isModifiable) {

        ClientEntity transportMock = createMock(ClientEntity.class);

        Map<String, String> props = new HashMap<String ,String>();

        props.put("TransportID", transportId);
        props.put("DevelopmentSystemID", developmentSystemId);
        props.put("IsModifiable", Boolean.valueOf(isModifiable).toString());
        props.put("Description", "S 8000038673: HCP CI Jenkins Deploy UC 1");
        props.put("Owner", SERVICE_USER);

        for(Map.Entry<String, String> e : props.entrySet()) {
            ClientProperty cp = new ClientPropertyImpl(e.getKey(),
                    new ClientObjectFactoryImpl().newPrimitiveValueBuilder().setValue(e.getValue()).build());
            expect(transportMock.getProperty(e.getKey())).andReturn(cp);
        }
        replay(transportMock);
        return transportMock;
    }
 
Example #13
Source File: MediaEntityTestITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #14
Source File: BasicITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void readHeaderInfoFromClientException1() throws Exception {
  ODataEntityRequest<ClientEntity> request = getClient().getRetrieveRequestFactory()
      .getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
          .appendEntitySetSegment(ES_MIX_PRIM_COLL_COMP).appendKeySegment("42").build());
  assertNotNull(request);
  setCookieHeader(request);
  request.setAccept("text/plain");
  try {
    request.execute();
    fail("Expected Exception not thrown!");
  } catch (final ODataClientErrorException e) {
    assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
    final ODataError error = e.getODataError();
    assertThat(error.getMessage(), containsString("key"));
  }    
}
 
Example #15
Source File: OrderBySystemQueryITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleOrderByDescending() {
  final ODataRetrieveResponse<ClientEntitySet> response =
      sendRequest(ES_ALL_PRIM, "PropertyByte,PropertyInt16 desc");
  assertEquals(4, response.getBody().getEntities().size());

  ClientEntity clientEntity = response.getBody().getEntities().get(0);
  assertEquals("10", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString());
  
  clientEntity = response.getBody().getEntities().get(1);
  assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString());

  clientEntity = response.getBody().getEntities().get(2);
  assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString());

  clientEntity = response.getBody().getEntities().get(3);
  assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString());
}
 
Example #16
Source File: OrderBySystemQueryITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void simpleOrderBy() {
  ODataRetrieveResponse<ClientEntitySet> response = null;

  response = sendRequest(ES_ALL_PRIM, "PropertyDate");
  assertEquals(4, response.getBody().getEntities().size());

  ClientEntity clientEntity = response.getBody().getEntities().get(0);
  assertEquals("0", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString());

  clientEntity = response.getBody().getEntities().get(1);
  assertEquals("10", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString());
  
  clientEntity = response.getBody().getEntities().get(2);
  assertEquals("32767", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString());

  clientEntity = response.getBody().getEntities().get(3);
  assertEquals("-32768", ((ClientValuable) clientEntity.getProperty("PropertyInt16")).getValue().toString());
}
 
Example #17
Source File: BasicBoundActionsITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void boundActionReturningComplexDerivedTypeWithComplexTypeSegInAction() throws Exception {
  Map<String, Object> segmentValues = new HashMap<String, Object>();
  segmentValues.put("PropertyInt16", 1);
  segmentValues.put("PropertyString", "1");
  URIBuilder builder = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESTwoKeyNav").
      appendKeySegment(segmentValues).appendPropertySegment("PropertyCompNav").
      appendDerivedEntityTypeSegment("olingo.odata.test1.CTTwoBasePrimCompNav").
      appendActionCallSegment("olingo.odata.test1."
          + "BAETTwoKeyNavCTBasePrimCompNavCTTwoBasePrimCompNavRTCTTwoBasePrimCompNav");
  
  Map<String, ClientValue> parameters = new HashMap<String, ClientValue>();
  
  final ODataInvokeRequest<ClientEntity> req =
      client.getInvokeRequestFactory().getActionInvokeRequest(builder.build(), ClientEntity.class, parameters);
  req.setFormat(ContentType.JSON_FULL_METADATA);
  req.setContentType(ContentType.APPLICATION_JSON.toContentTypeString() + ";odata.metadata=full");
  ClientEntity entity = req.execute().getBody();
  assertNotNull(entity);
  assertEquals(entity.getProperties().size(), 2);
  assertEquals(entity.getTypeName().getFullQualifiedNameAsString(), 
      "olingo.odata.test1.CTTwoBasePrimCompNav");
}
 
Example #18
Source File: BasicITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void test1Olingo1064() throws ODataDeserializerException {
  EdmMetadataRequest request = getClient().getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
  assertNotNull(request);
  setCookieHeader(request);    
  
  ODataRetrieveResponse<Edm> response = request.execute();
  saveCookieHeader(response);
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());

  Edm edm = response.getBody();
  
  EdmEnabledODataClient odataClient = ODataClientFactory.getEdmEnabledClient(SERVICE_URI, edm, null);
  final InputStream input = Thread.currentThread().getContextClassLoader().
      getResourceAsStream("ESCompAllPrimWithValueForComplexProperty.json");
  ClientEntity entity = odataClient.getReader().readEntity(input, ContentType.JSON);
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
  assertNotNull(entity.getProperty(PROPERTY_COMP).getComplexValue());
  assertEquals("olingo.odata.test1.CTAllPrim", entity.getProperty(PROPERTY_COMP).getComplexValue().getTypeName());
  assertEquals(PROPERTY_COMP, entity.getProperty(PROPERTY_COMP).getName());
  assertNull(entity.getProperty(PROPERTY_COMP).getComplexValue().get("PropertyString").
      getPrimitiveValue().toValue());
  assertNull(entity.getProperty(PROPERTY_COMP).getComplexValue().get("PropertyBoolean").
      getPrimitiveValue().toValue());
}
 
Example #19
Source File: JSONFormatConformanceTestITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * MUST NOT require <tt>odata.streaming=true</tt> in the <tt>Content-Type</tt> header (section 4.4).
 */
@Test
public void item6() throws EdmPrimitiveTypeException {
  final URI uri = edmClient.newURIBuilder().
      appendEntitySetSegment("Accounts").appendKeySegment(102).
      appendNavigationSegment("MyPaymentInstruments").appendKeySegment(102902).build();
  final ODataEntityRequest<ClientEntity> req = edmClient.getRetrieveRequestFactory().getEntityRequest(uri);

  // request format (via Accept header) does not contain odata.streaming=true
  assertEquals("application/json;odata.metadata=minimal", req.getAccept());

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

  // response payload is understood
  final ClientEntity entity = res.getBody();
  assertNotNull(entity);
  assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument", entity.getTypeName().toString());
  assertEquals(102902, entity.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
  assertEquals("Edm.DateTimeOffset", entity.getProperty("CreatedDate").getPrimitiveValue().getTypeName());
}
 
Example #20
Source File: NavigationITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void oneLevelToEntityWithKey() throws Exception {
  final ODataRetrieveResponse<ClientEntity> response =
      getClient().getRetrieveRequestFactory().getEntityRequest(
          getClient().newURIBuilder(TecSvcConst.BASE_URI)
              .appendEntitySetSegment("ESAllPrim").appendKeySegment(32767)
              .appendNavigationSegment("NavPropertyETTwoPrimMany").appendKeySegment(-365).build())
          .execute();
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());

  final ClientEntity entity = response.getBody();
  assertNotNull(entity);
  final ClientProperty property = entity.getProperty("PropertyString");
  assertNotNull(property);
  assertNotNull(property.getPrimitiveValue());
  assertEquals("Test String2", property.getPrimitiveValue().toValue());
}
 
Example #21
Source File: FunctionImportITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityWithoutEntitySet() throws Exception {
  ODataInvokeRequest<ClientEntity> request = getClient().getInvokeRequestFactory()
      .getFunctionInvokeRequest(
          getClient().newURIBuilder(TecSvcConst.BASE_URI).appendOperationCallSegment("FICRTETKeyNav").build(),
          ClientEntity.class);
  assertNotNull(request);
  setCookieHeader(request);

  final ODataInvokeResponse<ClientEntity> response = request.execute();
  saveCookieHeader(response);
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());

  final ClientEntity entity = response.getBody();
  assertNotNull(entity);
  final ClientProperty property = entity.getProperty("PropertyInt16");
  assertNotNull(property);
  assertShortOrInt(1, property.getPrimitiveValue().toValue());
}
 
Example #22
Source File: KeyAsSegmentTestITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void read(final ContentType contentType) {
  final URIBuilder uriBuilder = client.newURIBuilder(testKeyAsSegmentServiceRootURL).
      appendEntitySetSegment("Accounts").appendKeySegment(101);

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

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

  // In JSON with minimal metadata, links are not provided
  if (contentType.equals(ContentType.APPLICATION_ATOM_XML) || contentType.equals(ContentType.JSON_FULL_METADATA)) {
    assertFalse(entity.getEditLink().toASCIIString().contains("("));
    assertFalse(entity.getEditLink().toASCIIString().contains(")"));
  }
}
 
Example #23
Source File: BasicITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void test2Olingo1064() throws ODataDeserializerException {
  EdmMetadataRequest request = getClient().getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
  assertNotNull(request);
  setCookieHeader(request);    
  
  ODataRetrieveResponse<Edm> response = request.execute();
  saveCookieHeader(response);
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());

  Edm edm = response.getBody();
  
  EdmEnabledODataClient odataClient = ODataClientFactory.getEdmEnabledClient(SERVICE_URI, edm, null);
  final InputStream input = Thread.currentThread().getContextClassLoader().
      getResourceAsStream("ESCompAllPrimWithNullValueForComplexProperty.json");
  ClientEntity entity = odataClient.getReader().readEntity(input, ContentType.JSON);
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
  assertNotNull(entity.getProperty(PROPERTY_COMP).getComplexValue());
  assertEquals("olingo.odata.test1.CTAllPrim", entity.getProperty(PROPERTY_COMP).getComplexValue().getTypeName());
  assertEquals(PROPERTY_COMP, entity.getProperty(PROPERTY_COMP).getName());
  assertTrue(entity.getProperty(PROPERTY_COMP).hasNullValue());
}
 
Example #24
Source File: FilterSystemQueryITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void useFilterFactory() {
  final URIFilter filter = getFilterFactory().eq(
      getFilterArgFactory().property("PropertyInt16"), getFilterArgFactory().literal(new Integer(0)));

  final URIBuilder uriBuilder =
      getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).filter(filter);

  final ODataEntitySetRequest<ClientEntitySet> req =
      getClient().getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());

  final ODataRetrieveResponse<ClientEntitySet> result = req.execute();
  assertEquals(1, result.getBody().getEntities().size());

  ClientEntity clientEntity = result.getBody().getEntities().get(0);
  assertShortOrInt(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
}
 
Example #25
Source File: FilterSystemQueryITCase.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void unaryMinusOperatorDecimal() {
  ODataRetrieveResponse<ClientEntitySet> result = sendRequest(ES_TWO_KEY_NAV, "PropertyInt16 gt -2.0 add --3.0");
  assertEquals(2, result.getBody().getEntities().size());

  ClientEntity clientEntity = result.getBody().getEntities().get(0);
  assertShortOrInt(2, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
  assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());

  clientEntity = result.getBody().getEntities().get(1);
  assertShortOrInt(3, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
  assertEquals("1", clientEntity.getProperty("PropertyString").getPrimitiveValue().toValue());
}
 
Example #26
Source File: JSONTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void issue2OLINGO1073_WithEntitySet() throws Exception {
  final ClientEntity message = createClientEntity();
  
  InputStream inputStream = client.getWriter().writeEntity(message, ContentType.APPLICATION_JSON);
  ResWrap<Entity> entity = new JsonDeserializer(false).toEntity(inputStream);
  assertNotNull(entity);
  
  StringWriter writer = new StringWriter();
  setNavigationBindingLinkOnEntity(entity);
  
  client.getSerializer(ContentType.APPLICATION_JSON).write(writer, entity);
  assertNotNull(writer.toString());
  writer = new StringWriter();
  client.getSerializer(ContentType.APPLICATION_JSON).write(writer, 
      new ResWrap<URI>(URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/"), null, 
          URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/People('russellwhyte')")));
  assertNotNull(writer.toString());
  assertEquals("{\"@odata.context\":\"http://services.odata.org/V4/("
      + "S(fe5rsnxo3fkkkk2bvmh1nl1y))/TripPinServiceRW/\",\"@odata.id\":"
      + "\"http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/TripPinServiceRW/"
      + "People('russellwhyte')\"}", writer.toString());
  
  writer = new StringWriter();
  Link linkPayload = new Link();
  linkPayload.setBindingLink("Photos");
  linkPayload.setMediaETag("xyz");
  linkPayload.setInlineEntity(createEntity());
  linkPayload.setTitle("Photos");
  linkPayload.setHref("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/Photos");
  client.getSerializer(ContentType.APPLICATION_JSON).write(writer, 
      new ResWrap<Link>(URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/"), linkPayload.getMediaETag(), linkPayload));
  assertNotNull(writer.toString());
  assertEquals("{\"url\":\"http://services.odata.org/V4/"
      + "(S(fe5rsnxo3fkkkk2bvmh1nl1y))/TripPinServiceRW/Photos\"}", writer.toString());
}
 
Example #27
Source File: ClientEntitySerializer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ClientEntity entity, JsonGenerator generator, SerializerProvider provider) throws IOException {
    generator.writeStartObject();
    for (ClientProperty prop : entity.getProperties()) {
        generator.writeFieldName(prop.getName());
        generator.writeObject(prop.getValue());
    }
    generator.writeEndObject();
}
 
Example #28
Source File: FilterSystemQueryITCase.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void dateTimeOffsetSubDateTimeOffset() {
  ODataRetrieveResponse<ClientEntitySet> response =
      sendRequest(ES_ALL_PRIM, "PropertyDuration eq 2005-12-03T00:00:00Z sub 2005-12-03T00:00:00Z");
  assertEquals(2, response.getBody().getEntities().size());

  final ClientEntity clientEntity = response.getBody().getEntities().get(0);
  assertShortOrInt(0, clientEntity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
}
 
Example #29
Source File: AbstractTestITCase.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected ClientEntity read(final ContentType contentType, final URI editLink) {
  final ODataEntityRequest<ClientEntity> req = getClient().getRetrieveRequestFactory().getEntityRequest(editLink);
  req.setFormat(contentType);

  final ODataRetrieveResponse<ClientEntity> res = req.execute();
  final ClientEntity entity = res.getBody();

  assertNotNull(entity);

  if (ContentType.JSON_FULL_METADATA == contentType || ContentType.APPLICATION_ATOM_XML == contentType) {
    assertEquals(req.getURI(), entity.getEditLink());
  }

  return entity;
}
 
Example #30
Source File: ConditionalITCase.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void readNotModified() throws Exception {
  ODataEntityRequest<ClientEntity> request = getClient().getRetrieveRequestFactory().getEntityRequest(uriEntity);
  request.setIfNoneMatch("W/\"0\"");
  assertNotNull(request);
  setCookieHeader(request);
  final ODataRetrieveResponse<ClientEntity> response = request.execute();
  saveCookieHeader(response);
  assertEquals(HttpStatusCode.NOT_MODIFIED.getStatusCode(), response.getStatusCode());
}