org.apache.olingo.odata2.api.ep.EntityProviderReadProperties Java Examples

The following examples show how to use org.apache.olingo.odata2.api.ep.EntityProviderReadProperties. 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 readCustomizableFeedMappings() throws Exception {
  XmlEntityConsumer xec = new XmlEntityConsumer();

  EdmEntitySet entitySet = MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos");
  InputStream reqContent = createContentAsStream(PHOTO_XML);
  ODataEntry result =
      xec.readEntry(entitySet, reqContent, EntityProviderReadProperties.init().mergeSemantic(false).build());

  // verify
  EntryMetadata entryMetadata = result.getMetadata();
  assertEquals("http://localhost:19000/test/Container2.Photos(Id=1,Type='image%2Fpng')", entryMetadata.getId());

  Map<String, Object> data = result.getProperties();
  assertEquals("Образ", data.get("Содержание"));
  assertEquals("Photo1", data.get("Name"));
  assertEquals("image/png", data.get("Type"));
  assertNull(data.get("ignore"));
}
 
Example #2
Source File: XmlFeedConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readDeltaFeed() throws Exception {
  // prepare
  String content = readFile("feed_with_deleted_entries.xml");
  assertNotNull(content);

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

  XmlEntityConsumer xec = new XmlEntityConsumer();
  EntityProviderReadProperties consumerProperties = EntityProviderReadProperties.init().build();

  ODataDeltaFeed deltaFeed = xec.readFeed(entitySet, reqContent, consumerProperties);

  assertNotNull(deltaFeed);

  assertNotNull(deltaFeed.getDeletedEntries());
  assertNotNull(deltaFeed.getEntries());

  assertEquals(1, deltaFeed.getEntries().size());
  assertEquals(1, deltaFeed.getDeletedEntries().size());
}
 
Example #3
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 #4
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readDeltaLink() throws Exception {
  // prepare
  String content = readFile("feed_with_delta_link.xml");
  assertNotNull(content);

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

  // execute
  XmlEntityConsumer xec = new XmlEntityConsumer();
  EntityProviderReadProperties consumerProperties = EntityProviderReadProperties.init()
      .mergeSemantic(false).build();

  ODataFeed feed = xec.readFeed(entitySet, reqContent, consumerProperties);
  assertNotNull(feed);

  FeedMetadata feedMetadata = feed.getFeedMetadata();
  assertNotNull(feedMetadata);

  String deltaLink = feedMetadata.getDeltaLink();
  // Null means no deltaLink found
  assertNotNull(deltaLink);

  assertEquals("http://thisisadeltalink", deltaLink);
}
 
Example #5
Source File: JsonPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void simplePropertyWithStringToLongMappingStandalone() throws Exception {
  String simplePropertyJson = "{\"d\":{\"Age\":67}}";
  JsonReader reader = prepareReader(simplePropertyJson);
  final EdmProperty edmProperty =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age");

  EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);
  Map<String, Object> typeMappings = new HashMap<String, Object>();
  typeMappings.put("Age", Long.class);
  when(readProperties.getTypeMappings()).thenReturn(typeMappings);
  Map<String, Object> resultMap =
      new JsonPropertyConsumer().readPropertyStandalone(reader, edmProperty, readProperties);

  assertEquals(Long.valueOf(67), resultMap.get("Age"));
}
 
Example #6
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readCustomizableFeedMappingsWithMergeSemantic() throws Exception {
  XmlEntityConsumer xec = new XmlEntityConsumer();

  EdmEntitySet entitySet = MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos");
  InputStream reqContent = createContentAsStream(PHOTO_XML);
  ODataEntry result =
      xec.readEntry(entitySet, reqContent, EntityProviderReadProperties.init().mergeSemantic(true).build());

  // verify
  EntryMetadata entryMetadata = result.getMetadata();
  assertEquals("http://localhost:19000/test/Container2.Photos(Id=1,Type='image%2Fpng')", entryMetadata.getId());

  Map<String, Object> data = result.getProperties();
  assertEquals("Photo1", data.get("Name"));
  assertEquals("image/png", data.get("Type"));
  // ignored customizable feed mapping
  assertNull(data.get("Содержание"));
  assertNull(data.get("ignore"));
}
 
Example #7
Source File: XmlEntityConsumerTest.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("EmployeeContentOnlyWithAdditionalLink.xml");
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream contentBody = createContentAsStream(content);

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

  // verify
  assertEquals(9, result.getProperties().size());
  List<String> associationUris = result.getMetadata().getAssociationUris("ne_Manager");
  assertEquals(1, associationUris.size());
  assertEquals("Managers('1')", associationUris.get(0));
}
 
Example #8
Source File: ODataClient.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Reads a feed (the content of an EntitySet).
 * 
 * @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 ODataFeed containing the ODataEntries 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 ODataFeed readFeed(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.readFeed (contentType.type (),
      getEntitySet (resource_path), content,
      EntityProviderReadProperties.init ().build ());
}
 
Example #9
Source File: JsonFeedConsumerTest.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("JsonRoomsToEmployeesWithInlineTeams.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();
  ODataDeltaFeed feed = xec.readDeltaFeed(entitySet, stream, readProperties);
  assertNotNull(feed);
  assertEquals(2, feed.getEntries().size());

  Map<String, Object> inlineEntries = callback.getNavigationProperties();
  getExpandedData(inlineEntries, feed);
  for (ODataEntry entry : feed.getEntries()) {
    assertEquals(10, entry.getProperties().size());
    assertEquals(3, ((ODataEntry)entry.getProperties().get("ne_Team")).getProperties().size());
  }
}
 
Example #10
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void collectionComplexType() throws Exception {
  final String xml = "<d:AllLocations xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\">"
      + "<d:element><d:City><d:PostalCode>69124</d:PostalCode><d:CityName>Heidelberg</d:CityName></d:City>"
      + "<d:Country>Germany</d:Country></d:element>"
      + "<d:element m:type=\"RefScenario.c_Location\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">"
      + "<d:City m:type=\"RefScenario.c_City\"><d:PostalCode>69190</d:PostalCode><d:CityName>Walldorf</d:CityName>"
      + "</d:City><d:Country>Germany</d:Country></d:element>"
      + "</d:AllLocations>";
  @SuppressWarnings("unchecked")
  final List<?> result = (List<String>) new XmlPropertyConsumer().readCollection(createReaderForTest(xml, true),
      EntityInfoAggregator.create(MockFacade.getMockEdm().getDefaultEntityContainer()
          .getFunctionImport("AllLocations")),
      EntityProviderReadProperties.init().build());
  assertNotNull(result);
  assertEquals(2, result.size());
  @SuppressWarnings("unchecked")
  final Map<String, Object> secondLocation = (Map<String, Object>) result.get(1);
  assertEquals("Germany", secondLocation.get("Country"));
  @SuppressWarnings("unchecked")
  final Map<String, Object> secondCity = (Map<String, Object>) secondLocation.get("City");
  assertEquals("Walldorf", secondCity.get("CityName"));
}
 
Example #11
Source File: AtomEntityProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public Object readFunctionImport(final EdmFunctionImport functionImport, InputStream content,
    final EntityProviderReadProperties properties) throws EntityProviderException {
  try {
    if (functionImport.getReturnType().getType().getKind() == EdmTypeKind.ENTITY) {
      return new XmlEntityConsumer().readEntry(functionImport.getEntitySet(), content, properties);
    } else {
      final EntityPropertyInfo info = EntityInfoAggregator.create(functionImport);
      return functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY ?
        new XmlEntityConsumer().readCollection(info, content, properties) :
        new XmlEntityConsumer().readProperty(info, content, properties).get(info.getName());
    }
  } catch (final EdmException e) {
    throw new EntityProviderException(e.getMessageReference(), e);
  }
}
 
Example #12
Source File: JsonEntryConsumerTest.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);

  // execute
  JsonEntityConsumer xec = new JsonEntityConsumer();
  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("http://host:8080/ReferenceScenario.svc/Buildings('1')", associationUris.get(0));
}
 
Example #13
Source File: AtomFeedProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void unbalancedPropertyFeedWithSelect() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Companys");
  List<Map<String, Object>> originalData = createData(true);
  List<String> selectedPropertyNames = new ArrayList<String>();
  selectedPropertyNames.add("Id");
  selectedPropertyNames.add("Location");
  ExpandSelectTreeNode select =
      ExpandSelectTreeNode.entitySet(entitySet).selectedProperties(selectedPropertyNames).build();
  
  ODataResponse response = new AtomEntityProvider().writeFeed(entitySet, originalData,
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(select).
      isDataBasedPropertySerialization(true).build());

  EntityProviderReadProperties readProperties = EntityProviderReadProperties.init().mergeSemantic(false).build();
  XmlEntityConsumer consumer = new XmlEntityConsumer();
  ODataFeed feed = consumer.readFeed(entitySet, (InputStream) response.getEntity(), readProperties);

  compareList(originalData, feed.getEntries());
}
 
Example #14
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void readWithInlineContentIgnored() throws Exception {
  // prepare
  String content = readFile("expanded_team.xml");
  assertNotNull(content);

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams");
  InputStream reqContent = createContentAsStream(content);

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

  // validate
  assertNotNull(entry);
  Map<String, Object> properties = entry.getProperties();
  assertEquals("1", properties.get("Id"));
  assertEquals("Team 1", properties.get("Name"));
  assertEquals(Boolean.FALSE, properties.get("isScrumTeam"));
}
 
Example #15
Source File: JsonPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void veryLongStringStandalone() throws Exception {
  char[] chars = new char[32768];
  Arrays.fill(chars, 0, 32768, 'a');
  String propertyValue = new String(chars);
  String simplePropertyJson = "{\"d\":{\"Name\":\"" + propertyValue + "\"}}";
  JsonReader reader = prepareReader(simplePropertyJson);
  final EdmProperty edmProperty =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Room").getProperty("Name");

  EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);
  when(readProperties.getTypeMappings()).thenReturn(null);
  Map<String, Object> resultMap =
      new JsonPropertyConsumer().readPropertyStandalone(reader, edmProperty, readProperties);

  assertEquals(propertyValue, resultMap.get("Name"));
}
 
Example #16
Source File: XmlEntryConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void readContent(final XMLStreamReader reader, final EntityInfoAggregator eia,
    final EntityProviderReadProperties readProperties)
    throws EntityProviderException, XMLStreamException, EdmException {
  reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_CONTENT);

  final String contentType = reader.getAttributeValue(null, FormatXml.ATOM_TYPE);
  final String sourceLink = reader.getAttributeValue(null, FormatXml.ATOM_SRC);

  reader.nextTag();

  if (reader.isStartElement() && reader.getLocalName().equals(FormatXml.M_PROPERTIES)) {
    readProperties(reader, eia, readProperties);
  } else if (reader.isEndElement()) {
    reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_CONTENT);
  } else {
    throw new EntityProviderException(EntityProviderException.INVALID_STATE
        .addContent("Expected closing 'content' or starting 'properties' but found '"
            + reader.getLocalName() + "'."));
  }

  mediaMetadata.setContentType(contentType);
  mediaMetadata.setSourceLink(sourceLink);
}
 
Example #17
Source File: JsonEntityProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public Object readFunctionImport(final EdmFunctionImport functionImport, final InputStream content,
    final EntityProviderReadProperties properties) throws EntityProviderException {
  try {
    if (functionImport.getReturnType().getType().getKind() == EdmTypeKind.ENTITY) {
      return functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY
          ? new JsonEntityConsumer().readFeed(functionImport.getEntitySet(), content, properties)
          : new JsonEntityConsumer().readEntry(functionImport.getEntitySet(), content, properties);
    } else {
      final EntityPropertyInfo info = EntityInfoAggregator.create(functionImport);
      return functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY ?
          new JsonEntityConsumer().readCollection(info, content, properties) :
          new JsonEntityConsumer().readProperty(info, content, properties).get(info.getName());
    }
  } catch (final EdmException e) {
    throw new EntityProviderException(e.getMessageReference(), e);
  }
}
 
Example #18
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void complexPropertyNullValueNotAllowedButNotValidated() throws Exception {
  final String xml = "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08
      + "\" m:null=\"true\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" />";
  EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee")
      .getProperty("Location");
  EdmFacets facets = mock(EdmFacets.class);
  when(facets.isNullable()).thenReturn(false);
  when(property.getFacets()).thenReturn(facets);
  final EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);

  final Map<String, Object> resultMap = new XmlPropertyConsumer()
      .readProperty(createReaderForTest(xml, true), property, readProperties);
  assertFalse(resultMap.isEmpty());
  assertNull(resultMap.get("Location"));
}
 
Example #19
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Reads an inline Room at an Employee with specially formatted XML (see issue ODATAFORSAP-92).
 */
@Test
public void readWithInlineContentEmployeeRoomEntrySpecialXml() throws Exception {

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

  // 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");
  Map<String, Object> roomProperties = room.getProperties();
  assertEquals(4, roomProperties.size());
  assertEquals("1", roomProperties.get("Id"));
  assertEquals("Room 1", roomProperties.get("Name"));
  assertEquals(Short.valueOf("1"), roomProperties.get("Seats"));
  assertEquals(Short.valueOf("1"), roomProperties.get("Version"));
}
 
Example #20
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void validationOfNamespaceAtPropertiesSuccess() throws Exception {
  String roomWithValidNamespaces =
      "<?xml version='1.0' encoding='UTF-8'?>" +
          "<entry xmlns=\"http://www.w3.org/2005/Atom\" xml:base=\"http://localhost:19000/test/\">" +
          "  <id>http://localhost:19000/test/Rooms('1')</id>" +
          "  <title type=\"text\">Room 1</title>" +
          "  <updated>2013-01-11T13:50:50.541+01:00</updated>" +
          "  <content type=\"application/xml\">" +
          "    <m:properties xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">" +
          "      <d:Id xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\">1</d:Id>" +
          "    </m:properties>" +
          "  </content>" +
          "</entry>";

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream reqContent = createContentAsStream(roomWithValidNamespaces);
  XmlEntityConsumer xec = new XmlEntityConsumer();
  ODataEntry result =
      xec.readEntry(entitySet, reqContent, EntityProviderReadProperties.init().mergeSemantic(true).build());
  assertNotNull(result);
}
 
Example #21
Source File: XmlEntryConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void handleStartedTag(final XMLStreamReader reader, final EntityInfoAggregator eia,
    final EntityProviderReadProperties readProperties)
    throws EntityProviderException, XMLStreamException, EdmException {

  currentHandledStartTagName = reader.getLocalName();

  if (FormatXml.ATOM_ID.equals(currentHandledStartTagName)) {
    readId(reader);
  } else if (FormatXml.ATOM_ENTRY.equals(currentHandledStartTagName)) {
    readEntry(reader);
  } else if (FormatXml.ATOM_LINK.equals(currentHandledStartTagName)) {
    readLink(reader, eia, readProperties);
  } else if (FormatXml.ATOM_CONTENT.equals(currentHandledStartTagName)) {
    readContent(reader, eia, readProperties);
  } else if (FormatXml.M_PROPERTIES.equals(currentHandledStartTagName)) {
    readProperties(reader, eia, readProperties);
  } else if (!readProperties.getMergeSemantic()) {
    readCustomElement(reader, currentHandledStartTagName, eia, readProperties);
  } else {
    skipStartedTag(reader);
  }
}
 
Example #22
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 #23
Source File: GenericODataClient.java    From lemonaid with MIT License 5 votes vote down vote up
protected ODataFeed readFeed(String serviceUri, String contentType, String entitySetName)
		throws IOException, ODataException {
	initialize(serviceUri);
	EdmEntityContainer entityContainer = edm.getDefaultEntityContainer();
	String absolutUri = createUri(serviceUri, entitySetName, null);

	InputStream content = (InputStream) connect(absolutUri, contentType, GET).getContent();
	return EntityProvider.readFeed(contentType, entityContainer.getEntitySet(entitySetName), content,
			EntityProviderReadProperties.init().build());
}
 
Example #24
Source File: JsonFeedEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void unbalancedPropertyFeedWithInvalidProperty() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Companys");
  List<Map<String, Object>> originalData = createDataWithInvalidProperty(true);
  final ODataResponse response = new JsonEntityProvider().writeFeed(entitySet, originalData,
      EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).isDataBasedPropertySerialization(true).build());

  EntityProviderReadProperties readProperties = EntityProviderReadProperties.init().mergeSemantic(false).build();
  JsonEntityConsumer consumer = new JsonEntityConsumer();
  ODataFeed feed = consumer.readFeed(entitySet, (InputStream) response.getEntity(), readProperties);
  originalData.get(0).remove("Address");
  compareList(originalData, feed.getEntries());
}
 
Example #25
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testReadEntryWithMerge() throws Exception {
  // prepare
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  String content = EMPLOYEE_1_XML.replace("<d:Age>52</d:Age>", "");
  InputStream contentBody = createContentAsStream(content);

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

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

  // removed property
  assertNull(properties.get("Age"));

  // available properties
  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"));
  Calendar entryDate = (Calendar) properties.get("EntryDate");
  assertEquals(915148800000L, entryDate.getTimeInMillis());
  assertEquals(TimeZone.getTimeZone("GMT"), entryDate.getTimeZone());
  assertEquals("/SAP/PUBLIC/BC/NWDEMO_MODEL/IMAGES/Employee_1.png", properties.get("ImageUrl"));
}
 
Example #26
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void readComplexPropertyWithMappings() throws Exception {
  String xml =
      "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\""
          + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" m:type=\"RefScenario.c_Location\">" +
          "<Country>Germany</Country>" +
          "<City m:type=\"RefScenario.c_City\">" +
          "  <PostalCode>69124</PostalCode>" +
          "  <CityName>Heidelberg</CityName>" +
          "</City>" +
          "</Location>";
  XMLStreamReader reader = createReaderForTest(xml, true);

  EdmProperty locationComplexProperty =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");
  EdmProperty cityProperty = (EdmProperty) ((EdmComplexType) locationComplexProperty.getType()).getProperty("City");
  EdmProperty postalCodeProperty = (EdmProperty) ((EdmComplexType) cityProperty.getType()).getProperty("PostalCode");
  // Change the type of the PostalCode property to one that allows different Java types.
  when(postalCodeProperty.getType()).thenReturn(EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance());

  // Execute test
  EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);
  when(readProperties.getTypeMappings()).thenReturn(
      createTypeMappings("Location",
          createTypeMappings("City",
              createTypeMappings("CityName", String.class, "PostalCode", Long.class))));
  Map<String, Object> resultMap =
      new XmlPropertyConsumer().readProperty(reader, locationComplexProperty, readProperties);

  // verify
  Map<String, Object> locationMap = (Map<String, Object>) resultMap.get("Location");
  assertEquals("Germany", locationMap.get("Country"));
  Map<String, Object> cityMap = (Map<String, Object>) locationMap.get("City");
  assertEquals(Long.valueOf("69124"), cityMap.get("PostalCode"));
  assertEquals("Heidelberg", cityMap.get("CityName"));
}
 
Example #27
Source File: JsonPropertyConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void handleName(final JsonReader reader, final Map<String, Object> typeMappings,
    final EntityPropertyInfo entityPropertyInfo, final EntityProviderReadProperties readProperties,
    final Map<String, Object> result, final String nextName) throws EntityProviderException {
  if (!entityPropertyInfo.getName().equals(nextName)) {
    throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT.addContent(nextName));
  }
  final Object mapping = typeMappings == null ? null : typeMappings.get(nextName);
  final Object propertyValue = readPropertyValue(reader, entityPropertyInfo, mapping, readProperties);
  result.put(nextName, propertyValue);
}
 
Example #28
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void readComplexPropertyInvalidMapping() throws Exception {
  String xml =
      "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\""
          + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" type=\"RefScenario.c_Location\">" +
          "<Country>Germany</Country>" +
          "<City type=\"RefScenario.c_City\">" +
          "<PostalCode>69124</PostalCode>" +
          "<CityName>Heidelberg</CityName>" +
          "</City>" +
          "</Location>";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");

  EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);
  when(readProperties.getTypeMappings()).thenReturn(
      createTypeMappings("Location",
          createTypeMappings("City",
              createTypeMappings("PostalCode", Integer.class))));
  try {
    Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, readProperties);
    assertNotNull(resultMap);
  } catch (EntityProviderException e) {
    assertTrue(e.getCause() instanceof EdmSimpleTypeException);
    throw e;
  }
}
 
Example #29
Source File: JsonPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void simplePropertyWithNullMappingStandalone() throws Exception {
  String simplePropertyJson = "{\"d\":{\"Age\":67}}";
  JsonReader reader = prepareReader(simplePropertyJson);
  final EdmProperty edmProperty =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age");

  EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);
  when(readProperties.getTypeMappings()).thenReturn(null);
  Map<String, Object> resultMap =
      new JsonPropertyConsumer().readPropertyStandalone(reader, edmProperty, readProperties);

  assertEquals(Integer.valueOf(67), resultMap.get("Age"));
}
 
Example #30
Source File: ProviderFacadeImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readProperty() throws Exception {
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age");
  final String xml = "<Age xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">42</Age>";
  InputStream content = new ByteArrayInputStream(xml.getBytes("UTF-8"));
  final Map<String, Object> result =
      new ProviderFacadeImpl().readProperty(HttpContentType.APPLICATION_XML, property, content,
          EntityProviderReadProperties.init().build());
  assertFalse(result.isEmpty());
  assertEquals(42, result.get("Age"));
}