Java Code Examples for org.apache.olingo.odata2.api.edm.Edm#NAMESPACE_D_2007_08

The following examples show how to use org.apache.olingo.odata2.api.edm.Edm#NAMESPACE_D_2007_08 . 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: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void readComplexProperty() 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);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");

  Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, null);

  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("69124", cityMap.get("PostalCode"));
  assertEquals("Heidelberg", cityMap.get("CityName"));
}
 
Example 2
Source File: PropertyXmlChangeTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void complexProperty() throws Exception {
  final String url1 = "Employees('2')/Location";
  String requestBody = getBody(callUri(url1)).replace(CITY_2_NAME, "XXX");
  putUri(url1, requestBody, HttpContentType.APPLICATION_XML, HttpStatusCodes.NO_CONTENT);
  assertXpathEvaluatesTo("XXX", "/d:Location/d:City/d:CityName", getBody(callUri(url1)));

  final String url2 = "Employees('2')/Location/City";
  requestBody = getBody(callUri(url2)).replace("XXX", "YYY");
  putUri(url2, requestBody, HttpContentType.APPLICATION_XML, HttpStatusCodes.NO_CONTENT);
  assertXpathEvaluatesTo("YYY", "/d:City/d:CityName", getBody(callUri(url2)));

  requestBody = "<City xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\"><PostalCode>00000</PostalCode></City>";
  callUri(ODataHttpMethod.PATCH, url2, null, null, requestBody, HttpContentType.APPLICATION_XML,
      HttpStatusCodes.NO_CONTENT);
  assertXpathEvaluatesTo("YYY", "/d:City/d:CityName", getBody(callUri(url2)));
}
 
Example 3
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void readComplexPropertyWithInvalidName() throws Exception {
  String xml =
      "<Invalid 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>" +
          "</Invalid>";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");

  new XmlPropertyConsumer().readProperty(reader, property, null);
}
 
Example 4
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void readComplexPropertyWithInvalidDeepChild() 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\">" +
          "<Invalid>69124</Invalid>" +
          "<CityName>Heidelberg</CityName>" +
          "</City>" +
          "</Location>";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");

  new XmlPropertyConsumer().readProperty(reader, property, null);
}
 
Example 5
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readLargeStringPropertyValue() throws Exception {
  String name = StringHelper.generateData(77777);
  String xml = "<EmployeeName xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">" + name + "</EmployeeName>";
  InputStream content = createContentAsStream(xml);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("EmployeeName");

  Object result = new XmlEntityConsumer().readPropertyValue(property, content, String.class);

  assertEquals(name, result);
}
 
Example 6
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void readComplexPropertyWithLineBreaks() 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>" +
          "\n" +
          "<CityName>Heidelberg</CityName>" +
          "</City>" +
          "</Location>" +
          "\n        \n ";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");

  Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, null);

  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("69124", cityMap.get("PostalCode"));
  assertEquals("Heidelberg", cityMap.get("CityName"));
}
 
Example 7
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readIntegerProperty() throws Exception {
  String xml = "<Age xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">67</Age>";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age");

  Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, null);

  assertEquals(Integer.valueOf(67), resultMap.get("Age"));
}
 
Example 8
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readIntegerPropertyAsLong() throws Exception {
  String xml = "<Age xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">67</Age>";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age");

  EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);
  when(readProperties.getTypeMappings()).thenReturn(createTypeMappings("Age", Long.class));
  Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, readProperties);

  assertEquals(Long.valueOf(67), resultMap.get("Age"));
}
 
Example 9
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void collectionSimpleType() throws Exception {
  final String xml = "<AllUsedRoomIds xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">"
      + "<element>1</element>"
      + "<element m:null=\"true\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" />"
      + "<element></element>"
      + "</AllUsedRoomIds>";
  @SuppressWarnings("unchecked")
  final List<String> result = (List<String>) new XmlPropertyConsumer().readCollection(createReaderForTest(xml, true),
      EntityInfoAggregator.create(MockFacade.getMockEdm().getDefaultEntityContainer()
          .getFunctionImport("AllUsedRoomIds")),
      EntityProviderReadProperties.init().build());
  assertNotNull(result);
  assertEquals(Arrays.asList("1", null, ""), result);
}
 
Example 10
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readIntegerPropertyWithEmptyMapping() throws Exception {
  String xml = "<Age xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">67</Age>";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age");

  EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);
  when(readProperties.getTypeMappings()).thenReturn(new HashMap<String, Object>());
  Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, readProperties);

  assertEquals(Integer.valueOf(67), resultMap.get("Age"));
}
 
Example 11
Source File: XmlLinkConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void withInlineCount() throws Exception {
  final String xml = "<links xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">"
      + "<m:count xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">4</m:count>"
      + "<uri>" + SERVICE_ROOT + "Employees('5')</uri>"
      + "</links>";
  final List<String> links = new XmlLinkConsumer().readLinks(createReaderForTest(xml, true), null);
  assertEquals(1, links.size());
}
 
Example 12
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 13
Source File: EntryXmlChangeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void createMinimal() throws Exception {
  final String requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n"
      + "       xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n"
      + "       xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n"
      + "  <content><m:properties><d:Id>99</d:Id></m:properties></content>" + "\n"
      + "</entry>";

  final HttpResponse response =
      postUri("Teams()", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
  assertEquals(getEndpoint() + "Teams('4')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
}
 
Example 14
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readStringPropertyNullFalse() throws Exception {
  final String xml = "<EntryDate xmlns=\"" + Edm.NAMESPACE_D_2007_08
      + "\" m:null=\"false\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">1970-01-02T00:00:00</EntryDate>";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("EntryDate");

  final Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, null);

  assertEquals(86400000L, ((Calendar) resultMap.get("EntryDate")).getTimeInMillis());
}
 
Example 15
Source File: XmlLinkConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readEmptyList() throws Exception {
  final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><links xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\"/>";
  final List<String> links = new XmlLinkConsumer().readLinks(createReaderForTest(xml, true), null);
  assertNotNull(links);
  assertTrue(links.isEmpty());
}
 
Example 16
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void complexPropertyEmpty() throws Exception {
  final String xml = "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\" />";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");

  final Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, null);

  assertNotNull(resultMap.get("Location"));
  @SuppressWarnings("unchecked")
  final Map<String, Object> innerMap = (Map<String, Object>) resultMap.get("Location");
  assertTrue(innerMap.isEmpty());
}
 
Example 17
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readStringPropertyValue() throws Exception {
  String xml = "<EmployeeName xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">Max Mustermann</EmployeeName>";
  InputStream content = createContentAsStream(xml);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("EmployeeName");

  Object result = new XmlEntityConsumer().readPropertyValue(property, content, String.class);

  assertEquals("Max Mustermann", result);
}
 
Example 18
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void complexPropertyNullValueNotAllowed() throws Exception {
  final String xml = "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08
      + "\" m:null=\"true\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" />";
  XMLStreamReader reader = createReaderForTest(xml, true);
  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);

  new XmlPropertyConsumer().readProperty(reader, property, null);
}
 
Example 19
Source File: EntryXmlChangeTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void createWithAcceptHeaderEntry() throws Exception {
  // Create an entry for a type that has no media resource.
  String requestBody = getBody(callUri("Teams('1')"))
      .replace("'1'", "'9'")
      .replace("Id>1", "Id>9")
      .replace("Team 1", "Team X")
      .replaceAll("<link.+?/>", "");
  String requestContentType = HttpContentType.APPLICATION_ATOM_XML_ENTRY;
  HttpStatusCodes expectedStatusCode = HttpStatusCodes.CREATED;
  String headerName = "Accept";
  String headerValue = "application/atom+xml;type=entry";
  HttpResponse response =
      callUri(ODataHttpMethod.POST, "Teams()", headerName, headerValue, requestBody, requestContentType,
          expectedStatusCode);

  checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
  assertEquals(getEndpoint() + "Teams('4')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
  assertNull(response.getFirstHeader(HttpHeaders.ETAG));
  assertXpathEvaluatesTo("Team X", "/atom:entry/atom:content/m:properties/d:Name", getBody(response));

  // Create an entry for a type that has no media resource.
  // Add navigation to Employee('4') and Employee('5').
  requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n"
      + "       xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n"
      + "       xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n"
      + "  <author><name>no author</name></author>" + "\n"
      + "  <content type=\"application/xml\">" + "\n"
      + "    <m:properties>" + "\n"
      + "      <d:Id>109</d:Id>" + "\n"
      + "      <d:Name/>" + "\n"
      + "      <d:Seats>4</d:Seats>" + "\n"
      + "      <d:Version>2</d:Version>" + "\n"
      + "    </m:properties>" + "\n"
      + "  </content>" + "\n"
      + "  <id>Rooms('104')</id>" + "\n"
      + "  <title>Room 104</title>" + "\n"
      + "  <updated>2011-08-10T12:00:23Z</updated>" + "\n"
      + "  <link href=\"Employees('4')\"" + "\n"
      + "        rel=\"" + Edm.NAMESPACE_REL_2007_08 + "nr_Employees\"" + "\n"
      + "        type=\"" + HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8 + "\"/>" + "\n"
      + "  <link href=\"Employees('5')\"" + "\n"
      + "        rel=\"" + Edm.NAMESPACE_REL_2007_08 + "nr_Employees\"" + "\n"
      + "        type=\"" + HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8 + "\"/>" + "\n"
      + "</entry>";
  response = postUri("Rooms", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
  assertEquals(getEndpoint() + "Rooms('104')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
  checkEtag(response, "W/\"2\"");
  assertXpathEvaluatesTo("4", "/atom:entry/atom:content/m:properties/d:Seats", getBody(response));
  checkUri("Rooms('104')/nr_Employees('4')");
  checkUri("Rooms('104')/nr_Employees('5')");
}
 
Example 20
Source File: XmlLinkConsumerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void xmlContent() throws Exception {
  final String xml = "<uri xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\"><uri>X</uri></uri>";
  new XmlLinkConsumer().readLink(createReaderForTest(xml, true), null);
}