Java Code Examples for org.apache.olingo.client.api.domain.ClientEntity#setETag()

The following examples show how to use org.apache.olingo.client.api.domain.ClientEntity#setETag() . 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: EntityTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void complexNavigationProperties(final ContentType contentType) throws Exception {
  final InputStream input = getClass().getResourceAsStream("entity.withcomplexnavigation." + getSuffix(contentType));
  final ClientEntity entity = client.getBinder().getODataEntity(
      client.getDeserializer(contentType).toEntity(input));
  assertNotNull(entity);

  final ClientComplexValue addressValue = entity.getProperty("Address").getComplexValue();
  assertNotNull(addressValue);
  assertNotNull(addressValue.getNavigationLink("Country"));

  // ETag is not serialized
  entity.setETag(null);
  final ClientEntity written = client.getBinder().getODataEntity(
      new ResWrap<Entity>((URI) null, null, client.getBinder().getEntity(entity)));
  assertEquals(entity, written);
  input.close();
}
 
Example 2
Source File: AtomTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void issue1OLINGO1073() throws Exception {
  final ClientEntity message = client.getObjectFactory().
      newEntity(new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin.Person"));
  
  final ClientComplexValue cityComplexType = getCityComplexType();
  
  final ClientComplexValue locationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.Location");
  locationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln.")));
  locationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));

  final ClientComplexValue eventLocationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.EventLocation");
  eventLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("BuildingInfo",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln12.")));
  eventLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln12.")));
  eventLocationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));
  
  final ClientComplexValue airportLocationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.AirportLocation");
  airportLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln123.")));
  airportLocationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));
  
  final ClientCollectionValue<ClientValue> collectionAddressInfo = client.getObjectFactory().
      newCollectionValue("Microsoft.OData.SampleService.Models.TripPin.Location");
  collectionAddressInfo.add(locationComplexType);
  collectionAddressInfo.add(eventLocationComplexType);
  collectionAddressInfo.add(airportLocationComplexType);
  
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("UserName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("russellwhyte")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("FirstName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("Russell")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("LastName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("Whyte")));
  
  final ClientCollectionValue<ClientValue> emailCollectionValue = client.getObjectFactory().
      newCollectionValue("String");
  emailCollectionValue.add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("[email protected]"));
  emailCollectionValue.add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("[email protected]"));
  message.getProperties().add(client.getObjectFactory().newCollectionProperty("Emails", emailCollectionValue));
  
  message.getProperties().add(client.getObjectFactory().newCollectionProperty("AddressInfo", collectionAddressInfo));
  message.getProperties().add(client.getObjectFactory().newEnumProperty("Gender", 
      client.getObjectFactory().newEnumValue(
          "Microsoft.OData.SampleService.Models.TripPin.PersonGender", "Male")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Concurrency", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildInt64(Long.valueOf("636293755917400747"))));
  message.setId(URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/People('russellwhyte')"));
  message.setETag("W/\"08D491CCBE417AAB\"");
  message.setEditLink(URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/People('russellwhyte')"));

  String actual = IOUtils.toString(client.getWriter().writeEntity(message, ContentType.APPLICATION_ATOM_XML));
  actual = actual.substring(actual.indexOf("<entry"));
  assertNotNull(actual);
  String expected = IOUtils.toString(getClass().getResourceAsStream("olingo1073_1.xml"));
  expected = expected.substring(expected.indexOf("<entry"));
  expected = expected.trim().replace("\n", "").replace("\r", "").replace("\t", "");
  assertEquals(expected, actual);
}
 
Example 3
Source File: AtomTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void issue2OLINGO1073() throws Exception {
  final ClientEntity message = client.getObjectFactory().
      newEntity(new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin.Person"));
  
  final ClientComplexValue cityComplexType = getCityComplexType();
  
  final ClientComplexValue locationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.Location");
  locationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln.")));
  locationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));

  final ClientComplexValue eventLocationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.EventLocation");
  eventLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("BuildingInfo",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln12.")));
  eventLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln12.")));
  eventLocationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));
  
  final ClientComplexValue airportLocationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.AirportLocation");
  airportLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln123.")));
  airportLocationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));
  
  final ClientCollectionValue<ClientValue> collectionAddressInfo = client.getObjectFactory().
      newCollectionValue("Microsoft.OData.SampleService.Models.TripPin.Location");
  collectionAddressInfo.add(locationComplexType);
  collectionAddressInfo.add(eventLocationComplexType);
  collectionAddressInfo.add(airportLocationComplexType);
  
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("UserName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("russellwhyte")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("FirstName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("Russell")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("LastName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("Whyte")));
  
  final ClientCollectionValue<ClientValue> emailCollectionValue = client.getObjectFactory().
      newCollectionValue("String");
  emailCollectionValue.add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("[email protected]"));
  emailCollectionValue.add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("[email protected]"));
  message.getProperties().add(client.getObjectFactory().newCollectionProperty("Emails", emailCollectionValue));
  
  message.getProperties().add(client.getObjectFactory().newCollectionProperty("AddressInfo", collectionAddressInfo));
  message.getProperties().add(client.getObjectFactory().newEnumProperty("Gender", 
      client.getObjectFactory().newEnumValue(
          "Microsoft.OData.SampleService.Models.TripPin.PersonGender", "Male")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Concurrency", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildInt64(Long.valueOf("636293755917400747"))));
  message.setId(URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/People('russellwhyte')"));
  message.setETag("W/\"08D491CCBE417AAB\"");
  message.setEditLink(URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/People('russellwhyte')"));

  InputStream inputStream = client.getWriter().writeEntity(message, ContentType.APPLICATION_ATOM_XML);
  ResWrap<Entity> entity = new AtomDeserializer().toEntity(inputStream);
  assertNotNull(entity);
  assertEquals(7, entity.getPayload().getProperties().size());
  assertEquals(3, entity.getPayload().getProperty("AddressInfo").asCollection().size());
  assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Location", 
      ((ComplexValue)entity.getPayload().getProperty("AddressInfo").asCollection().get(0)).getTypeName());
  assertEquals("#Microsoft.OData.SampleService.Models.TripPin.EventLocation", 
      ((ComplexValue)entity.getPayload().getProperty("AddressInfo").asCollection().get(1)).getTypeName());
  assertEquals("#Microsoft.OData.SampleService.Models.TripPin.AirportLocation", 
      ((ComplexValue)entity.getPayload().getProperty("AddressInfo").asCollection().get(2)).getTypeName());
  assertEquals("Collection(Microsoft.OData.SampleService.Models.TripPin.Location)", 
      entity.getPayload().getProperty("AddressInfo").getType());
}
 
Example 4
Source File: JSONTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void issue3OLINGO1073() throws Exception {
  final ClientEntity message = client.getObjectFactory().
      newEntity(new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin.Person"));
  
  final ClientComplexValue cityComplexType = getCityComplexType();
  
  final ClientComplexValue locationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.Location");
  locationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln.")));
  locationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));

  final ClientComplexValue eventLocationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.EventLocation");
  eventLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("BuildingInfo",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln12.")));
  eventLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln12.")));
  eventLocationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));
  
  final ClientComplexValue airportLocationComplexType = client.getObjectFactory().
      newComplexValue("Microsoft.OData.SampleService.Models.TripPin.AirportLocation");
  airportLocationComplexType.add(client.getObjectFactory().newPrimitiveProperty("Address",
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("187 Suffolk Ln123.")));
  airportLocationComplexType.add(client.getObjectFactory().newComplexProperty("City",cityComplexType));
  
  final ClientCollectionValue<ClientValue> collectionAddressInfo = client.getObjectFactory().
      newCollectionValue("Microsoft.OData.SampleService.Models.TripPin.Location");
  collectionAddressInfo.add(locationComplexType);
  collectionAddressInfo.add(eventLocationComplexType);
  collectionAddressInfo.add(airportLocationComplexType);
  
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("UserName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("russellwhyte")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("FirstName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("Russell")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("LastName", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildString("Whyte")));
  
  final ClientCollectionValue<ClientValue> emailCollectionValue = client.getObjectFactory().
      newCollectionValue("String");
  emailCollectionValue.add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("[email protected]"));
  emailCollectionValue.add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("[email protected]"));
  message.getProperties().add(client.getObjectFactory().newCollectionProperty("Emails", emailCollectionValue));
  
  message.getProperties().add(client.getObjectFactory().newCollectionProperty("AddressInfo", collectionAddressInfo));
  message.getProperties().add(client.getObjectFactory().newEnumProperty("Gender", 
      client.getObjectFactory().newEnumValue(
          "Microsoft.OData.SampleService.Models.TripPin.PersonGender", "Male")));
  message.getProperties().add(client.getObjectFactory().newPrimitiveProperty("Concurrency", 
      client.getObjectFactory().newPrimitiveValueBuilder().buildInt64(Long.valueOf("636293755917400747"))));
  message.setId(URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/People('russellwhyte')"));
  message.setETag("W/\"08D491CCBE417AAB\"");
  message.setEditLink(URI.create("http://services.odata.org/V4/(S(fe5rsnxo3fkkkk2bvmh1nl1y))/"
      + "TripPinServiceRW/People('russellwhyte')"));

  InputStream inputStream = client.getWriter().writeEntity(message, ContentType.JSON_FULL_METADATA);
  ResWrap<Entity> entity = new JsonDeserializer(true).toEntity(inputStream);
  assertNotNull(entity);
  assertEquals(7, entity.getPayload().getProperties().size());
  assertEquals(3, entity.getPayload().getProperty("AddressInfo").asCollection().size());
  assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Location", 
      ((ComplexValue)entity.getPayload().getProperty("AddressInfo").asCollection().get(0)).getTypeName());
  assertEquals("#Microsoft.OData.SampleService.Models.TripPin.EventLocation", 
      ((ComplexValue)entity.getPayload().getProperty("AddressInfo").asCollection().get(1)).getTypeName());
  assertEquals("#Microsoft.OData.SampleService.Models.TripPin.AirportLocation", 
      ((ComplexValue)entity.getPayload().getProperty("AddressInfo").asCollection().get(2)).getTypeName());
  assertEquals("Collection(Microsoft.OData.SampleService.Models.TripPin.Location)", 
      entity.getPayload().getProperty("AddressInfo").getType());
}