Java Code Examples for org.apache.olingo.odata2.api.ep.entry.ODataEntry#getMediaMetadata()

The following examples show how to use org.apache.olingo.odata2.api.ep.entry.ODataEntry#getMediaMetadata() . 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: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readIncompleteEntry() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream reqContent = createContentAsStream(ROOM_1_XML);
  final ODataEntry result =
      new XmlEntityConsumer().readEntry(entitySet, reqContent, EntityProviderReadProperties.init().build());

  final EntryMetadata entryMetadata = result.getMetadata();
  assertEquals("http://localhost:19000/test/Rooms('1')", entryMetadata.getId());
  assertEquals("W/\"1\"", entryMetadata.getEtag());
  assertNull(entryMetadata.getUri());

  final MediaMetadata mediaMetadata = result.getMediaMetadata();
  assertEquals(HttpContentType.APPLICATION_XML, mediaMetadata.getContentType());
  assertNull(mediaMetadata.getSourceLink());
  assertNull(mediaMetadata.getEditLink());
  assertNull(mediaMetadata.getEtag());

  final Map<String, Object> properties = result.getProperties();
  assertEquals(1, properties.size());
  assertEquals("1", properties.get("Id"));
  assertFalse(properties.containsKey("Seats"));
}
 
Example 2
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readIncompleteEntryMerge() throws Exception {
  XmlEntityConsumer xec = new XmlEntityConsumer();

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream reqContent = createContentAsStream(ROOM_1_XML);
  ODataEntry result =
      xec.readEntry(entitySet, reqContent, EntityProviderReadProperties.init().mergeSemantic(true).build());

  // verify
  EntryMetadata entryMetadata = result.getMetadata();
  assertEquals("http://localhost:19000/test/Rooms('1')", entryMetadata.getId());
  assertEquals("W/\"1\"", entryMetadata.getEtag());
  assertEquals(null, entryMetadata.getUri());

  MediaMetadata mediaMetadata = result.getMediaMetadata();
  assertEquals("application/xml", mediaMetadata.getContentType());
  assertEquals(null, mediaMetadata.getSourceLink());
  assertEquals(null, mediaMetadata.getEditLink());
  assertEquals(null, mediaMetadata.getEtag());

  Map<String, Object> properties = result.getProperties();
  assertEquals(1, properties.size());
  assertEquals("1", properties.get("Id"));

  assertEquals("Rooms('1')/nr_Building", result.getMetadata().getAssociationUris("nr_Building").get(0));
  assertEquals("Rooms('1')/nr_Employees", result.getMetadata().getAssociationUris("nr_Employees").get(0));
}
 
Example 3
Source File: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readIncompleteEntry() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream reqContent = createContentAsStream(ROOM_1_XML);
  EntityStream stream = new EntityStream();
  stream.setContent(reqContent);
  stream.setReadProperties(DeserializerProperties.init().build());

  XmlEntityDeserializer xec = new XmlEntityDeserializer();
  // execute
  ODataEntry result = xec.readEntry(entitySet, stream);
  final EntryMetadata entryMetadata = result.getMetadata();
  assertEquals("http://localhost:19000/test/Rooms('1')", entryMetadata.getId());
  assertEquals("W/\"1\"", entryMetadata.getEtag());
  assertNull(entryMetadata.getUri());

  final MediaMetadata mediaMetadata = result.getMediaMetadata();
  assertEquals(HttpContentType.APPLICATION_XML, mediaMetadata.getContentType());
  assertNull(mediaMetadata.getSourceLink());
  assertNull(mediaMetadata.getEditLink());
  assertNull(mediaMetadata.getEtag());

  final Map<String, Object> properties = result.getProperties();
  assertEquals(1, properties.size());
  assertEquals("1", properties.get("Id"));
  assertFalse(properties.containsKey("Seats"));
}
 
Example 4
Source File: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readIncompleteEntryMerge() throws Exception {
  XmlEntityDeserializer xec = new XmlEntityDeserializer();

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream reqContent = createContentAsStream(ROOM_1_XML);
  EntityStream stream = new EntityStream();
  stream.setContent(reqContent);
  stream.setReadProperties(DeserializerProperties.init().build());

  // execute
  ODataEntry result = xec.readEntry(entitySet, stream);
  // verify
  EntryMetadata entryMetadata = result.getMetadata();
  assertEquals("http://localhost:19000/test/Rooms('1')", entryMetadata.getId());
  assertEquals("W/\"1\"", entryMetadata.getEtag());
  assertEquals(null, entryMetadata.getUri());

  MediaMetadata mediaMetadata = result.getMediaMetadata();
  assertEquals("application/xml", mediaMetadata.getContentType());
  assertEquals(null, mediaMetadata.getSourceLink());
  assertEquals(null, mediaMetadata.getEditLink());
  assertEquals(null, mediaMetadata.getEtag());

  Map<String, Object> properties = result.getProperties();
  assertEquals(1, properties.size());
  assertEquals("1", properties.get("Id"));

  assertEquals("Rooms('1')/nr_Building", result.getMetadata().getAssociationUris("nr_Building").get(0));
  assertEquals("Rooms('1')/nr_Employees", result.getMetadata().getAssociationUris("nr_Employees").get(0));
}
 
Example 5
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void readEntryAtomProperties() throws Exception {
  // prepare
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream contentBody = createContentAsStream(EMPLOYEE_1_XML);

  // execute
  XmlEntityConsumer xec = new XmlEntityConsumer();
  ODataEntry result =
      xec.readEntry(entitySet, contentBody, EntityProviderReadProperties.init().mergeSemantic(true).build());

  // verify
  EntryMetadata metadata = result.getMetadata();
  assertEquals("http://localhost:19000/Employees('1')", metadata.getId());
  assertEquals("W/\"1\"", metadata.getEtag());
  List<String> associationUris = metadata.getAssociationUris("ne_Room");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Room", associationUris.get(0));
  associationUris = metadata.getAssociationUris("ne_Manager");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Manager", associationUris.get(0));
  associationUris = metadata.getAssociationUris("ne_Team");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Team", associationUris.get(0));

  assertEquals(null, metadata.getUri());

  MediaMetadata mm = result.getMediaMetadata();
  assertEquals("Employees('1')/$value", mm.getSourceLink());
  assertEquals("mmEtag", mm.getEtag());
  assertEquals("application/octet-stream", mm.getContentType());
  assertEquals("Employees('1')/$value", mm.getEditLink());

  Map<String, Object> data = result.getProperties();
  assertEquals(9, data.size());
  assertEquals("1", data.get("EmployeeId"));
  assertEquals("Walter Winter", data.get("EmployeeName"));
  assertEquals("1", data.get("ManagerId"));
  assertEquals("1", data.get("RoomId"));
  assertEquals("1", data.get("TeamId"));
}
 
Example 6
Source File: JsonEntryConsumerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void readSimpleEmployeeEntry() throws Exception {
  ODataEntry result = prepareAndExecuteEntry(SIMPLE_ENTRY_EMPLOYEE, "Employees", DEFAULT_PROPERTIES);

  // verify
  Map<String, Object> properties = result.getProperties();
  assertEquals(9, properties.size());

  assertEquals("1", properties.get("EmployeeId"));
  assertEquals("Walter Winter", properties.get("EmployeeName"));
  assertEquals("1", properties.get("ManagerId"));
  assertEquals("1", properties.get("RoomId"));
  assertEquals("1", properties.get("TeamId"));
  Map<String, Object> location = (Map<String, Object>) properties.get("Location");
  assertEquals(2, location.size());
  assertEquals("Germany", location.get("Country"));
  Map<String, Object> city = (Map<String, Object>) location.get("City");
  assertEquals(2, city.size());
  assertEquals("69124", city.get("PostalCode"));
  assertEquals("Heidelberg", city.get("CityName"));
  assertEquals(Integer.valueOf(52), properties.get("Age"));
  Calendar entryDate = (Calendar) properties.get("EntryDate");
  assertEquals(915148800000L, entryDate.getTimeInMillis());
  assertEquals(TimeZone.getTimeZone("GMT"), entryDate.getTimeZone());
  assertEquals("Employees('1')/$value", properties.get("ImageUrl"));

  List<String> associationUris = result.getMetadata().getAssociationUris("ne_Manager");
  assertEquals(1, associationUris.size());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Employees('1')/ne_Manager", associationUris.get(0));

  associationUris = result.getMetadata().getAssociationUris("ne_Team");
  assertEquals(1, associationUris.size());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Employees('1')/ne_Team", associationUris.get(0));

  associationUris = result.getMetadata().getAssociationUris("ne_Room");
  assertEquals(1, associationUris.size());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Employees('1')/ne_Room", associationUris.get(0));

  MediaMetadata mediaMetadata = result.getMediaMetadata();
  assertEquals("image/jpeg", mediaMetadata.getContentType());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Employees('1')/$value", mediaMetadata.getEditLink());
  assertEquals("Employees('1')/$value", mediaMetadata.getSourceLink());
  assertNull(mediaMetadata.getEtag());
}
 
Example 7
Source File: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void readEntryAtomProperties() throws Exception {
  // prepare
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream contentBody = createContentAsStream(EMPLOYEE_1_XML);

  EntityStream stream = new EntityStream();
  stream.setContent(contentBody);
  stream.setReadProperties(DeserializerProperties.init().build());

  // execute
  XmlEntityDeserializer xec = new XmlEntityDeserializer();
  ODataEntry result = xec.readEntry(entitySet, stream);
  // verify
  EntryMetadata metadata = result.getMetadata();
  assertEquals("http://localhost:19000/Employees('1')", metadata.getId());
  assertEquals("W/\"1\"", metadata.getEtag());
  List<String> associationUris = metadata.getAssociationUris("ne_Room");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Room", associationUris.get(0));
  associationUris = metadata.getAssociationUris("ne_Manager");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Manager", associationUris.get(0));
  associationUris = metadata.getAssociationUris("ne_Team");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Team", associationUris.get(0));

  assertEquals(null, metadata.getUri());

  MediaMetadata mm = result.getMediaMetadata();
  assertEquals("Employees('1')/$value", mm.getSourceLink());
  assertEquals("mmEtag", mm.getEtag());
  assertEquals("application/octet-stream", mm.getContentType());
  assertEquals("Employees('1')/$value", mm.getEditLink());

  Map<String, Object> data = result.getProperties();
  assertEquals(9, data.size());
  assertEquals("1", data.get("EmployeeId"));
  assertEquals("Walter Winter", data.get("EmployeeName"));
  assertEquals("1", data.get("ManagerId"));
  assertEquals("1", data.get("RoomId"));
  assertEquals("1", data.get("TeamId"));
}
 
Example 8
Source File: JsonEntryDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void readSimpleEmployeeEntry() throws Exception {
  ODataEntry result = prepareAndExecuteEntry(SIMPLE_ENTRY_EMPLOYEE, "Employees", DEFAULT_PROPERTIES);

  // verify
  Map<String, Object> properties = result.getProperties();
  assertEquals(9, properties.size());

  assertEquals("1", properties.get("EmployeeId"));
  assertEquals("Walter Winter", properties.get("EmployeeName"));
  assertEquals("1", properties.get("ManagerId"));
  assertEquals("1", properties.get("RoomId"));
  assertEquals("1", properties.get("TeamId"));
  Map<String, Object> location = (Map<String, Object>) properties.get("Location");
  assertEquals(2, location.size());
  assertEquals("Germany", location.get("Country"));
  Map<String, Object> city = (Map<String, Object>) location.get("City");
  assertEquals(2, city.size());
  assertEquals("69124", city.get("PostalCode"));
  assertEquals("Heidelberg", city.get("CityName"));
  assertEquals(Integer.valueOf(52), properties.get("Age"));
  Calendar entryDate = (Calendar) properties.get("EntryDate");
  assertEquals(915148800000L, entryDate.getTimeInMillis());
  assertEquals(TimeZone.getTimeZone("GMT"), entryDate.getTimeZone());
  assertEquals("Employees('1')/$value", properties.get("ImageUrl"));

  List<String> associationUris = result.getMetadata().getAssociationUris("ne_Manager");
  assertEquals(1, associationUris.size());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Employees('1')/ne_Manager", associationUris.get(0));

  associationUris = result.getMetadata().getAssociationUris("ne_Team");
  assertEquals(1, associationUris.size());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Employees('1')/ne_Team", associationUris.get(0));

  associationUris = result.getMetadata().getAssociationUris("ne_Room");
  assertEquals(1, associationUris.size());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Employees('1')/ne_Room", associationUris.get(0));

  MediaMetadata mediaMetadata = result.getMediaMetadata();
  assertEquals("image/jpeg", mediaMetadata.getContentType());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Employees('1')/$value", mediaMetadata.getEditLink());
  assertEquals("Employees('1')/$value", mediaMetadata.getSourceLink());
  assertNull(mediaMetadata.getEtag());
}