org.apache.olingo.odata2.api.ep.entry.ODataEntry Java Examples

The following examples show how to use org.apache.olingo.odata2.api.ep.entry.ODataEntry. 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: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testReadEntryRequestInvalidMapping() throws Exception {
  XmlEntityDeserializer xec = new XmlEntityDeserializer();

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream content = createContentAsStream(EMPLOYEE_1_XML);

  EntityStream stream = new EntityStream();
  stream.setContent(content);
  stream.setReadProperties(DeserializerProperties.init().addTypeMappings(
      createTypeMappings("EmployeeName", Integer.class)).build());

  // execute
  ODataEntry result = xec.readEntry(entitySet, stream);
  // verify
  Map<String, Object> properties = result.getProperties();
  assertEquals(9, properties.size());
}
 
Example #2
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 #3
Source File: XmlFeedDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Rooms navigate to Employees and has inline entry Teams
 * E.g: Rooms('1')/nr_Employees?$expand=ne_Team
 * @throws Exception
 */
@Test
public void roomsFeedWithRoomsToEmployeesInlineTeams() throws Exception {
  InputStream stream = getFileAsStream("RoomsToEmployeesWithInlineTeams.xml");
  assertNotNull(stream);
  EntityStream es = new EntityStream();
  es.setContent(stream);
  es.setReadProperties(DEFAULT_PROPERTIES);
  ODataClientImpl client = new ODataClientImpl();
  ContentTypeBasedDeserializer deserializer = client.createDeserializer("application/atom+xml");
  ODataFeed feed =
      deserializer.readFeed( MockFacade.getMockEdm().getDefaultEntityContainer()
          .getEntitySet(
              "Employees"), es);
  assertNotNull(feed);
  assertEquals(2, feed.getEntries().size());

  for (ODataEntry entry : feed.getEntries()) {
    assertEquals(10, entry.getProperties().size());
    assertEquals(3, ((ODataEntry)entry.getProperties().get("ne_Team")).getProperties().size());
  }
}
 
Example #4
Source File: JsonEntryDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readContentOnlyEmployeeWithAdditionalLink() throws Exception {
  // prepare
  String content = readFile("JsonEmployeeContentOnlyWithAdditionalLink.json");
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream contentBody = createContentAsStream(content);
  EntityStream entityStream = new EntityStream();
  entityStream.setContent(contentBody);
  entityStream.setReadProperties(DeserializerProperties.init().build());

  // execute
  JsonEntityDeserializer xec = new JsonEntityDeserializer();
  ODataEntry result =
      xec.readEntry(entitySet, entityStream);

  // verify
  assertEquals(9, result.getProperties().size());
  List<String> associationUris = result.getMetadata().getAssociationUris("ne_Manager");
  assertEquals(1, associationUris.size());
  assertEquals("http://host:8080/ReferenceScenario.svc/Managers('1')", associationUris.get(0));
}
 
Example #5
Source File: ODataClient.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Reads an entry (an Entity, a property, a complexType, ...).
 * 
 * @param resource_path the resource path to the parent of the requested
 *    EntitySet, as defined in {@link #getResourcePath(URI)}.
 * @param query_parameters Query parameters, as defined in {@link URI}.
 * 
 * @return an ODataEntry for the given {@code resource_path}.
 * 
 * @throws HttpException if the server emits an HTTP error code.
 * @throws IOException if the connection with the remote service fails.
 * @throws EdmException if the EDM does not contain the given entitySetName.
 * @throws EntityProviderException if reading of data (de-serialization)
 *    fails.
 * @throws UriSyntaxException violation of the OData URI construction rules.
 * @throws UriNotMatchingException URI parsing exception.
 * @throws ODataException encapsulate the OData exceptions described above.
 * @throws InterruptedException if running thread has been interrupted.
 */
public ODataEntry readEntry(String resource_path,
   Map<String, String> query_parameters) throws IOException, ODataException, InterruptedException
{
   if (resource_path == null || resource_path.isEmpty ())
      throw new IllegalArgumentException (
         "resource_path must not be null or empty.");
   
   ContentType contentType = ContentType.APPLICATION_ATOM_XML;
   
   String absolutUri = serviceRoot.toString () + '/' + resource_path;
   
   // Builds the query parameters string part of the URL.
   absolutUri = appendQueryParam (absolutUri, query_parameters);
   
   InputStream content = execute (absolutUri, contentType, "GET");
   
   return EntityProvider.readEntry(contentType.type (),
      getEntitySet (resource_path), content,
      EntityProviderReadProperties.init ().build ());
}
 
Example #6
Source File: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void readAndExpectException(final EdmEntitySet entitySet, final InputStream reqContent, final boolean merge,
    final MessageReference messageReference) throws ODataMessageException {
  try {
    EntityStream stream = new EntityStream();
    stream.setContent(reqContent);
    stream.setReadProperties(DeserializerProperties.init().build());

    // execute
    XmlEntityDeserializer xec = new XmlEntityDeserializer();
    ODataEntry result =
        xec.readEntry(entitySet, stream);
    assertNotNull(result);
    Assert.fail("Expected exception with MessageReference '" + messageReference.getKey() + "' was not thrown.");
  } catch (ODataMessageException e) {
    assertEquals(messageReference.getKey(), e.getMessageReference().getKey());
    // assertEquals(messageReference.getContent(), e.getMessageReference().getContent());
    throw e;
  }
}
 
Example #7
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Reads an employee with inlined but <code>NULL</code> room navigation property
 * (which has {@link com.sap.core.odata.api.edm.EdmMultiplicity#ONE EdmMultiplicity#ONE}).
 */
@Test
public void readWithInlineContentEmployeeNullRoomEntry() throws Exception {

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream reqContent = createContentAsStream(EMPLOYEE_1_NULL_ROOM_XML);

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

  // validate
  assertNotNull(entry);
  Map<String, Object> properties = entry.getProperties();
  assertEquals("1", properties.get("EmployeeId"));
  assertEquals("Walter Winter", properties.get("EmployeeName"));
  ODataEntry room = (ODataEntry) properties.get("ne_Room");
  assertNull(room);
}
 
Example #8
Source File: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readEntryLinks() 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
  List<String> associationUris = result.getMetadata().getAssociationUris("ne_Room");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Room", associationUris.get(0));
  associationUris = result.getMetadata().getAssociationUris("ne_Manager");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Manager", associationUris.get(0));
  associationUris = result.getMetadata().getAssociationUris("ne_Team");
  assertEquals(1, associationUris.size());
  assertEquals("Employees('1')/ne_Team", associationUris.get(0));
}
 
Example #9
Source File: JsonEntryConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readEntryWithNullProperty() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  final String content = "{\"Id\":\"99\",\"Seats\":null}";

  for (final boolean merge : new boolean[] { false, true }) {
    final ODataEntry result = new JsonEntityConsumer().readEntry(entitySet, createContentAsStream(content),
        EntityProviderReadProperties.init().mergeSemantic(merge).build());

    final Map<String, Object> properties = result.getProperties();
    assertNotNull(properties);
    assertEquals(2, properties.size());
    assertEquals("99", properties.get("Id"));
    assertTrue(properties.containsKey("Seats"));
    assertNull(properties.get("Seats"));

    assertTrue(result.getMetadata().getAssociationUris("nr_Employees").isEmpty());
    checkMediaDataInitial(result.getMediaMetadata());
  }
}
 
Example #10
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadEntryRequestObjectMapping() throws Exception {
  XmlEntityConsumer xec = new XmlEntityConsumer();

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream content = createContentAsStream(EMPLOYEE_1_XML);
  ODataEntry result =
      xec.readEntry(entitySet, content,
          EntityProviderReadProperties.init().mergeSemantic(true).addTypeMappings(
              createTypeMappings("EmployeeName", Object.class)).build());

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

  assertEquals("1", properties.get("EmployeeId"));
  Object o = properties.get("EmployeeName");
  assertTrue(o instanceof String);
  assertEquals("Walter Winter", properties.get("EmployeeName"));
  assertEquals("1", properties.get("ManagerId"));
  assertEquals("1", properties.get("RoomId"));
  assertEquals("1", properties.get("TeamId"));
}
 
Example #11
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a room with inlined but <code>NULL</code> employees navigation property
 * (which has {@link com.sap.core.odata.api.edm.EdmMultiplicity#MANY EdmMultiplicity#MANY}).
 */
@Test
public void readWithInlineContentRoomNullEmployeesEntry() throws Exception {

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream reqContent = createContentAsStream(ROOM_1_NULL_EMPLOYEE_XML);

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

  // validate
  assertNotNull(entry);
  Map<String, Object> properties = entry.getProperties();
  assertEquals("1", properties.get("Id"));
  ODataEntry room = (ODataEntry) properties.get("ne_Employees");
  assertNull(room);
}
 
Example #12
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readEntryNullProperty() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  final String content = EMPLOYEE_1_XML.replace("<d:EntryDate>1999-01-01T00:00:00</d:EntryDate>",
      "<d:EntryDate m:null='true' />");
  InputStream contentBody = createContentAsStream(content);

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

  final Map<String, Object> properties = result.getProperties();
  assertEquals(9, properties.size());
  assertTrue(properties.containsKey("EntryDate"));
  assertNull(properties.get("EntryDate"));
}
 
Example #13
Source File: JsonEntryDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readContentOnlyRoomWithAdditionalLink() throws Exception {
  // prepare
  String content = readFile("JsonRoomContentOnlyWithAdditionalLink.json");
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream contentBody = createContentAsStream(content);
  EntityStream entityStream = new EntityStream();
  entityStream.setContent(contentBody);
  entityStream.setReadProperties(DeserializerProperties.init().build());

  // execute
  JsonEntityDeserializer xec = new JsonEntityDeserializer();
  ODataEntry result =
      xec.readEntry(entitySet, entityStream);

  // verify
  assertEquals(4, result.getProperties().size());
  List<String> associationUris = result.getMetadata().getAssociationUris("nr_Building");
  assertEquals(1, associationUris.size());
  assertEquals("http://host:8080/ReferenceScenario.svc/Buildings('1')", associationUris.get(0));
}
 
Example #14
Source File: JsonFeedDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void emptyFeedWithoutDAndResults() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams");
  InputStream contentBody = createContentAsStream("[]");
  EntityStream entityStream = new EntityStream();
  entityStream.setContent(contentBody);
  entityStream.setReadProperties(DEFAULT_PROPERTIES);
  final ODataFeed feed = new JsonEntityDeserializer().readFeed(entitySet, entityStream);
  assertNotNull(feed);
  final List<ODataEntry> entries = feed.getEntries();
  assertNotNull(entries);
  assertEquals(0, entries.size());
  final FeedMetadata feedMetadata = feed.getFeedMetadata();
  assertNotNull(feedMetadata);
  assertNull(feedMetadata.getInlineCount());
  assertNull(feedMetadata.getNextLink());
}
 
Example #15
Source File: JsonEntryDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readSimpleTeamEntry() throws Exception {
  ODataEntry result = prepareAndExecuteEntry(SIMPLE_ENTRY_TEAM, "Teams", DEFAULT_PROPERTIES);

  Map<String, Object> properties = result.getProperties();
  assertNotNull(properties);
  assertEquals("1", properties.get("Id"));
  assertEquals("Team 1", properties.get("Name"));
  assertEquals(Boolean.FALSE, properties.get("isScrumTeam"));
  assertNull(properties.get("nt_Employees"));

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

  checkMediaDataInitial(result.getMediaMetadata());
}
 
Example #16
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readContentOnlyRoomWithAdditionalLink() throws Exception {
  // prepare
  String content = readFile("RoomContentOnlyWithAdditionalLink.xml");
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream contentBody = createContentAsStream(content);

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

  // verify
  assertEquals(4, result.getProperties().size());
  List<String> associationUris = result.getMetadata().getAssociationUris("nr_Building");
  assertEquals(1, associationUris.size());
  assertEquals("Buildings('1')", associationUris.get(0));
}
 
Example #17
Source File: JsonFeedDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Rooms has an inline feed Employees and Rooms has Inline entry Buildings
 * E.g: Rooms?$expand=nr_Employees,nr_Building
 * Empty Inline entity is also part of payload
 * @throws Exception
 */
@Test
public void roomsFeedWithRoomInlineEmployeesInlineBuildings() throws Exception {
  InputStream stream = getFileAsStream("JsonRooms_InlineEmployees_InlineBuilding.json");
  assertNotNull(stream);
  
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  JsonEntityDeserializer xec = new JsonEntityDeserializer();
  EntityStream entityStream = new EntityStream();
  entityStream.setContent(stream);
  entityStream.setReadProperties(DeserializerProperties.init()
      .build());
  ODataDeltaFeed feed = xec.readDeltaFeed(entitySet, entityStream);
  assertNotNull(feed);
  assertEquals(3, feed.getEntries().size());

  for (ODataEntry entry : feed.getEntries()) {
    assertEquals(6, entry.getProperties().size());
    for (ODataEntry employeeEntry : ((ODataFeed)entry.getProperties().get("nr_Employees")).getEntries()) {
      assertEquals(9, employeeEntry.getProperties().size());
    }
    assertEquals(3, ((ODataEntry)entry.getProperties().get("nr_Building")).getProperties().size());
  }
}
 
Example #18
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse updateEntity(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final boolean merge, final String contentType) throws ODataException {
  Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  if (!appliesFilter(entitySet, data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  final EdmEntityType entityType = entitySet.getEntityType();
  final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
      .mergeSemantic(merge)
      .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
      .build();
  final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);

  setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), merge);

  return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
}
 
Example #19
Source File: JPALink.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private List<String> extractLinkURI(ODataEntry oDataEntry, String navigationPropertyName) {

  List<String> links = new ArrayList<String>();

  String link = null;
  Object object = oDataEntry.getProperties().get(navigationPropertyName);
  if (object == null) {
    return links;
  }
  if (object instanceof ODataEntry) {
    link = ((ODataEntry) object).getMetadata().getUri();
    if (!link.isEmpty()) {
      links.add(link);
    }
  } else {
    for (ODataEntry entry : (List<ODataEntry>) object) {
      link = entry.getMetadata().getUri();
      if (link != null && link.isEmpty() == false) {
        links.add(link);
      }
    }
  }

  return links;
}
 
Example #20
Source File: XmlFeedDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readProductsFeedEndToEnd() throws Exception {
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  String xml = readFile("metadataProducts.xml");
  InputStream reader = createStreamReader(xml);
  EdmDataServices result = parser.readMetadata(reader, true);
  assertEquals(1, result.getEdm().getSchemas().size());
  ClientEdm edm = result.getEdm();
  InputStream file = getFileAsStream("ProductsFeed.xml");
  assertNotNull(file);
  EntityStream es = new EntityStream();
  es.setContent(file);
  es.setReadProperties(DEFAULT_PROPERTIES);
  ODataClientImpl client = new ODataClientImpl();
  ContentTypeBasedDeserializer deserializer = client.createDeserializer("application/atom+xml");
  ODataFeed feed =
      deserializer.readFeed( edm.getEntitySets().get(0), es);
  assertNotNull(feed);
  
  List<ODataEntry> oDataEntries = feed.getEntries();
  
  for (ODataEntry entry : oDataEntries) {
    assertEquals(6, entry.getProperties().size());
    assertEquals(4, ((ODataEntry)entry.getProperties().get("Supplier")).getProperties().size());
  }
}
 
Example #21
Source File: JsonEntryConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Employee with inline entity Room with inline entity Buildings 
 * Scenario of 1:1:1 navigation
 * E.g: Employees('1')?$expand=ne_Room/nr_Building
 * @throws Exception
 */
@Test
public void employeesEntryWithEmployeeToRoomToBuilding() throws Exception {
  InputStream stream = getFileAsStream("JsonEmployeeInlineRoomBuilding.json");
  assertNotNull(stream);
  FeedCallback callback = new FeedCallback();

  EntityProviderReadProperties readProperties = EntityProviderReadProperties.init()
      .mergeSemantic(false).callback(callback).build();

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  JsonEntityConsumer xec = new JsonEntityConsumer();
  ODataEntry result =
      xec.readEntry(entitySet, stream, readProperties);
  assertNotNull(result);
  assertEquals(9, result.getProperties().size());

  Map<String, Object> inlineEntries = callback.getNavigationProperties();
  getExpandedData(inlineEntries, result, entitySet.getEntityType());
  assertEquals(10, result.getProperties().size());
  assertEquals(5, ((ODataEntry)result.getProperties().get("ne_Room")).getProperties().size());
  assertEquals(3, ((ODataEntry)((ODataEntry)result.getProperties().get("ne_Room")).getProperties()
      .get("nr_Building")).getProperties().size());
}
 
Example #22
Source File: JsonEntryDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Employee with inline entity Room with inline entity Buildings 
 * Scenario of 1:1:1 navigation
 * E.g: Employees('1')?$expand=ne_Room/nr_Building
 * @throws Exception
 */
@Test
public void employeesEntryWithEmployeeToRoomToBuildingWithTypeMappings() throws Exception {
  InputStream stream = getFileAsStream("JsonEmployeeInlineRoomBuilding.json");
  assertNotNull(stream);
  EntityStream entityStream = new EntityStream();
  entityStream.setContent(stream);
  Map<String, Object> typeMappings = new HashMap<String, Object>();
  typeMappings.put("EntryDate", java.sql.Timestamp.class);
  typeMappings.put("Name", String.class);
  entityStream.setReadProperties(DeserializerProperties.init().addTypeMappings(typeMappings)
      .build());
  
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  JsonEntityDeserializer xec = new JsonEntityDeserializer();
  ODataEntry result =
      xec.readEntry(entitySet, entityStream);
  assertNotNull(result);
  assertEquals(10, result.getProperties().size());
  assertEquals(5, ((ODataEntry)result.getProperties().get("ne_Room")).getProperties().size());
  assertEquals(3, ((ODataEntry)((ODataEntry)result.getProperties().get("ne_Room")).getProperties()
      .get("nr_Building")).getProperties().size());
}
 
Example #23
Source File: ProviderFacadeImplTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readEntry() throws Exception {
  final String contentType = ContentType.APPLICATION_ATOM_XML_ENTRY.toContentTypeString();
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream content = new ByteArrayInputStream(EMPLOYEE_1_XML.getBytes("UTF-8"));

  final ODataEntry result =
      new ProviderFacadeImpl().readEntry(contentType, entitySet, content, EntityProviderReadProperties.init()
          .mergeSemantic(true).build());
  assertNotNull(result);
  assertFalse(result.containsInlineEntry());
  assertNotNull(result.getExpandSelectTree());
  assertTrue(result.getExpandSelectTree().isAll());
  assertNotNull(result.getMetadata());
  assertNull(result.getMetadata().getEtag());
  assertNotNull(result.getMediaMetadata());
  assertEquals(HttpContentType.APPLICATION_OCTET_STREAM, result.getMediaMetadata().getContentType());
  assertNotNull(result.getProperties());
  assertEquals(52, result.getProperties().get("Age"));
}
 
Example #24
Source File: JsonEntryDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readSimpleBuildingEntryWithoutD() throws Exception {
  ODataEntry result = prepareAndExecuteEntry(SIMPLE_ENTRY_BUILDING_WITHOUT_D, "Buildings", DEFAULT_PROPERTIES);
  // verify
  Map<String, Object> properties = result.getProperties();
  assertNotNull(properties);
  assertEquals("1", properties.get("Id"));
  assertEquals("Building 1", properties.get("Name"));
  assertNull(properties.get("Image"));
  assertNull(properties.get("nb_Rooms"));

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

  checkMediaDataInitial(result.getMediaMetadata());
}
 
Example #25
Source File: JsonEntryDeepInsertEntryTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void innerEntryNoMediaResourceWithCallback() throws Exception {
  EntryCallback callback = new EntryCallback();
  EntityProviderReadProperties readProperties =
      EntityProviderReadProperties.init().mergeSemantic(false).callback(callback).build();
  ODataEntry outerEntry = prepareAndExecuteEntry(EMPLOYEE_WITH_INLINE_TEAM, "Employees", readProperties);

  assertThat(outerEntry.getProperties().get("ne_Team"), nullValue());

  ODataEntry innerTeam = callback.getEntry();
  Map<String, Object> innerTeamProperties = innerTeam.getProperties();

  assertEquals("1", innerTeamProperties.get("Id"));
  assertEquals("Team 1", innerTeamProperties.get("Name"));
  assertEquals(Boolean.FALSE, innerTeamProperties.get("isScrumTeam"));
  assertNull(innerTeamProperties.get("nt_Employees"));

  List<String> associationUris = innerTeam.getMetadata().getAssociationUris("nt_Employees");
  assertEquals(1, associationUris.size());
  assertEquals("http://localhost:8080/ReferenceScenario.svc/Teams('1')/nt_Employees", associationUris.get(0));
}
 
Example #26
Source File: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readContentOnlyRoom() throws Exception {
  // prepare
  String content = readFile("RoomContentOnly.xml");
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream contentBody = createContentAsStream(content);

  // execute
  XmlEntityDeserializer xec = new XmlEntityDeserializer();
  EntityStream stream = new EntityStream();
  stream.setReadProperties(DeserializerProperties.init().build());
  stream.setContent(contentBody);
  ODataEntry result =
      xec.readEntry(entitySet, stream);

  // verify
  assertEquals(4, result.getProperties().size());
}
 
Example #27
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Employee with inline entity Room with inline entity Buildings 
 * Scenario of 1:1:1 navigation
 * E.g: Employees('1')?$expand=ne_Rooms/nr_Buildings
 * @throws Exception
 */
@Test
public void employeesEntryWithEmployeeToRoomToBuilding() throws Exception {
  InputStream stream = getFileAsStream("Employee_InlineRoomBuilding.xml");
  assertNotNull(stream);
  FeedCallback callback = new FeedCallback();

  EntityProviderReadProperties readProperties = EntityProviderReadProperties.init()
      .mergeSemantic(false).callback(callback).build();

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  XmlEntityConsumer xec = new XmlEntityConsumer();
  ODataEntry result =
      xec.readEntry(entitySet, stream, readProperties);
  assertNotNull(result);
  assertEquals(9, result.getProperties().size());

  Map<String, Object> inlineEntries = callback.getNavigationProperties();
  getExpandedData(inlineEntries, result);
  assertEquals(10, result.getProperties().size());
  assertEquals(5, ((ODataEntry)result.getProperties().get("ne_Room")).getProperties().size());
  assertEquals(3, ((ODataEntry)((ODataEntry)result.getProperties().get("ne_Room")).getProperties()
      .get("nr_Building")).getProperties().size());
}
 
Example #28
Source File: JsonEntryDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * @param inlineEntries
 * @param feed
 * @param entry
 */
private void getExpandedData(Map<String, Object> inlineEntries, ODataEntry entry) {
  assertNotNull(entry);
  Map<String, ExpandSelectTreeNode> expandNodes = entry.getExpandSelectTree().getLinks();
  for (Entry<String, ExpandSelectTreeNode> expand : expandNodes.entrySet()) {
    assertNotNull(expand.getKey());
    if (inlineEntries.containsKey(expand.getKey() + entry.getMetadata().getId())) {
      if (inlineEntries.get(expand.getKey() + entry.getMetadata().getId()) instanceof ODataFeed) {
        ODataFeed innerFeed = (ODataFeed) inlineEntries.get(expand.getKey() + entry.getMetadata().getId());
        assertNotNull(innerFeed);
        getExpandedData(inlineEntries, innerFeed);
        entry.getProperties().put(expand.getKey(), innerFeed);
      } else if (inlineEntries.get(expand.getKey() + entry.getMetadata().getId()) instanceof ODataEntry) {
        ODataEntry innerEntry = (ODataEntry) inlineEntries.get(expand.getKey() + entry.getMetadata().getId());
        assertNotNull(innerEntry);
        getExpandedData(inlineEntries, innerEntry);
        entry.getProperties().put(expand.getKey(), innerEntry);
      }
    }
  }
}
 
Example #29
Source File: XmlEntryConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of {@link ODataEntry}, an empty list, a single {@link ODataEntry} or <code>NULL</code> based on
 * <code>isFeed</code> value and <code>inlineEntries</code> content.
 * 
 * @param isFeed
 * @param inlineEntries
 * @return
 */
private Object extractODataEntity(final boolean isFeed, final List<ODataEntry> inlineEntries) {
  if (isFeed) {
    // TODO: fill metadata correctly with inline count and inline next link. Both are currently ignored.
    return new ODataDeltaFeedImpl(inlineEntries, new FeedMetadataImpl());
  } else if (!inlineEntries.isEmpty()) {
    return inlineEntries.get(0);
  }
  return null;
}
 
Example #30
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"));
}